Class: Teamsupport::REST::Request
- Inherits:
-
Object
- Object
- Teamsupport::REST::Request
- Defined in:
- lib/teamsupport/rest/request.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
-
#request_method ⇒ Object
(also: #verb)
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 = {}) ⇒ Teamsupport::REST::Request
constructor
private
Initialize a new REST Request object.
-
#perform ⇒ Array, Hash
Perform an HTTP REST request and return response body or raise the error.
Constructor Details
#initialize(client, request_method, path, options = {}) ⇒ Teamsupport::REST::Request
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a new REST Request object
25 26 27 28 29 30 31 32 |
# File 'lib/teamsupport/rest/request.rb', line 25 def initialize(client, request_method, path, = {}) @client = client @uri = Addressable::URI.parse(path.start_with?('http') ? path : @client.api_url + path) @request_method = request_method @headers = Teamsupport::Headers.new(@client, @request_method, @uri, ).request_headers @path = uri.path @options = end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
12 13 14 |
# File 'lib/teamsupport/rest/request.rb', line 12 def client @client end |
#headers ⇒ Object
Returns the value of attribute headers.
12 13 14 |
# File 'lib/teamsupport/rest/request.rb', line 12 def headers @headers end |
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/teamsupport/rest/request.rb', line 12 def @options end |
#path ⇒ Object
Returns the value of attribute path.
12 13 14 |
# File 'lib/teamsupport/rest/request.rb', line 12 def path @path end |
#request_method ⇒ Object Also known as: verb
Returns the value of attribute request_method.
12 13 14 |
# File 'lib/teamsupport/rest/request.rb', line 12 def request_method @request_method end |
#uri ⇒ Object
Returns the value of attribute uri.
12 13 14 |
# File 'lib/teamsupport/rest/request.rb', line 12 def uri @uri end |
Instance Method Details
#perform ⇒ Array, Hash
Perform an HTTP REST request and return response body or raise the error
42 43 44 45 46 47 48 49 |
# File 'lib/teamsupport/rest/request.rb', line 42 def perform = @request_method == :get ? :params : :body # For non-GET requests need to send the options as JSON in the request body response = http_client.headers(@headers).public_send(@request_method, @uri.to_s, => @options) response_body = response.body.empty? ? '' : symbolize_keys!(response.parse) response_headers = response.headers fail_or_return_response_body(response.code, response_body, response_headers) end |