Class: Bambora::ResponseAdapterFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/bambora/factories/response_adapter_factory.rb

Overview

Selects an adapter for parsing an HTTP response body

Class Method Summary collapse

Class Method Details

.for(response) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bambora/factories/response_adapter_factory.rb', line 8

def for(response)
  content_type = response.headers['Content-Type'].split(';').first
  case content_type
    when 'application/json'
      Bambora::JSONResponse.new(response)
    when 'text/html'
      # Currently, the only endpoint that responds with text/html is /scripts/payment_profiles.asp
      Bambora::Bank::Adapters::PaymentProfileResponse.new(response)
    else raise Bambora::Client::Error, "Unknown Content Type: #{content_type}. Response Body: #{response.body}"
  end
end