Avatax_AddressService 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Avatax_AddressService.gemspec +1 -1
- data/lib/avatax_addressservice.rb +5 -3
- data/test/test_address.rb +104 -90
- metadata +1 -1
@@ -18,9 +18,11 @@ module AvaTax
|
|
18
18
|
@machine = machine == nil ? "" : machine
|
19
19
|
|
20
20
|
#Set @def_locn to the Avatax-x.x.x gem install library. This enables the ruby programs to
|
21
|
-
#find other objects that it needs.
|
22
|
-
|
23
|
-
|
21
|
+
#find other objects that it needs.
|
22
|
+
spec = Gem::Specification.find_by_name("Avatax_AddressService")
|
23
|
+
gem_root = spec.gem_dir
|
24
|
+
@def_locn = gem_root + "/lib"
|
25
|
+
|
24
26
|
#Open Avatax Error Log
|
25
27
|
@log = File.new(@def_locn + '\address_log.txt', "w")
|
26
28
|
@log.puts "#{Time.now}: Address service started"
|
data/test/test_address.rb
CHANGED
@@ -1,105 +1,119 @@
|
|
1
|
-
#Load the Avalara Address Service module
|
1
|
+
#Load the Avalara Address Service module
|
2
2
|
require 'avatax_addressservice'
|
3
3
|
#require green_shoes for the GUI
|
4
4
|
require 'green_shoes'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
para "Line 2:"
|
28
|
-
@line2 = edit_line
|
29
|
-
para "Line 3:"
|
30
|
-
@line3 = edit_line
|
31
|
-
para "City"
|
32
|
-
@city = edit_line width: 100, text: "bainbridge"
|
33
|
-
para "State"
|
34
|
-
@state = edit_line width: 40, text: 'WA'
|
35
|
-
para "Zip"
|
36
|
-
@zip = edit_line width: 60, text: "98110"
|
37
|
-
para "Country"
|
38
|
-
@country = edit_line width: 30, text: "US"
|
39
|
-
para "Textcase"
|
40
|
-
@textcase = "Default"
|
41
|
-
list_box items: ["Default", "Upper", "Mixed"],
|
42
|
-
width: 120, choose: @textcase do |list|
|
43
|
-
@textcase = list.text
|
44
|
-
end
|
45
|
-
@validate = button "Validate"
|
46
|
-
end
|
6
|
+
Shoes.app :width => 400, :height => 400 do
|
7
|
+
background orange
|
8
|
+
border("#BE8",
|
9
|
+
strokewidth: 6)
|
10
|
+
stack(margin: 15) do
|
11
|
+
para
|
12
|
+
para "Enter Avalara credentials"
|
13
|
+
para "Username:"
|
14
|
+
@username = edit_line
|
15
|
+
para "Password:"
|
16
|
+
@password = edit_line :secret => true
|
17
|
+
para
|
18
|
+
@confirm = button "Confirm"
|
19
|
+
para
|
20
|
+
@confirm.click {
|
21
|
+
name = 'Avalara Inc.'
|
22
|
+
clientname = 'MyShoppingCart'
|
23
|
+
adapter = 'Avatax SDK for Ruby 1.0.1'
|
24
|
+
machine = 'Lenovo W520 Windows 7'
|
25
|
+
#Create an address service instance
|
26
|
+
AddrService = AvaTax::AddressService.new(@username.text,@password.text,name,clientname,adapter,machine)
|
47
27
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
Shoes.app :width => 400, :height => 700, :left => 1000, :title => "Avalara - Address Validation Result" do
|
58
|
-
|
59
|
-
background orange..blue
|
60
|
-
|
61
|
-
stack :margin => 10 do
|
62
|
-
#Display result
|
28
|
+
#Open a window to get the address to validate
|
29
|
+
Shoes.app :width => 400, :height => 700, :title => "Avalara - Address Validation Tester" do
|
30
|
+
|
31
|
+
#Set window characteristics
|
32
|
+
background green..orange
|
33
|
+
|
34
|
+
#Get the address to validate from the user
|
35
|
+
stack :margin => 10 do
|
36
|
+
#Get user input
|
63
37
|
para "Line 1:"
|
64
|
-
edit_line :
|
38
|
+
@line1 = edit_line text: "100 rav"
|
65
39
|
para "Line 2:"
|
66
|
-
|
40
|
+
@line2 = edit_line
|
67
41
|
para "Line 3:"
|
68
|
-
|
42
|
+
@line3 = edit_line
|
69
43
|
para "City"
|
70
|
-
edit_line :text
|
44
|
+
@city = edit_line width: 100, text: "bainbridge"
|
71
45
|
para "State"
|
72
|
-
edit_line :
|
73
|
-
para "Zip"
|
74
|
-
edit_line :text
|
46
|
+
@state = edit_line width: 40, text: 'WA'
|
47
|
+
para "Zip"
|
48
|
+
@zip = edit_line width: 60, text: "98110"
|
75
49
|
para "Country"
|
76
|
-
edit_line :
|
50
|
+
@country = edit_line width: 30, text: "US"
|
51
|
+
para "Textcase"
|
52
|
+
@textcase = "Default"
|
53
|
+
list_box items: ["Default", "Upper", "Mixed"],
|
54
|
+
width: 120, choose: @textcase do |list|
|
55
|
+
@textcase = list.text
|
56
|
+
end
|
57
|
+
@validate = button "Validate"
|
77
58
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
59
|
+
|
60
|
+
#When the user clicks the Validate button then call the Validate service
|
61
|
+
@validate.click {
|
62
|
+
|
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)
|
66
|
+
|
67
|
+
|
68
|
+
if val_addr[:ResultCode] == "Success"
|
69
|
+
#Display validated result in a new window
|
70
|
+
Shoes.app :width => 400, :height => 700, :left => 1000, :title => "Avalara - Address Validation Result" do
|
82
71
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
72
|
+
background orange..blue
|
73
|
+
|
74
|
+
stack :margin => 10 do
|
75
|
+
#Display result
|
76
|
+
para "Line 1:"
|
77
|
+
edit_line :text => val_addr[:Line1]
|
78
|
+
para "Line 2:"
|
79
|
+
edit_line :text => val_addr[:Line2]
|
80
|
+
para "Line 3:"
|
81
|
+
edit_line :text => val_addr[:Line3]
|
82
|
+
para "City"
|
83
|
+
edit_line :text => val_addr[:City]
|
84
|
+
para "State"
|
85
|
+
edit_line :text => val_addr[:Region]
|
86
|
+
para "Zip"
|
87
|
+
edit_line :text => val_addr[:PostalCode]
|
88
|
+
para "Country"
|
89
|
+
edit_line :text => val_addr[:Country]
|
90
|
+
end
|
91
|
+
end
|
96
92
|
else
|
97
|
-
#
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
93
|
+
#Display error message in a new window
|
94
|
+
Shoes.app :width => 400, :height => 500, :title => "Address Validation Error" do
|
95
|
+
|
96
|
+
background orange..red
|
97
|
+
|
98
|
+
if val_addr[:ResultCode] == "Error"
|
99
|
+
stack :margin => 10 do
|
100
|
+
#Dispay error details
|
101
|
+
para "RESULT: #{val_addr[:ResultCode]}"
|
102
|
+
para "SUMMARY: #{val_addr[:Summary]}"
|
103
|
+
para "DETAILS: #{val_addr[:Details]}"
|
104
|
+
para "HELP LINK: #{val_addr[:Helplink]}"
|
105
|
+
para "REFERS TO: #{val_addr[:RefersTo]}"
|
106
|
+
para "SEVERITY: #{val_addr[:Severity]}"
|
107
|
+
para "SOURCE #{val_addr[:Source]}"
|
108
|
+
end
|
109
|
+
else
|
110
|
+
#Dispay error details
|
111
|
+
para "RESULT: Error"
|
112
|
+
para "SUMMARY: Unexpected error"
|
113
|
+
para "DETAILS: An unexpected error has occurred ... please check address_log.txt for details"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end}
|
117
|
+
end}
|
118
|
+
end
|
104
119
|
end
|
105
|
-
|