Class: DogePapi::DogeChain

Inherits:
Object
  • Object
show all
Defined in:
lib/doge/chain.rb

Constant Summary collapse

BASE_URI =
'http://dogechain.info/chain/Dogecoin/q'
CALLS_RETURNING_INTEGER =
[:getblockcount]
CALLS_RETURNING_FLOAT =
[
  :addressbalance       ,
  :getdifficulty        ,
  :getreceivedbyaddress ,
  :getsentbyaddress     ,
  :totalbc
]
CALLS_RETURNING_JSON =
[:transactions]

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/doge/chain.rb', line 25

def method_missing m, *args, &block
  output = fetch_uri build_uri(m, args)
  output = output.to_i        if CALLS_RETURNING_INTEGER.include? m
  output = output.to_f        if CALLS_RETURNING_FLOAT.include? m
  output = JSON.parse(output) if CALLS_RETURNING_JSON.include? m
  output
end

Instance Method Details

#build_uri(m, params) ⇒ Object



16
17
18
19
# File 'lib/doge/chain.rb', line 16

def build_uri m, params
  list = params.join '/'
  URI.parse "#{BASE_URI}/#{m}/#{list}"
end

#fetch_uri(uri) ⇒ Object



21
22
23
# File 'lib/doge/chain.rb', line 21

def fetch_uri uri
  uri.open.read
end