class Datacash::Client

Constants

ENDPOINTS

Attributes

client[R]
environment[R]
password[R]
rest_client[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/datacash/client.rb, line 9
def initialize(options={})
  @client      = options.fetch(:client, Datacash.configuration.client)
  @password    = options.fetch(:password, Datacash.configuration.password)
  @environment    = options.fetch(:environment, Datacash.configuration.environment)
  @rest_client = options.fetch(:rest_client, RestClient)
end

Public Instance Methods

post(request) click to toggle source
# File lib/datacash/client.rb, line 16
def post(request)
  prepare_request(request)

  handle_response(
    rest_client.post(endpoint, request.to_xml, :content_type => :xml, :accept => :xml)
  )
end
query(datacash_reference) click to toggle source
# File lib/datacash/client.rb, line 24
def query(datacash_reference)
  request = Request::Request.new(transaction: {
    historic_transaction: { 
      method: "query", reference: datacash_reference
    }
  })
  post(request)
end

Private Instance Methods

endpoint() click to toggle source
# File lib/datacash/client.rb, line 40
def endpoint
  ENDPOINTS[environment]
end
handle_response(raw_response) click to toggle source
# File lib/datacash/client.rb, line 48
def handle_response(raw_response)
  response = Response::Response.new(parse_response_to_hash(raw_response))
  response.raw = raw_response
  if response.reason =~ /invalid client\/pass/i
    raise AuthenticationError, response
  end
  response
end
parse_response_to_hash(response) click to toggle source
# File lib/datacash/client.rb, line 36
def parse_response_to_hash(response)
  MultiXml.parse(response, :symbolize_keys => true)[:Response]
end
prepare_request(request) click to toggle source
# File lib/datacash/client.rb, line 44
def prepare_request(request)
  request.add_authentication(client: client, password: password)
end