Class: FlyIO::Response
- Inherits:
-
Object
- Object
- FlyIO::Response
- Defined in:
- lib/fly_io/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
(also: #data)
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#raw_body ⇒ Object
readonly
Returns the value of attribute raw_body.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #accepted? ⇒ Boolean
-
#initialize(status:, headers:, body:, raw_body:, request:) ⇒ Response
constructor
A new instance of Response.
- #method_missing(name, *arguments) ⇒ Object
- #no_content? ⇒ Boolean
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(status:, headers:, body:, raw_body:, request:) ⇒ Response
Returns a new instance of Response.
7 8 9 10 11 12 13 14 15 |
# File 'lib/fly_io/response.rb', line 7 def initialize(status:, headers:, body:, raw_body:, request:) @status = Integer(status) @headers = headers.freeze @body = body @raw_body = raw_body @request = request.freeze @request_id = headers["fly-request-id"] || headers["x-request-id"] freeze end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *arguments) ⇒ Object
35 36 37 38 39 |
# File 'lib/fly_io/response.rb', line 35 def method_missing(name, *arguments) return body.public_send(name) if arguments.empty? && body.respond_to?(name) super end |
Instance Attribute Details
#body ⇒ Object (readonly) Also known as: data
Returns the value of attribute body.
5 6 7 |
# File 'lib/fly_io/response.rb', line 5 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/fly_io/response.rb', line 5 def headers @headers end |
#raw_body ⇒ Object (readonly)
Returns the value of attribute raw_body.
5 6 7 |
# File 'lib/fly_io/response.rb', line 5 def raw_body @raw_body end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
5 6 7 |
# File 'lib/fly_io/response.rb', line 5 def request @request end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
5 6 7 |
# File 'lib/fly_io/response.rb', line 5 def request_id @request_id end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/fly_io/response.rb', line 5 def status @status end |
Instance Method Details
#[](key) ⇒ Object
31 32 33 |
# File 'lib/fly_io/response.rb', line 31 def [](key) body.respond_to?(:[]) ? body[key] : nil end |
#accepted? ⇒ Boolean
23 24 25 |
# File 'lib/fly_io/response.rb', line 23 def accepted? status == 202 end |
#no_content? ⇒ Boolean
27 28 29 |
# File 'lib/fly_io/response.rb', line 27 def no_content? status == 204 end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
41 42 43 |
# File 'lib/fly_io/response.rb', line 41 def respond_to_missing?(name, include_private = false) body.respond_to?(name, include_private) || super end |
#success? ⇒ Boolean
19 20 21 |
# File 'lib/fly_io/response.rb', line 19 def success? (200..299).cover?(status) end |