Avatax_AddressService 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTRjMDdhZmFjZGUxNzdjZjA5N2EyMDM5OTIwNGM4NWEyZDBmNGQzMQ==
4
+ MmFjMjMyYzQxYmNkMGNhNDZjYTU0NjM2MDk3NTA0ZDA1NDAyZjFjMQ==
5
5
  data.tar.gz: !binary |-
6
- MjAyYjBhYmMxN2RjMjM3MGZlNWIxZTgzODE0MjU2MWI4NTIwZDM3OA==
6
+ MmQwMjA5ZjQwMGViNzJmOWE2NzhjYTkxNzU5NWUwYzExZGQ3Njk5Mg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Yzc2ZWIwNTMxNGRkZDkyODk3NDNkOGZiMGM2YTBhNzg4NGMxMTdhN2IxZTY3
10
- YzY3Nzk3YWY5NzY1M2ViOTBmZDljMzU0YWU2MThlYjAwMTg2OGUxZTg2N2Qx
11
- YTI2Nzc5ODVjZDUzMDY4NWU3OWZhZTEwYmM3ZDVjNzkxYTE0NGY=
9
+ ZDU3ZDQ1OWNiMWQzMDMyMmIyMWNjMTZmYmI1NTFiYjVhOWRmYWU3OTA1Njlm
10
+ NjY1Mjk3NGQ3ZjEwZWE1ZDJhYTI1NGY4YTVlNTM1YjkzYjI4N2U0ZjZmZWE1
11
+ MzQxMWUzMTg5ZDI3NTI3MDM2YTY1NzdlYzgyNGEzN2VlNjVmYzM=
12
12
  data.tar.gz: !binary |-
13
- NmRiOTVmYzIzMTcxZmQ0YjMwMGE2NjU0MDdhNmUyNDkzMjdkMTU2M2E3Mzc3
14
- ZThhMmFjNWQ0ODdmNDgxZGRkNTRhOTU5MzJmNzU0MDUzZjgyMWE5N2RlY2E4
15
- MWY1MzdiYTVjMWMyMzdiNGJlMmU0NDVmNDA0NTgyNzgyZjE3NzE=
13
+ NzBiZTY2ZTIzMzJjMWIzNjgzYzcxYzY1MWVkYWFhNDFhNDBmNmQ2NjQxMjY2
14
+ NjE1NDFhOGEwNTYxMDkyOWU5YzA1MmY5MDIwYzlkMjUzNDgyNmQwMDI0ZWI4
15
+ MGVlYmQ0ZDY4NzZkOTdiN2YxYzlhOGVlOGU2NWU2MGVjYWZiNWI=
Binary file
@@ -1,19 +1,17 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "Avatax_AddressService"
3
- s.version = "1.0.6"
3
+ s.version = "1.0.7"
4
4
  s.date = "2012-12-16"
5
5
  s.author = "Graham S Wilson"
6
6
  s.email = "support@Avalara.com"
7
- s.summary = "Ruby SDK for Avatax Address Web Services"
7
+ s.summary = "Ruby SDK for Avatax Address Web Services "
8
8
  s.homepage = "http://www.avalara.com/"
9
9
  s.license = 'MIT'
10
10
  s.description = "Ruby SDK provides means of communication with Avatax Web Services."
11
11
  s.files = ["lib/address_log.txt", "lib/addressservice_dev.wsdl", "lib/addressservice_prd.wsdl", "lib/avatax_addressservice.rb",
12
- "lib/template_validate.erb","lib/template_ping.erb","lib/template_isauthorized.erb",
13
- "lib/xpath_validate.txt", "lib/xpath_ping.txt","lib/xpath_isauthorized.txt","test/test_address.rb",
12
+ "lib/template_validate.erb","lib/template_ping.erb","lib/template_isauthorized.erb","test/test_address.rb",
14
13
  "Avatax_AddressService.gemspec", "Avatax Ruby SDK Guide.docx", "LICENSE.txt"]
15
14
  # s.add_dependency "nokogiri", ">= 1.4.0", "< 1.6"
16
- s.add_dependency "nokogiri", ">= 1.4.0"
17
15
  s.add_dependency "savon", ">= 2.3.0"
18
16
  s.required_ruby_version = '>=1.9.1'
19
17
  s.post_install_message = 'Thanks for installing the Avalara AddressService Ruby SDK. Refer to "Avatax Ruby SDK User Guide.docx" to get started.'
@@ -1,40 +1,49 @@
1
1
  require 'savon'
2
2
  require 'erb'
