class CoinMarket::Client
Attributes
api_key[RW]
convert[RW]
limit[RW]
start[RW]
Public Class Methods
new(options = {}) { |self| ... }
click to toggle source
# 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
Public Instance Methods
request(endpoint, id=nil, options={})
click to toggle source
# 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
Private Instance Methods
build_url(endpoint, id, options={})
click to toggle source
# File lib/coin_market/client.rb, line 28 def build_url(endpoint, id, options={}) id = id.downcase.gsub(/\s/, '-').gsub(/[^\w-]/, '') unless id.nil? url = [@@base_uri, endpoint, id].compact.join('/') end
read_url(url)
click to toggle source
# File lib/coin_market/client.rb, line 33 def read_url(url) open(url).read end