Class: Fal::Response
- Inherits:
-
Object
- Object
- Fal::Response
- Defined in:
- lib/fal/response.rb
Overview
Parses HTTP responses and creates appropriate objects.
Instance Method Summary collapse
- #data ⇒ Object
- #error_message ⇒ Object
-
#initialize(http_response) ⇒ Response
constructor
A new instance of Response.
- #request_id ⇒ Object
- #status_code ⇒ Object
- #success? ⇒ Boolean
- #to_status ⇒ Object
Constructor Details
#initialize(http_response) ⇒ Response
Returns a new instance of Response.
8 9 10 |
# File 'lib/fal/response.rb', line 8 def initialize(http_response) @http_response = http_response end |
Instance Method Details
#data ⇒ Object
20 21 22 |
# File 'lib/fal/response.rb', line 20 def data @data ||= parse_body end |
#error_message ⇒ Object
28 29 30 |
# File 'lib/fal/response.rb', line 28 def data["detail"] || data["message"] || "Unknown error" end |
#request_id ⇒ Object
24 25 26 |
# File 'lib/fal/response.rb', line 24 def request_id data["request_id"] end |
#status_code ⇒ Object
12 13 14 |
# File 'lib/fal/response.rb', line 12 def status_code @http_response.status.to_i end |
#success? ⇒ Boolean
16 17 18 |
# File 'lib/fal/response.rb', line 16 def success? status_code >= 200 && status_code < 300 end |
#to_status ⇒ Object
32 33 34 |
# File 'lib/fal/response.rb', line 32 def to_status status_class.new(data) end |