Method: CoinbaseCommerce::Client#request
- Defined in:
- lib/coinbase_commerce/client.rb
#request(method, path, params = {}) ⇒ Object
request section
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/coinbase_commerce/client.rb', line 63 def request(method, path, params = {}) @last_response = nil url = api_url(path, @api_uri) headers = request_headers(@api_key) body = nil query_params = nil case method.to_s.downcase.to_sym when :get, :head, :delete query_params = params else body = params.to_json end u = URI.parse(path) unless u.query.nil? query_params ||= {} query_params = Hash[URI.decode_www_form(u.query)].merge(query_params) end http_resp = execute_request_with_rescues(@api_uri) do @conn.run_request(method, url, body, headers) do |req| req.params = query_params unless query_params.nil? end end begin resp = CoinbaseCommerceResponse.from_faraday_response(http_resp) rescue JSON::ParserError raise Errors.general_api_error(http_resp.status, http_resp.body) end @last_response = resp resp end |