Class: Poms::Api::Request
- Inherits:
-
Object
- Object
- Poms::Api::Request
- Extended by:
- Forwardable
- 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.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #get? ⇒ Boolean
-
#initialize(method, uri, body = nil, headers = {}) ⇒ Request
constructor
A new instance of Request.
- #post? ⇒ Boolean
Constructor Details
#initialize(method, uri, body = nil, headers = {}) ⇒ Request
Returns a new instance of Request.
23 24 25 26 27 28 29 30 31 |
# File 'lib/poms/api/request.rb', line 23 def initialize(method, uri, body = nil, headers = {}) @method = method.to_sym unless i(get post).include?(@method) raise ArgumentError, 'method should be :get or :post' end @uri = uri @body = body.to_s @headers = headers.to_h end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
13 14 15 |
# File 'lib/poms/api/request.rb', line 13 def body @body end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
13 14 15 |
# File 'lib/poms/api/request.rb', line 13 def uri @uri end |
Class Method Details
.get(*args) ⇒ Object
15 16 17 |
# File 'lib/poms/api/request.rb', line 15 def self.get(*args) new(:get, *args) end |
.post(*args) ⇒ Object
19 20 21 |
# File 'lib/poms/api/request.rb', line 19 def self.post(*args) new(:post, *args) end |
Instance Method Details
#get? ⇒ Boolean
33 34 35 |
# File 'lib/poms/api/request.rb', line 33 def get? @method == :get end |
#post? ⇒ Boolean
37 38 39 |
# File 'lib/poms/api/request.rb', line 37 def post? @method == :post end |