ziptax 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c03de0d5649f47596a9c9faddaeb2f51aa30501
4
+ data.tar.gz: 7f4ec97a2e2200d2a33f136c7a3f14ffaada37bf
5
+ SHA512:
6
+ metadata.gz: 17bc5d039af1a6db1993176a36a59453ff8fe410214a33b1d2af12bc2cde7da40bad84bda8c520f807ac72d7ab03e54500498a99e3d3f829f464155d711981fb
7
+ data.tar.gz: cda8978e29f8a71fe83eea5574df2316c058886e9fbcd69bf67ddc270ee12fd9e262e531bfb36912b2bb0e364bf736d6c68f63aae6d2f03b9ab2542d1f183343
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zip_tax.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Bryce McDonnell
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # ZipTax
2
+
3
+ Zip-Tax.com provides a very simple API for querying sales and use tax
4
+ rates in most zip codes in the United States. This gem provides a thin
5
+ wrapper around the API to quickly and easily retrieve sales tax rates by
6
+ zip code.
7
+
8
+ [Official documentation for the API](http://docs.zip-tax.com/en/latest/index.html) is hosted by Zip-Tax.
9
+
10
+ You will need an API key to get started (sadly, no free developer accounts exist)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'ziptax'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install ziptax
25
+
26
+ ## Usage
27
+
28
+ Try it out in irb:
29
+
30
+ ```bash
31
+ gem install ziptax
32
+ irb -r ziptax
33
+ ```
34
+ ```ruby
35
+ ZipTax::SalesTax.request_for(key: '<yourkeyhere>', postalcode: '10003')
36
+ # => {
37
+ "version": "v20",
38
+ "rCode": 100,
39
+ "results": [
40
+ {
41
+ "geoPostalCode": "10003",
42
+ "geoCity": "NEW YORK CITY",
43
+ "geoCounty": "NEW YORK",
44
+ "geoState": "NY",
45
+ "taxSales": 0.088749997317791,
46
+ "taxUse": 0.088749997317791,
47
+ "txbService": "L",
48
+ "txbFreight": "Y",
49
+ "stateSalesTax": 0.03999999910593,
50
+ "stateUseTax": 0.03999999910593,
51
+ "citySalesTax": 0.045000001788139,
52
+ "cityUseTax": 0.045000001788139,
53
+ "cityTaxCode": "NE 8081",
54
+ "countySalesTax": 0,
55
+ "countyUseTax": 0,
56
+ "countyTaxCode": "",
57
+ "districtSalesTax": 0.003749999916181,
58
+ "districtUseTax": 0.003749999916181
59
+ },
60
+ {
61
+ "geoPostalCode": "10003",
62
+ "geoCity": "NEW YORK",
63
+ "geoCounty": "NEW YORK",
64
+ "geoState": "NY",
65
+ "taxSales": 0.088749997317791,
66
+ "taxUse": 0.088749997317791,
67
+ "txbService": "L",
68
+ "txbFreight": "Y",
69
+ "stateSalesTax": 0.03999999910593,
70
+ "stateUseTax": 0.03999999910593,
71
+ "citySalesTax": 0.045000001788139,
72
+ "cityUseTax": 0.045000001788139,
73
+ "cityTaxCode": "NE 8081",
74
+ "countySalesTax": 0,
75
+ "countyUseTax": 0,
76
+ "countyTaxCode": "",
77
+ "districtSalesTax": 0.003749999916181,
78
+ "districtUseTax": 0.003749999916181
79
+ }
80
+ ]
81
+ }
82
+ ```
83
+
84
+ ## Contributing
85
+
86
+ 1. Fork it ( https://github.com/brycemcd/ziptax/fork )
87
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
88
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
89
+ 4. Push to the branch (`git push origin my-new-feature`)
90
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/zip_tax.rb ADDED
@@ -0,0 +1,7 @@
1
+ module ZipTax
2
+ end
3
+
4
+ require "zip_tax/version"
5
+ require_relative 'zip_tax/sales_tax'
6
+ require_relative 'zip_tax/response'
7
+ require_relative 'zip_tax/result'
@@ -0,0 +1,17 @@
1
+ module ZipTax
2
+ class Response < OpenStruct
3
+
4
+ def success?
5
+ self.rCode && self.rCode == 100
6
+ end
7
+
8
+ def self.new_from_http_request(response_hsh)
9
+ #NOTE: xml is not supported by this gem right now
10
+ # it is supported in the API
11
+ hsh = JSON.parse(response_hsh)
12
+ resp = ZipTax::Response.new(hsh)
13
+ resp.results = hsh['results'].collect { |result| ZipTax::Result.new(result) }
14
+ resp
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module ZipTax
2
+ class Result < OpenStruct
3
+ end
4
+ end
@@ -0,0 +1,41 @@
1
+ require 'rack/utils'
2
+ require 'ostruct'
3
+ require 'json'
4
+
5
+ module ZipTax
6
+ class SalesTax
7
+ attr_reader :key, :postalcode, :state, :city, :format
8
+
9
+ BASE_URL="http://api.zip-tax.com/request/v20"
10
+
11
+ def initialize(key: nil,
12
+ postalcode: nil,
13
+ state: nil,
14
+ city: nil)
15
+
16
+ fail ArgumentError, "postalcode and key (api key) are required arguments" if !key || !postalcode
17
+ @key = key
18
+ @postalcode = postalcode.to_s
19
+ @state = state
20
+ @city = city
21
+ @format = 'json'
22
+ end
23
+
24
+ def request_url
25
+ query = {key: @key, postalcode: @postalcode, state: @state, city: @city, format: @format}
26
+ "#{BASE_URL}?#{Rack::Utils.build_query(query)}"
27
+ end
28
+
29
+ def request_tax
30
+ url = URI(request_url)
31
+ resp = Net::HTTP.get(url)
32
+ ZipTax::Response.new_from_http_request(resp)
33
+ end
34
+
35
+ def self.request_for(key: nil, postalcode: nil, state: nil, city: nil)
36
+
37
+ rt = self.new(key: key, postalcode: postalcode, state: state, city: city)
38
+ rt.request_tax
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module ZipTax
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZipTax::Response do
4
+ let(:fake_response) {
5
+ <<-STR
6
+ {
7
+ "version": "v20",
8
+ "rCode": 100,
9
+ "results": [
10
+ {
11
+ "geoPostalCode": "10801",
12
+ "geoCity": "NEW ROCHELLE",
13
+ "geoCounty": "WESTCHESTER",
14
+ "geoState": "NY",
15
+ "taxSales": 0.083750002086163,
16
+ "taxUse": 0.083750002086163,
17
+ "txbService": "L",
18
+ "txbFreight": "Y",
19
+ "stateSalesTax": 0.03999999910593,
20
+ "stateUseTax": 0.03999999910593,
21
+ "citySalesTax": 0.03999999910593,
22
+ "cityUseTax": 0.03999999910593,
23
+ "cityTaxCode": "NE 6861",
24
+ "countySalesTax": 0,
25
+ "countyUseTax": 0,
26
+ "countyTaxCode": "WE 5581",
27
+ "districtSalesTax": 0.003749999916181,
28
+ "districtUseTax": 0.003749999916181
29
+ }
30
+ ]
31
+ }
32
+ STR
33
+ }
34
+ describe '.new_from_http_request' do
35
+ context "on success" do
36
+ let(:resp) { ZipTax::Response.new_from_http_request(fake_response) }
37
+ it "creates a new Response object" do
38
+ expect(resp).to be_kind_of ZipTax::Response
39
+ end
40
+
41
+ it "creates result objects" do
42
+ expect(resp.results).to be_kind_of Array
43
+ expect(resp.results.first).to be_kind_of ZipTax::Result
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "#success?" do
49
+ it "is true if rCode == 100" do
50
+ expect(ZipTax::Response.new({rCode: 100}).success?).to be_truthy
51
+ end
52
+
53
+ it "is false if rCode != 100" do
54
+ expect(ZipTax::Response.new({rCode: 101}).success?).to be_falsey
55
+ end
56
+
57
+ it "is false if no rCode" do
58
+ expect(ZipTax::Response.new({notrCode: 101}).success?).to be_falsey
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZipTax::SalesTax do
4
+ let(:fake_response) {
5
+ <<-STR
6
+ {
7
+ "version": "v20",
8
+ "rCode": 100,
9
+ "results": [
10
+ {
11
+ "geoPostalCode": "10801",
12
+ "geoCity": "NEW ROCHELLE",
13
+ "geoCounty": "WESTCHESTER",
14
+ "geoState": "NY",
15
+ "taxSales": 0.083750002086163,
16
+ "taxUse": 0.083750002086163,
17
+ "txbService": "L",
18
+ "txbFreight": "Y",
19
+ "stateSalesTax": 0.03999999910593,
20
+ "stateUseTax": 0.03999999910593,
21
+ "citySalesTax": 0.03999999910593,
22
+ "cityUseTax": 0.03999999910593,
23
+ "cityTaxCode": "NE 6861",
24
+ "countySalesTax": 0,
25
+ "countyUseTax": 0,
26
+ "countyTaxCode": "WE 5581",
27
+ "districtSalesTax": 0.003749999916181,
28
+ "districtUseTax": 0.003749999916181
29
+ }
30
+ ]
31
+ }
32
+ STR
33
+ }
34
+ describe "#new" do
35
+ it "errors if key or postal code are not set" do
36
+ expect {
37
+ ZipTax::SalesTax.new(postalcode: '001245')
38
+ }.to raise_exception(ArgumentError, /api key/i)
39
+
40
+ expect {
41
+ ZipTax::SalesTax.new(key: 'abc123')
42
+ }.to raise_exception(ArgumentError, /postalcode/i)
43
+ end
44
+
45
+ it "sets all possible parameters to the api" do
46
+ rq = ZipTax::SalesTax.new(key: 'abc123',
47
+ postalcode: '000123',
48
+ state: 'NY',
49
+ city: 'New York'
50
+ )
51
+ expect(rq).to be_kind_of ZipTax::SalesTax
52
+ [:key, :postalcode, :state, :city].each do |attr|
53
+ expect(rq.send(attr.to_sym)).to_not be_nil
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#request_tax" do
59
+ context "success" do
60
+ it "returns a json response" do
61
+ expect(Net::HTTP).to receive(:get).and_return(fake_response)
62
+ rq = ZipTax::SalesTax.new(key: 'abc123', postalcode: 000123)
63
+ resp = rq.request_tax
64
+ expect(resp).to be_kind_of ZipTax::Response
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "#request_url" do
70
+ it "includes the keys/values included as get params on the base url" do
71
+ rq = ZipTax::SalesTax.new(key: 'abc123', postalcode: "00012")
72
+ expect(rq.request_url).to eql("#{ZipTax::SalesTax::BASE_URL}?key=abc123&postalcode=00012&state&city&format=json")
73
+ end
74
+ end
75
+
76
+ describe ".request_for" do
77
+ it "calls the API endpoing in one method call" do
78
+ expect(Net::HTTP).to receive(:get).and_return(fake_response)
79
+ rq = ZipTax::SalesTax.request_for(key: 'abc123', postalcode: '00123')
80
+ expect(rq).to be_kind_of ZipTax::Response
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,11 @@
1
+ require_relative '../lib/zip_tax'
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |expectations|
5
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
6
+ end
7
+
8
+ config.mock_with :rspec do |mocks|
9
+ mocks.verify_partial_doubles = true
10
+ end
11
+ end
data/ziptax.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zip_tax/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ziptax"
8
+ spec.version = ZipTax::VERSION
9
+ spec.authors = ["Bryce McDonnell"]
10
+ spec.email = ["bryce@bridgetownint.com"]
11
+ spec.summary = %q{Consumes Zip-Tax.com API and returns tax rates}
12
+ spec.description = %q{Fetch calculated sales tax rate at the zip code area of specificity by consuming the Zip-Tax.com API}
13
+ spec.homepage = "https://github.com/brycemcd/ziptax"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.3"
23
+ spec.add_development_dependency "rspec", "~> 3.1"
24
+ spec.add_dependency 'rack', '~> 1.4'
25
+
26
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ziptax
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bryce McDonnell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.4'
69
+ description: Fetch calculated sales tax rate at the zip code area of specificity by
70
+ consuming the Zip-Tax.com API
71
+ email:
72
+ - bryce@bridgetownint.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/zip_tax.rb
84
+ - lib/zip_tax/response.rb
85
+ - lib/zip_tax/result.rb
86
+ - lib/zip_tax/sales_tax.rb
87
+ - lib/zip_tax/version.rb
88
+ - spec/lib/zip_tax/response_spec.rb
89
+ - spec/lib/zip_tax/sales_tax_spec.rb
90
+ - spec/spec_helper.rb
91
+ - ziptax.gemspec
92
+ homepage: https://github.com/brycemcd/ziptax
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Consumes Zip-Tax.com API and returns tax rates
116
+ test_files:
117
+ - spec/lib/zip_tax/response_spec.rb
118
+ - spec/lib/zip_tax/sales_tax_spec.rb
119
+ - spec/spec_helper.rb