3
- require 'nokogiri'
4
3
 
5
4
  module AvaTax
6
5
  #Avalara address class
7
6
  class AddressService
8
7
  def initialize(credentials)
9
8
 
9
+ #Set @def_locn to the Avatax-x.x.x gem install library. This enables the ruby programs to
10
+ #find other objects that it needs.
11
+ spec = Gem::Specification.find_by_name("Avatax_AddressService")
12
+ gem_root = spec.gem_dir
13
+ @def_locn = gem_root + "/lib"
14
+
10
15
  #Extract data from hash
11
16
  username = credentials[:username]
12
17
  password = credentials[:password]
13
18
  name = credentials[:name]
14
19
  clientname = credentials[:clientname]
15
20
  adapter = credentials[:adapter]
16
- machine = credentials[:machine]
21
+ machine = credentials[:machine]
22
+ use_production_account = credentials[:use_production_account]
17
23
 
18
24
  #Set credentials and Profile information
19
25
  @username = username == nil ? "" : username
20
26
  @password = password == nil ? "" : password
21
27
  @name = name == nil ? "" : name
22
- @clientname = clientname == nil ? "" : clientname
23
- @adapter = adapter == nil ? "" : adapter
28
+ @clientname = (clientname == nil or clientname == "") ? "Avatax Address Service SDK for Ruby Default Client Name" : clientname
29
+ @adapter = (adapter == nil or adapter == "") ? spec.summary + spec.version.to_s : adapter
24
30
  @machine = machine == nil ? "" : machine
25
-
26
- #Set @def_locn to the Avatax-x.x.x gem install library. This enables the ruby programs to
27
- #find other objects that it needs.
28
- spec = Gem::Specification.find_by_name("Avatax_AddressService")
29
- gem_root = spec.gem_dir
30
- @def_locn = gem_root + "/lib"
31
+ @use_production_account = (use_production_account != true) ? false : use_production_account
31
32
 
32
33
  #Open Avatax Error Log
33
34
  @log = File.new(@def_locn + '/address_log.txt', "w")
34
- @log.puts "#{Time.now}: Address service started"
35
-
36
- #log :false turns off HTTP logging
37
- @client = Savon.client(wsdl: @def_locn + '/addressservice_dev.wsdl', log: false)
35
+
36
+ #Get service details from WSDL - control_array[2] contains the WSDL read from the address_control file
37
+ #log :false turns off HTTP logging. Select either Dev or Prod depending on the value of the boolean value 'use_production_account'
38
+ if @use_production_account
39
+ @log.puts "#{Time.now}: Avalara Production Address service started"
40
+ #log :false turns off HTTP logging
41
+ @client = Savon.client(wsdl: @def_locn + '/addressservice_prd.wsdl', log: false)
42
+ else
43
+ @log.puts "#{Time.now}: Avalara Development Address service started"
44
+ #log :false turns off HTTP logging
45
+ @client = Savon.client(wsdl: @def_locn + '/addressservice_dev.wsdl', log: false)
46
+ end
38
47
 
39
48
  begin
40
49
  #Read in the SOAP template for Ping
@@ -56,14 +65,18 @@ module AvaTax
56
65
  rescue
57
66
  @log.puts "#{Time.now}: Error loading the IsAuthorized template"
58
67
  end
59
- # Create hash for validate result
60
- @return_data = Hash.new
68
+
69
+ # Create hash for result
70
+ @response = Hash.new
61
71
  end
62
72
 
63
73
  ############################################################################################################
64
74
  # ping - Verifies connectivity to the web service and returns version information
65
75
  ############################################################################################################
66
76
  def ping(message = nil)
77
+
78
+ @service = 'Ping'
79
+
67
80
  #Read in the SOAP template
68
81
  @message = message == nil ? "?" : message
69
82
 
@@ -75,20 +88,14 @@ module AvaTax
75
88
 
76
89
  # Make the call to the Avalara Ping service
77
90
  begin
78
- @response = @client.call(:ping, xml: @soap).to_s
79
- rescue
80
- @log.puts "#{Time.now}: Error calling Ping service ... check username and password"
81
- end
82
- # Load the response into a Nokogiri object and remove namespaces
83
- @doc = Nokogiri::XML(@response).remove_namespaces!
84
-
85
- #Read in an array of XPATH pointers
86
- @ping_xpath = File.readlines(@def_locn + '/xpath_ping.txt')
87
-
88
- #Read each array element, extract the result returned by the service and place in a the @return_data hash
89
- @ping_xpath.each{|xpath| @return_data[xpath[2...xpath.length].chomp.to_sym] = @doc.xpath(xpath).text}
91
+ @response = @client.call(:ping, xml: @soap).to_hash
90
92
 
