Skip to content

Commit 2d8f285

Browse files
authored
Merge pull request #567 from avsek477/pulse-examples
pulse examples added
2 parents fabfc1c + a47c393 commit 2d8f285

File tree

3 files changed

+114
-4
lines changed

3 files changed

+114
-4
lines changed

CHANGELOG

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
4.0.17
2+
- added pulse examples
3+
14
4.0.16
25
- fix: unsubscribe fails depending on channel id type
36

examples/rest2/pulse.js

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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', 'COMMENTS'
17+
],
18+
rows: pulseHistRes.map(({ id, mts, userID, title, content, comments }) => [
19+
id,
20+
new Date(mts).toLocaleString(),
21+
userID,
22+
(title && title.substring(0, 15)) || '-',
23+
content.substring(0, 15),
24+
comments // number of comments
25+
])
26+
})
27+
const pulseMsg = new PulseMessage({
28+
title: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
29+
content: 'Contrary to popular belief, Lorem Ipsum is not simply random text.',
30+
isPublic: 0,
31+
isPin: 1
32+
})
33+
34+
debug('submitting pulse message: %s', pulseMsg.toString())
35+
36+
let pulse
37+
try {
38+
pulse = await rest.addPulse(pulseMsg)
39+
} catch (e) {
40+
return debug('pulse message submittion failed: %s', e.message)
41+
}
42+
43+
debug('pulse message submission response')
44+
debugTable({
45+
headers: [
46+
'PID', 'MTS', 'PUID', 'TITLE', 'CONTENT'
47+
],
48+
rows: [[
49+
pulse.id,
50+
new Date(pulse.mts).toLocaleString(),
51+
pulse.userID,
52+
(pulse.title && pulse.title.substring(0, 15)) || '-',
53+
pulse.content.substring(0, 15)
54+
]]
55+
})
56+
57+
const pulseComment = new PulseMessage({
58+
parent: pulse.id,
59+
content: 'No more seven warlords of the sea',
60+
isPublic: 0,
61+
isPin: 1
62+
})
63+
64+
debug('submitting pulse comment: %s', pulseComment.toString())
65+
let comment
66+
try {
67+
comment = await rest.addPulseComment(pulseComment)
68+
} catch (e) {
69+
return debug('pulse comment submittion failed: %s', e.message)
70+
}
71+
72+
debug('pulse comment submission response')
73+
debugTable({
74+
headers: [
75+
'PID', 'MTS', 'PARENT', 'PUID', 'COMMENT'
76+
],
77+
rows: [[
78+
comment.id,
79+
new Date(comment.mts).toLocaleString(),
80+
comment.parent,
81+
comment.userID,
82+
comment.content.substring(0, 15)
83+
]]
84+
})
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')
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+
})
106+
})

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bitfinex-api-node",
3-
"version": "4.0.16",
3+
"version": "4.0.17",
44
"description": "Node reference library for Bitfinex API",
55
"engines": {
66
"node": ">=8.3.0"
@@ -33,7 +33,8 @@
3333
"Cris Mihalache <cris.m@bitfinex.com> (https://www.bitfinex.com)",
3434
"Robert Kowalski <robert@bitfinex.com> (https://www.bitfinex.com)",
3535
"Simone Poggi <simone@bitfinex.com> (https://www.bitfinex.com)",
36-
"Paolo Ardoino <paolo@bitfinex.com> (https://www.bitfinex.com)"
36+
"Paolo Ardoino <paolo@bitfinex.com> (https://www.bitfinex.com)",
37+
"Abhishek Shrestha <abhishek.shrestha@bitfinex.com> (https://www.bitfinex.com)"
3738
],
3839
"license": "MIT",
3940
"bugs": {
@@ -67,8 +68,8 @@
6768
"blessed": "^0.1.81",
6869
"blessed-contrib": "^4.8.19",
6970
"cli-table3": "^0.6.0",
70-
"bfx-api-node-models": "^1.2.1",
71-
"bfx-api-node-rest": "^3.0.8",
71+
"bfx-api-node-models": "^1.3.1",
72+
"bfx-api-node-rest": "^3.1.0",
7273
"bfx-api-node-util": "^1.0.2",
7374
"bfx-api-node-ws1": "^1.0.0",
7475
"bignumber.js": "^9.0.0",

0 commit comments

Comments
 (0)