Avatax_AddressService 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Avatax_AddressService.gemspec +2 -2
- data/lib/avatax_addressservice.rb +141 -132
- data/test/test_address.rb +27 -10
- metadata +2 -2
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "Avatax_AddressService"
|
3
|
-
s.version = "1.0.
|
4
|
-
s.date = "2012-
|
3
|
+
s.version = "1.0.5"
|
4
|
+
s.date = "2012-12-16"
|
5
5
|
s.author = "Graham S Wilson"
|
6
6
|
s.email = "support@Avalara.com"
|
7
7
|
s.summary = "Ruby SDK for Avatax Address Web Services"
|
@@ -3,178 +3,187 @@ require 'erb'
|
|
3
3
|
require 'nokogiri'
|
4
4
|
|
5
5
|
module AvaTax
|
6
|
-
|
7
6
|
#Avalara address class
|
8
|
-
class AddressService
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
7
|
+
class AddressService
|
8
|
+
def initialize(credentials)
|
9
|
+
|
10
|
+
#Extract data from hash
|
11
|
+
username = credentials[:username]
|
12
|
+
password = credentials[:password]
|
13
|
+
name = credentials[:name]
|
14
|
+
clientname = credentials[:clientname]
|
15
|
+
adapter = credentials[:adapter]
|
16
|
+
machine = credentials[:machine]
|
17
|
+
|
18
|
+
#Set credentials and Profile information
|
19
|
+
@username = username == nil ? "" : username
|
20
|
+
@password = password == nil ? "" : password
|
21
|
+
@name = name == nil ? "" : name
|
22
|
+
@clientname = clientname == nil ? "" : clientname
|
23
|
+
@adapter = adapter == nil ? "" : adapter
|
24
|
+
@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
|
+
|
32
|
+
#Open Avatax Error Log
|
33
|
+
@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)
|
38
|
+
|
39
|
+
begin
|
40
|
+
#Read in the SOAP template for Ping
|
41
|
+
@template_ping = ERB.new(File.read(@def_locn + '\template_ping.erb'))
|
42
|
+
rescue
|
43
|
+
@log.puts "#{Time.now}: Error loading the Ping template"
|
44
|
+
end
|
45
|
+
|
46
|
+
begin
|
47
|
+
#Read in the SOAP template for Validate
|
48
|
+
@template_validate = ERB.new(File.read(@def_locn + '\template_validate.erb'))
|
49
|
+
rescue
|
50
|
+
@log.puts "#{Time.now}: Error loading the Validate template"
|
51
|
+
end
|
52
|
+
|
53
|
+
begin
|
54
|
+
#Read in the SOAP template for IsAuthorized
|
55
|
+
@template_isauthorized = ERB.new(File.read(@def_locn + '\template_isauthorized.erb'))
|
56
|
+
rescue
|
57
|
+
@log.puts "#{Time.now}: Error loading the IsAuthorized template"
|
58
|
+
end
|
59
|
+
# Create hash for validate result
|
60
|
+
@return_data = Hash.new
|
55
61
|
end
|
56
62
|
|
57
|
-
############################################################################################################
|
58
|
-
# ping - Verifies connectivity to the web service and returns version information
|
59
|
-
############################################################################################################
|
63
|
+
############################################################################################################
|
64
|
+
# ping - Verifies connectivity to the web service and returns version information
|
65
|
+
############################################################################################################
|
60
66
|
def ping(message = nil)
|
61
67
|
#Read in the SOAP template
|
62
|
-
@message = message == nil ? "?" : message
|
68
|
+
@message = message == nil ? "?" : message
|
63
69
|
|
64
|
-
# Subsitute real vales for template place holders
|
70
|
+
# Subsitute real vales for template place holders
|
65
71
|
@soap = @template_ping.result(binding)
|
66
|
-
|
72
|
+
|
67
73
|
#Clear return hash
|
68
74
|
@return_data.clear
|
69
|
-
|
75
|
+
|
70
76
|
# Make the call to the Avalara Ping service
|
71
77
|
begin
|
72
78
|
@response = @client.call(:ping, xml: @soap).to_s
|
73
|
-
|
74
|
-
|
79
|
+
rescue
|
80
|
+
@log.puts "#{Time.now}: Error calling Ping service ... check username and password"
|
75
81
|
end
|
76
82
|
# Load the response into a Nokogiri object and remove namespaces
|
77
|
-
@doc = Nokogiri::XML(@response).remove_namespaces!
|
78
|
-
|
79
|
-
#Read in an array of XPATH pointers
|
83
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
84
|
+
|
85
|
+
#Read in an array of XPATH pointers
|
80
86
|
@ping_xpath = File.readlines(@def_locn + '\xpath_ping.txt')
|
81
|
-
|
87
|
+
|
82
88
|
#Read each array element, extract the result returned by the service and place in a the @return_data hash
|
83
89
|
@ping_xpath.each{|xpath| @return_data[xpath[2...xpath.length].chomp.to_sym] = @doc.xpath(xpath).text}
|
84
|
-
|
90
|
+
|
85
91
|
return @return_data
|
86
92
|
end
|
87
93
|
|
88
94
|
############################################################################################################
|
89
95
|
# validate - call the adddress validation service
|
90
96
|
############################################################################################################
|
91
|
-
def validate(
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
#
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
97
|
+
def validate(address)
|
98
|
+
|
99
|
+
#Extract data from hash
|
100
|
+
addresscode = address[:addresscode]
|
101
|
+
line1 = address[:line1]
|
102
|
+
line2 = address[:line2]
|
103
|
+
line3 = address[:line3]
|
104
|
+
city = address[:city]
|
105
|
+
region = address[:region]
|
106
|
+
postalcode = address[:postalcode]
|
107
|
+
country = address[:country]
|
108
|
+
taxregionid = address[:taxregionid]
|
109
|
+
latitude = address[:latitude]
|
110
|
+
longitude = address[:longitude]
|
111
|
+
textcase = address[:textcase]
|
112
|
+
coordinates = address[:coordinates]
|
113
|
+
taxability = address[:taxability]
|
114
|
+
|
115
|
+
#Set parms passed by user - If Nil then default else use passed value
|
116
|
+
@addresscode = addresscode == nil ? "123" : addresscode
|
117
|
+
@line1 = line1 == nil ? "" : line1
|
118
|
+
@line2 = line2 == nil ? "" : line2
|
119
|
+
@line3 = line3 == nil ? "" : line3
|
120
|
+
@city = city == nil ? "" : city
|
121
|
+
@region = region == nil ? "" : region
|
122
|
+
@postalcode = postalcode == nil ? "" : postalcode
|
123
|
+
@country = country == nil ? "" : country
|
124
|
+
@taxregionid = taxregionid == nil ? "0" : taxregionid
|
125
|
+
@latitude = latitude == nil ? "" : latitude
|
126
|
+
@longitude = longitude == nil ? "" : longitude
|
127
|
+
@textcase = textcase == nil ? "Default" : textcase
|
128
|
+
@coordinates = coordinates == nil ? "true" : coordinates
|
129
|
+
@taxability = taxability == nil ? "false" : taxability
|
130
|
+
|
131
|
+
# Subsitute real vales for template place holders
|
132
|
+
@soap = @template_validate.result(binding)
|
133
|
+
|
134
|
+
#Clear return hash
|
135
|
+
@return_data.clear
|
136
|
+
|
137
|
+
# Make the call to the Avalara Validate service
|
138
|
+
begin
|
139
|
+
@response = @client.call(:validate, xml: @soap).to_s
|
140
|
+
|
141
|
+
rescue
|
142
|
+
@log.puts "#{Time.now}: Error calling Validate service ... check username and password"
|
143
|
+
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
|
146
155
|
end
|
147
|
-
|
156
|
+
|
148
157
|
############################################################################################################
|
149
158
|
#Verifies connectivity to the web service and returns version information about the service.
|
150
159
|
############################################################################################################
|
151
160
|
def isauthorized(operation = nil)
|
152
161
|
#Read in the SOAP template
|
153
|
-
@operation = operation == nil ? "?" : operation
|
162
|
+
@operation = operation == nil ? "?" : operation
|
154
163
|
|
155
|
-
# Subsitute real vales for template place holders
|
164
|
+
# Subsitute real vales for template place holders
|
156
165
|
@soap = @template_isauthorized.result(binding)
|
157
|
-
|
158
|
-
|
166
|
+
|
167
|
+
#Clear return hash
|
159
168
|
@return_data.clear
|
160
|
-
|
169
|
+
|
161
170
|
# Make the call to the Avalara Ping service
|
162
171
|
begin
|
163
172
|
@response = @client.call(:is_authorized, xml: @soap).to_s
|
164
|
-
|
165
|
-
|
173
|
+
rescue
|
174
|
+
@log.puts "#{Time.now}: Error calling IsAuthorized service ... check username and password"
|
166
175
|
end
|
167
|
-
|
176
|
+
|
168
177
|
# Load the response into a Nokogiri object and remove namespaces
|
169
|
-
@doc = Nokogiri::XML(@response).remove_namespaces!
|
170
|
-
|
171
|
-
#Read in an array of XPATH pointers
|
178
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
179
|
+
|
180
|
+
#Read in an array of XPATH pointers
|
172
181
|
@isauthorized_xpath = File.readlines(@def_locn + '\xpath_isauthorized.txt')
|
173
|
-
|
182
|
+
|
174
183
|
#Read each array element, extract the result returned by the service and place in a the @return_data hash
|
175
184
|
@isauthorized_xpath.each{|xpath| @return_data[xpath[2...xpath.length].chomp.to_sym] = @doc.xpath(xpath).text}
|
176
|
-
|
185
|
+
|
177
186
|
return @return_data
|
178
187
|
end
|
179
|
-
end
|
188
|
+
end
|
180
189
|
end
|
data/test/test_address.rb
CHANGED
@@ -3,6 +3,12 @@ require 'avatax_addressservice'
|
|
3
3
|
#require green_shoes for the GUI
|
4
4
|
require 'green_shoes'
|
5
5
|
|
6
|
+
#Create new Credentials hash object
|
7
|
+
credentials = Hash.new
|
8
|
+
|
9
|
+
#Create new Address hash object
|
10
|
+
address = Hash.new
|
11
|
+
|
6
12
|
Shoes.app :width => 400, :height => 400 do
|
7
13
|
background orange
|
8
14
|
border("#BE8",
|
@@ -11,19 +17,21 @@ Shoes.app :width => 400, :height => 400 do
|
|
11
17
|
para
|
12
18
|
para "Enter Avalara credentials"
|
13
19
|
para "Username:"
|
14
|
-
@username = edit_line
|
20
|
+
@username = edit_line text: "USERNAME"
|
15
21
|
para "Password:"
|
16
|
-
@password = edit_line :secret => true
|
22
|
+
@password = edit_line text: "PASSWORD", :secret => true
|
17
23
|
para
|
18
24
|
@confirm = button "Confirm"
|
19
25
|
para
|
20
26
|
@confirm.click {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
27
|
+
credentials[:username] = @username.text
|
28
|
+
credentials[:password] = @password.text
|
29
|
+
credentials[:name] = 'Avalara Inc.'
|
30
|
+
credentials[:clientname] = 'MyShoppingCart'
|
31
|
+
credentials[:adapter] = 'Avatax SDK for Ruby 1.0.5'
|
32
|
+
credentials[:machine] = 'Lenovo W520 Windows 7'
|
25
33
|
#Create an address service instance
|
26
|
-
AddrService = AvaTax::AddressService.new(
|
34
|
+
AddrService = AvaTax::AddressService.new(credentials)
|
27
35
|
|
28
36
|
#Open a window to get the address to validate
|
29
37
|
Shoes.app :width => 400, :height => 700, :title => "Avalara - Address Validation Tester" do
|
@@ -59,10 +67,19 @@ Shoes.app :width => 400, :height => 400 do
|
|
59
67
|
|
60
68
|
#When the user clicks the Validate button then call the Validate service
|
61
69
|
@validate.click {
|
70
|
+
address[:line1] = @line1.text
|
71
|
+
address[:line2] = @line2.text
|
72
|
+
address[:line3] = @line3.text
|
73
|
+
address[:city] = @city.text
|
74
|
+
address[:region] = @state.text
|
75
|
+
address[:postalcode] = @zip.text
|
76
|
+
address[:country]= @country.text
|
77
|
+
address[:textcase] = @textcase
|
78
|
+
address[:addresscode] = "123"
|
79
|
+
|
80
|
+
#Call the validate service - passing the address as a Hash
|
62
81
|
|
63
|
-
|
64
|
-
#Call the validate service
|
65
|
-
val_addr = AddrService.validate(nil, @line1.text, nil, nil, @city.text, @state.text, @zip.text, 'US', nil, nil, nil, @textcase, nil, nil)
|
82
|
+
val_addr = AddrService.validate(address)
|
66
83
|
|
67
84
|
|
68
85
|
if val_addr[:ResultCode] == "Success"
|
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.
|
4
|
+
version: 1.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|