Class: Smartsheet::API::FaradayResponse
- Inherits:
-
Object
- Object
- Smartsheet::API::FaradayResponse
- Defined in:
- lib/smartsheet/api/faraday_adapter/faraday_response.rb
Overview
Builds response objects from Faraday response environments
Direct Known Subclasses
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#reason_phrase ⇒ Object
readonly
Returns the value of attribute reason_phrase.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(faraday_env) ⇒ FaradayResponse
constructor
A new instance of FaradayResponse.
Constructor Details
#initialize(faraday_env) ⇒ FaradayResponse
Returns a new instance of FaradayResponse.
22 23 24 25 26 |
# File 'lib/smartsheet/api/faraday_adapter/faraday_response.rb', line 22 def initialize(faraday_env) @status_code = faraday_env[:status] @reason_phrase = faraday_env[:reason_phrase] @headers = faraday_env[:response_headers] end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
20 21 22 |
# File 'lib/smartsheet/api/faraday_adapter/faraday_response.rb', line 20 def headers @headers end |
#reason_phrase ⇒ Object (readonly)
Returns the value of attribute reason_phrase.
20 21 22 |
# File 'lib/smartsheet/api/faraday_adapter/faraday_response.rb', line 20 def reason_phrase @reason_phrase end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
20 21 22 |
# File 'lib/smartsheet/api/faraday_adapter/faraday_response.rb', line 20 def status_code @status_code end |
Class Method Details
.from_response_env(faraday_env) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/smartsheet/api/faraday_adapter/faraday_response.rb', line 5 def self.from_response_env(faraday_env) if faraday_env[:body].kind_of?(Hash) && faraday_env[:body].key?(:errorCode) FaradayErrorResponse.new(faraday_env[:body], faraday_env) elsif faraday_env.success? FaradaySuccessResponse.new(faraday_env[:body], faraday_env) else raise HttpResponseError.new( status_code: faraday_env[:status], reason_phrase: faraday_env[:reason_phrase], headers: faraday_env[:response_headers], message: "#{faraday_env[:status]} #{faraday_env[:reason_phrase]}" ) end end |