Skip to content

Commit 713ba94

Browse files
committed
pulse examples added
1 parent fabfc1c commit 713ba94

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

examples/rest2/pulse.js

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
'use strict'
2+
3+
const { PulseMessage } = require('bfx-api-node-models')
4+
const runExample = require('../util/run_example')
5+
6+
module.exports = runExample({
7+
name: 'rest-pulse',
8+
rest: { env: true, transform: true }
9+
}, async ({ debug, debugTable, rest }) => {
10+
debug('gettting pulse history..')
11+
const pulseHistRes = await rest.pulseHistory()
12+
13+
debug('pulse history response')
14+
debugTable({
15+
headers: [
16+
'PID', 'MTS', 'PUID', 'TITLE', 'CONTENT'
17+
],
18+
rows: pulseHistRes.map(({ id, mts, userID, title, content }) => [
19+
id,
20+
new Date(mts).toLocaleString(),
21+
userID,
22+
(title && title.substring(0, 10)) || '-',
23+
content.substring(0, 10)
24+
])
25+
})
26+
const pulseMsg = new PulseMessage({
27+
title: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
28+
content: 'Contrary to popular belief, Lorem Ipsum is not simply random text.',
29+
isPublic: 0,
30+
isPin: 1
31+
})
32+
33+
debug('submitting pulse message: %s', pulseMsg.toString())
34+
35+
let pulse
36+
try {
37+
pulse = await rest.addPulse(pulseMsg)
38+
} catch (e) {
39+
return debug('pulse message submittion failed: %s', e.message)
40+
}
41+
42+
debug('pulse message submission response')
43+
debugTable({
44+
headers: [
45+
'PID', 'MTS', 'PUID', 'TITLE', 'CONTENT'
46+
],
47+
rows: [[
48+
pulse.id,
49+
new Date(pulse.mts).toLocaleString(),
50+
pulse.userID,
51+
(pulse.title && pulse.title.substring(0, 10)) || '-',
52+
pulse.content.substring(0, 10)
53+
]]
54+
})
55+
const pulseComment = new PulseMessage({
56+
parent: pulse.id,
57+
title: '1234 5678 Foo Bar Baz Qux TITLE',
58+
content: '1234 5678 Foo Bar Baz Qux Content',
59+
isPublic: 0,
60+
isPin: 1
61+
})
62+
63+
debug('submitting pulse comment: %s', pulseComment.toString())
64+
let comment
65+
try {
66+
comment = await rest.addPulseComment(pulseComment)
67+
} catch (e) {
68+
return debug('pulse comment submittion failed: %s', e.message)
69+
}
70+
71+
debug('pulse comment submission response')
72+
debugTable({
73+
headers: [
74+
'PID', 'MTS', 'PARENT', 'PUID', 'TITLE', 'CONTENT'
75+
],
76+
rows: [[
77+
comment.id,
78+
new Date(comment.mts).toLocaleString(),
79+
comment.parent,
80+
comment.userID,
81+
(comment.title && comment.title.substring(0, 10)) || '-',
82+
comment.content.substring(0, 10)
83+
]]
84+
})
85+
})

0 commit comments

Comments
 (0)