| 
 | 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, requires :parent (pulse id) to  | 
 | 62 | +    # be present in request payload  | 
 | 63 | +    #  | 
 | 64 | +    # @param [Hash] pulse  | 
 | 65 | +    #  | 
 | 66 | +    # @return [Hash] pulse  | 
 | 67 | +    #  | 
 | 68 | +    # @see https://docs.bitfinex.com/reference#rest-auth-pulse-add  | 
 | 69 | +    ###  | 
 | 70 | +    def submit_pulse_comment(pulse)  | 
 | 71 | +      if pulse[:parent].to_s.strip.empty?  | 
 | 72 | +        raise ":parent (pulse id value) is required for comments"  | 
 | 73 | +      end  | 
 | 74 | +      resp = authenticated_post("auth/w/pulse/add", params: pulse).body  | 
 | 75 | +      Bitfinex::Models::Pulse.unserialize(resp)  | 
 | 76 | +    end  | 
 | 77 | + | 
 | 78 | +    ###  | 
 | 79 | +    # Delete Pulse message  | 
 | 80 | +    #  | 
 | 81 | +    # @param [string] id pulse id  | 
 | 82 | +    #  | 
 | 83 | +    # @return [boolean] true if success, false if error  | 
 | 84 | +    #  | 
 | 85 | +    # @see https://docs.bitfinex.com/reference#rest-auth-pulse-del  | 
 | 86 | +    ###  | 
 | 87 | +    def delete_pulse(id)  | 
 | 88 | +      resp = authenticated_post("auth/w/pulse/del", params: { :pid => id }).body  | 
 | 89 | +      if resp[0] == 1  | 
 | 90 | +        return true  | 
 | 91 | +      end  | 
 | 92 | +      return false  | 
 | 93 | +    end  | 
 | 94 | + | 
 | 95 | +    private  | 
 | 96 | + | 
 | 97 | +    def deserialize_pulse_with_profile(payload)  | 
 | 98 | +      pulse = Bitfinex::Models::Pulse.unserialize(payload)  | 
 | 99 | +      if pulse[:profile].any?  | 
 | 100 | +        pulse[:profile] = Bitfinex::Models::PulseProfile.unserialize(pulse[:profile][0])  | 
 | 101 | +      end  | 
 | 102 | +      pulse  | 
 | 103 | +    end  | 
 | 104 | +  end  | 
 | 105 | +end  | 
0 commit comments