Avatax_TaxService 1.0.9 → 1.0.10

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGVmYmFjNDYyZDFhMDI0MmJiNTE0MmViZWRmZDgxMTFlOGJmMTVmNw==
4
+ MzljMDBmYjY0MTllMGIzNzFjZWMzNjI1Y2YwMmExYmQzOGUyYzZhNg==
5
5
  data.tar.gz: !binary |-
6
- MjAyNjkwNGRjYTY3NDFlODdlNmQ4ZGE0NzQzMmFmNTE4MTEwMTA3YQ==
6
+ Nzg1NTBmYWI1YWE4Nzg5Yjc1OTMyY2U5NDA0MDgzZGYwM2Y5YjBjZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Zjk2YTFiMDIwZTE0OWEyYTc4MmMzMjQ2ODg1Mzk3NmNhZDNkMTA1YjdlYjRi
10
- Mzc0NjQ0ZjM1M2MwYzcxN2M0NDkxZTFlODQ2OTAzNWNlNDM0MDZkZDI2NjAx
11
- MjAxOTg2OTFlNWZlNmE3ODMyZDE0ODM2MWI3OTFlZjcyNGNjZGM=
9
+ ZTk5N2FmYmZiNDNmYTM3MDQwN2Q2MGRiMDE1OTA2MDMzZDlmZDcxY2M3Nzgy
10
+ Y2NiMDU4ZDkxNGMxOGJlOTNhYjA4NTk5YmJkZWRjY2I0YjliZGU2OThhMzVm
11
+ OTA5MzlmY2IwMGEwNzc4MjcwZGVmNjdiYWY4ZDVlODE0Y2FiMGM=
12
12
  data.tar.gz: !binary |-
13
- MTEzMDU2ZGUzM2Q3MTUxZWMxY2I2MmRjYTk2ZjBkNzliZmFiODc5NDU4YmE3
14
- ODBhNjliN2RkMTJhMjEwOTUwMzAxMTU2YTY0NWNjZjBhMzI3MTlmNDAxY2Yx
15
- MWM4YTFlODdhYTMwNDUyYTkyZDgyMmU5MDI0NWY3MThkNWRjMzY=
13
+ OTU1MmRjNTI3NmZlNTVkZjU1YzFlOWQ2MTZlNzNhZWFkMzRlZDBjMjdkMTE5
14
+ ZDliZmUyY2IyNTc3ZDcyNzRhMDNmYWIzMTU0MGNmNmNiYTYwNGNiZjk4MjQx
15
+ MWY3NzcyNzllNjIzMjhmMDMzNDdlZmM0OWE4ZWM2Zjg5MzcxNDk=
@@ -1,20 +1,18 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "Avatax_TaxService"
3
- s.version = "1.0.9"
3
+ s.version = "1.0.10"
4
4
  s.date = "2012-10-28"
5
5
  s.author = "Graham S Wilson"
6
6
  s.email = "support@Avalara.com"
7
- s.summary = "Ruby SDK for Avatax Web Services"
7
+ s.summary = "Avatax SDK for Ruby "
8
8
  s.homepage = "http://www.avalara.com/"
9
9
  s.description = "Ruby SDK provides means of communication with Avatax Web Services."
10
10
  s.license = 'MIT'
11
11
  s.files = ["lib/tax_log.txt", "lib/taxservice_dev.wsdl", "lib/taxservice_prd.wsdl", "lib/avatax_taxservice.rb",
12
12
  "lib/template_adjusttax.erb", "lib/template_canceltax.erb", "lib/template_committax.erb","lib/template_gettax.erb",
13
13
  "lib/template_gettaxhistory.erb","lib/template_isauthorized.erb","lib/template_ping.erb","lib/template_posttax.erb",
14
- "lib/template_reconciletaxhistory.erb","lib/xpath_adjtax.txt","lib/xpath_cancel.txt","lib/xpath_commit.txt","lib/xpath_gettax.txt",
15
- "lib/xpath_gettaxhistory.txt","lib/xpath_isauthorized.txt","lib/xpath_ping.txt","lib/xpath_post.txt","lib/xpath_reconciletaxhistory.txt",
16
- "test/test_adjtax.rb","test/test_gettax.rb","test/test_gettaxhistory.rb","test/test_reconciletaxhistory.rb", "Avatax_TaxService.gemspec",
17
- "Avatax Ruby SDK Guide.docx", "LICENSE.txt"]
14
+ "lib/template_reconciletaxhistory.erb","test/test_adjtax.rb","test/test_gettax.rb","test/test_gettaxhistory.rb",
15
+ "test/test_reconciletaxhistory.rb", "Avatax_TaxService.gemspec","Avatax Ruby SDK Guide.docx", "LICENSE.txt"]
18
16
  s.add_dependency "nokogiri", ">= 1.4.0"
