Class: SeaShanty::Response
- Inherits:
-
Object
- Object
- SeaShanty::Response
- Defined in:
- lib/sea_shanty/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#original_response ⇒ Object
readonly
Returns the value of attribute original_response.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(status:, message:, headers:, body:, original_response: ORIGINAL_RESPONSE_NOT_PRESENT) ⇒ Response
constructor
A new instance of Response.
- #to_h ⇒ Object
- #was_stored? ⇒ Boolean
Constructor Details
#initialize(status:, message:, headers:, body:, original_response: ORIGINAL_RESPONSE_NOT_PRESENT) ⇒ Response
Returns a new instance of Response.
18 19 20 21 22 23 24 |
# File 'lib/sea_shanty/response.rb', line 18 def initialize(status:, message:, headers:, body:, original_response: ORIGINAL_RESPONSE_NOT_PRESENT) @status = Integer(status, status.is_a?(String) ? 10 : 0) @message = @headers = headers @body = body @original_response = original_response end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/sea_shanty/response.rb', line 5 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/sea_shanty/response.rb', line 5 def headers @headers end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
5 6 7 |
# File 'lib/sea_shanty/response.rb', line 5 def @message end |
#original_response ⇒ Object (readonly)
Returns the value of attribute original_response.
5 6 7 |
# File 'lib/sea_shanty/response.rb', line 5 def original_response @original_response end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/sea_shanty/response.rb', line 5 def status @status end |
Class Method Details
.from_h(hash) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/sea_shanty/response.rb', line 8 def from_h(hash) new( status: hash.fetch(:status).fetch(:code), message: hash.fetch(:status).fetch(:message), headers: hash.fetch(:headers), body: hash.fetch(:body).fetch(:encoding).empty? ? nil : hash.fetch(:body).fetch(:string) ) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
44 45 46 47 48 |
# File 'lib/sea_shanty/response.rb', line 44 def ==(other) self.class === other && status == other.status && == other. && headers == other.headers && body == other.body end |
#hash ⇒ Object
52 53 54 |
# File 'lib/sea_shanty/response.rb', line 52 def hash [self.class, status, , headers, body].hash end |
#to_h ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sea_shanty/response.rb', line 26 def to_h { status: { code: status, message: }, headers: headers, body: { string: body.to_s, encoding: body.nil? ? "" : body.encoding.name } } end |
#was_stored? ⇒ Boolean
40 41 42 |
# File 'lib/sea_shanty/response.rb', line 40 def was_stored? ORIGINAL_RESPONSE_NOT_PRESENT != original_response end |