active_tax 0.2.0 → 0.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: d4d0012857ee4032097f829452269524e44fe789
4
- data.tar.gz: 94956a278ff955a87884fbdf7b0888492f57943a
3
+ metadata.gz: 0709470838c0295b2053399c4db34539d0267c22
4
+ data.tar.gz: d709eba5a20e3f2cac2b2200f68937573216c1e2
5
5
  SHA512:
6
- metadata.gz: 00dde154464596f7d955d96f2fc6d9e0cd6e4511ed5433c380f1c32482faf38fe66052c79f23612da4f144ff79c9e4262ab2dc8bccbc8a4475b09d159b9394e8
7
- data.tar.gz: ef24236126b982b04238e1ad2fa2ae0bd58eb9835132051da0f58c380cc73bedc608dbb90dc7ac3c632d0f613a9dbac3ea7f701b5b29391653b4cb1fdf502520
6
+ metadata.gz: 028982ffd0f26d9b33b3e3be95b966db52f48eb94859d15f4f879dc920b7da8145ec6d6654224553247e6293c6a5a3c8d07a791f8596ab1bc2e9bde98e8c953f
7
+ data.tar.gz: 08fed24e91b981bc2770c211ca60128b226b0c7f19d6face2326e4fb283f2903f8f43faa5b04f89a498a07eef6a276d634c58688554df0aaf1a4e32b9bbdec0b
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Jamon Holmgren
1
+ Copyright (c) 2012-2014 Jamon Holmgren
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
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.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # ActiveTax
2
2
 
3
- A Ruby gem for retrieving local sales tax rates from various government APIs. Currently
4
- only supports Washington State sales tax, but feel free to write your own state's implementations
5
- and do pull requests.
3
+ A Ruby gem for retrieving local sales tax rates from various government APIs.
4
+ Currently only supports Washington State sales tax, but feel free to write your
5
+ own state's implementations and do pull requests.
6
6
 
7
7
  ## Installation
8
8
 
@@ -10,26 +10,21 @@ Add this line to your application's Gemfile:
10
10
 
11
11
  gem 'active_tax'
12
12
 
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install active_tax
20
-
21
13
  ## Usage
22
14
 
23
15
  ```ruby
24
-
25
- tax_rate = ActiveTax::Tax.rate({
16
+ tax = ActiveTax::Tax.new({
26
17
  address: "6500 Linderson Way",
27
- city: "",
18
+ city: "Tumwater",
19
+ state: "WA", # must be two-letter state abbreviation
28
20
  zip: "98501",
29
- state: "WA"
30
21
  })
31
22
 
32
- puts tax_rate #=> 0.087
23
+ # tax is a Struct with #rate, #location_code, and #result_code properties.
24
+
25
+ puts tax.rate #=> 0.087
26
+ puts tax.location_code #=> "3406"
27
+ puts tax.result_code #=> "0"
33
28
  ```
34
29
 
35
30
  ## Contributing
@@ -40,3 +35,7 @@ Contributions are very welcome!
40
35
  2. Commit your changes (`git commit -am 'Added some feature'`)
41
36
  3. Push to the branch (`git push origin my-new-feature`)
42
37
  4. Create new Pull Request
38
+
39
+ ## License
40
+
41
+ MIT
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ t.pattern = "test/test_*.rb"
9
+ end
data/active_tax.gemspec CHANGED
@@ -7,13 +7,18 @@ Gem::Specification.new do |gem|
7
7
  gem.description = "A Ruby gem for retrieving local sales tax rates from various government APIs. Currently only supports Washington State tax, but feel free to submit pull requests."
8
8
  gem.summary = "A Ruby gem for retrieving local sales tax rates from various government APIs."
9
9
  gem.homepage = "https://github.com/jamonholmgren/active_tax"
10
+ gem.license = "MIT"
10
11
 
11
12
  gem.platform = Gem::Platform::RUBY
12
13
 
13
14
  gem.files = `git ls-files`.split($\)
14
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ # gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test)/})
16
17
  gem.name = "active_tax"
17
18
  gem.require_paths = ["lib"]
18
19
  gem.version = ActiveTax::VERSION
20
+
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "minitest"
23
+ gem.add_development_dependency "minitest-reporters"
19
24
  end
@@ -3,7 +3,7 @@ module ActiveTax
3
3
  class WA
4
4
  API_URI = "http://dor.wa.gov/AddressRates.aspx"
5
5
 
6
- def self.rate(address={})
6
+ def self.tax(address={})
7
7
  # http://dor.wa.gov/AddressRates.aspx?output=text&addr=6500%20Linderson%20way&city=&zip=98501
8
8
  params = {
9
9
  output: "text",
@@ -13,7 +13,7 @@ module ActiveTax
13
13
  }
14
14
 
15
15
  require 'net/http' # Needed for HTTP requests
16
-
16
+
17
17
  uri = URI("#{API_URI}")
18
18
  uri.query = URI.encode_www_form(params)
19
19
 
@@ -21,13 +21,17 @@ module ActiveTax
21
21
 
22
22
  # LocationCode=3406 Rate=0.087 ResultCode=0
23
23
  if res.is_a?(Net::HTTPSuccess)
24
- result = self.parse_result(res.body)
25
- return result["Rate"].to_f
24
+ normalize(self.parse_result(res.body))
26
25
  else
27
- return false
26
+ false
28
27
  end
29
28
  end
30
29
 
30
+ def self.rate(address={})
31
+ tax_data = tax(address)
32
+ tax_data && tax_data.rate
33
+ end
34
+
31
35
  def self.parse_result(text)
32
36
  r = {}
33
37
  items = text.split(" ")
@@ -37,6 +41,11 @@ module ActiveTax
37
41
  end
38
42
  r