19
17
  s.add_dependency "savon", ">= 2.3.0"
20
18
  s.required_ruby_version = '>= 1.9.1'
@@ -1,12 +1,18 @@
1
1
  require 'savon'
2
2
  require 'erb'
3
- require 'nokogiri'
4
3
  require 'benchmark'
5
4
 
6
5
  module AvaTax
7
6
  #Avalara tax class
8
7
  class TaxService
9
8
  def initialize(credentials)
9
+
10
+ #Retrieve gemspec details
11
+ spec = Gem::Specification.find_by_name("Avatax_TaxService")
12
+ #Set @def_locn to the Avatax-x.x.x gem install library. This enables the ruby programs to
13
+ #find other objects that it needs.
14
+ gem_root = spec.gem_dir
15
+ @def_locn = gem_root + "/lib"
10
16
 
11
17
  #Extract data from hash
12
18
  username = credentials[:username]
@@ -15,31 +21,34 @@ module AvaTax
15
21
  clientname = credentials[:clientname]
16
22
  adapter = credentials[:adapter]
17
23
  machine = credentials[:machine]
24
+ use_production_account = credentials[:use_production_account]
18
25
 
19
26
  #Set credentials and Profile information
20
27
  @username = username == nil ? "" : username
21
28
  @password = password == nil ? "" : password
22
29
  @name = name == nil ? "" : name
23
- @clientname = clientname == nil ? "" : clientname
24
- @adapter = adapter == nil ? "" : adapter
30
+ @clientname = (clientname == nil or clientname == "") ? "Avatax SDK for Ruby Default Client Name" : clientname
31
+ @adapter = (adapter == nil or adapter == "") ? spec.summary + spec.version.to_s : adapter
25
32
  @machine = machine == nil ? "" : machine
33
+ @use_production_account = (use_production_account != true) ? false : use_production_account
26
34
 
27
- #Set @def_locn to the Avatax-x.x.x gem install library. This enables the ruby programs to
28
- #find other objects that it needs.
29
- spec = Gem::Specification.find_by_name("Avatax_TaxService")
30
- gem_root = spec.gem_dir
31
- @def_locn = gem_root + "/lib"
32
35
 
33
36
  #Header for response data
34
37
  @responsetime_hdr = " (User) (System) (Total) (Real)"
35
38
 
36
39
  #Open Avatax Error Log
37
40
  @log = File.new(@def_locn + '/tax_log.txt', "w")
38
- @log.puts "#{Time.now}: Tax service started"
39
41
 
40
42
  #Get service details from WSDL - control_array[2] contains the WSDL read from the address_control file
41
- #log :false turns off HTTP logging
42
- @client = Savon.client(wsdl: @def_locn + '/taxservice_dev.wsdl', log: false)
43
+ #log :false turns off HTTP logging. Select either Dev or Prod depending on the value of the boolean value 'use_production_account'
44
+ if @use_production_account
45
+ @log.puts "#{Time.now}: Avalara Production Tax service started"
46
+ @client = Savon.client(wsdl: @def_locn + '/taxservice_prd.wsdl', log: false)
47
+ else
48
+ @log.puts "#{Time.now}: Avalara Development Tax service started"
49
+ @client = Savon.client(wsdl: @def_locn + '/taxservice_dev.wsdl', log: false)
50
+ end
51
+
43
52
 
44
53
  #Read in the SOAP template for Get tax
45
54
  begin
@@ -105,42 +114,51 @@ module AvaTax
105
114
  end
106
115
 
107
116
  # Create hash for validate result
108
- @return_data = Hash.new
117
+ @response = Hash.new
109
118
  end
110
119
 
111
120
  ####################################################################################################
112
121
  # ping - Verifies connectivity to the web service and returns version information about the service.
113
122
  ####################################################################################################
114
- def ping(message = nil)
115
- #Read in the SOAP template
116
- @message = message == nil ? "?" : message
123
+ def ping(document)
124
+
125
+ @service = 'Ping'
126
+
127
+ #Extract data from document hash
128
+ xtract(document)
117
129
 
118
130
  # Subsitute real vales for template place holders
119
131
  @soap = @template_ping.result(binding)
120
-
121
- #Clear return hash
122
- @return_data.clear
123
-
132
+ if @debug
133
+ @log.puts "#{Time.now}: SOAP request created:"
134
+ @log.puts @soap
135
+ end
136
+
124
137
  # Make the call to the Avalara service
125
138
  begin
