Class: Fal::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/fal/response.rb

Overview

Parses HTTP responses and creates appropriate objects.

Instance Method Summary collapse

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

#dataObject



20
21
22
# File 'lib/fal/response.rb', line 20

def data
  @data ||= parse_body
end

#error_messageObject



28
29
30
# File 'lib/fal/response.rb', line 28

def error_message
  data["detail"] || data["message"] || "Unknown error"
end

#request_idObject



24
25
26
# File 'lib/fal/response.rb', line 24

def request_id
  data["request_id"]
end

#status_codeObject



12
13
14
# File 'lib/fal/response.rb', line 12

def status_code
  @http_response.status.to_i
end

#success?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/fal/response.rb', line 16

def success?
  status_code >= 200 && status_code < 300
end

#to_statusObject



32
33
34
# File 'lib/fal/response.rb', line 32

def to_status
  status_class.new(data)
end