class Koine::RestClient::Request
request object :reek: TooManyInstanceVariables
Attributes
base_url[RW]
body[R]
headers[RW]
method[RW]
path[RW]
query_params[RW]
Public Class Methods
new(base_url: '', query_params: {}, path: '', headers: {}, method: 'get')
click to toggle source
# 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
Public Instance Methods
options()
click to toggle source
# File lib/koine/rest_client/request.rb, line 52 def options { body: body, headers: headers }.compact.reject do |_key, value| value.empty? end end
url()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
:reek: ManualDispatch
# File lib/koine/rest_client/request.rb, line 59 def with_added_options(options) object = self options.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)
click to toggle source
# 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)
click to toggle source
# File lib/koine/rest_client/request.rb, line 31 def with_base_url(base_url) new(:base_url, base_url) end
with_body(body)
click to toggle source
# File lib/koine/rest_client/request.rb, line 43 def with_body(body) new(:body, body) end
with_method(method)
click to toggle source
# File lib/koine/rest_client/request.rb, line 23 def with_method(method) new(:method, method) end
with_path(path)
click to toggle source
# File lib/koine/rest_client/request.rb, line 27 def with_path(path) new(:path, path) end
Private Instance Methods
body=(body)
click to toggle source
# File lib/koine/rest_client/request.rb, line 89 def body=(body) if json_request? && body.is_a?(Hash) body = JSON.dump(body) end @body = body end
json_request?()
click to toggle source
rubocop:disable Performance/Casecmp
# File lib/koine/rest_client/request.rb, line 98 def json_request? headers.find do |key, value| key.downcase == 'content-type' && value.downcase.match('application/json') end end
new(attribute, value)
click to toggle source
:reek: FeatureEnvy
# File lib/koine/rest_client/request.rb, line 82 def new(attribute, value) dup.tap do |object| object.send("#{attribute}=", value) object.freeze end end