Class: AccessGrid::Request
- Inherits:
-
Object
- Object
- AccessGrid::Request
- Defined in:
- lib/accessgrid/request.rb
Overview
Builds and configures HTTP requests for the AccessGrid API.
Constant Summary collapse
- PAYLOAD_SIGNATURE_PARAM =
:sig_payload- HTTP_METHODS =
{ get: Net::HTTP::Get, post: Net::HTTP::Post, put: Net::HTTP::Put, patch: Net::HTTP::Patch, delete: Net::HTTP::Delete }.freeze
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(attrs) ⇒ Request
constructor
A new instance of Request.
- #net_http_request ⇒ Object
Constructor Details
#initialize(attrs) ⇒ Request
Returns a new instance of Request.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/accessgrid/request.rb', line 19 def initialize(attrs) # required attributes @http_method = attrs.fetch(:http_method) @provided_host = attrs.fetch(:host) @provided_path = attrs.fetch(:path) # optional attributes @account_id = attrs.fetch(:account_id, nil) @body = attrs.fetch(:body, nil) @params = attrs.fetch(:params, nil) || {} # computed attributes initialize_payload initialize_uri end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
17 18 19 |
# File 'lib/accessgrid/request.rb', line 17 def account_id @account_id end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
17 18 19 |
# File 'lib/accessgrid/request.rb', line 17 def body @body end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
17 18 19 |
# File 'lib/accessgrid/request.rb', line 17 def http_method @http_method end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
17 18 19 |
# File 'lib/accessgrid/request.rb', line 17 def params @params end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
17 18 19 |
# File 'lib/accessgrid/request.rb', line 17 def payload @payload end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
17 18 19 |
# File 'lib/accessgrid/request.rb', line 17 def uri @uri end |
Instance Method Details
#net_http_request ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/accessgrid/request.rb', line 35 def net_http_request return @net_http_request if defined?(@net_http_request) @net_http_request = generate_net_http_request!.tap do |req| req['Content-Type'] = 'application/json' req['X-ACCT-ID'] = account_id req['User-Agent'] = "accessgrid.rb @ v#{AccessGrid::VERSION}" req.body = body.to_json if body && !get? end end |