Class: Etherscan::Client
- Inherits:
-
Object
- Object
- Etherscan::Client
- Defined in:
- lib/etherscan/client.rb
Constant Summary collapse
- URL =
'https://api.etherscan.io/'.freeze
- HEADERS =
{'Content-Type' => 'application/json', 'Accept' => 'application/json'}.freeze
Instance Attribute Summary collapse
- #adapter ⇒ Object
- #conn ⇒ Object
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#raise_exceptions ⇒ Object
readonly
Returns the value of attribute raise_exceptions.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #get(params = {}) ⇒ Object
-
#initialize(params = {}) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #raise_exceptions? ⇒ Boolean
Constructor Details
#initialize(params = {}) {|_self| ... } ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/etherscan/client.rb', line 11 def initialize( params = {} ) @key = params.fetch(:key, Etherscan.config.key) @url = params.fetch(:url, Etherscan.config.url || URL) @adapter = params.fetch(:adapter, adapter) @conn = params.fetch(:conn, conn) @user_agent = params.fetch(:user_agent, "etherscan/#{Etherscan::VERSION};ruby") @headers = HEADERS.merge('User-Agent' => @user_agent) @raise_exceptions = params.fetch(:raise_exceptions, Etherscan.config.raise_exceptions || true) yield self if block_given? end |
Instance Attribute Details
#adapter ⇒ Object
41 42 43 |
# File 'lib/etherscan/client.rb', line 41 def adapter @adapter ||= Faraday.default_adapter end |
#conn ⇒ Object
34 35 36 37 38 39 |
# File 'lib/etherscan/client.rb', line 34 def conn @conn ||= Faraday.new(url: @url) do |conn| conn.request :url_encoded conn.adapter adapter end end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
8 9 10 |
# File 'lib/etherscan/client.rb', line 8 def headers @headers end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/etherscan/client.rb', line 8 def key @key end |
#raise_exceptions ⇒ Object (readonly)
Returns the value of attribute raise_exceptions.
8 9 10 |
# File 'lib/etherscan/client.rb', line 8 def raise_exceptions @raise_exceptions end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/etherscan/client.rb', line 8 def url @url end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
8 9 10 |
# File 'lib/etherscan/client.rb', line 8 def user_agent @user_agent end |
Instance Method Details
#get(params = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/etherscan/client.rb', line 22 def get(params = {}) endpoint = 'api' merged_params = params.merge({apikey: key}) response = conn.get(url) do |req| req.headers = headers req.params = merged_params end fail Etherscan::Exception, response if raise_exceptions? && response.status != 200 response end |
#raise_exceptions? ⇒ Boolean
45 46 47 |
# File 'lib/etherscan/client.rb', line 45 def raise_exceptions? @raise_exceptions end |