Skip to content

Commit b5ed0b9

Browse files
committed
added fetch pulse comments example
1 parent 713ba94 commit b5ed0b9

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

examples/rest2/pulse.js

+32-11
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ module.exports = runExample({
1313
debug('pulse history response')
1414
debugTable({
1515
headers: [
16-
'PID', 'MTS', 'PUID', 'TITLE', 'CONTENT'
16+
'PID', 'MTS', 'PUID', 'TITLE', 'CONTENT', 'COMMENTS'
1717
],
18-
rows: pulseHistRes.map(({ id, mts, userID, title, content }) => [
18+
rows: pulseHistRes.map(({ id, mts, userID, title, content, comments }) => [
1919
id,
2020
new Date(mts).toLocaleString(),
2121
userID,
22-
(title && title.substring(0, 10)) || '-',
23-
content.substring(0, 10)
22+
(title && title.substring(0, 15)) || '-',
23+
content.substring(0, 15),
24+
comments // number of comments
2425
])
2526
})
2627
const pulseMsg = new PulseMessage({
@@ -48,14 +49,14 @@ module.exports = runExample({
4849
pulse.id,
4950
new Date(pulse.mts).toLocaleString(),
5051
pulse.userID,
51-
(pulse.title && pulse.title.substring(0, 10)) || '-',
52-
pulse.content.substring(0, 10)
52+
(pulse.title && pulse.title.substring(0, 15)) || '-',
53+
pulse.content.substring(0, 15)
5354
]]
5455
})
56+
5557
const pulseComment = new PulseMessage({
5658
parent: pulse.id,
57-
title: '1234 5678 Foo Bar Baz Qux TITLE',
58-
content: '1234 5678 Foo Bar Baz Qux Content',
59+
content: 'No more seven warlords of the sea',
5960
isPublic: 0,
6061
isPin: 1
6162
})
@@ -71,15 +72,35 @@ module.exports = runExample({
7172
debug('pulse comment submission response')
7273
debugTable({
7374
headers: [
74-
'PID', 'MTS', 'PARENT', 'PUID', 'TITLE', 'CONTENT'
75+
'PID', 'MTS', 'PARENT', 'PUID', 'COMMENT'
7576
],
7677
rows: [[
7778
comment.id,
7879
new Date(comment.mts).toLocaleString(),
7980
comment.parent,
8081
comment.userID,
81-
(comment.title && comment.title.substring(0, 10)) || '-',
82-
comment.content.substring(0, 10)
82+
comment.content.substring(0, 15)
8383
]]
8484
})
85+
86+
debug('gettting pulse comments..')
87+
const pulseComments = await rest.fetchPulseComments({
88+
parent: pulse.id,
89+
isPublic: 0, // 0 for comments made by you; 1 for all comments of the pulse
90+
limit: 3, // fetch given number of comments for this pulse
91+
end: 0 // fetch comments from a given starttime in milliseconds
92+
})
93+
94+
debug('pulse comments response: %O', pulseComments)
95+
debugTable({
96+
headers: [
97+
'PID', 'MTS', 'PUID', 'COMMENT'
98+
],
99+
rows: pulseComments.map(({ id, mts, userID, content }) => [
100+
id,
101+
new Date(mts).toLocaleString(),
102+
userID,
103+
content.substring(0, 15)
104+
])
105+
})
85106
})

0 commit comments

Comments
 (0)