Class: Billwise

Inherits:
Object
  • Object
show all
Defined in:
lib/billwise4r.rb

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Billwise

Instantiates a new Billwise class



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/billwise4r.rb', line 9

def initialize(params={})
  # Make sure all params we need are here or raise an error
  check_initialization_params(params)

  @companyCd        =  params[:companyCd]
  log               =  params[:log]           || false
  log_level         =  params[:log_level]     || :info
  @httpi_log        =  params[:httpi_log]     || false
  @ssl_verify_mode  =  params[:verify_mode]   || :peer
  @read_timeout     =  params[:read_timeout]  || 300
  @open_timeout     =  params[:open_timeout]  || 60

  Savon.configure do |config|
    config.log            =  log
    config.log_level      =  log_level
    config.env_namespace  =  :soap
  end

  HTTPI.log = @httpi_log

  @soap_endpoint   =  URI.parse params[:endpoint] || 'https://cwa021.connect4billing.com:8443/axis2/services/ConnectSmService.ConnectSmServiceHttpSoap12Endpoint/'
  @soap_namespace  =  params[:namespace]          || 'http://connectsm.ws.bwse.com/xsd'
  @soap_version    =  2

  # Build our SOAP driver
  @soap_driver = Savon::Client.new do
    wsse.credentials params[:username] , params[:password]
    wsdl.document =  'https://cwa021.connect4billing.com:8443/axis2/services/ConnectSmService?wsdl'
  end

  @soap_driver.http.read_timeout                =  @read_timeout
  @soap_driver.http.open_timeout                =  @open_timeout
  @soap_driver.http.auth.ssl.verify_mode        =  @ssl_verify_mode.to_sym                                     # or one of [:peer, :fail_if_no_peer_cert, :client_once]
  @soap_driver.http.auth.ssl.cert_key_file      =  params[:cert_key_file]      if  params[:cert_key_file]      # the private key file to use
  @soap_driver.http.auth.ssl.cert_key_password  =  params[:cert_key_password]  if  params[:cert_key_password]  # the key file's password
  @soap_driver.http.auth.ssl.cert_file          =  params[:cert_file]          if  params[:cert_file]          # the certificate file to use
  @soap_driver.http.auth.ssl.ca_cert_file       =  params[:ca_cert_file]       if  params[:ca_cert_file]       # the ca certificate file to use

  @tag_order                                    =  tag_order

  MultiXml.parser                               =  :nokogiri
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, params) ⇒ Hash

A catch all for the methods defined by the WSDL refer to the Billwise API documentation for details

Returns:

  • (Hash)

    the Billwise response



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/billwise4r.rb', line 57

def method_missing(method, params)
  begin
    HTTPI.log = @httpi_log
    response = @soap_driver.request :wsdl, method do |soap, wsse|
      soap.version                   =  @soap_version
      soap.endpoint                  =  @soap_endpoint
      soap.namespaces                =  Hash.new
      soap.namespaces["xmlns:soap"]  =  "http://www.w3.org/2003/05/soap-envelope"
      soap.namespaces["xmlns:ins0"]  =  @soap_namespace

      fields = { :companyCd => @companyCd }.merge!(params)

      fields = order_hash(:method=>method, :fields=>fields)

      soap.body = fields

    end
    response.to_hash["#{method}_response".to_sym][:return]
  rescue Savon::SOAP::Fault => fault
    response = {'error' => 'soapfault', 'message' => fault}
  end
end