126
- @response = @client.call(:ping, xml: @soap).to_s
127
- rescue
128
- @log.puts "#{Time.now}: Error calling Ping service ... check that your account name and password are correct."
129
- end
130
- # Load the response into a Nokogiri object and remove namespaces
131
- @doc = Nokogiri::XML(@response).remove_namespaces!
132
-
133
- #Read in an array of XPATH pointers
134
- @ping_xpath = File.readlines(@def_locn + '/xpath_ping.txt')
135
-
136
- #Parse the returned repsonse and return to caller as a hash
137
- @ping_xpath.each do |xpath|
138
- if xpath.rstrip.length != 0
139
- @return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
139
+ # Call using debug
140
+ if @debug
141
+ # Use Ruby built in Benchmark function to record response times
142
+ @log.puts "#{Time.now}: Calling #{@service} Service"
143
+ time = Benchmark.measure do
144
+ # Call Ping Service
145
+ @response = @client.call(:ping, xml: @soap).to_hash
146
+ end
147
+ @log.puts "Response times for Ping:"
148
+ @log.puts @responsetime_hdr
149
+ @log.puts time
150
+ else
151
+ # Call Ping Service
152
+ @response = @client.call(:ping, xml: @soap).to_hash
140
153
  end
154
+
155
+ return @response
156
+
157
+ #Capture unexpected errors
158
+ rescue Savon::Error => error
159
+ abend(error)
141
160
  end
142
-
143
- return @return_data
161
+
144
162
  end
145
163
 
146
164
  ####################################################################################################
@@ -148,6 +166,8 @@ module AvaTax
148
166
  ####################################################################################################
149
167
  def gettax(document)
150
168
 
169
+ @service = 'GetTax'
170
+
151
171
  #Extract data from document hash
152
172
  xtract(document)
153
173
 
@@ -174,14 +194,12 @@ module AvaTax
174
194
 
175
195
  # Subsitute template place holders with real values
176
196
  @soap = @template_gettax.result(binding)
197
+ # If in debug mode write SOAP request to log
177
198
  if @debug
178
199
  @log.puts "#{Time.now}: SOAP request created:"
179
- @log.puts @soap
200
+ @log.puts @soap
180
201
  end
181
202
 
182
- #Clear return hash
183
- @return_data.clear
184
-
185
203
  # Make the call to the Avalara service
186
204
  begin
187
205
  # Call using debug
@@ -189,53 +207,24 @@ module AvaTax
189
207
  # Use Ruby built in Benchmark function to record response times
190
208
  @log.puts "#{Time.now}: Calling GetTax Service for DocCode: #{@doccode}"
191
209
  time = Benchmark.measure do
192
- # Call GetTax Service
193
- @response = @client.call(:get_tax, xml: @soap).to_s
210
+ # Call GetTax Service
211
+ @response = @client.call(:get_tax, xml: @soap).to_hash
194
212
  end
195
213
  @log.puts "Response times for GetTax:"
196
- @log.puts @responsetime_hdr
197
- @log.puts time
214
+ @log.puts @responsetime_hdr
215
+ @log.puts time
198
216
  else
199
217
  # Call GetTax Service
200
- @response = @client.call(:get_tax, xml: @soap).to_s
218
+ @response = @client.call(:get_tax, xml: @soap).to_hash
201
219
  end
202
- #Capture unexpected errors
203
- rescue
204
- @log.puts "#{Time.now}: Error calling GetTax service ... check that your account name and password are correct."
205
- end
206
-
207
- #Parse the response
208
- #Read in an array of XPATH pointers
209
- @gettax_xpath = File.readlines(@def_locn + '/xpath_gettax.txt')
210
220
 
211
- # Call using debug
212
- if @debug
213
- # Use Ruby built in Benchmark function to record response times
214
- @log.puts "#{Time.now}: Parsing the GeTax response:"
215
- time = Benchmark.measure do
216
- # Load the response into a Nokogiri object and remove namespaces
217
- @doc = Nokogiri::XML(@response).remove_namespaces!
218
- #Parse the returned repsonse and return to caller as a hash
219
- @gettax_xpath.each do |xpath|
220
- if xpath.rstrip.length != 0
221
- @return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
222
- end
223
- end
224
- end
225
- @log.puts @responsetime_hdr
226
- @log.puts time
227
- else
228
- # Load the response into a Nokogiri object and remove namespaces
229
- @doc = Nokogiri::XML(@response).remove_namespaces!
230
- #Parse the returned repsonse and return to caller as a hash
231
- @gettax_xpath.each do |xpath|
232
- if xpath.rstrip.length != 0
233
- @return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
234
- end
235
- end
236
- end
237
221
  #Return data to calling program
238
- return @return_data
222
+ return @response
223
+
224
+ #Capture unexpected errors
225
+ rescue Savon::Error => error
226
+ abend(error)
227
+ end
239
228
  end
240
229
 
241
230
  ####################################################################################################
