Class: Caplinked::Request
- Inherits:
-
Object
- Object
- Caplinked::Request
- Defined in:
- lib/caplinked/request.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
-
#request_method ⇒ Object
Returns the value of attribute request_method.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(client, request_method, path, options = {}) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
Constructor Details
#initialize(client, request_method, path, options = {}) ⇒ Request
Returns a new instance of Request.
11 12 13 14 15 16 17 |
# File 'lib/caplinked/request.rb', line 11 def initialize(client, request_method, path, = {}) @client = client @request_method = request_method @uri = Addressable::URI.parse("#{client.api_scheme}://#{client.api_host}#{path}") @path = @uri.path @options = end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
9 10 11 |
# File 'lib/caplinked/request.rb', line 9 def client @client end |
#headers ⇒ Object
Returns the value of attribute headers.
9 10 11 |
# File 'lib/caplinked/request.rb', line 9 def headers @headers end |
#params ⇒ Object
Returns the value of attribute params.
9 10 11 |
# File 'lib/caplinked/request.rb', line 9 def params @params end |
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/caplinked/request.rb', line 9 def path @path end |
#request_method ⇒ Object
Returns the value of attribute request_method.
9 10 11 |
# File 'lib/caplinked/request.rb', line 9 def request_method @request_method end |
#uri ⇒ Object
Returns the value of attribute uri.
9 10 11 |
# File 'lib/caplinked/request.rb', line 9 def uri @uri end |
Instance Method Details
#perform ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/caplinked/request.rb', line 19 def perform @uri.query_values = @options.delete(:params) response = HTTP.headers(req_headers).request(@request_method, @uri.to_s, @options) response_body = response.body.empty? ? '' : change_keys_to_symbols(response.parse) response_headers = response.headers fail_or_return_response_body(response.code, response_body, response_headers) end |