class Blockchain::ExchangeRateExplorer

Attributes

client[R]

Public Class Methods

new(base_url = nil, api_code = nil) click to toggle source
# File lib/blockchain/exchangerates.rb, line 10
def initialize(base_url = nil, api_code = nil)
    @client = Client.new(base_url, api_code)
end

Public Instance Methods

from_btc(ccy = nil, satoshi_value) click to toggle source
# File lib/blockchain/exchangerates.rb, line 42
def from_btc(ccy = nil, satoshi_value)
    params = {'value' => satoshi_value}
    if !ccy.nil? then params['currency'] = ccy end
    return @client.call_api('frombtc', data: params).to_f
end
get_ticker() click to toggle source
# File lib/blockchain/exchangerates.rb, line 19
def get_ticker()
    params = {}
    response = @client.call_api('ticker', data: params)
    json_response = JSON.parse(response)

    ticker = {}
    json_response.each do |key,value|
        json_ccy = json_response[key]
        ccy = Currency.new(json_ccy['last'],
                            json_ccy['buy'],
                            json_ccy['sell'],
                            json_ccy['symbol'],
                            json_ccy['15m'])
        ticker[key] = ccy
    end
    return ticker
end
proxy(method_name, *args) click to toggle source
# File lib/blockchain/exchangerates.rb, line 14
def proxy(method_name, *args)
    warn "[DEPRECATED] avoid use of static methods, use an instance of ExchangeRateExplorer class instead."
    send(method_name, *args)
end
to_btc(ccy, value) click to toggle source
# File lib/blockchain/exchangerates.rb, line 37
def to_btc(ccy, value)
    params = { 'currency' => ccy, 'value' => value}
    return @client.call_api('tobtc', data: params).to_f
end