91
- return @return_data
93
+ return @response
94
+
95
+ #Capture unexpected errors
96
+ rescue Savon::Error => error
97
+ abend(error)
98
+ end
92
99
  end
93
100
 
94
101
  ############################################################################################################
@@ -96,6 +103,8 @@ module AvaTax
96
103
  ############################################################################################################
97
104
  def validate(address)
98
105
 
106
+ @service = 'Validate'
107
+
99
108
  #Extract data from hash
100
109
  addresscode = address[:addresscode]
101
110
  line1 = address[:line1]
@@ -131,59 +140,55 @@ module AvaTax
131
140
  # Subsitute real vales for template place holders
132
141
  @soap = @template_validate.result(binding)
133
142
 
134
- #Clear return hash
135
- @return_data.clear
136
-
137
143
  # Make the call to the Avalara Validate service
138
144
  begin
139
- @response = @client.call(:validate, xml: @soap).to_s
145
+ @response = @client.call(:validate, xml: @soap).to_hash
140
146
 
141
- rescue
142
- @log.puts "#{Time.now}: Error calling Validate service ... check username and password"
147
+ return @response
148
+
149
+ #Capture unexpected errors
150
+ rescue Savon::Error => error
151
+ abend(error)
143
152
  end
144
-
145
- # Load the response into a Nokogiri object and remove namespaces
146
- @doc = Nokogiri::XML(@response).remove_namespaces!
147
-
148
- #Read in an array of XPATH pointers
149
- @validate_xpath = File.readlines(@def_locn + '/xpath_validate.txt')
150
-
151
- #Read each array element, extract the result returned by the service and place in a the @return_data hash
152
- @validate_xpath.each{|xpath| @return_data[xpath[2...xpath.length].chomp.to_sym] = @doc.xpath(xpath).text}
153
-
154
- return @return_data
155
153
  end
156
154
 
157
155
  ############################################################################################################
158
156
  #Verifies connectivity to the web service and returns version information about the service.
159
157
  ############################################################################################################
160
158
  def isauthorized(operation = nil)
159
+
160
+ @service = 'IsAuthorized'
161
+
161
162
  #Read in the SOAP template
162
163
  @operation = operation == nil ? "?" : operation
163
164
 
164
165
  # Subsitute real vales for template place holders
165
166
  @soap = @template_isauthorized.result(binding)
166
167
 
167
- #Clear return hash
168
- @return_data.clear
169
-
170
168
  # Make the call to the Avalara Ping service
171
169
  begin
172
- @response = @client.call(:is_authorized, xml: @soap).to_s
173
- rescue
174
- @log.puts "#{Time.now}: Error calling IsAuthorized service ... check username and password"
175
- end
176
-
177
- # Load the response into a Nokogiri object and remove namespaces
178
- @doc = Nokogiri::XML(@response).remove_namespaces!
179
-
180
- #Read in an array of XPATH pointers
181
- @isauthorized_xpath = File.readlines(@def_locn + '/xpath_isauthorized.txt')
170
+ @response = @client.call(:is_authorized, xml: @soap).to_hash
182
171
 
183
- #Read each array element, extract the result returned by the service and place in a the @return_data hash
184
- @isauthorized_xpath.each{|xpath| @return_data[xpath[2...xpath.length].chomp.to_sym] = @doc.xpath(xpath).text}
185
-
186
- return @return_data
172
+ return @response
173
+
174
+ #Capture unexpected errors
175
+ rescue Savon::Error => error
176
+ abend(error)
177
+ end
178
+ end
179
+
180
+ private
181
+ ############################################################################################################
182
+ # abend - Unexpected error handling
183
+ ############################################################################################################
184
+ def abend(error)
185
+ @log.puts "An unexpected error occurred: Response from server = #{error}"
186
+ @log.puts "#{Time.now}: Error calling #{@service} service ... check that your account name and password are correct."
187
+ @response = error.to_hash
188
+ @response[:result_code] = 'Error'
189
+ @response[:summary] = @response[:fault][:faultcode]
190
+ @response[:details] = @response[:fault][:faultstring]
191
+ return @response
187
192
  end
188
193
  end
189
194
  end
data/test/test_address.rb CHANGED
@@ -8,8 +8,9 @@ credentials = Hash.new
8
8
 
9
9
  #Create new Address hash object
10
10
  address = Hash.new
