avalara 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -1
- data/.travis.yml +2 -2
- data/Gemfile.lock +6 -5
- data/{Readme.md → README.md} +1 -1
- data/avalara.gemspec +1 -1
- data/lib/avalara.rb +11 -11
- data/lib/avalara/errors.rb +13 -2
- data/lib/avalara/response/invoice.rb +12 -5
- data/lib/avalara/types/stash.rb +1 -3
- data/lib/avalara/version.rb +1 -1
- data/spec/avalara.yml.example +2 -1
- data/spec/fixtures/net/geographical_tax_no_sales.yml +63 -0
- data/spec/models/avalara_spec.rb +17 -17
- metadata +10 -9
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
avalara (0.0
|
4
|
+
avalara (0.1.0)
|
5
5
|
hashie
|
6
|
-
httparty
|
6
|
+
httparty (~> 0.13.5)
|
7
7
|
multi_json
|
8
8
|
|
9
9
|
GEM
|
@@ -17,11 +17,12 @@ GEM
|
|
17
17
|
diff-lcs (1.1.3)
|
18
18
|
factory_girl (2.5.0)
|
19
19
|
activesupport
|
20
|
-
hashie (
|
21
|
-
httparty (0.
|
22
|
-
|
20
|
+
hashie (3.4.1)
|
21
|
+
httparty (0.13.5)
|
22
|
+
json (~> 1.8)
|
23
23
|
multi_xml (>= 0.5.2)
|
24
24
|
i18n (0.6.0)
|
25
|
+
json (1.8.2)
|
25
26
|
multi_json (1.8.0)
|
26
27
|
multi_xml (0.5.5)
|
27
28
|
rake (0.9.2.2)
|
data/{Readme.md → README.md}
RENAMED
@@ -101,4 +101,4 @@ If you want to contribute, please fork this repo and make a pull request back. I
|
|
101
101
|
|
102
102
|
* [Adam Fortuna](http://github.com/adamfortuna)
|
103
103
|
* [James Cox](http://github.com/adamfortuna)
|
104
|
-
* [Dan Sosedoff](http://github.com/sosedoff)
|
104
|
+
* [Dan Sosedoff](http://github.com/sosedoff)
|
data/avalara.gemspec
CHANGED
data/lib/avalara.rb
CHANGED
@@ -26,7 +26,7 @@ module Avalara
|
|
26
26
|
def self.configure(&block)
|
27
27
|
configuration(&block)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def self.endpoint
|
31
31
|
configuration.endpoint
|
32
32
|
end
|
@@ -54,17 +54,17 @@ module Avalara
|
|
54
54
|
def self.version=(version)
|
55
55
|
configuration.version = version
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def self.geographical_tax(latitude, longitude, sales_amount)
|
59
59
|
uri = [
|
60
|
-
configuration.endpoint,
|
61
|
-
configuration.version,
|
62
|
-
"tax",
|
60
|
+
configuration.endpoint,
|
61
|
+
configuration.version,
|
62
|
+
"tax",
|
63
63
|
"#{latitude},#{longitude}",
|
64
64
|
"get"
|
65
65
|
].join("/")
|
66
|
-
|
67
|
-
response = API.get(uri,
|
66
|
+
|
67
|
+
response = API.get(uri,
|
68
68
|
:headers => API.headers_for('0'),
|
69
69
|
:query => {:saleamount => sales_amount},
|
70
70
|
:basic_auth => authentication
|
@@ -75,11 +75,11 @@ module Avalara
|
|
75
75
|
puts "Timed out"
|
76
76
|
raise TimeoutError
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
def self.get_tax(invoice)
|
80
80
|
uri = [endpoint, version, 'tax', 'get'].join('/')
|
81
81
|
|
82
|
-
response = API.post(uri,
|
82
|
+
response = API.post(uri,
|
83
83
|
:body => invoice.to_json,
|
84
84
|
:headers => API.headers_for(invoice.to_json.length),
|
85
85
|
:basic_auth => authentication
|
@@ -100,10 +100,10 @@ module Avalara
|
|
100
100
|
rescue Exception => e
|
101
101
|
raise Error.new(e)
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
private
|
105
105
|
|
106
106
|
def self.authentication
|
107
107
|
{ :username => username, :password => password}
|
108
108
|
end
|
109
|
-
end
|
109
|
+
end
|
data/lib/avalara/errors.rb
CHANGED
@@ -4,5 +4,16 @@ module Avalara
|
|
4
4
|
Error = Class.new(StandardError)
|
5
5
|
TimeoutError = Class.new(Error)
|
6
6
|
NotImplementedError = Class.new(Error)
|
7
|
-
ApiError
|
8
|
-
|
7
|
+
class ApiError < Class.new(Error) do
|
8
|
+
def initialize(response = nil)
|
9
|
+
@message = response
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def message
|
14
|
+
@message
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
+
require 'hashie/extensions/symbolize_keys'
|
4
|
+
|
3
5
|
module Avalara
|
4
6
|
module Response
|
5
7
|
class Invoice < Avalara::Types::Stash
|
8
|
+
|
6
9
|
property :doc_code, :from => :DocCode
|
7
10
|
property :doc_date, :from => :DocDate
|
8
11
|
property :timestamp, :from => :Timestamp
|
@@ -18,31 +21,35 @@ module Avalara
|
|
18
21
|
property :result_code, :from => :ResultCode
|
19
22
|
property :messages, :from => :Messages
|
20
23
|
|
24
|
+
def initialize(response)
|
25
|
+
super(Hashie::Extensions::SymbolizeKeys.symbolize_keys(response))
|
26
|
+
end
|
27
|
+
|
21
28
|
def success?
|
22
29
|
result_code == 'Success'
|
23
30
|
end
|
24
|
-
|
31
|
+
|
25
32
|
def Messages=(new_messages)
|
26
33
|
self.messages = []
|
27
34
|
new_messages.each do |message|
|
28
35
|
self.messages << Message.new(message)
|
29
36
|
end
|
30
37
|
end
|
31
|
-
|
38
|
+
|
32
39
|
def TaxLines=(lines)
|
33
40
|
self.tax_lines = []
|
34
41
|
lines.each do |line|
|
35
42
|
self.tax_lines << TaxLine.new(line)
|
36
43
|
end
|
37
44
|
end
|
38
|
-
|
45
|
+
|
39
46
|
def TaxAddresses=(addresses)
|
40
47
|
self.tax_addresses = []
|
41
48
|
addresses.each do |address|
|
42
49
|
self.tax_addresses << TaxAddress.new(address)
|
43
50
|
end
|
44
51
|
end
|
45
|
-
|
52
|
+
|
46
53
|
end
|
47
54
|
end
|
48
|
-
end
|
55
|
+
end
|
data/lib/avalara/types/stash.rb
CHANGED
data/lib/avalara/version.rb
CHANGED
data/spec/avalara.yml.example
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: https://%{API_USERNAME}:%{API_PASSWORD}@development.avalara.net:443/1.0/tax/47.627935,-122.51702/get?saleamount=100
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
accept:
|
9
|
+
- application/json
|
10
|
+
content-type:
|
11
|
+
- text/json
|
12
|
+
date:
|
13
|
+
- Tue, 09 Jun 2015 16:05:47 GMT
|
14
|
+
user-agent:
|
15
|
+
- avalara/0.1.0 (Rubygems; Ruby 2.2.1 x86_64-darwin14)
|
16
|
+
content-length:
|
17
|
+
- '0'
|
18
|
+
response: !ruby/struct:VCR::Response
|
19
|
+
status: !ruby/struct:VCR::ResponseStatus
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
cache-control:
|
24
|
+
- private
|
25
|
+
content-type:
|
26
|
+
- text/json; charset=utf-8
|
27
|
+
server:
|
28
|
+
- Microsoft-IIS/7.5
|
29
|
+
x-aspnet-version:
|
30
|
+
- 4.0.30319
|
31
|
+
x-powered-by:
|
32
|
+
- ASP.NET
|
33
|
+
date:
|
34
|
+
- Tue, 09 Jun 2015 16:05:41 GMT
|
35
|
+
content-length:
|
36
|
+
- '397'
|
37
|
+
body: |
|
38
|
+
{
|
39
|
+
"Rate": 0.087,
|
40
|
+
"Tax": 8.7,
|
41
|
+
"TaxDetails": [
|
42
|
+
{
|
43
|
+
"Country": "US",
|
44
|
+
"Region": "WA",
|
45
|
+
"JurisType": "State",
|
46
|
+
"JurisCode": "53",
|
47
|
+
"Rate": 0.065,
|
48
|
+
"Tax": 6.5,
|
49
|
+
"JurisName": "WASHINGTON",
|
50
|
+
"TaxName": "WA STATE TAX"}
|
51
|
+
,{
|
52
|
+
"Country": "US",
|
53
|
+
"Region": "WA",
|
54
|
+
"JurisType": "City",
|
55
|
+
"JurisCode": "03736",
|
56
|
+
"Rate": 0.022,
|
57
|
+
"Tax": 2.2,
|
58
|
+
"JurisName": "BAINBRIDGE ISLAND",
|
59
|
+
"TaxName": "WA CITY TAX"}
|
60
|
+
]
|
61
|
+
,
|
62
|
+
"ResultCode": "Success"}
|
63
|
+
http_version: '1.1'
|
data/spec/models/avalara_spec.rb
CHANGED
@@ -66,7 +66,7 @@ describe Avalara do
|
|
66
66
|
}.to change(configuration, :username).to('username')
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
describe '.password' do
|
71
71
|
it 'returns the configuration password' do
|
72
72
|
configuration.password = 'password'
|
@@ -98,7 +98,7 @@ describe Avalara do
|
|
98
98
|
let(:invoice) { Factory.build_via_new(:invoice, doc_date: doc_date) }
|
99
99
|
let(:request) { Avalara.get_tax(invoice) }
|
100
100
|
subject { request }
|
101
|
-
|
101
|
+
|
102
102
|
context 'failure' do
|
103
103
|
let(:invoice) { Factory.build_via_new(:invoice, customer_code: nil) }
|
104
104
|
use_vcr_cassette 'get_tax/failure'
|
@@ -106,7 +106,7 @@ describe Avalara do
|
|
106
106
|
it 'rasises an error' do
|
107
107
|
expect { subject }.to raise_error(Avalara::ApiError)
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
context 'the returned error' do
|
111
111
|
subject do
|
112
112
|
begin
|
@@ -115,7 +115,7 @@ describe Avalara do
|
|
115
115
|
e.message.messages.first
|
116
116
|
end
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
its(:details) { should == "This value must be specified." }
|
120
120
|
its(:refers_to) { should == "CustomerCode" }
|
121
121
|
its(:severity) { should == "Error" }
|
@@ -123,7 +123,7 @@ describe Avalara do
|
|
123
123
|
its(:summary) { should == "CustomerCode is required." }
|
124
124
|
end
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
context 'on timeout' do
|
128
128
|
it 'raises an avalara timeout error' do
|
129
129
|
Avalara::API.should_receive(:post).and_raise(Timeout::Error)
|
@@ -133,9 +133,9 @@ describe Avalara do
|
|
133
133
|
|
134
134
|
context 'success' do
|
135
135
|
use_vcr_cassette 'get_tax/success'
|
136
|
-
|
136
|
+
|
137
137
|
it { should be_kind_of Avalara::Response::Invoice }
|
138
|
-
|
138
|
+
|
139
139
|
its(:doc_code) { should_not be_nil }
|
140
140
|
its(:doc_date) { should == "2012-01-01" }
|
141
141
|
its(:result_code) { should == "Success" }
|
@@ -146,7 +146,7 @@ describe Avalara do
|
|
146
146
|
its(:total_exemption) { should == "10" }
|
147
147
|
its(:total_tax) { should == "0" }
|
148
148
|
its(:total_tax_calculated) { should == "0" }
|
149
|
-
|
149
|
+
|
150
150
|
it 'returns 1 tax line' do
|
151
151
|
subject.tax_lines.length.should == 1
|
152
152
|
end
|
@@ -154,11 +154,11 @@ describe Avalara do
|
|
154
154
|
it 'returns 1 tax address' do
|
155
155
|
subject.tax_addresses.length.should == 1
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
context 'the returned tax line' do
|
159
159
|
let(:tax_line) { request.tax_lines.first }
|
160
160
|
subject { tax_line }
|
161
|
-
|
161
|
+
|
162
162
|
its(:line_no) { should == "1" }
|
163
163
|
its(:tax_code) { should == "P0000000" }
|
164
164
|
its(:taxability) { should == "true" }
|
@@ -168,11 +168,11 @@ describe Avalara do
|
|
168
168
|
its(:discount) { should == "0" }
|
169
169
|
its(:tax_calculated) { should == "0" }
|
170
170
|
its(:exemption) { should == "10" }
|
171
|
-
|
171
|
+
|
172
172
|
it 'returns 1 tax detail' do
|
173
173
|
subject.tax_details.length.should == 1
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
context 'the returned tax detail' do
|
177
177
|
subject { tax_line.tax_details.first }
|
178
178
|
|
@@ -189,16 +189,16 @@ describe Avalara do
|
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
192
|
+
## Missing VCR
|
192
193
|
describe '.geographical_tax' do
|
193
194
|
let(:latitude) { '47.627935' }
|
194
195
|
let(:longitude) { '-122.51702' }
|
195
196
|
let(:sales_amount) { 100 }
|
196
197
|
|
197
198
|
subject { Avalara.geographical_tax(latitude, longitude, sales_amount) }
|
199
|
+
|
198
200
|
use_vcr_cassette 'geographical_tax_no_sales'
|
199
|
-
|
200
|
-
|
201
|
-
expect { subject }.to raise_error(Avalara::NotImplementedError)
|
202
|
-
end
|
201
|
+
|
202
|
+
its(:rate) { should == 0.087 }
|
203
203
|
end
|
204
|
-
end
|
204
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avalara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
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:
|
12
|
+
date: 2015-06-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hashie
|
@@ -32,17 +32,17 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: 0.13.5
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 0.13.5
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: multi_json
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,8 +138,8 @@ files:
|
|
138
138
|
- Gemfile
|
139
139
|
- Gemfile.lock
|
140
140
|
- LICENSE
|
141
|
+
- README.md
|
141
142
|
- Rakefile
|
142
|
-
- Readme.md
|
143
143
|
- avalara.gemspec
|
144
144
|
- lib/avalara.rb
|
145
145
|
- lib/avalara/api.rb
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- spec/factories/detail_levels.rb
|
168
168
|
- spec/factories/invoices.rb
|
169
169
|
- spec/factories/lines.rb
|
170
|
+
- spec/fixtures/net/geographical_tax_no_sales.yml
|
170
171
|
- spec/fixtures/net/get_tax/failure.yml
|
171
172
|
- spec/fixtures/net/get_tax/success.yml
|
172
173
|
- spec/models/avalara/configuration_spec.rb
|
@@ -199,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
200
|
version: '0'
|
200
201
|
requirements: []
|
201
202
|
rubyforge_project:
|
202
|
-
rubygems_version: 1.8.23
|
203
|
+
rubygems_version: 1.8.23.2
|
203
204
|
signing_key:
|
204
205
|
specification_version: 3
|
205
206
|
summary: A Ruby interface to the Avalara Tax API
|
@@ -209,6 +210,7 @@ test_files:
|
|
209
210
|
- spec/factories/detail_levels.rb
|
210
211
|
- spec/factories/invoices.rb
|
211
212
|
- spec/factories/lines.rb
|
213
|
+
- spec/fixtures/net/geographical_tax_no_sales.yml
|
212
214
|
- spec/fixtures/net/get_tax/failure.yml
|
213
215
|
- spec/fixtures/net/get_tax/success.yml
|
214
216
|
- spec/models/avalara/configuration_spec.rb
|
@@ -221,4 +223,3 @@ test_files:
|
|
221
223
|
- spec/support/avalara.rb
|
222
224
|
- spec/support/factory_girl.rb
|
223
225
|
- spec/support/vcr.rb
|
224
|
-
has_rdoc:
|