39
43
  end
44
+
45
+ def self.normalize(tax_data)
46
+ Struct.new(:rate, :location_code, :result_code)
47
+ .new(tax_data["Rate"].to_f, tax_data["LocationCode"], tax_data["ResultCode"])
48
+ end
40
49
  end
41
50
  WASHINGTON = WA unless defined?(WASHINGTON)
42
51
  end
@@ -1,27 +1,50 @@
1
1
  module ActiveTax
2
2
  class Tax
3
- attr_accessor :state, :api_class
3
+ attr_accessor :state, :address, :api_class
4
4
 
5
5
  def self.rate(address={})
6
6
  raise StandardError, "You must provide a state to use ActiveTax::Tax.rate" unless address[:state]
7
- self.new(address[:state]).rate_from_address(address)
7
+ self.new(address).rate
8
8
  end
9
9
 
10
- def initialize(state)
11
- self.state = state
10
+ def initialize(address)
11
+ self.state = address[:state]
12
+ self.address = address
13
+
14
+ determine_state_api
12
15
  end
13
16
 
14
17
  def rate_from_address(address={})
15
- self.state = address[:state] if address[:state]
18
+ raise "#rate_from_address is deprecated. Use #rate instead."
19
+ end
20
+
21
+ def tax
22
+ @tax ||= self.api_class.tax(address)
23
+ end
16
24
 
25
+ def rate
26
+ tax.rate
27
+ end
28
+
29
+ def location_code
30
+ tax.location_code
31
+ end
32
+
33
+ def result_code
34
+ tax.result_code
35
+ end
36
+
37
+ private
38
+
39
+ def determine_state_api
17
40
  case self.state.upcase
18
- when "WA", "WASHINGTON"
19
- self.api_class = States::WA
20
- else
21
- raise StandardError, "API for #{self.state.upcase} not yet implemented in ActiveTax."
41
+ when "WA", "WASHINGTON" then self.api_class = States::WA
42
+ else raise StandardError, "API for #{self.state.upcase} not yet implemented in ActiveTax."
22
43
  end
44
+ end
45
+
46
+ def api_data
23
47
 
24
- self.api_class.rate(address)
25
48
  end
26
49
  end
27
50
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveTax
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,5 @@
1
+ require 'active_tax'
2
+ require "minitest/autorun"
3
+ require "minitest/reporters"
4
+
5
+ Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new(color: true)
data/test/test_tax.rb ADDED
@@ -0,0 +1,38 @@
1
+ require_relative './test_helper'
2
+
3
+ class TestTax < Minitest::Unit::TestCase
4
+ def test_real_rate
5
+ rate = ActiveTax::Tax.rate({
6
+ address: "6500 Linderson Way",
7
+ city: "",
8
+ zip: "98501",
9
+ state: "WA"
10
+ })
11
+
12
+ assert_in_delta rate * 100.0, 8.2, 2.5 # 8.2%, within about 2.5%
13
+ end
14
+
15
+ def test_bad_rate
16
+ rate = ActiveTax::Tax.rate({
17
+ address: "",
18
+ city: "",
19
+ zip: "",
20
+ state: "WA"
21
+ })
22
+
23
+ assert_equal rate, -1
24
+ end
25
+
26
+ def test_other_tax_info
27
+ tax = ActiveTax::Tax.new({
28
+ address: "6500 Linderson Way",
29
+ city: "Tumwater",
30
+ zip: "98501",
31
+ state: "WA"
32
+ })
33
+
34
+ assert_in_delta tax.rate * 100.0, 8.2, 2.5 # 8.2%, within about 2.5%
35
+ assert_equal tax.location_code, "3406"
36
+ assert_equal tax.result_code, "0"
37
+ end
38
+ end
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_tax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamon Holmgren
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-11 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2016-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-reporters
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
13
55
  description: A Ruby gem for retrieving local sales tax rates from various government
14
56
  APIs. Currently only supports Washington State tax, but feel free to submit pull
15
57
  requests.
@@ -19,8 +61,8 @@ executables: []
19
61
  extensions: []
20
62
  extra_rdoc_files: []
21
63
  files:
22
- - .DS_Store
23
- - .gitignore
64
+ - ".DS_Store"
65
+ - ".gitignore"
24
66
  - Gemfile
25
67
  - LICENSE
26
68
  - README.md
@@ -30,8 +72,11 @@ files:
30
72
  - lib/active_tax/states/wa.rb
31
73
  - lib/active_tax/tax.rb
32
74
  - lib/active_tax/version.rb
75
+ - test/test_helper.rb
76
+ - test/test_tax.rb
33
77
  homepage: https://github.com/jamonholmgren/active_tax
34
- licenses: []
78
+ licenses:
79
+ - MIT
35
80
  metadata: {}
36
81
  post_install_message:
37
82
  rdoc_options: []
@@ -39,18 +84,20 @@ require_paths:
39
84
  - lib
40
85
  required_ruby_version: !ruby/object:Gem::Requirement
41
86
  requirements:
42
- - - '>='
87
+ - - ">="
43
88
  - !ruby/object:Gem::Version
44
89
  version: '0'
45
90
  required_rubygems_version: !ruby/object:Gem::Requirement
46
91
  requirements:
47
- - - '>='
92
+ - - ">="
48
93
  - !ruby/object:Gem::Version
49
94
  version: '0'
50
95
  requirements: []
51
96
  rubyforge_project:
52
- rubygems_version: 2.1.11
97
+ rubygems_version: 2.4.5
53
98
  signing_key:
54
99
  specification_version: 4
55
100
  summary: A Ruby gem for retrieving local sales tax rates from various government APIs.
56
- test_files: []
101
+ test_files:
102
+ - test/test_helper.rb
103
+ - test/test_tax.rb