@@ -243,6 +232,8 @@ module AvaTax
243
232
  ####################################################################################################
244
233
  def adjusttax(document)
245
234
 
235
+ @service = 'AdjustTax'
236
+
246
237
  #Extract data from document hash
247
238
  xtract(document)
248
239
 
@@ -259,8 +250,8 @@ module AvaTax
259
250
  @log.puts "#{Time.now}: Address #{line1}, #{line2}, #{line3}, #{city}, #{region}, #{postalcode}, #{country} failed to validate."
260
251
  end
261
252
  @log.puts "Response times for Address Validation:"
262
- @log.puts @responsetime_hdr
263
- @log.puts time
253
+ @log.puts @responsetime_hdr
254
+ @log.puts time
264
255
  else
265
256
  #Validate with no benchmarking
266
257
  valaddr
@@ -271,12 +262,9 @@ module AvaTax
271
262
  @soap = @template_adjust.result(binding)
272
263
  if @debug
273
264
  @log.puts "#{Time.now}: SOAP request created:"
274
- @log.puts @soap
265
+ @log.puts @soap
275
266
  end
276
267
 
277
- #Clear return hash
278
- @return_data.clear
279
-
280
268
  # Make the call to the Avalara service
281
269
  begin
282
270
  # Call using debug
@@ -285,52 +273,24 @@ module AvaTax
285
273
  @log.puts "#{Time.now}: Calling AdjustTax Service for DocCode: #{@doccode}"
286
274
  time = Benchmark.measure do
287
275
  # Call AdjustTax Service
288
- @response = @client.call(:adjust_tax, xml: @soap).to_s
276
+ @response = @client.call(:adjust_tax, xml: @soap).to_hash
289
277
  end
290
278
  @log.puts "Response times for AdjustTax:"
291
- @log.puts @responsetime_hdr
292
- @log.puts time
279
+ @log.puts @responsetime_hdr
280
+ @log.puts time
293
281
  else
294
- # Call AdjustTax Service
295
- @response = @client.call(:adjust_tax, xml: @soap).to_s
282
+ # Call AdjustTax Service
283
+ @response = @client.call(:adjust_tax, xml: @soap).to_hash
296
284
  end
297
- #Capture unexpected errors
298
- rescue
299
- @log.puts "#{Time.now}: Error calling AdjustTax service ... check that your account name and password are correct."
300
- end
301
285
 
302
- #Parse the response
303
- #Read in an array of XPATH pointers
304
- @adjtax_xpath = File.readlines(@def_locn + '/xpath_adjtax.txt')
305
-
306
- # Call using debug
307
- if @debug
308
- # Use Ruby built in Benchmark function to record response times
309
- @log.puts "#{Time.now}: Parsing the AdjustTax response:"
310
- time = Benchmark.measure do
311
- # Load the response into a Nokogiri object and remove namespaces
312
- @doc = Nokogiri::XML(@response).remove_namespaces!
313
- #Parse the returned repsonse and return to caller as a hash
314
- @adjtax_xpath.each do |xpath|
315
- if xpath.rstrip.length != 0
316
- @return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
317
- end
318
- end
319
- end
320
- @log.puts @responsetime_hdr
321
- @log.puts time
322
- else
323
- # Load the response into a Nokogiri object and remove namespaces
324
- @doc = Nokogiri::XML(@response).remove_namespaces!
325
- #Parse the returned repsonse and return to caller as a hash
326
- @adjtax_xpath.each do |xpath|
327
- if xpath.rstrip.length != 0
328
- @return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
329
- end
330
- end
286
+ #Return data to calling program
287
+ return @response
288
+
289
+ #Capture unexpected errors
290
+ rescue Savon::Error => error
291
+ abend(error)
331
292
  end
332
- #Return data to calling program
333
- return @return_data
293
+
334
294
  end
335
295
 
336
296
  ####################################################################################################
@@ -338,6 +298,8 @@ module AvaTax
338
298
  ####################################################################################################
339
299
  def posttax(document)
340
300
 
301
+ @service = 'PostTax'
302
+
341
303
  #Extract data from document hash
342
304
  xtract(document)
343
305
 
@@ -345,12 +307,9 @@ module AvaTax
345
307
  @soap = @template_post.result(binding)
346
308
  if @debug
347
309
  @log.puts "#{Time.now}: SOAP request created:"
348
- @log.puts @soap
310
+ @log.puts @soap
349
311
  end
350
312
 
351
- #Clear return hash
352
- @return_data.clear
353
-
354
313
  # Make the call to the Avalara service
355
314
  begin
356
315
  # Call using debug
@@ -359,58 +318,32 @@ module AvaTax
359
318
  @log.puts "#{Time.now}: Calling PostTax Service for DocCode: #{@doccode}"
