Class: Acter::Response
- Inherits:
-
Object
- Object
- Acter::Response
- Defined in:
- lib/acter/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#body_is_json ⇒ Object
(also: #body_is_json?)
readonly
Returns the value of attribute body_is_json.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#success ⇒ Object
(also: #success?)
readonly
Returns the value of attribute success.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(status, headers, body) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(status, headers, body) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/acter/response.rb', line 5 def initialize(status, headers, body) @status = status @success = (200..299).include?(status[/\d+/].to_i) @headers = headers.sort.map {|a| a.join(": ") } @body = case body when String @body_is_json = false body else @body_is_json = true MultiJson.dump(body, pretty: true) end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
24 25 26 |
# File 'lib/acter/response.rb', line 24 def body @body end |
#body_is_json ⇒ Object (readonly) Also known as: body_is_json?
Returns the value of attribute body_is_json.
24 25 26 |
# File 'lib/acter/response.rb', line 24 def body_is_json @body_is_json end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
24 25 26 |
# File 'lib/acter/response.rb', line 24 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
24 25 26 |
# File 'lib/acter/response.rb', line 24 def status @status end |
#success ⇒ Object (readonly) Also known as: success?
Returns the value of attribute success.
24 25 26 |
# File 'lib/acter/response.rb', line 24 def success @success end |
Class Method Details
.new_from_faraday(faraday_response) ⇒ Object
19 20 21 22 |
# File 'lib/acter/response.rb', line 19 def self.new_from_faraday(faraday_response) status_string = "#{faraday_response.status} #{faraday_response.reason_phrase}" new(status_string, faraday_response.headers, faraday_response.body) end |