Class: Poms::Api::Request
- Inherits:
-
Object
- Object
- Poms::Api::Request
- Defined in:
- lib/poms/api/request.rb
Overview
The ‘Request` object is an implementation-agnostic description of an HTTP request, representing a combination of an HTTP method, URI, body and headers.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #attributes ⇒ Object
- #get? ⇒ Boolean
-
#initialize(uri:, method: :get, credentials: nil, body: nil, headers: {}) ⇒ Request
constructor
A new instance of Request.
- #merge(new_attributes) ⇒ Object
- #post? ⇒ Boolean
Constructor Details
#initialize(uri:, method: :get, credentials: nil, body: nil, headers: {}) ⇒ Request
Returns a new instance of Request.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/poms/api/request.rb', line 11 def initialize( uri:, method: :get, credentials: nil, body: nil, headers: {} ) @uri = uri @method = method.to_sym @body = body || '' @headers = headers.to_h.freeze @credentials = credentials validate! freeze end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/poms/api/request.rb', line 9 def body @body end |
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
9 10 11 |
# File 'lib/poms/api/request.rb', line 9 def credentials @credentials end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
9 10 11 |
# File 'lib/poms/api/request.rb', line 9 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
9 10 11 |
# File 'lib/poms/api/request.rb', line 9 def method @method end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
9 10 11 |
# File 'lib/poms/api/request.rb', line 9 def uri @uri end |
Instance Method Details
#attributes ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/poms/api/request.rb', line 27 def attributes { method: method, uri: uri, body: body, headers: headers, credentials: credentials } end |
#get? ⇒ Boolean
37 38 39 |
# File 'lib/poms/api/request.rb', line 37 def get? @method == :get end |
#merge(new_attributes) ⇒ Object
23 24 25 |
# File 'lib/poms/api/request.rb', line 23 def merge(new_attributes) self.class.new(attributes.merge(new_attributes)) end |
#post? ⇒ Boolean
41 42 43 |
# File 'lib/poms/api/request.rb', line 41 def post? @method == :post end |