11
+ val_addr = Hash.new
11
12
 
12
- Shoes.app :width => 400, :height => 400 do
13
+ Shoes.app :width => 400, :height => 460 do
13
14
  background orange
14
15
  border("#BE8",
15
16
  strokewidth: 6)
@@ -19,7 +20,9 @@ Shoes.app :width => 400, :height => 400 do
19
20
  para "Username:"
20
21
  @username = edit_line text: "USERNAME"
21
22
  para "Password:"
22
- @password = edit_line text: "PASSWORD", :secret => true
23
+ @password = edit_line text: "PASSWORD", :secret => true
24
+ para "Test Production:"
25
+ @use_production_account = edit_line text: "false"
23
26
  para
24
27
  @confirm = button "Confirm"
25
28
  para
@@ -27,12 +30,18 @@ Shoes.app :width => 400, :height => 400 do
27
30
  credentials[:username] = @username.text
28
31
  credentials[:password] = @password.text
29
32
  credentials[:name] = 'Avalara Inc.'
30
- credentials[:clientname] = 'MyShoppingCart'
31
- credentials[:adapter] = 'Avatax SDK for Ruby 1.0.5'
33
+ credentials[:clientname] = ''
34
+ credentials[:adapter] = ''
32
35
  credentials[:machine] = 'Lenovo W520 Windows 7'
36
+ if @use_production_account.text == 'true' then
37
+ credentials[:use_production_account] = !!@use_production_account
38
+ else
39
+ credentials[:use_production_account] = nil
40
+ end
41
+
33
42
  #Create an address service instance
34
43
  AddrService = AvaTax::AddressService.new(credentials)
35
-
44
+
36
45
  #Open a window to get the address to validate
37
46
  Shoes.app :width => 400, :height => 700, :title => "Avalara - Address Validation Tester" do
38
47
 
@@ -78,50 +87,62 @@ Shoes.app :width => 400, :height => 400 do
78
87
  address[:addresscode] = "123"
79
88
 
80
89
  #Call the validate service - passing the address as a Hash
81
-
82
90
  val_addr = AddrService.validate(address)
83
-
84
-
85
- if val_addr[:ResultCode] == "Success"
91
+
92
+ if val_addr[:validate_response][:validate_result][:result_code] == "Success"
86
93
  #Display validated result in a new window
87
- Shoes.app :width => 400, :height => 700, :left => 1000, :title => "Avalara - Address Validation Result" do
94
+ Shoes.app :width => 400, :height => 1000, :left => 1000, :title => "Avalara - Address Validation Result" do
88
95
 
89
96
  background orange..blue
90
-
97
+
91
98
  stack :margin => 10 do
92
99
  #Display result
93
- para "Line 1:"
94
- edit_line :text => val_addr[:Line1]
100
+ para "Line 1:"
101
+ edit_line :text => val_addr[:validate_response][:validate_result][:valid_addresses][:valid_address][:line1]
95
102
  para "Line 2:"
96
- edit_line :text => val_addr[:Line2]
103
+ edit_line :text => val_addr[:validate_response][:validate_result][:valid_addresses][:valid_address][:line2]
97
104
  para "Line 3:"
98
- edit_line :text => val_addr[:Line3]
105
+ edit_line :text => val_addr[:validate_response][:validate_result][:valid_addresses][:valid_address][:line3]
99
106
  para "City"
100
- edit_line :text => val_addr[:City]
107
+ edit_line :text => val_addr[:validate_response][:validate_result][:valid_addresses][:valid_address][:city]
101
108
  para "State"
102
- edit_line :text => val_addr[:Region]
109
+ edit_line :text => val_addr[:validate_response][:validate_result][:valid_addresses][:valid_address][:region]
103
110
  para "Zip"
104
- edit_line :text => val_addr[:PostalCode]
111
+ edit_line :text => val_addr[:validate_response][:validate_result][:valid_addresses][:valid_address][:postal_code]
105
112
  para "Country"
106
- edit_line :text => val_addr[:Country]
113
+ edit_line :text => val_addr[:validate_response][:validate_result][:valid_addresses][:valid_address][:country]
114
+ para
115
+ para "Latitude"
116
+ edit_line :text => val_addr[:validate_response][:validate_result][:valid_addresses][:valid_address][:latitude]
117
+ para "Longitude"
118
+ edit_line :text => val_addr[:validate_response][:validate_result][:valid_addresses][:valid_address][:longitude]
119
+ para "County"
120
+ edit_line :text => val_addr[:validate_response][:validate_result][:valid_addresses][:valid_address][:county]
121
+ para "FIPS Code"
122
+ edit_line :text => val_addr[:validate_response][:validate_result][:valid_addresses][:valid_address][:fips_code]
123
+ para "Carrier Route"
124
+ edit_line :text => val_addr[:validate_response][:validate_result][:valid_addresses][:valid_address][:carrier_route]
125
+ para "Post Net"
126
+ edit_line :text => val_addr[:validate_response][:validate_result][:valid_addresses][:valid_address][:post_net]
107
127
  end
