Class: SeaShanty::Request
- Inherits:
-
Object
- Object
- SeaShanty::Request
- Defined in:
- lib/sea_shanty/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(method:, url:, headers:, body:) ⇒ Request
constructor
A new instance of Request.
- #to_h ⇒ Object
Constructor Details
#initialize(method:, url:, headers:, body:) ⇒ Request
Returns a new instance of Request.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sea_shanty/request.rb', line 9 def initialize(method:, url:, headers:, body:) @method = method @url = case url when String URI.parse(url) when URI url else raise ArgumentError, "url should be a String or an URI" end @headers = headers @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/sea_shanty/request.rb', line 7 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
7 8 9 |
# File 'lib/sea_shanty/request.rb', line 7 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
7 8 9 |
# File 'lib/sea_shanty/request.rb', line 7 def method @method end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
7 8 9 |
# File 'lib/sea_shanty/request.rb', line 7 def url @url end |
Instance Method Details
#to_h ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sea_shanty/request.rb', line 23 def to_h { method: method.to_s, url: url.to_s, headers: headers, body: { string: body.to_s, encoding: body.nil? ? "" : body.encoding.name } } end |