Skip to content

Commit 7f459e1

Browse files
committed
restv2 adding pulse resource support
1 parent cac18d9 commit 7f459e1

File tree

7 files changed

+228
-0
lines changed

7 files changed

+228
-0
lines changed

CHANGELOG

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
1.0.10
2+
- Adds function rest/v2 get_pulse_profile
3+
- Adds function rest/v2 get_public_pulse_history
4+
- Adds function rest/v2 submit_pulse
5+
- Adds function rest/v2 delete_pulse
6+
- Adds function rest/v2 get_private_pulse_history
7+
- Adds function rest/v2 submit_pulse_comment
8+
19
1.0.9
210

311
- Fixes bug with API v2 transfer

examples/rest/v2/pulse.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
require_relative '../../../lib/bitfinex.rb'
2+
3+
client = Bitfinex::RESTv2.new({
4+
:url => ENV['REST_URL'],
5+
:api_key => ENV['API_KEY'],
6+
:api_secret => ENV['API_SECRET']
7+
})
8+
9+
# Get pulse profile
10+
p client.get_pulse_profile('Bitfinex')
11+
12+
# Get public pulse history
13+
p client.get_public_pulse_history({ :limit => 5 })
14+
15+
# Submit new Pulse message
16+
pulse = client.submit_pulse({
17+
:title => '1234 5678 Foo Bar Baz Qux TITLE',
18+
:content => '1234 5678 Foo Bar Baz Qux Content',
19+
:isPublic => 0,
20+
:isPin => 1
21+
})
22+
p pulse
23+
24+
# Delete Pulse message
25+
p "About to delete pulse: #{pulse[:id]}"
26+
p client.delete_pulse(pulse[:id])
27+
28+
# Get private pulse history
29+
p client.get_private_pulse_history()
30+
31+
# Submit Pulse message comment
32+
# 1 - create pulse message
33+
pulse2 = client.submit_pulse({
34+
:title => '2 1234 5678 Foo Bar Baz Qux TITLE',
35+
:content => '2 1234 5678 Foo Bar Baz Qux Content',
36+
:isPublic => 0,
37+
:isPin => 1
38+
})
39+
40+
# 2 - submit comment for above pulse message
41+
p client.submit_pulse_comment({
42+
:parent => pulse2[:id],
43+
:title => 'comment 2 1234 5678 Foo Bar Baz Qux TITLE',
44+
:content => 'comment 2 1234 5678 Foo Bar Baz Qux Content',
45+
:isPublic => 0,
46+
:isPin => 1
47+
})

lib/bitfinex.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@
3434
require_relative './models/trading_ticker'
3535
require_relative './models/user_info'
3636
require_relative './models/wallet'
37+
require_relative './models/pulse_profile'
38+
require_relative './models/pulse'

lib/models/pulse.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require_relative './model'
2+
3+
module Bitfinex
4+
module Models
5+
class Pulse < Model
6+
BOOL_FIELDS = []
7+
FIELDS = {
8+
:id => 0,
9+
:mts_create => 1,
10+
:pulse_user_id => 3,
11+
:title => 5,
12+
:content => 6,
13+
:is_pin => 9,
14+
:is_public => 10,
15+
:comments_disabled => 11,
16+
:tags => 12,
17+
:attachments => 13,
18+
:meta => 14,
19+
:likes => 15,
20+
:profile => 18,
21+
:comments => 19
22+
}
23+
24+
FIELDS.each do |key, index|
25+
attr_accessor key
26+
end
27+
28+
def initialize (data)
29+
super(data, FIELDS, BOOL_FIELDS)
30+
end
31+
32+
def self.unserialize (data)
33+
Model.unserialize(data, FIELDS, BOOL_FIELDS)
34+
end
35+
end
36+
end
37+
end

lib/models/pulse_profile.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require_relative './model'
2+
3+
module Bitfinex
4+
module Models
5+
class PulseProfile < Model
6+
BOOL_FIELDS = []
7+
FIELDS = {
8+
:id => 0,
9+
:mts_create => 1,
10+
:nickname => 3,
11+
:picture => 5,
12+
:text => 6,
13+
:twitter_handle => 9,
14+
:followers => 11,
15+
:following => 12
16+
}
17+
18+
FIELDS.each do |key, index|
19+
attr_accessor key
20+
end
21+
22+
def initialize (data)
23+
super(data, FIELDS, BOOL_FIELDS)
24+
end
25+
26+
def self.unserialize (data)
27+
return Model.unserialize(data, FIELDS, BOOL_FIELDS)
28+
end
29+
end
30+
end
31+
end

