Module: BitcoinValue

Defined in:
lib/bitcoin_value.rb

Constant Summary collapse

VERSION =
'0.0.10'
API_URL =
'https://api.bitcoinaverage.com/ticker'
VALID_FIATS =
[
  :AUD, :BRL, :CAD, :CHF, :CNY, :EUR, :GBP, :HKD, :ILS, :JPY,
  :NOK, :NZD, :PLN, :RUB, :SEK, :SGD, :TRY, :USD, :ZAR
]

Class Method Summary collapse

Class Method Details

.method_missing(meth, *args, &block) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
# File 'lib/bitcoin_value.rb', line 15

def method_missing(meth, *args, &block)
  currency = meth.upcase.to_sym
  raise ArgumentError, "Cannot fetch data for #{currency}, as it is not offered by the API!" if !VALID_FIATS.include?(currency)
  JSON.parse(Mechanize.new.get("#{API_URL}/#{currency}").body)['24h_avg']
end