Class: KazeClient::Request
Overview
Represents request to a Kaze API
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_HEADERS =
Those headers are added on all requests by default
{ 'Content-Type' => 'application/json', 'Accept' => 'application/json' }.freeze
Instance Attribute Summary collapse
-
#body ⇒ nil, ...
The body for the request.
-
#headers ⇒ nil, Hash
The headers for the request.
-
#method ⇒ String, Symbol
readonly
The HTTP verb to use for the request.
-
#query ⇒ nil, Hash
The query parameters for the request.
-
#url ⇒ String
readonly
The API endpoint.
Instance Method Summary collapse
-
#error_for(response) ⇒ KazeClient::Error::Generic
The adequate error object according to the given response.
-
#initialize(method, url) ⇒ Request
constructor
A new instance of Request.
-
#parameters ⇒ Hash
The arguments to give to the HTTParty call.
Constructor Details
#initialize(method, url) ⇒ Request
Returns a new instance of Request.
46 47 48 49 50 51 52 |
# File 'lib/kaze_client/request/request.rb', line 46 def initialize(method, url) @method = method @url = url @query = nil @body = nil @headers = {} end |
Instance Attribute Details
#body ⇒ nil, ...
Returns The body for the request.
37 38 39 |
# File 'lib/kaze_client/request/request.rb', line 37 def body @body end |
#headers ⇒ nil, Hash
Returns The headers for the request.
42 43 44 |
# File 'lib/kaze_client/request/request.rb', line 42 def headers @headers end |
#method ⇒ String, Symbol (readonly)
Returns The HTTP verb to use for the request.
21 22 23 |
# File 'lib/kaze_client/request/request.rb', line 21 def method @method end |
#query ⇒ nil, Hash
Returns The query parameters for the request.
31 32 33 |
# File 'lib/kaze_client/request/request.rb', line 31 def query @query end |
#url ⇒ String (readonly)
Returns The API endpoint.
26 27 28 |
# File 'lib/kaze_client/request/request.rb', line 26 def url @url end |
Instance Method Details
#error_for(response) ⇒ KazeClient::Error::Generic
Returns The adequate error object according to the given response.
68 69 70 71 72 73 74 75 |
# File 'lib/kaze_client/request/request.rb', line 68 def error_for(response) error = response.parsed_response['error'] = response.parsed_response['message'] return non_generic_error(error, , response) if error != 'generic' generic_http_error(error, , response) end |
#parameters ⇒ Hash
Returns The arguments to give to the HTTParty call.
60 61 62 63 64 |
# File 'lib/kaze_client/request/request.rb', line 60 def parameters { query: make_query, body: make_body, headers: make_headers }.reject { |_k, v| v.blank? } end |