-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from Daniel1984/feature/restv2-pulse-support
restv2 adding pulse resource support
- Loading branch information
Showing
8 changed files
with
233 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | |
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'bitfinex-rb' | ||
spec.version = '1.0.9' | ||
spec.version = '1.0.10' | ||
spec.authors = ['Bitfinex'] | ||
spec.email = ['[email protected]'] | ||
spec.summary = %q{Bitfinex API Wrapper} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require_relative '../../../lib/bitfinex.rb' | ||
|
||
client = Bitfinex::RESTv2.new({ | ||
:url => ENV['REST_URL'], | ||
:api_key => ENV['API_KEY'], | ||
:api_secret => ENV['API_SECRET'] | ||
}) | ||
|
||
# Get pulse profile | ||
p client.get_pulse_profile('Bitfinex') | ||
|
||
# Get public pulse history | ||
p client.get_public_pulse_history({ :limit => 5 }) | ||
|
||
# Submit new Pulse message | ||
pulse = client.submit_pulse({ | ||
:title => '1234 5678 Foo Bar Baz Qux TITLE', | ||
:content => '1234 5678 Foo Bar Baz Qux Content', | ||
:isPublic => 0, | ||
:isPin => 1 | ||
}) | ||
p pulse | ||
|
||
# Delete Pulse message | ||
p "About to delete pulse: #{pulse[:id]}" | ||
p client.delete_pulse(pulse[:id]) | ||
|
||
# Get private pulse history | ||
p client.get_private_pulse_history() | ||
|
||
# Submit Pulse message comment | ||
# 1 - create pulse message | ||
pulse2 = client.submit_pulse({ | ||
:title => '2 1234 5678 Foo Bar Baz Qux TITLE', | ||
:content => '2 1234 5678 Foo Bar Baz Qux Content', | ||
:isPublic => 0, | ||
:isPin => 1 | ||
}) | ||
|
||
# 2 - submit comment for above pulse message | ||
p client.submit_pulse_comment({ | ||
:parent => pulse2[:id], | ||
:title => 'comment 2 1234 5678 Foo Bar Baz Qux TITLE', | ||
:content => 'comment 2 1234 5678 Foo Bar Baz Qux Content', | ||
:isPublic => 0, | ||
:isPin => 1 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require_relative './model' | ||
|
||
module Bitfinex | ||
module Models | ||
class Pulse < Model | ||
BOOL_FIELDS = [] | ||
FIELDS = { | ||
:id => 0, | ||
:mts_create => 1, | ||
:pulse_user_id => 3, | ||
:title => 5, | ||
:content => 6, | ||
:is_pin => 9, | ||
:is_public => 10, | ||
:comments_disabled => 11, | ||
:tags => 12, | ||
:attachments => 13, | ||
:meta => 14, | ||
:likes => 15, | ||
:profile => 18, | ||
:comments => 19 | ||
} | ||
|
||
FIELDS.each do |key, index| | ||
attr_accessor key | ||
end | ||
|
||
def initialize (data) | ||
super(data, FIELDS, BOOL_FIELDS) | ||
end | ||
|
||
def self.unserialize (data) | ||
Model.unserialize(data, FIELDS, BOOL_FIELDS) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require_relative './model' | ||
|
||
module Bitfinex | ||
module Models | ||
class PulseProfile < Model | ||
BOOL_FIELDS = [] | ||
FIELDS = { | ||
:id => 0, | ||
:mts_create => 1, | ||
:nickname => 3, | ||
:picture => 5, | ||
:text => 6, | ||
:twitter_handle => 9, | ||
:followers => 11, | ||
:following => 12 | ||
} | ||
|
||
FIELDS.each do |key, index| | ||
attr_accessor key | ||
end | ||
|
||
def initialize (data) | ||
super(data, FIELDS, BOOL_FIELDS) | ||
end | ||
|
||
def self.unserialize (data) | ||
return Model.unserialize(data, FIELDS, BOOL_FIELDS) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
module Bitfinex | ||
module RESTv2Pulse | ||
### | ||
# Get Pulse Profile | ||
# | ||
# @param [string] nickname Nickname of pulse profile | ||
# | ||
# @return [Hash] the Pulse Profile | ||
# | ||
# @see https://docs.bitfinex.com/reference#rest-public-pulse-profile | ||
### | ||
def get_pulse_profile(nickname) | ||
resp = get("pulse/profile/#{nickname}").body | ||
Bitfinex::Models::PulseProfile.unserialize(resp) | ||
end | ||
|
||
### | ||
# Get Public Pulse History | ||
# | ||
# @param [int] end (optional) Return only the entries after this timestamp | ||
# @param [int] limit (optional) Limit the number of entries to return. Default is 25. | ||
# | ||
# @return [Array] public pulse message | ||
# | ||
# @see https://docs.bitfinex.com/reference#rest-public-pulse-hist | ||
### | ||
def get_public_pulse_history(params = {}) | ||
pulses = get("pulse/hist", params).body | ||
pulses.map { |p| deserialize_pulse_with_profile(p) } | ||
end | ||
|
||
### | ||
# Get Private Pulse History | ||
# | ||
# @param [int] isPublic allows to receive the public pulse history with the UID_LIKED field | ||
# | ||
# @return [Array] private pulse message | ||
# | ||
# @see https://docs.bitfinex.com/reference#rest-auth-pulse-hist | ||
### | ||
def get_private_pulse_history(params = {}) | ||
pulses = authenticated_post("auth/r/pulse/hist", params).body | ||
pulses.map { |p| deserialize_pulse_with_profile(p) } | ||
end | ||
|
||
### | ||
# Submit new Pulse message | ||
# | ||
# @param [Hash] pulse | ||
# | ||
# @return [Hash] pulse | ||
# | ||
# @see https://docs.bitfinex.com/reference#rest-auth-pulse-add | ||
### | ||
def submit_pulse(pulse) | ||
resp = authenticated_post("auth/w/pulse/add", params: pulse).body | ||
Bitfinex::Models::Pulse.unserialize(resp) | ||
end | ||
|
||
### | ||
# Submit Pulse message comment, requires :parent (pulse id) to | ||
# be present in request payload | ||
# | ||
# @param [Hash] pulse | ||
# | ||
# @return [Hash] pulse | ||
# | ||
# @see https://docs.bitfinex.com/reference#rest-auth-pulse-add | ||
### | ||
def submit_pulse_comment(pulse) | ||
if pulse[:parent].to_s.strip.empty? | ||
raise ":parent (pulse id value) is required for comments" | ||
end | ||
resp = authenticated_post("auth/w/pulse/add", params: pulse).body | ||
Bitfinex::Models::Pulse.unserialize(resp) | ||
end | ||
|
||
### | ||
# Delete Pulse message | ||
# | ||
# @param [string] id pulse id | ||
# | ||
# @return [boolean] true if success, false if error | ||
# | ||
# @see https://docs.bitfinex.com/reference#rest-auth-pulse-del | ||
### | ||
def delete_pulse(id) | ||
resp = authenticated_post("auth/w/pulse/del", params: { :pid => id }).body | ||
if resp[0] == 1 | ||
return true | ||
end | ||
return false | ||
end | ||
|
||
private | ||
|
||
def deserialize_pulse_with_profile(payload) | ||
pulse = Bitfinex::Models::Pulse.unserialize(payload) | ||
if pulse[:profile].any? | ||
pulse[:profile] = Bitfinex::Models::PulseProfile.unserialize(pulse[:profile][0]) | ||
end | ||
pulse | ||
end | ||
end | ||
end |