360
319
  time = Benchmark.measure do
361
320
  # Call PostTax Service
362
- @response = @client.call(:post_tax, xml: @soap).to_s
321
+ @response = @client.call(:post_tax, xml: @soap).to_hash
363
322
  end
364
323
  @log.puts "Response times for PostTax:"
365
- @log.puts @responsetime_hdr
366
- @log.puts time
324
+ @log.puts @responsetime_hdr
325
+ @log.puts time
367
326
  else
368
- # Call PostTax Service
369
- @response = @client.call(:post_tax, xml: @soap).to_s
327
+ # Call PostTax Service
328
+ @response = @client.call(:post_tax, xml: @soap).to_hash
370
329
  end
371
- #Capture unexpected errors
372
- rescue
373
- @log.puts "#{Time.now}: Error calling PostTax service ... check that your account name and password are correct."
374
- end
375
-
376
- #Parse the response
377
- #Read in an array of XPATH pointers
378
- @posttax_xpath = File.readlines(@def_locn + '/xpath_post.txt')
379
330
 
380
- # Call using debug
381
- if @debug
382
- # Use Ruby built in Benchmark function to record response times
383
- @log.puts "#{Time.now}: Parsing the PostTax response:"
384
- time = Benchmark.measure do
385
- # Load the response into a Nokogiri object and remove namespaces
386
- @doc = Nokogiri::XML(@response).remove_namespaces!
387
- #Parse the returned repsonse and return to caller as a hash
388
- @posttax_xpath.each do |xpath|
389
- if xpath.rstrip.length != 0
390
- @return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
391
- end
392
- end
393
- end
394
- @log.puts @responsetime_hdr
395
- @log.puts time
396
- else
397
- # Load the response into a Nokogiri object and remove namespaces
398
- @doc = Nokogiri::XML(@response).remove_namespaces!
399
- #Parse the returned repsonse and return to caller as a hash
400
- @posttax_xpath.each do |xpath|
401
- if xpath.rstrip.length != 0
402
- @return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
403
- end
404
- end
405
- end
406
331
  #Return data to calling program
407
- return @return_data
332
+ return @response
333
+
334
+ #Capture unexpected errors
335
+ rescue Savon::Error => error
336
+ abend(error)
337
+ end
338
+
408
339
  end
409
340
 
410
341
  ####################################################################################################
411
342
  # committax - Calls the Avatax CommitTax Service
412
343
  ####################################################################################################
413
344
  def committax(document)
345
+
346
+ @service = 'CommitTax'
414
347
 
415
348
  #Extract data from document hash
416
349
  xtract(document)
@@ -419,12 +352,9 @@ module AvaTax
419
352
  @soap = @template_commit.result(binding)
420
353
  if @debug
421
354
  @log.puts "#{Time.now}: SOAP request created:"
422
- @log.puts @soap
355
+ @log.puts @soap
423
356
  end
424
357
 
425
- #Clear return hash
426
- @return_data.clear
427
-
428
358
  # Make the call to the Avalara service
429
359
  begin
430
360
  # Call using debug
@@ -433,52 +363,23 @@ module AvaTax
433
363
  @log.puts "#{Time.now}: Calling CommitTax Service for DocCode: #{@doccode}"
434
364
  time = Benchmark.measure do
435
365
  # Call CommitTax Service
436
- @response = @client.call(:commit_tax, xml: @soap).to_s
366
+ @response = @client.call(:commit_tax, xml: @soap).to_hash
437
367
  end
438
368
  @log.puts "Response times for CommitTax:"
439
369
  @log.puts @responsetime_hdr
440
370
  @log.puts time
441
371
  else
442
372
  # Call CommitTax Service
443
- @response = @client.call(:commit_tax, xml: @soap).to_s
373
+ @response = @client.call(:commit_tax, xml: @soap).to_hash
444
374
  end
445
- #Capture unexpected errors
446
- rescue
447
- @log.puts "#{Time.now}: Error calling CommitTax service ... check that your account name and password are correct."
448
- end
449
-
450
- #Parse the response
451
- #Read in an array of XPATH pointers
452
- @committax_xpath = File.readlines(@def_locn + '/xpath_commit.txt')
453
375
 
454
- # Call using debug
455
- if @debug
456
- # Use Ruby built in Benchmark function to record response times
457
- @log.puts "#{Time.now}: Parsing the commitTax response:"
458
- time = Benchmark.measure do
459
- # Load the response into a Nokogiri object and remove namespaces
460
- @doc = Nokogiri::XML(@response).remove_namespaces!
461
- #Parse the returned repsonse and return to caller as a hash
462
- @committax_xpath.each do |xpath|
463
- if xpath.rstrip.length != 0
464
- @return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
465
- end
466
- end
467
- end
468
- @log.puts @responsetime_hdr
469
- @log.puts time
470
- else
471
- # Load the response into a Nokogiri object and remove namespaces
472
- @doc = Nokogiri::XML(@response).remove_namespaces!
473
- #Parse the returned repsonse and return to caller as a hash
474
- @Committax_xpath.each do |xpath|
475
- if xpath.rstrip.length != 0
476
- @return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
477
- end
478
- end
479
- end
480
376
  #Return data to calling program
