billwise4r 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+ gem "savon"
3
+ gem "multi_xml"
4
+
5
+ group :development do
6
+ gem "shoulda", ">= 0"
7
+ gem "bundler", "~> 1.0.0"
8
+ gem "jeweler", "~> 1.5.1"
9
+ gem "rcov", ">= 0"
10
+ gem "awesome_print"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ awesome_print (0.3.1)
5
+ builder (3.0.0)
6
+ crack (0.1.8)
7
+ git (1.2.5)
8
+ jeweler (1.5.1)
9
+ bundler (~> 1.0.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ multi_xml (0.2.0)
13
+ rake (0.8.7)
14
+ rcov (0.9.9)
15
+ rcov (0.9.9-java)
16
+ savon (0.7.9)
17
+ builder (>= 2.1.2)
18
+ crack (>= 0.1.4)
19
+ shoulda (2.11.3)
20
+
21
+ PLATFORMS
22
+ java
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ awesome_print
27
+ bundler (~> 1.0.0)
28
+ jeweler (~> 1.5.1)
29
+ multi_xml
30
+ rcov
31
+ savon
32
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Jason Goecke
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ billwise4r
2
+ ==========
3
+
4
+ Gem for working with the Billwise SOAP/XML API.
5
+
6
+ Examples
7
+ --------
8
+
9
+ require 'billwise4r'
10
+
11
+ billwise = Billwise.new({ :company_id => 123,
12
+ :username => 'user',
13
+ :password => 'pass',
14
+ :wsdl_url => 'https://cwa021.connect4billing.com/axis2/services/ConnectSmService?wsdl',
15
+ :endpoint => 'https://cwa021.connect4billing.com/axis2/services/ConnectSmService.ConnectSmServiceHttpSoap12Endpoint/',
16
+ :namespace => 'http://connectsm.ws.bwse.com/xsd',
17
+ :log => true})
18
+
19
+ customer = billwise.find_customer(987)
20
+ services = billwise.find_services({ :customerCd => '000123',
21
+ :serviceId => 'A000000000000456',
22
+ :status => 'A' })
23
+
24
+ Copyright
25
+ ---------
26
+
27
+ Copyright (c) 2010 Jason Goecke. See LICENSE.txt for further details.
28
+
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "billwise4r"
16
+ gem.homepage = "http://github.com/tropo/billwise4r"
17
+ gem.license = "MIT"
18
+ gem.summary = "Ruby lib for consuming the Billwise SOAP/XML API"
19
+ gem.description = "Ruby lib for consuming the Billwise SOAP/XML API"
20
+ gem.email = "jason@goecke.net"
21
+ gem.authors = ["Jason Goecke"]
22
+ gem.add_runtime_dependency 'savon'
23
+ gem.add_development_dependency 'rspec'
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'lib' << 'test'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ require 'rcov/rcovtask'
35
+ Rcov::RcovTask.new do |test|
36
+ test.libs << 'test'
37
+ test.pattern = 'test/**/test_*.rb'
38
+ test.verbose = true
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "billwise4r #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,85 @@
1
+ class Billwise
2
+ ##
3
+ # Instantiates a new Billwise class
4
+ #
5
+ def initialize(params={})
6
+ # Make sure all params we need are here or raise an error
7
+ check_initialization_params(params)
8
+
9
+ @companyCd = params[:companyCd]
10
+ log = params[:log] || false
11
+ log_level = params[:log_level] || false
12
+
13
+ #Build our SOAP driver
14
+ Savon::SOAP.version = 2
15
+ Savon::WSSE.username = params[:username]
16
+ Savon::WSSE.password = params[:password]
17
+ Savon::Request.log = log
18
+ Savon::Request.log_level = log_level
19
+
20
+ @soap_driver = Savon::Client.new params[:wsdlUrl] || 'https://cwa021.connect4billing.com/axis2/services/ConnectSmService?wsdl'
21
+ @soap_endpoint = URI.parse params[:endpoint] || 'https://cwa021.connect4billing.com/axis2/services/ConnectSmService.ConnectSmServiceHttpSoap12Endpoint/'
22
+ @soap_namespace = namespace = params[:namespace] || 'http://connectsm.ws.bwse.com/xsd'
23
+
24
+ @tag_order = tag_order
25
+
26
+ MultiXml.parser = :nokogiri
27
+ end
28
+
29
+ ##
30
+ # A catch all for the methods defined by the WSDL
31
+ # refer to the Billwise API documentation for details
32
+ #
33
+ # @return [Hash] the Billwise response
34
+ def method_missing(method, params)
35
+ response = @soap_driver.send(method) do |soap, wsse|
36
+ soap.endpoint = @soap_endpoint
37
+ soap.namespaces["xmlns:wsdl"] = @soap_namespace
38
+
39
+ fields = { :companyCd => @companyCd }.merge!(params)
40
+ fields.merge!({ :order! => @tag_order[method] }) if @tag_order[method]
41
+
42
+ soap.body = fields
43
+ end
44
+ response.to_hash["#{method}_response".to_sym][:return]
45
+ end
46
+
47
+ private
48
+
49
+ ##
50
+ # Checks that the required params have been provided, or rasies an error
51
+ def check_initialization_params(params={})
52
+ raise ArgumentError, "You must provide Billwise connection parameters." if params.length == 0
53
+ %w(companyCd username password).each { |param| raise ArgumentError, "You must provide a valid #{param}." if params[param.to_sym].nil? }
54
+ end
55
+
56
+ ##
57
+ # Traverses the WSDL to create a hash of methods and their ordered parameters
58
+ # only necessary since the Billwise SOAP/XML API requires attributes in order
59
+ # and the Ruby MRI likes to alphabetize, so Savon allows us to set a specific
60
+ # order when building the XML
61
+ #
62
+ # @return [Hash] the methods and their ordered parameters
63
+ def tag_order
64
+ actions = {}
65
+ MultiXml.parse(@soap_driver.wsdl.to_s)['definitions']['types']['schema'][2]['element'].each do |action|
66
+ attributes = []
67
+ if action['complexType']['sequence']['element'].instance_of?(Hash)
68
+ attributes << action['complexType']['sequence']['element']['name'].to_sym
69
+ else
70
+ action['complexType']['sequence']['element'].each { |item| attributes << item['name'].to_sym }
71
+ end
72
+ actions[decamelize(action['name']).to_sym] = attributes
73
+ end
74
+ actions
75
+ end
76
+
77
+ ##
78
+ # Decamelizes a string
79
+ #
80
+ # @param [required, String] the string to be decamelized
81
+ # @return [String] the decamelized string
82
+ def decamelize(string)
83
+ string.gsub(/[A-Z]/) { |p| '_' + p.downcase }
84
+ end
85
+ end
data/lib/billwise4r.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'savon'
2
+ require 'multi_xml'
3
+ require 'billwise4r/billwise4r'
@@ -0,0 +1,48 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Billwise" do
4
+ before(:all) do
5
+ @options = { :companyCd => 124,
6
+ :username => 'user',
7
+ :password => 'pass',
8
+ :log => false }
9
+
10
+ @billwise = Billwise.new @options
11
+ end
12
+
13
+ it "should create a Billwise object" do
14
+ @billwise = Billwise.new @options
15
+ @billwise.instance_of?(Billwise).should == true
16
+ end
17
+
18
+ it "should raise errors if required params are not passed" do
19
+ begin
20
+ Billwise.new
21
+ rescue => e
22
+ e.to_s.should == "You must provide Billwise connection parameters."
23
+ end
24
+
25
+ begin
26
+ Billwise.new({ :companyCd => 100 })
27
+ rescue => e
28
+ e.to_s.should == "You must provide a valid username."
29
+ end
30
+ end
31
+
32
+ it "should find a valid customer" do
33
+ result = @billwise.find_customer({ :customerCd => '000155' })
34
+ result[:customer_cd].should == "000155"
35
+ end
36
+
37
+ it "should find that customers invoices" do
38
+ result = @billwise.find_invoices({ :customerCd => '000155' })
39
+ result[0][:invoice_number].should == "STMNT-201005"
40
+ end
41
+
42
+ it "should find services" do
43
+ result = @billwise.find_services({ :customerCd => '000155',
44
+ :serviceId => 'A000000000046590',
45
+ :status => 'A' })
46
+ result[:service_id].should == 'A000000000046590'
47
+ end
48
+ end