taxjar-ruby 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a24105fb53dc4c4d32428f281018b7d38462860b
4
- data.tar.gz: cbf114a54aa13bcc1e0bd16b2d05e743a74970dd
3
+ metadata.gz: de60a587fe7825100a642391d002f1c99d52f0ab
4
+ data.tar.gz: e92d5eec0d405dfe7ac2de168bbb996d714fb687
5
5
  SHA512:
6
- metadata.gz: aac27c83a06389a8fde8dca6e51ea7cd8446bea7693a32a2d4ea6c5fd2f04113f158850a09d02f5ae19b9d929705868e67c9a533bb4833bfa7cea3e42127858f
7
- data.tar.gz: 9913a9425272d1d1be3608c754d01eead9bd3d56bc50126f3e4ad360136b89002123d79b8dfcc1d78ef21abecc168dd7770cb714a3f1ee43826a9758a86ee83e
6
+ metadata.gz: 99d505a853e4c8d01f1126ff3f5dbfb8698a3e2dbc63bb14ff9fcd431cd196d9a73e584775587cc61d101b1b78e26b80eb8212ae5a478903530d6d226cf705d4
7
+ data.tar.gz: 6ea9d5d6d01e8235f2d2d47e5e4e21c5a2388e83ddb05bbdf4b09611bcbef0595b79bf3f522cd16fed2cde859134b8860ca0c9bdf90704e898d8f8c214eca6de
data/.travis.yml CHANGED
@@ -6,4 +6,7 @@ rvm:
6
6
  - "2.1"
7
7
  - "2.2"
8
8
 
9
- script: bundle exec rspec
9
+ script: bundle exec rspec
10
+
11
+ before_install:
12
+ - gem install bundler
data/README.md CHANGED
@@ -776,6 +776,109 @@ client.delete_refund(321)
776
776
  }>