481
- return @return_data
377
+ return @response
378
+
379
+ #Capture unexpected errors
380
+ rescue Savon::Error => error
381
+ abend(error)
382
+ end
482
383
  end
483
384
 
484
385
  ####################################################################################################
@@ -486,6 +387,8 @@ module AvaTax
486
387
  ####################################################################################################
487
388
  def canceltax(document)
488
389
 
390
+ @service = 'CancelTax'
391
+
489
392
  #Extract data from document hash
490
393
  xtract(document)
491
394
 
@@ -493,12 +396,9 @@ module AvaTax
493
396
  @soap = @template_cancel.result(binding)
494
397
  if @debug
495
398
  @log.puts "#{Time.now}: SOAP request created:"
496
- @log.puts @soap
399
+ @log.puts @soap
497
400
  end
498
401
 
499
- #Clear return hash
500
- @return_data.clear
501
-
502
402
  # Make the call to the Avalara service
503
403
  begin
504
404
  # Call using debug
@@ -507,52 +407,23 @@ module AvaTax
507
407
  @log.puts "#{Time.now}: Calling CancelTax Service for DocCode: #{@doccode}"
508
408
  time = Benchmark.measure do
509
409
  # Call CancelTax Service
510
- @response = @client.call(:cancel_tax, xml: @soap).to_s
410
+ @response = @client.call(:cancel_tax, xml: @soap).to_hash
511
411
  end
512
412
  @log.puts "Response times for CancelTax:"
513
- @log.puts @responsetime_hdr
514
- @log.puts time
413
+ @log.puts @responsetime_hdr
414
+ @log.puts time
515
415
  else
516
- # Call CancelTax Service
517
- @response = @client.call(:cancel_tax, xml: @soap).to_s
416
+ # Call CancelTax Service
417
+ @response = @client.call(:cancel_tax, xml: @soap).to_hash
518
418
  end
519
- #Capture unexpected errors
520
- rescue
521
- @log.puts "#{Time.now}: Error calling CancelTax service ... check that your account name and password are correct."
522
- end
523
-
524
- #Parse the response
525
- #Read in an array of XPATH pointers
526
- @canceltax_xpath = File.readlines(@def_locn + '/xpath_cancel.txt')
527
419
 
528
- # Call using debug
529
- if @debug
530
- # Use Ruby built in Benchmark function to record response times
531
- @log.puts "#{Time.now}: Parsing the CancelTax response:"
532
- time = Benchmark.measure do
533
- # Load the response into a Nokogiri object and remove namespaces
534
- @doc = Nokogiri::XML(@response).remove_namespaces!
535
- #Parse the returned repsonse and return to caller as a hash
536
- @canceltax_xpath.each do |xpath|
537
- if xpath.rstrip.length != 0
538
- @return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
539
- end
540
- end
541
- end
542
- @log.puts @responsetime_hdr
543
- @log.puts time
544
- else
545
- # Load the response into a Nokogiri object and remove namespaces
546
- @doc = Nokogiri::XML(@response).remove_namespaces!
547
- #Parse the returned repsonse and return to caller as a hash
548
- @canceltax_xpath.each do |xpath|
549
- if xpath.rstrip.length != 0
550
- @return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
551
- end
552
- end
553
- end
554
420
  #Return data to calling program
555
- return @return_data
421
+ return @response
422
+
423
+ #Capture unexpected errors
424
+ rescue Savon::Error => error
425
+ abend(error)
426
+ end
556
427
  end
557
428
 
558
429
  ####################################################################################################
@@ -560,6 +431,8 @@ module AvaTax
560
431
  ####################################################################################################
561
432
  def gettaxhistory(document)
562
433
 
434
+ @service = 'GetTaxHistory'
435
+
563
436
  #Extract data from document hash
564
437
  xtract(document)
565
438
 
@@ -567,12 +440,9 @@ module AvaTax
567
440
  @soap = @template_gettaxhistory.result(binding)
568
441
  if @debug
569
442
  @log.puts "#{Time.now}: SOAP request created:"
570
- @log.puts @soap
443
+ @log.puts @soap
571
444
  end
572
445
 
573
- #Clear return hash
574
- @return_data.clear
575
-
576
446
  # Make the call to the Avalara service
