Class: Web3::Eth::Etherscan

Inherits:
Object
  • Object
show all
Defined in:
lib/web3ethereum/etherscan.rb

Constant Summary collapse

DEFAULT_CONNECT_OPTIONS =
{
    open_timeout: 10,
    read_timeout: 70,
    parse_result: true,
    url: 'https://api.etherscan.io/api'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, connect_options: DEFAULT_CONNECT_OPTIONS) ⇒ Etherscan

Returns a new instance of Etherscan.



15
16
17
18
# File 'lib/web3ethereum/etherscan.rb', line 15

def initialize api_key, connect_options: DEFAULT_CONNECT_OPTIONS
  @api_key = api_key
  @connect_options = connect_options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/web3ethereum/etherscan.rb', line 20

def method_missing m, *args
  api_module, action = m.to_s.split '_', 2
  raise "Calling method must be in form <module>_<action>" unless action

  arguments = args[0].kind_of?(String) ? { address: args[0] } : args[0]
  result = request api_module, action, arguments

  if connect_options[:parse_result]
    begin
      JSON.parse result
    rescue
      result
    end
  else
    result
  end

end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



13
14
15
# File 'lib/web3ethereum/etherscan.rb', line 13

def api_key
  @api_key
end

#connect_optionsObject (readonly)

Returns the value of attribute connect_options.



13
14
15
# File 'lib/web3ethereum/etherscan.rb', line 13

def connect_options
  @connect_options
end