Class: CoinMarket::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/coin_market/client.rb

Constant Summary collapse

@@api_version =
'v1'
@@base_uri =
"https://api.coinmarketcap.com/v1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



10
11
12
13
14
15
16
# File 'lib/coin_market/client.rb', line 10

def initialize(options = {})
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end

  yield(self) if block_given?
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



8
9
10
# File 'lib/coin_market/client.rb', line 8

def api_key
  @api_key
end

#convertObject

Returns the value of attribute convert.



8
9
10
# File 'lib/coin_market/client.rb', line 8

def convert
  @convert
end

#limitObject

Returns the value of attribute limit.



8
9
10
# File 'lib/coin_market/client.rb', line 8

def limit
  @limit
end

#startObject

Returns the value of attribute start.



8
9
10
# File 'lib/coin_market/client.rb', line 8

def start
  @start
end

Instance Method Details

#request(endpoint, id = nil, options = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/coin_market/client.rb', line 18

def request(endpoint, id=nil, options={})
  res = read_url(build_url(endpoint, id, options))
  JSON.parse(res)
rescue OpenURI::HTTPError => e
  puts "ERROR: #{e}"
  []
end