Class: SynapsePayRest::CryptoQuote

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse_pay_rest/models/crypto_quote/crypto_quote.rb

Overview

Represents a public key record and holds methods for getting crypto quote from API calls. This is built on top of the SynapsePayRest::Client class and is intended to make it easier to use the API without knowing payload formats or knowledge of REST.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ CryptoQuote

Note:

Do not call directly. Use other class method to instantiate via API action.

Returns a new instance of CryptoQuote.



35
36
37
# File 'lib/synapse_pay_rest/models/crypto_quote/crypto_quote.rb', line 35

def initialize(**options)
  options.each { |key, value| instance_variable_set("@#{key}", value) }
end

Instance Attribute Details

#btcusdObject (readonly)

Returns the value of attribute btcusd.



7
8
9
# File 'lib/synapse_pay_rest/models/crypto_quote/crypto_quote.rb', line 7

def btcusd
  @btcusd
end

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/synapse_pay_rest/models/crypto_quote/crypto_quote.rb', line 7

def client
  @client
end

#ethusdObject (readonly)

Returns the value of attribute ethusd.



7
8
9
# File 'lib/synapse_pay_rest/models/crypto_quote/crypto_quote.rb', line 7

def ethusd
  @ethusd
end

#usdbtcObject (readonly)

Returns the value of attribute usdbtc.



7
8
9
# File 'lib/synapse_pay_rest/models/crypto_quote/crypto_quote.rb', line 7

def usdbtc
  @usdbtc
end

#usdethObject (readonly)

Returns the value of attribute usdeth.



7
8
9
# File 'lib/synapse_pay_rest/models/crypto_quote/crypto_quote.rb', line 7

def usdeth
  @usdeth
end

Class Method Details

.from_response(client, response) ⇒ Object

Note:

Shouldn’t need to call this directly.

Creates a crypto quote from a response hash.



14
15
16
17
18
19
20
21
22
23
# File 'lib/synapse_pay_rest/models/crypto_quote/crypto_quote.rb', line 14

def from_response(client, response)
  args = {
    client:                    client,
    btcusd:        response['BTCUSD'],
    ethusd:        response['ETHUSD'],
    usdbtc:        response['USDBTC'],
    usdeth:        response['USDETH']
  }
  self.new(args)
end

.get(client:) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
# File 'lib/synapse_pay_rest/models/crypto_quote/crypto_quote.rb', line 25

def get(client:)
  raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
  response = client.crypto_quotes.get()
  self.from_response(client, response)
end