577
447
  begin
578
448
  # Call using debug
@@ -581,52 +451,23 @@ module AvaTax
581
451
  @log.puts "#{Time.now}: Calling GetTaxHistory Service"
582
452
  time = Benchmark.measure do
583
453
  # Call GetTaxHistory Service
584
- @response = @client.call(:get_tax_history, xml: @soap).to_s
454
+ @response = @client.call(:get_tax_history, xml: @soap).to_hash
585
455
  end
586
456
  @log.puts "Response times for GetTaxHistory:"
587
- @log.puts @responsetime_hdr
588
- @log.puts time
457
+ @log.puts @responsetime_hdr
458
+ @log.puts time
589
459
  else
590
- # Call GetTaxHistory Service
591
- @response = @client.call(:get_tax_history, xml: @soap).to_s
460
+ # Call GetTaxHistory Service
461
+ @response = @client.call(:get_tax_history, xml: @soap).to_hash
592
462
  end
593
- #Capture unexpected errors
594
- rescue
595
- @log.puts "#{Time.now}: Error calling GetTaxHistory service ... check that your account name and password are correct."
596
- end
597
-
598
- #Parse the response
599
- #Read in an array of XPATH pointers
600
- @gettaxhistory_xpath = File.readlines(@def_locn + '/xpath_gettaxhistory.txt')
601
463
 
602
- # Call using debug
603
- if @debug
604
- # Use Ruby built in Benchmark function to record response times
605
- @log.puts "#{Time.now}: Parsing the GetTaxHistory response:"
606
- time = Benchmark.measure do
607
- # Load the response into a Nokogiri object and remove namespaces
608
- @doc = Nokogiri::XML(@response).remove_namespaces!
609
- #Parse the returned repsonse and return to caller as a hash
610
- @gettaxhistory_xpath.each do |xpath|
611
- if xpath.rstrip.length != 0
612
- @return_data[xpath.gsub('/', '').chomp.gsub('"', '').to_sym] = @doc.search(xpath).map{ |n| n.text}
613
- end
614
- end
615
- end
616
- @log.puts @responsetime_hdr
617
- @log.puts time
618
- else
619
- # Load the response into a Nokogiri object and remove namespaces
620
- @doc = Nokogiri::XML(@response).remove_namespaces!
621
- #Parse the returned repsonse and return to caller as a hash
622
- @gettaxhistory_xpath.each do |xpath|
623
- if xpath.rstrip.length != 0
624
- @return_data[xpath.gsub('/', '').chomp.gsub('"', '').to_sym] = @doc.search(xpath).map{ |n| n.text}
625
- end
626
- end
627
- end
628
464
  #Return data to calling program
629
- return @return_data
465
+ return @response
466
+
467
+ #Capture unexpected errors
468
+ rescue Savon::Error => error
469
+ abend(error)
470
+ end
630
471
  end
631
472
 
632
473
  ####################################################################################################
@@ -634,6 +475,9 @@ module AvaTax
634
475
  ####################################################################################################
635
476
  def reconciletaxhistory(document)
636
477
 
478
+
479
+ @service = 'ReconcileTaxHistory'
480
+
637
481
  #Extract data from document hash
638
482
  xtract(document)
639
483
 
@@ -641,12 +485,9 @@ module AvaTax
641
485
  @soap = @template_reconciletaxhistory.result(binding)
642
486
  if @debug
643
487
  @log.puts "#{Time.now}: SOAP request created:"
644
- @log.puts @soap
488
+ @log.puts @soap
645
489
  end
646
490
 
647
- #Clear return hash
648
- @return_data.clear
649
-
650
491
  # Make the call to the Avalara service
651
492
  begin
652
493
  # Call using debug
@@ -655,84 +496,48 @@ module AvaTax
655
496
  @log.puts "#{Time.now}: Calling ReconcileTaxHistory Service"
656
497
  time = Benchmark.measure do
657
498
  # Call ReconcileTaxHistory Service
658
- @response = @client.call(:reconcile_tax_history, xml: @soap).to_s
499
+ @response = @client.call(:reconcile_tax_history, xml: @soap).to_hash
659
500
  end
660
501
  @log.puts "Response times for ReconcileTaxHistory:"
661
502
  @log.puts @responsetime_hdr
662
503
  @log.puts time
663
504
  else
664
505
  # Call ReconcileTaxHistory Service
665
- @response = @client.call(:reconcile_tax_history, xml: @soap).to_s
506
+ @response = @client.call(:reconcile_tax_history, xml: @soap).to_hash
666
507
  end
