Class: RailsCosmos::Http::Response
- Inherits:
-
Object
- Object
- RailsCosmos::Http::Response
- Defined in:
- lib/rails_cosmos/http/response.rb
Overview
RailsCosmos::Http::Response
A wrapper around HTTP responses to provide a consistent interface for handling API responses. This class parses JSON responses and provides helper methods to check response success.
Instance Attribute Summary collapse
-
#body ⇒ Hash
readonly
The parsed response body as a Hash.
-
#raw_body ⇒ String?
readonly
The raw response body as a string, or nil if absent.
-
#status ⇒ Integer
readonly
The HTTP status code.
Instance Method Summary collapse
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
25 26 27 28 29 |
# File 'lib/rails_cosmos/http/response.rb', line 25 def initialize(response) @raw_body = response.body.present? ? response.body : {} @body = response.body.present? ? JSON.parse(response.body) : {} @status = response.status end |
Instance Attribute Details
#body ⇒ Hash (readonly)
The parsed response body as a Hash.
22 23 24 |
# File 'lib/rails_cosmos/http/response.rb', line 22 def body @body end |
#raw_body ⇒ String? (readonly)
The raw response body as a string, or nil if absent.
22 23 24 |
# File 'lib/rails_cosmos/http/response.rb', line 22 def raw_body @raw_body end |
#status ⇒ Integer (readonly)
The HTTP status code.
22 23 24 |
# File 'lib/rails_cosmos/http/response.rb', line 22 def status @status end |
Instance Method Details
#success? ⇒ Boolean
31 32 33 |
# File 'lib/rails_cosmos/http/response.rb', line 31 def success? (200..299).include?(status) end |