class SvcParty::ApiResponseHandler

Public Class Methods

error(ex) click to toggle source
# File lib/svc_party/api_response_handler.rb, line 5
def self.error(ex)
  SvcParty::ApiResponse.new(false, 500, ex.message)
end
new(response) click to toggle source
# File lib/svc_party/api_response_handler.rb, line 9
def initialize(response)
  @response = response
end

Public Instance Methods

call() click to toggle source
# File lib/svc_party/api_response_handler.rb, line 13
def call
  api_response
end

Private Instance Methods

api_response() click to toggle source
# File lib/svc_party/api_response_handler.rb, line 19
def api_response
  code = @response.response.code.to_i
  response = @response.parsed_response

  return SvcParty::ApiResponse.new(true, code, response) if (200..299).cover? code
  return SvcParty::ApiResponse.new(true, code, @response.response.header['location']) if code == 302

  SvcParty::ApiResponse.new(false, code, response)
end