777
777
  ```
778
778
 
779
+ ### Validate a VAT number
780
+
781
+ #### Definition
782
+
783
+ ```ruby
784
+ client.validate
785
+ ```
786
+
787
+ #### Example Request
788
+
789
+ ```ruby
790
+ require 'taxjar'
791
+ client = Taxjar::Client.new(api_key: '9e0cd62a22f451701f29c3bde214')
792
+
793
+ validation = client.validate({
794
+ :vat => 'FR40303265045'
795
+ })
796
+ ```
797
+
798
+ #### Example Response
799
+
800
+ ```ruby
801
+ #<Taxjar::Validation @attrs={
802
+ :valid => true,
803
+ :exists => true,
804
+ :vies_available => true,
805
+ :vies_response => {
806
+ :country_code => "FR",
807
+ :vat_number => "40303265045",
808
+ :request_date => "2016-02-10",
809
+ :valid => true,
810
+ :name => "SA SODIMAS",
811
+ :address => "11 RUE AMPERE\n26600 PONT DE L ISERE"
812
+ }
813
+ }>
814
+ ```
815
+
816
+ ### Summarize tax rates for all regions
817
+
818
+ #### Definition
819
+
820
+ ```ruby
821
+ client.summary_rates
822
+ ```
823
+
824
+ #### Example Request
825
+
826
+ ```ruby
827
+ require 'taxjar'
828
+ client = Taxjar::Client.new(api_key: '9e0cd62a22f451701f29c3bde214')
829
+
830
+ summarized_rates = client.summary_rates
831
+ ```
832
+
833
+ #### Example Response
834
+
835
+ ```ruby
836
+ [
837
+ {
838
+ :country_code => "US",
839
+ :country => "United States",
840
+ :region_code => "CA",
841
+ :region => "California",
842
+ :minimum_rate => {
843
+ :label => "State Tax",
844
+ :rate => 0.065
845
+ },
846
+ :average_rate => {
847
+ :label => "Tax",
848
+ :rate => 0.0827
849
+ }
850
+ },
851
+ {
852
+ :country_code => "CA",
853
+ :country => "Canada",
854
+ :region_code => "BC",
855
+ :region => "British Columbia",
856
+ :minimum_rate => {
857
+ :label => "GST",
858
+ :rate => 0.05
859
+ },
860
+ :average_rate => {
861
+ :label => "PST",
862
+ :rate => 0.12
863
+ }
864
+ },
865
+ {
866
+ :country_code => "UK",
867
+ :country => "United Kingdom",
868
+ :region_code => nil,
869
+ :region => nil,
870
+ :minimum_rate => {
871
+ :label => "VAT",
872
+ :rate => 0.2
873
+ },
874
+ :average_rate => {
875
+ :label => "VAT",
876
+ :rate => 0.2
877
+ }
878
+ }
879
+ ]
880
+ ```
881
+
779
882
  ## Tests
780
883
 
781
884
  An RSpec test suite is available to ensure API functionality:
data/lib/taxjar.rb CHANGED
@@ -8,7 +8,9 @@ require "taxjar/order"
8
8
  require "taxjar/rate"
9
9
  require "taxjar/refund"
10
10
  require "taxjar/shipping"
11
+ require "taxjar/summary_rate"
11
12
  require "taxjar/tax"
13
+ require "taxjar/validation"
12
14
  require "taxjar/version"
13
15
 
14
16
  module Taxjar
@@ -8,12 +8,20 @@ module Taxjar
8
8
  perform_get_with_objects("/v2/categories", 'categories', options, Taxjar::Category)
9
9
  end
10
10
 
11
- def rates_for_location(postal_code, options ={})
11
+ def rates_for_location(postal_code, options = {})
12
12
  perform_get_with_object("/v2/rates/#{postal_code}", 'rate', options, Taxjar::Rate)
13
13
  end
14
14
 
15
15
  def tax_for_order(options = {})
16
16
  perform_post_with_object("/v2/taxes", 'tax', options, Taxjar::Tax)
17
17
  end
18
+
19
+ def validate(options = {})
20
+ perform_get_with_object("/v2/validation", 'validation', options, Taxjar::Validation)
21
+ end
22
+
23
+ def summary_rates(options = {})
24
+ perform_get_with_objects("/v2/summary_rates", 'summary_rates', options, Taxjar::SummaryRate)
25
+ end
18
26
  end
19
27
  end
@@ -0,0 +1,29 @@
1
+ require 'taxjar/base'
2
+
3
+ module Taxjar
4
+ class SummaryRate < Taxjar::Base
5
+ extend ModelAttribute
6
+
7
+ attribute :country_code, :string
8
+ attribute :country, :string
9
+ attribute :region_code, :string
10
+ attribute :region, :string
11
+
12
+ class MinimumRate < SummaryRate
13
+ extend ModelAttribute
14
+
15
+ attribute :label, :string
16
+ attribute :rate, :float
17
+ end
18
+
19
+ class AverageRate < SummaryRate
20
+ extend ModelAttribute
21
+
22
+ attribute :label, :string
23
+ attribute :rate, :float
24
+ end
25
+
26
+ object_attr_reader MinimumRate, :minimum_rate
27
+ object_attr_reader AverageRate, :average_rate
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ require 'taxjar/base'
2
+
3
+ module Taxjar
4
+ class Validation < Taxjar::Base
5
+ extend ModelAttribute
6
+
7
+ attribute :valid, :boolean
8
+ attribute :exists, :boolean
9
+ attribute :vies_available, :boolean
10
+
11
+ class ViesResponse < Validation
12
+ extend ModelAttribute
13
+
14
+ attribute :vat_number, :string
15
+ attribute :request_date, :string
16
+ attribute :valid, :boolean
17
+ attribute :name, :string
18
+ attribute :address, :string
19
+ end
20
+
21
+ object_attr_reader ViesResponse, :vies_response
22
+ end
23
+ end
@@ -6,11 +6,11 @@ module Taxjar
6
6
  end
7
7
 
8
8
  def minor
9
- 2
9
+ 3
10
10
  end
11
11
 
12
12
  def patch
13
- 2
13
+ 0
14
14
  end
15
15
 
16
16
  def pre
@@ -0,0 +1,46 @@
1
+ {
2
+ "summary_rates": [
3
+ {
4
+ "country_code": "US",
5
+ "country": "United States",
6
+ "region_code": "CA",
7
+ "region": "California",
8
+ "minimum_rate": {
9
+ "label": "State Tax",
10
+ "rate": 0.065
11
+ },
12
+ "average_rate": {
13
+ "label": "Tax",
14
+ "rate": 0.0827
15
+ }
16
+ },
17
+ {
18
+ "country_code": "CA",
19
+ "country": "Canada",
20
+ "region_code": "BC",
21
+ "region": "British Columbia",
22
+ "minimum_rate": {
23
+ "label": "GST",
24
+ "rate": 0.05
25
+ },
26
+ "average_rate": {
27
+ "label": "PST",
28
+ "rate": 0.12
29
+ }
30
+ },
31
+ {
32
+ "country_code": "UK",
33
+ "country": "United Kingdom",
34
+ "region_code": null,
35
+ "region": null,
36
+ "minimum_rate": {
37
+ "label": "VAT",
38
+ "rate": 0.2
39
+ },
40
+ "average_rate": {
41
+ "label": "VAT",
42
+ "rate": 0.2
43
+ }
44
+ }
45
+ ]
46
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "validation": {
3
+ "valid": true,
4
+ "exists": true,
5
+ "vies_available": true,
6
+ "vies_response": {
7
+ "country_code": "FR",
8
+ "vat_number": "40303265045",
9
+ "request_date": "2016-02-10",
10
+ "valid": true,
11
+ "name": "SA SODIMAS",
12
+ "address": "11 RUE AMPERE\n26600 PONT DE L ISERE"
13
+ }
14
+ }
15
+ }
@@ -156,4 +156,59 @@ describe Taxjar::API do
156
156
  expect(tax.breakdown.line_items[0].special_tax_rate).to eq(0)
157
157
  end
158
158
  end
159
+
160
+ describe '#validate' do
161
+ before do
162
+ @params = 'vat=FR40303265045'
163
+ stub_get("/v2/validation?#{@params}").to_return(body: fixture('validation.json'),
164
+ headers: {content_type: 'application/json; charset=utf-8'})
165
+ @validation = {
166
+ :vat => 'FR40303265045'
167
+ }
168
+ end
169
+
170
+ it 'requests the right resource' do
171
+ @client.validate(@validation)
172
+ expect(a_get("/v2/validation?#{@params}")).to have_been_made
173
+ end
174
+
175
+ it 'returns the requested validation' do
176
+ validation = @client.validate(@validation)
177
+ expect(validation).to be_a Taxjar::Validation
178
+ expect(validation.valid).to eq(true)
179
+ expect(validation.exists).to eq(true)
180
+ expect(validation.vies_available).to eq(true)
181
+ expect(validation.vies_response.vat_number).to eq('40303265045')
182
+ expect(validation.vies_response.request_date).to eq('2016-02-10')
183
+ expect(validation.vies_response.valid).to eq(true)
184
+ expect(validation.vies_response.name).to eq('SA SODIMAS')
185
+ expect(validation.vies_response.address).to eq("11 RUE AMPERE\n26600 PONT DE L ISERE")
186
+ end
187
+ end
188
+
189
+ describe '#summary_rates' do
190
+ before do
191
+ stub_get('/v2/summary_rates').to_return(body: fixture('summary_rates.json'),
192
+ headers: {content_type: 'application/json; charset=utf-8'})
193
+ end
194
+
195
+ it 'requests the right resource' do
196
+ @client.summary_rates
197
+ expect(a_get('/v2/summary_rates')).to have_been_made
198
+ end
199
+
200
+ it 'returns the requested summarized rates' do
201
+ summarized_rates = @client.summary_rates
202
+ expect(summarized_rates).to be_an Array
203
+ expect(summarized_rates.first).to be_a Taxjar::SummaryRate
204
+ expect(summarized_rates.first.country_code).to eq('US')
205
+ expect(summarized_rates.first.country).to eq('United States')
206
+ expect(summarized_rates.first.region_code).to eq('CA')
207
+ expect(summarized_rates.first.region).to eq('California')
208
+ expect(summarized_rates.first.minimum_rate.label).to eq('State Tax')
209
+ expect(summarized_rates.first.minimum_rate.rate).to eq(0.065)
210
+ expect(summarized_rates.first.average_rate.label).to eq('Tax')
211
+ expect(summarized_rates.first.average_rate.rate).to eq(0.0827)
212
+ end
213
+ end
159
214
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taxjar-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TaxJar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-03 00:00:00.000000000 Z
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -126,7 +126,9 @@ files:
126
126
  - lib/taxjar/rate.rb
127
127
  - lib/taxjar/refund.rb
128
128
  - lib/taxjar/shipping.rb
129
+ - lib/taxjar/summary_rate.rb
129
130
  - lib/taxjar/tax.rb
131
+ - lib/taxjar/validation.rb
130
132
  - lib/taxjar/version.rb
131
133
  - spec/fixtures/categories.json
132
134
  - spec/fixtures/order.json
@@ -135,7 +137,9 @@ files:
135
137
  - spec/fixtures/rates_intl.json
136
138
  - spec/fixtures/refund.json
137
139
  - spec/fixtures/refunds.json
140
+ - spec/fixtures/summary_rates.json
138
141
  - spec/fixtures/taxes.json
142
+ - spec/fixtures/validation.json
139
143
  - spec/helper.rb
140
144
  - spec/taxjar/api/api_spec.rb
141
145
  - spec/taxjar/api/order_spec.rb
@@ -165,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
169
  version: '0'
166
170
  requirements: []
167
171
  rubyforge_project:
168
- rubygems_version: 2.4.3
172
+ rubygems_version: 2.4.5.1
169
173
  signing_key:
170
174
  specification_version: 4
171
175
  summary: Ruby wrapper for Taxjar API
@@ -177,7 +181,9 @@ test_files:
177
181
  - spec/fixtures/rates_intl.json
178
182
  - spec/fixtures/refund.json
179
183
  - spec/fixtures/refunds.json
184
+ - spec/fixtures/summary_rates.json
180
185
  - spec/fixtures/taxes.json
186
+ - spec/fixtures/validation.json
181
187
  - spec/helper.rb
182
188
  - spec/taxjar/api/api_spec.rb
183
189
  - spec/taxjar/api/order_spec.rb