Class EWS::Transporter
In: lib/ews/transporter.rb
Parent: Object

A Transporter is responsible for communicating with the E-xact Web Service in whichever dialect is chosen by the user. The available options are:

  :json     REST with JSON payload
  :rest     REST with XML payload (default)
  :soap     SOAP

The Transporter will connect to the service, using SSL if required, and will encode Reqests to send to the service, and decode Responses received from the service.

Once configured to connect to a particular service, it can be used repeatedly to send as many transactions as required.

Methods

new   submit  

Public Class methods

Initialize a Transporter.

You can specify the URL you would like the Transporter to connect to, although it defaults to api.e-xact.com, the location of our transaction processing web service.

You can also specify a hash of options as follows:

  :transport_type   the transport_type for this transporter (defaults to :rest)

The default certificates are those required to connect to api.e-xact.com and the default transport_type is :rest. The default transport_type can be overridden on a per-transaction basis, if you choose to do so, by specifying it as a parameter to the submit method.

[Source]

    # File lib/ews/transporter.rb, line 30
30:     def initialize(url = "https://api.e-xact.com", options = {})
31:       @url = URI.parse(url.gsub(/\/$/,''))
32:       @transport_type = options[:transport_type] || :rest
33: 
34:       @@issuer_cert ||= File.dirname(__FILE__)+"/../../certs/equifax_ca.cer"
35:       @@server_cert ||= File.new(File.dirname(__FILE__)+"/../../certs/exact.cer").read
36:     end

Public Instance methods

Submit a transaction request to the server

transaction:the Request object to encode for transmission to the server
transport_type:(optional) the transport type to use for this transaction only. If it is not specified, the Transporter‘s transport type will be used

[Source]

    # File lib/ews/transporter.rb, line 42
42:     def submit(transaction, transport_type = nil)
43:       raise "Request not supplied" if transaction.nil?
44:       return false unless transaction.valid?
45: 
46:       transport_type ||= @transport_type
47: 
48:       raise "Transport type #{transport_type} is not supported" unless @@transport_types.include? transport_type
49: 
50:       transport_details = @@transport_types[transport_type]
51:       
52:       request = build_http_request(transaction, transport_type, transport_details[:suffix])
53:       request.basic_auth(transaction.gateway_id, transaction.password)
54:       request.add_field "Accept", transport_details[:content_type]
55:       request.add_field "User-Agent", "exact4r v0.7"
56:       request.add_field "Content-type", "#{transport_details[:content_type]}; charset=UTF-8"
57: 
58:       response = get_connection.request(request)
59: 
60:       case response
61:       when Net::HTTPSuccess then EWS::Transaction::Mapping.send "#{transport_type}_to_response", response.body
62:       else
63:         r = ::EWS::Transaction::Response.new
64:         if(transport_type == :soap)
65:           # we may have a SOAP Fault
66:           r = EWS::Transaction::Mapping.send "#{transport_type}_to_response", response.body
67:         end
68: 
69:         # SOAP Fault may already have populated the error_number etc.
70:         unless r.error_number
71:           # populate the error number and description
72:           r.error_number = response.code.to_i
73:           r.error_description = response.message
74:         end
75:         
76:         r
77:       end
78: 
79:     end

[Validate]