class CryptoVal::CryptoExchange::Cryptonator
Constants
- DEFAULT_CURRENCY
- DEFAULT_SYMBOL
Attributes
currency[R]
symbol[R]
Public Class Methods
fetch(opts={})
click to toggle source
# File lib/crypto_val/crypto_exchange/cryptonator.rb, line 17 def self.fetch opts={} new(opts).fetch end
new(opts={})
click to toggle source
# File lib/crypto_val/crypto_exchange/cryptonator.rb, line 8 def initialize opts={} @symbol = opts[:symbol] || DEFAULT_SYMBOL @currency = opts[:currency] || DEFAULT_CURRENCY end
Public Instance Methods
fetch()
click to toggle source
# File lib/crypto_val/crypto_exchange/cryptonator.rb, line 13 def fetch format_response end
Private Instance Methods
base_url()
click to toggle source
# File lib/crypto_val/crypto_exchange/cryptonator.rb, line 23 def base_url "https://api.cryptonator.com" end
format_response()
click to toggle source
# File lib/crypto_val/crypto_exchange/cryptonator.rb, line 47 def format_response { symbol: parsed["ticker"]["base"], currency: parsed["ticker"]["target"], price: parsed["ticker"]["price"].to_f } end
get_response()
click to toggle source
# File lib/crypto_val/crypto_exchange/cryptonator.rb, line 35 def get_response uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri.request_uri) http.request(request).body end
parsed()
click to toggle source
# File lib/crypto_val/crypto_exchange/cryptonator.rb, line 43 def parsed @parsed ||= JSON.parse(response) end
response()
click to toggle source
# File lib/crypto_val/crypto_exchange/cryptonator.rb, line 31 def response @response ||= get_response end
url()
click to toggle source
# File lib/crypto_val/crypto_exchange/cryptonator.rb, line 27 def url "#{base_url}/api/ticker/#{@symbol}-#{@currency}" end