108
128
  end
109
- else
129
+ else
110
130
  #Display error message in a new window
111
131
  Shoes.app :width => 400, :height => 500, :title => "Address Validation Error" do
112
132
 
113
133
  background orange..red
114
134
 
115
- if val_addr[:ResultCode] == "Error"
135
+ if val_addr[:validate_response][:validate_result][:result_code] == "Error"
136
+
116
137
  stack :margin => 10 do
117
138
  #Dispay error details
118
- para "RESULT: #{val_addr[:ResultCode]}"
119
- para "SUMMARY: #{val_addr[:Summary]}"
120
- para "DETAILS: #{val_addr[:Details]}"
121
- para "HELP LINK: #{val_addr[:Helplink]}"
122
- para "REFERS TO: #{val_addr[:RefersTo]}"
123
- para "SEVERITY: #{val_addr[:Severity]}"
124
- para "SOURCE #{val_addr[:Source]}"
139
+ para "RESULT: #{val_addr[:validate_response][:validate_result][:result_code]}"
140
+ para "SUMMARY: #{val_addr[:validate_response][:validate_result][:messages][:message][:summary]}"
141
+ para "DETAILS: #{val_addr[:validate_response][:validate_result][:messages][:message][:details]}"
142
+ para "HELP LINK: #{val_addr[:validate_response][:validate_result][:messages][:message][:help_link]}"
143
+ para "REFERS TO: #{val_addr[:validate_response][:validate_result][:messages][:message][:refers_to]}"
144
+ para "SEVERITY: #{val_addr[:validate_response][:validate_result][:messages][:message][:severity]}"
145
+ para "SOURCE #{val_addr[:validate_response][:validate_result][:messages][:message][:source]}"
125
146
  end
126
147
  else
127
148
  #Dispay error details
@@ -129,8 +150,8 @@ Shoes.app :width => 400, :height => 400 do
129
150
  para "SUMMARY: Unexpected error"
130
151
  para "DETAILS: An unexpected error has occurred ... please check address_log.txt for details"
131
152
  end
132
- end
153
+ end
133
154
  end}
134
155
  end}
135
156
  end
136
- end
157
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Avatax_AddressService
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Graham S Wilson
@@ -10,20 +10,6 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2012-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: nokogiri
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ! '>='
18
- - !ruby/object:Gem::Version
19
- version: 1.4.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ! '>='
25
- - !ruby/object:Gem::Version
26
- version: 1.4.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: savon
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -51,9 +37,6 @@ files:
51
37
  - lib/template_validate.erb
52
38
  - lib/template_ping.erb
53
39
  - lib/template_isauthorized.erb
54
- - lib/xpath_validate.txt
55
- - lib/xpath_ping.txt
56
- - lib/xpath_isauthorized.txt
57
40
  - test/test_address.rb
58
41
  - Avatax_AddressService.gemspec
59
42
  - Avatax Ruby SDK Guide.docx
@@ -1,4 +0,0 @@
1
- //TransactionId
2
- //ResultCode
3
- //Operations
4
- //Expires
data/lib/xpath_ping.txt DELETED
@@ -1,9 +0,0 @@
1
- //TransactionId
2
- //ResultCode
3
- //Summary
4
- //Details
5
- //Helplink
6
- //RefersTo
7
- //Severity
8
- //Source
9
- //Version
@@ -1,29 +0,0 @@
1
- //TransactionId
2
- //ResultCode
3
- //Summary
4
- //Details
5
- //Helplink
6
- //RefersTo
7
- //Severity
8
- //Source
9
- //AddressCode
10
- //Line1
11
- //Line2
12
- //Line3
13
- //Line4
14
- //City
15
- //Region
16
- //PostalCode
17
- //Country
18
- //TaxRegionId
19
- //Latitude
20
- //Longitude
21
- //County
22
- //FipsCode
23
- //CarrierRoute
24
- //PostNet
25
- //AddressType
26
- //Longitude
27
- //ValidateStatus
28
- //Geocode
29
- //Taxable