class CryptocoinchartsApi::Client
Constants
- BASE_URL
Public Class Methods
debug()
click to toggle source
# File lib/cryptocoincharts_api.rb, line 14 def self.debug @debug ||= false end
debug=(v)
click to toggle source
# File lib/cryptocoincharts_api.rb, line 18 def self.debug=(v) @debug = !!v end
new()
click to toggle source
# File lib/cryptocoincharts_api.rb, line 12 def initialize; end
Private Instance Methods
api_call(method_name, options, verb=:get)
click to toggle source
# File lib/cryptocoincharts_api.rb, line 26 def api_call(method_name, options, verb=:get) response = connection(method_name, options, verb) puts response.inspect if self.class.debug parse_response response end
connection(method_name, options, verb)
click to toggle source
# File lib/cryptocoincharts_api.rb, line 40 def connection(method_name, options, verb) conn = Faraday.new(:url => BASE_URL) do |faraday| faraday.request :url_encoded faraday.response(:logger) if self.class.debug faraday.adapter Faraday.default_adapter faraday.headers['User-Agent'] = "CryptocoinchartsAPI rubygem v#{VERSION}" end case verb when :put then conn.put(method_name, options) when :post then conn.post(method_name, options) when :delete then conn.delete(method_name, options) else conn.get(method_name, options) end end
parse_response(response)
click to toggle source
# File lib/cryptocoincharts_api.rb, line 32 def parse_response(response) if response.status.to_i == 200 JSON.parse response.body, symbolize_names: true else raise response.status.to_s end end