Avatax_AddressService 1.0.12 → 2.0.1
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.
- checksums.yaml +5 -13
- data/Avatax_AddressService.gemspec +19 -19
- data/LICENSE.txt +20 -20
- data/lib/address_log.txt +1 -1
- data/lib/{addressservice_dev.wsdl → addressservice.wsdl} +289 -289
- data/lib/avatax_addressservice.rb +187 -199
- data/lib/template_isauthorized.erb +21 -21
- data/lib/template_ping.erb +21 -21
- data/lib/template_validate.erb +39 -39
- data/samples/PingTest.rb +26 -25
- data/samples/ValidateAddressTest.rb +49 -50
- data/spec/addressservice_spec.rb +41 -41
- data/spec/isauthorized_spec.rb +76 -76
- data/spec/ping_spec.rb +76 -76
- data/spec/spec_helper.rb +16 -16
- data/spec/validate_spec.rb +84 -84
- metadata +14 -16
- data/Avatax Ruby SDK Guide.docx +0 -0
- data/lib/addressservice_prd.wsdl +0 -290
|
@@ -1,200 +1,188 @@
|
|
|
1
|
-
require 'savon'
|
|
2
|
-
require 'erb'
|
|
3
|
-
|
|
4
|
-
module AvaTax
|
|
5
|
-
#Avalara address class
|
|
6
|
-
class AddressService
|
|
7
|
-
def initialize(credentials)
|
|
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
|
-
|
|
15
|
-
#Extract data from hash
|
|
16
|
-
username = credentials[:username]
|
|
17
|
-
password = credentials[:password]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@
|
|
30
|
-
@
|
|
31
|
-
@
|
|
32
|
-
@
|
|
33
|
-
@
|
|
34
|
-
@
|
|
35
|
-
|
|
36
|
-
#Open Avatax Error Log
|
|
37
|
-
@log = File.new(@def_locn + '/address_log.txt', "w")
|
|
38
|
-
|
|
39
|
-
#Get service details from WSDL - control_array[2] contains the WSDL read from the address_control file
|
|
40
|
-
#log :false turns off HTTP logging. Select either Dev or Prod depending on the value of the boolean value 'use_production_account'
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
#
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
#
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
#
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
response
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
:helplink => response[:helplink],
|
|
189
|
-
:refersto => response[:refersto],
|
|
190
|
-
:severity => response[:severity],
|
|
191
|
-
:source => response[:source]
|
|
192
|
-
}]
|
|
193
|
-
#remove all the error information from the hash
|
|
194
|
-
response[:messages][0].each do |k,v|
|
|
195
|
-
response.delete(k)
|
|
196
|
-
end
|
|
197
|
-
return response
|
|
198
|
-
end
|
|
199
|
-
end
|
|
1
|
+
require 'savon'
|
|
2
|
+
require 'erb'
|
|
3
|
+
|
|
4
|
+
module AvaTax
|
|
5
|
+
#Avalara address class
|
|
6
|
+
class AddressService
|
|
7
|
+
def initialize(credentials)
|
|
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
|
+
|
|
15
|
+
#Extract data from hash
|
|
16
|
+
username = credentials[:username] || ""
|
|
17
|
+
password = credentials[:password] || ""
|
|
18
|
+
service_url = credentials[:service_url]
|
|
19
|
+
if service_url.nil? or service_url.empty?
|
|
20
|
+
raise ArgumentError, "service_url is required"
|
|
21
|
+
end
|
|
22
|
+
name = credentials[:name] || ""
|
|
23
|
+
clientname = (credentials[:clientname].nil? or credentials[:clientname].empty? ) ? "AvataxRubySDK" : credentials[:clientname]
|
|
24
|
+
adapter = (credentials[:adapter].nil? or credentials[:adapter].empty?) ? spec.summary + spec.version.to_s : credentials[:adapter]
|
|
25
|
+
machine = credentials[:machine] || ""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
#Set credentials and Profile information
|
|
29
|
+
@username = username
|
|
30
|
+
@password = password
|
|
31
|
+
@name = name
|
|
32
|
+
@clientname = clientname
|
|
33
|
+
@adapter = adapter
|
|
34
|
+
@machine = machine
|
|
35
|
+
|
|
36
|
+
#Open Avatax Error Log
|
|
37
|
+
@log = File.new(@def_locn + '/address_log.txt', "w")
|
|
38
|
+
|
|
39
|
+
#Get service details from WSDL - control_array[2] contains the WSDL read from the address_control file
|
|
40
|
+
#log :false turns off HTTP logging. Select either Dev or Prod depending on the value of the boolean value 'use_production_account'
|
|
41
|
+
@log.puts "#{Time.now}: Avalara Address service started"
|
|
42
|
+
#log :false turns off HTTP logging
|
|
43
|
+
@client = Savon.client(wsdl: @def_locn + '/addressservice.wsdl', endpoint: URI.parse(service_url+"/Address/AddressSvc.asmx"), log: false)
|
|
44
|
+
|
|
45
|
+
begin
|
|
46
|
+
#Read in the SOAP template for Ping
|
|
47
|
+
@template_ping = ERB.new(File.read(@def_locn + '/template_ping.erb'))
|
|
48
|
+
rescue
|
|
49
|
+
@log.puts "#{Time.now}: Error loading the Ping template"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
begin
|
|
53
|
+
#Read in the SOAP template for Validate
|
|
54
|
+
@template_validate = ERB.new(File.read(@def_locn + '/template_validate.erb'))
|
|
55
|
+
rescue
|
|
56
|
+
@log.puts "#{Time.now}: Error loading the Validate template"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
begin
|
|
60
|
+
#Read in the SOAP template for IsAuthorized
|
|
61
|
+
@template_isauthorized = ERB.new(File.read(@def_locn + '/template_isauthorized.erb'))
|
|
62
|
+
rescue
|
|
63
|
+
@log.puts "#{Time.now}: Error loading the IsAuthorized template"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Create hash for result
|
|
67
|
+
@response = Hash.new
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
############################################################################################################
|
|
71
|
+
# ping - Verifies connectivity to the web service and returns version information
|
|
72
|
+
############################################################################################################
|
|
73
|
+
def ping(message = nil)
|
|
74
|
+
|
|
75
|
+
#Read in the SOAP template
|
|
76
|
+
@message = message == nil ? "?" : message
|
|
77
|
+
|
|
78
|
+
# Subsitute real vales for template place holders
|
|
79
|
+
@soap = @template_ping.result(binding)
|
|
80
|
+
|
|
81
|
+
# Make the call to the Avalara Ping service
|
|
82
|
+
begin
|
|
83
|
+
@response = @client.call(:ping, xml: @soap).to_hash
|
|
84
|
+
|
|
85
|
+
#Strip off outer layer of the hash - not needed
|
|
86
|
+
return messages_to_array(@response[:ping_response][:ping_result])
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
#Capture unexpected errors
|
|
90
|
+
rescue Savon::Error => error
|
|
91
|
+
abend(error)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
############################################################################################################
|
|
96
|
+
# validate - call the adddress validation service
|
|
97
|
+
############################################################################################################
|
|
98
|
+
def validate(address)
|
|
99
|
+
|
|
100
|
+
#create instance variables for each entry in input
|
|
101
|
+
address.each do |k,v|
|
|
102
|
+
instance_variable_set("@#{k}",v)
|
|
103
|
+
end
|
|
104
|
+
#set required default values for missing required inputs
|
|
105
|
+
@taxregionid ||= "0"
|
|
106
|
+
@textcase ||= "Default"
|
|
107
|
+
@coordinates ||= false
|
|
108
|
+
@taxability ||= false
|
|
109
|
+
|
|
110
|
+
# Subsitute real values for template place holders
|
|
111
|
+
@soap = @template_validate.result(binding)
|
|
112
|
+
|
|
113
|
+
# Make the call to the Avalara Validate service
|
|
114
|
+
begin
|
|
115
|
+
@response = @client.call(:validate, xml: @soap).to_hash
|
|
116
|
+
|
|
117
|
+
#Strip off outer layer of the hash - not needed
|
|
118
|
+
return messages_to_array(@response[:validate_response][:validate_result])
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
#Capture unexpected errors
|
|
122
|
+
rescue Savon::Error => error
|
|
123
|
+
abend(error)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
############################################################################################################
|
|
128
|
+
#Verifies connectivity to the web service and returns version information about the service.
|
|
129
|
+
############################################################################################################
|
|
130
|
+
def isauthorized(operation = nil)
|
|
131
|
+
|
|
132
|
+
#Read in the SOAP template
|
|
133
|
+
@operation = operation == nil ? "?" : operation
|
|
134
|
+
|
|
135
|
+
# Subsitute real vales for template place holders
|
|
136
|
+
@soap = @template_isauthorized.result(binding)
|
|
137
|
+
|
|
138
|
+
# Make the call to the Avalara Ping service
|
|
139
|
+
begin
|
|
140
|
+
@response = @client.call(:is_authorized, xml: @soap).to_hash
|
|
141
|
+
|
|
142
|
+
#Strip off outer layer of the hash - not needed
|
|
143
|
+
return messages_to_array(@response[:is_authorized_response][:is_authorized_result])
|
|
144
|
+
|
|
145
|
+
#Capture unexpected errors
|
|
146
|
+
rescue Savon::Error => error
|
|
147
|
+
abend(error)
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
private
|
|
152
|
+
############################################################################################################
|
|
153
|
+
# abend - Unexpected error handling
|
|
154
|
+
############################################################################################################
|
|
155
|
+
def abend(error)
|
|
156
|
+
@log.puts "An unexpected error occurred: Response from server = #{error}"
|
|
157
|
+
@log.puts "#{Time.now}: Error calling #{@service} service ... check that your account name and password are correct."
|
|
158
|
+
@response = error.to_hash
|
|
159
|
+
@response[:result_code] = 'Error'
|
|
160
|
+
@response[:summary] = @response[:fault][:faultcode]
|
|
161
|
+
@response[:details] = @response[:fault][:faultstring]
|
|
162
|
+
return messages_to_array(@response)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
############################################################################################################
|
|
166
|
+
#standardizes error message format to an array of messages - nokogiri will collapse a single element array into the response hash.
|
|
167
|
+
############################################################################################################
|
|
168
|
+
def messages_to_array(response)
|
|
169
|
+
if not response[:messages].nil?
|
|
170
|
+
return response
|
|
171
|
+
end
|
|
172
|
+
# add the messages array to the response - if we got here, there was only one error.
|
|
173
|
+
response[:messages] = [{
|
|
174
|
+
:summary => response[:summary],
|
|
175
|
+
:details => response[:details],
|
|
176
|
+
:helplink => response[:helplink],
|
|
177
|
+
:refersto => response[:refersto],
|
|
178
|
+
:severity => response[:severity],
|
|
179
|
+
:source => response[:source]
|
|
180
|
+
}]
|
|
181
|
+
#remove all the error information from the hash
|
|
182
|
+
response[:messages][0].each do |k,v|
|
|
183
|
+
response.delete(k)
|
|
184
|
+
end
|
|
185
|
+
return response
|
|
186
|
+
end
|
|
187
|
+
end
|
|
200
188
|
end
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://avatax.avalara.com/services">
|
|
2
|
-
<soapenv:Header>
|
|
3
|
-
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
|
4
|
-
<wsse:UsernameToken wsu:Id="UsernameToken-7" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
|
|
5
|
-
<wsse:Username><%= @username %></wsse:Username>
|
|
6
|
-
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"><%= @password %></wsse:Password>
|
|
7
|
-
<wsu:Created>2012-03-02T23:41:44.511Z</wsu:Created>
|
|
8
|
-
</wsse:UsernameToken>
|
|
9
|
-
</wsse:Security>
|
|
10
|
-
<ser:Profile>
|
|
11
|
-
<ser:Name><%= @name %></ser:Name>
|
|
12
|
-
<ser:Client><%= @clientname %></ser:Client>
|
|
13
|
-
<ser:Adapter><%= @adapter %></ser:Adapter>
|
|
14
|
-
<ser:Machine><%= @machine %></ser:Machine>
|
|
15
|
-
</ser:Profile>
|
|
16
|
-
</soapenv:Header>
|
|
17
|
-
<soapenv:Body>
|
|
18
|
-
<ser:IsAuthorized>
|
|
19
|
-
<ser:Operations><%= @operation %></ser:Operations>
|
|
20
|
-
</ser:IsAuthorized>
|
|
21
|
-
</soapenv:Body>
|
|
1
|
+
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://avatax.avalara.com/services">
|
|
2
|
+
<soapenv:Header>
|
|
3
|
+
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
|
4
|
+
<wsse:UsernameToken wsu:Id="UsernameToken-7" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
|
|
5
|
+
<wsse:Username><%= @username %></wsse:Username>
|
|
6
|
+
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"><%= @password %></wsse:Password>
|
|
7
|
+
<wsu:Created>2012-03-02T23:41:44.511Z</wsu:Created>
|
|
8
|
+
</wsse:UsernameToken>
|
|
9
|
+
</wsse:Security>
|
|
10
|
+
<ser:Profile>
|
|
11
|
+
<ser:Name><%= @name %></ser:Name>
|
|
12
|
+
<ser:Client><%= @clientname %></ser:Client>
|
|
13
|
+
<ser:Adapter><%= @adapter %></ser:Adapter>
|
|
14
|
+
<ser:Machine><%= @machine %></ser:Machine>
|
|
15
|
+
</ser:Profile>
|
|
16
|
+
</soapenv:Header>
|
|
17
|
+
<soapenv:Body>
|
|
18
|
+
<ser:IsAuthorized>
|
|
19
|
+
<ser:Operations><%= @operation %></ser:Operations>
|
|
20
|
+
</ser:IsAuthorized>
|
|
21
|
+
</soapenv:Body>
|
|
22
22
|
</soapenv:Envelope>
|
data/lib/template_ping.erb
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://avatax.avalara.com/services">
|
|
2
|
-
<soapenv:Header>
|
|
3
|
-
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
|
4
|
-
<wsse:UsernameToken wsu:Id="UsernameToken-7" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
|
|
5
|
-
<wsse:Username><%= @username %></wsse:Username>
|
|
6
|
-
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"><%= @password %></wsse:Password>
|
|
7
|
-
<wsu:Created>2012-03-02T23:41:44.511Z</wsu:Created>
|
|
8
|
-
</wsse:UsernameToken>
|
|
9
|
-
</wsse:Security>
|
|
10
|
-
<ser:Profile>
|
|
11
|
-
<ser:Name><%= @name %></ser:Name>
|
|
12
|
-
<ser:Client><%= @clientname %></ser:Client>
|
|
13
|
-
<ser:Adapter><%= @adapter %></ser:Adapter>
|
|
14
|
-
<ser:Machine><%= @machine %></ser:Machine>
|
|
15
|
-
</ser:Profile>
|
|
16
|
-
</soapenv:Header>
|
|
17
|
-
<soapenv:Body>
|
|
18
|
-
<ser:Ping>
|
|
19
|
-
<ser:Message><%= @ping_message %></ser:Message>
|
|
20
|
-
</ser:Ping>
|
|
21
|
-
</soapenv:Body>
|
|
1
|
+
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://avatax.avalara.com/services">
|
|
2
|
+
<soapenv:Header>
|
|
3
|
+
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
|
4
|
+
<wsse:UsernameToken wsu:Id="UsernameToken-7" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
|
|
5
|
+
<wsse:Username><%= @username %></wsse:Username>
|
|
6
|
+
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"><%= @password %></wsse:Password>
|
|
7
|
+
<wsu:Created>2012-03-02T23:41:44.511Z</wsu:Created>
|
|
8
|
+
</wsse:UsernameToken>
|
|
9
|
+
</wsse:Security>
|
|
10
|
+
<ser:Profile>
|
|
11
|
+
<ser:Name><%= @name %></ser:Name>
|
|
12
|
+
<ser:Client><%= @clientname %></ser:Client>
|
|
13
|
+
<ser:Adapter><%= @adapter %></ser:Adapter>
|
|
14
|
+
<ser:Machine><%= @machine %></ser:Machine>
|
|
15
|
+
</ser:Profile>
|
|
16
|
+
</soapenv:Header>
|
|
17
|
+
<soapenv:Body>
|
|
18
|
+
<ser:Ping>
|
|
19
|
+
<ser:Message><%= @ping_message %></ser:Message>
|
|
20
|
+
</ser:Ping>
|
|
21
|
+
</soapenv:Body>
|
|
22
22
|
</soapenv:Envelope>
|