667
- #Capture unexpected errors
668
- rescue
669
- @log.puts "#{Time.now}: Error calling ReconcileTaxHistory service ... check that your account name and password are correct."
670
- end
671
-
672
- #Parse the response
673
- #Read in an array of XPATH pointers
674
- @reconciletaxhistory_xpath = File.readlines(@def_locn + '/xpath_reconciletaxhistory.txt')
675
508
 
676
- # Call using debug
677
- if @debug
678
- # Use Ruby built in Benchmark function to record response times
679
- @log.puts "#{Time.now}: Parsing the ReconcileTaxHistory response:"
680
- time = Benchmark.measure do
681
- # Load the response into a Nokogiri object and remove namespaces
682
- @doc = Nokogiri::XML(@response).remove_namespaces!
683
- #Parse the returned repsonse and return to caller as a hash
684
- @reconciletaxhistory_xpath.each do |xpath|
685
- if xpath.rstrip.length != 0
686
- @return_data[xpath.gsub('/', '').chomp.gsub('"', '').to_sym] = @doc.search(xpath).map{ |n| n.text}
687
- end
688
- end
689
- end
690
- @log.puts @responsetime_hdr
691
- @log.puts time
692
- else
693
- # Load the response into a Nokogiri object and remove namespaces
694
- @doc = Nokogiri::XML(@response).remove_namespaces!
695
- #Parse the returned repsonse and return to caller as a hash
696
- @reconciletaxhistory_xpath.each do |xpath|
697
- if xpath.rstrip.length != 0
698
- @return_data[xpath.gsub('/', '').chomp.gsub('"', '').to_sym] = @doc.search(xpath).map{ |n| n.text}
699
- end
700
- end
701
- end
702
509
  #Return data to calling program
703
- return @return_data
510
+ return @response
511
+
512
+ #Capture unexpected errors
513
+ rescue Savon::Error => error
514
+ abend(error)
515
+ end
704
516
  end
705
517
 
706
518
  ############################################################################################################
707
519
  # isauthorized - Verifies connectivity to the web service and returns expiry information about the service.
708
520
  ############################################################################################################
709
521
  def isauthorized(operation = nil)
522
+
523
+ @service = 'IsAuthorized'
524
+
710
525
  #Read in the SOAP template
711
526
  @operation = operation == nil ? "?" : operation
712
527
 
713
528
  # Subsitute real vales for template place holders
714
529
  @soap = @template_isauthorized.result(binding)
715
530
 
716
- #Clear return hash
717
- @return_data.clear
718
-
719
531
  # Make the call to the Avalara service
720
532
  begin
721
- @response = @client.call(:is_authorized, xml: @soap).to_s
722
- rescue
723
- @log.puts "#{Time.now}: Error calling IsAuthorized service ... check username and password"
724
- end
725
-
726
- # Load the response into a Nokogiri object and remove namespaces
727
- @doc = Nokogiri::XML(@response).remove_namespaces!
728
-
729
- #Read in an array of XPATH pointers
730
- @isauthorized_xpath = File.readlines(@def_locn + '/xpath_isauthorized.txt')
533
+ @response = @client.call(:is_authorized, xml: @soap).to_hash
731
534
 
732
- #Read each array element, extract the result returned by the service and place in a the @return_data hash
733
- @isauthorized_xpath.each{|xpath| @return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.xpath(xpath).text}
734
-
735
- return @return_data
535
+ return @response
536
+
537
+ #Capture unexpected errors
538
+ rescue Savon::Error => error
539
+ abend(error)
540
+ end
736
541
  end
737
542
 
738
543
  private
@@ -816,6 +621,7 @@ module AvaTax
816
621
  pagesize = document[:pagesize]
817
622
  debug = document[:debug]
818
623
  validate = document[:validate]
624
+ message = document[:message]
819
625
 
820
626
  #Set parms passed by user - If Nil then default else use passed value
821
627
  @companycode = companycode == nil ? "" : companycode
@@ -866,9 +672,22 @@ module AvaTax
866
672
  @lastdoccode = lastdoccode == nil ? "" : lastdoccode
867
673
  @pagesize = pagesize == nil ? "" : pagesize
868
674
  @debug = debug == nil ? false : debug
869
- @message = ""
675
+ @ping_message = message
870
676
 
871
677
  end
872
-
678
+
679
+ ############################################################################################################
680
+ # abend - Unexpected error handling
681
+ ############################################################################################################
682
+ def abend(error)
683
+ @log.puts "An unexpected error occurred: Response from server = #{error}"
684
+ @log.puts "#{Time.now}: Error calling #{@service} service ... check that your account name and password are correct."
685
+ @response = error.to_hash
686
+ @response[:result_code] = 'Error'
687
+ @response[:summary] = @response[:fault][:faultcode]
688
+ @response[:details] = @response[:fault][:faultstring]
689
+ return @response
690
+ end
691
+
873
692
  end
874
693
  end