lib/rest/v2.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
require_relative './v2/wallet'
1010
require_relative './v2/funding'
1111
require_relative './v2/positions'
12+
require_relative './v2/pulse'
1213

1314
module Bitfinex
1415
class RESTv2
@@ -27,6 +28,7 @@ class RESTv2
2728
include Bitfinex::RESTv2Wallet
2829
include Bitfinex::RESTv2Funding
2930
include Bitfinex::RESTv2Positions
31+
include Bitfinex::RESTv2Pulse
3032

3133
def initialize(args = {})
3234
self.api_endpoint = args[:url] ? "#{args[:url]}/v2/" : "https://api.bitfinex.com/v2/"

lib/rest/v2/pulse.rb

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
module Bitfinex
2+
module RESTv2Pulse
3+
###
4+
# Get Pulse Profile
5+
#
6+
# @param [string] nickname Nickname of pulse profile
7+
#
8+
# @return [Hash] the Pulse Profile
9+
#
10+
# @see https://docs.bitfinex.com/reference#rest-public-pulse-profile
11+
###
12+
def get_pulse_profile(nickname)
13+
resp = get("pulse/profile/#{nickname}").body
14+
Bitfinex::Models::PulseProfile.unserialize(resp)
15+
end
16+
17+
###
18+
# Get Public Pulse History
19+
#
20+
# @param [int] end (optional) Return only the entries after this timestamp
21+
# @param [int] limit (optional) Limit the number of entries to return. Default is 25.
22+
#
23+
# @return [Array] public pulse message
24+
#
25+
# @see https://docs.bitfinex.com/reference#rest-public-pulse-hist
26+
###
27+
def get_public_pulse_history(params = {})
28+
pulses = get("pulse/hist", params).body
29+
pulses.map { |p| deserialize_pulse_with_profile(p) }
30+
end
31+
32+
###
33+
# Get Private Pulse History
34+
#
35+
# @param [int] isPublic allows to receive the public pulse history with the UID_LIKED field
36+
#
37+
# @return [Array] private pulse message
38+
#
39+
# @see https://docs.bitfinex.com/reference#rest-auth-pulse-hist
40+
###
41+
def get_private_pulse_history(params = {})
42+
pulses = authenticated_post("auth/r/pulse/hist", params).body
43+
pulses.map { |p| deserialize_pulse_with_profile(p) }
44+
end
45+
46+
###
47+
# Submit new Pulse message
48+
#
49+
# @param [Hash] pulse
50+
#
51+
# @return [Hash] pulse
52+
#
53+
# @see https://docs.bitfinex.com/reference#rest-auth-pulse-add
54+
###
55+
def submit_pulse(pulse)
56+
resp = authenticated_post("auth/w/pulse/add", params: pulse).body
57+
Bitfinex::Models::Pulse.unserialize(resp)
58+
end
59+
60+
###
61+
# Submit Pulse message comment
62+
#
63+
# @param [Hash] pulse
64+
#
65+
# @return [Hash] pulse
66+
#
67+
# @see https://docs.bitfinex.com/reference#rest-auth-pulse-add
68+
###
69+
def submit_pulse_comment(pulse)
70+
resp = authenticated_post("auth/w/pulse/add", params: pulse).body
71+
Bitfinex::Models::Pulse.unserialize(resp)
72+
end
73+
74+
###
75+
# Delete Pulse message
76+
#
77+
# @param [string] id pulse id
78+
#
79+
# @return [boolean] true if success, false if error
80+
#
81+
# @see https://docs.bitfinex.com/reference#rest-auth-pulse-del
82+
###
83+
def delete_pulse(id)
84+
resp = authenticated_post("auth/w/pulse/del", params: { :pid => id }).body
85+
if resp[0] == 1
86+
return true
87+
end
88+
return false
89+
end
90+
91+
private
92+
93+
def deserialize_pulse_with_profile(payload)
94+
pulse = Bitfinex::Models::Pulse.unserialize(payload)
95+
if pulse[:profile].any?
96+
pulse[:profile] = Bitfinex::Models::PulseProfile.unserialize(pulse[:profile][0])
97+
end
98+
pulse
99+
end
100+
end
101+
end

0 commit comments

Comments
 (0)