Class: Web3::Eth::Etherscan
- Inherits:
-
Object
- Object
- Web3::Eth::Etherscan
- 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
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#connect_options ⇒ Object
readonly
Returns the value of attribute connect_options.
Instance Method Summary collapse
-
#initialize(api_key, connect_options: DEFAULT_CONNECT_OPTIONS) ⇒ Etherscan
constructor
A new instance of Etherscan.
- #method_missing(m, *args) ⇒ Object
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 = 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 [:parse_result] begin JSON.parse result rescue result end else result end end |
Instance Attribute Details
#api_key ⇒ Object (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_options ⇒ Object (readonly)
Returns the value of attribute connect_options.
13 14 15 |
# File 'lib/web3ethereum/etherscan.rb', line 13 def @connect_options end |