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.
10 11 12 13 14 15 16 |
# File 'lib/caplinked/request.rb', line 10 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.
8 9 10 |
# File 'lib/caplinked/request.rb', line 8 def client @client end |
#headers ⇒ Object
Returns the value of attribute headers.
8 9 10 |
# File 'lib/caplinked/request.rb', line 8 def headers @headers end |
#params ⇒ Object
Returns the value of attribute params.
8 9 10 |
# File 'lib/caplinked/request.rb', line 8 def params @params end |
#path ⇒ Object
Returns the value of attribute path.
8 9 10 |
# File 'lib/caplinked/request.rb', line 8 def path @path end |
#request_method ⇒ Object
Returns the value of attribute request_method.
8 9 10 |
# File 'lib/caplinked/request.rb', line 8 def request_method @request_method end |
#uri ⇒ Object
Returns the value of attribute uri.
8 9 10 |
# File 'lib/caplinked/request.rb', line 8 def uri @uri end |
Instance Method Details
#perform ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/caplinked/request.rb', line 18 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 |