Class: Koine::RestClient::Request
- Inherits:
-
Object
- Object
- Koine::RestClient::Request
- Defined in:
- lib/koine/rest_client/request.rb
Overview
request object :reek:TooManyInstanceVariables
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#query_params ⇒ Object
readonly
Returns the value of attribute query_params.
Instance Method Summary collapse
-
#initialize(base_url: '', query_params: {}, path: '', headers: {}, method: 'get') ⇒ Request
constructor
A new instance of Request.
- #options ⇒ Object
- #url ⇒ Object
- #with_added_headers(headers) ⇒ Object
-
#with_added_options(options) ⇒ Object
:reek:ManualDispatch.
- #with_added_query_params(query_params) ⇒ Object
- #with_base_url(base_url) ⇒ Object
- #with_body(body) ⇒ Object
- #with_method(method) ⇒ Object
- #with_path(path) ⇒ Object
Constructor Details
#initialize(base_url: '', query_params: {}, path: '', headers: {}, method: 'get') ⇒ Request
Returns a new instance of Request.
15 16 17 18 19 20 21 |
# File 'lib/koine/rest_client/request.rb', line 15 def initialize(base_url: '', query_params: {}, path: '', headers: {}, method: 'get') @method = method @base_url = base_url @path = path @query_params = query_params @headers = headers end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
9 10 11 |
# File 'lib/koine/rest_client/request.rb', line 9 def base_url @base_url end |
#body ⇒ Object
Returns the value of attribute body.
13 14 15 |
# File 'lib/koine/rest_client/request.rb', line 13 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
11 12 13 |
# File 'lib/koine/rest_client/request.rb', line 11 def headers @headers end |
#method ⇒ Object
Returns the value of attribute method.
8 9 10 |
# File 'lib/koine/rest_client/request.rb', line 8 def method @method end |
#path ⇒ Object
Returns the value of attribute path.
10 11 12 |
# File 'lib/koine/rest_client/request.rb', line 10 def path @path end |
#query_params ⇒ Object
Returns the value of attribute query_params.
12 13 14 |
# File 'lib/koine/rest_client/request.rb', line 12 def query_params @query_params end |
Instance Method Details
#options ⇒ Object
52 53 54 55 56 |
# File 'lib/koine/rest_client/request.rb', line 52 def { body: body, headers: headers }.compact.reject do |_key, value| value.empty? end end |
#url ⇒ Object
47 48 49 50 |
# File 'lib/koine/rest_client/request.rb', line 47 def url url = "#{@base_url.delete_suffix('/')}/#{path.delete_prefix('/')}" Url.new(url).with_query_params(query_params).to_s(unescape: ',') end |
#with_added_headers(headers) ⇒ Object
39 40 41 |
# File 'lib/koine/rest_client/request.rb', line 39 def with_added_headers(headers) new(:headers, @headers.merge(headers).compact) end |
#with_added_options(options) ⇒ Object
:reek:ManualDispatch
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/koine/rest_client/request.rb', line 59 def () object = self .each do |key, value| if respond_to?("with_#{key}") object = object.send("with_#{key}", value) end if respond_to?("with_added_#{key}") object = object.send("with_added_#{key}", value) end end object end |
#with_added_query_params(query_params) ⇒ Object
35 36 37 |
# File 'lib/koine/rest_client/request.rb', line 35 def with_added_query_params(query_params) new(:query_params, @query_params.merge(query_params).compact) end |
#with_base_url(base_url) ⇒ Object
31 32 33 |
# File 'lib/koine/rest_client/request.rb', line 31 def with_base_url(base_url) new(:base_url, base_url) end |
#with_body(body) ⇒ Object
43 44 45 |
# File 'lib/koine/rest_client/request.rb', line 43 def with_body(body) new(:body, body) end |
#with_method(method) ⇒ Object
23 24 25 |
# File 'lib/koine/rest_client/request.rb', line 23 def with_method(method) new(:method, method) end |
#with_path(path) ⇒ Object
27 28 29 |
# File 'lib/koine/rest_client/request.rb', line 27 def with_path(path) new(:path, path) end |