Class: Smartsheet::API::FaradayResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/smartsheet/api/faraday_adapter/faraday_response.rb

Overview

Builds response objects from Faraday response environments

Direct Known Subclasses

FaradayErrorResponse, FaradaySuccessResponse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#headersObject (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_phraseObject (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_codeObject (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