active_tax 0.1.0

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.
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_tax.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jamon Holmgren
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,42 @@
1
+ # ActiveTax
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.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'active_tax'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install active_tax
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+
25
+ tax_rate = ActiveTax::Tax.rate {
26
+ address: "6500 Linderson Way",
27
+ city: "",
28
+ zip: "98501",
29
+ state: "WA"
30
+ }
31
+
32
+ puts tax_rate #=> 0.087
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ Contributions are very welcome!
38
+
39
+ 1. Fork it
40
+ 2. Commit your changes (`git commit -am 'Added some feature'`)
41
+ 3. Push to the branch (`git push origin my-new-feature`)
42
+ 4. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/active_tax/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jamon Holmgren"]
6
+ gem.email = ["jamon@clearsightstudio.com"]
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
+ gem.summary = "A Ruby gem for retrieving local sales tax rates from various government APIs."
9
+ gem.homepage = "https://github.com/jamonholmgren/active_tax"
10
+
11
+ gem.platform = Gem::Platform::RUBY
12
+
13
+ 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)/})
16
+ gem.name = "active_tax"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = ActiveTax::VERSION
19
+ end
@@ -0,0 +1,42 @@
1
+ module ActiveTax
2
+ module States
3
+ class WA
4
+ API_URI = "http://dor.wa.gov/AddressRates.aspx"
5
+
6
+ def self.rate(address={})
7
+ # http://dor.wa.gov/AddressRates.aspx?output=text&addr=6500%20Linderson%20way&city=&zip=98501
8
+ params = {
9
+ output: "text",
10
+ addr: "#{address[:address]}",
11
+ city: "#{address[:city]}",
12
+ zip: "#{address[:zip]}"
13
+ }
14
+
15
+ require 'net/http' # Needed for HTTP requests
16
+
17
+ uri = URI("#{API_URI}")
18
+ uri.query = URI.encode_www_form(params)
19
+
20
+ res = Net::HTTP.get_response(uri)
21
+
22
+ # LocationCode=3406 Rate=0.087 ResultCode=0
23
+ if res.is_a?(Net::HTTPSuccess)
24
+ result = self.parse_result(res.body)
25
+ return result["Rate"].to_f
26
+ else
27
+ return false
28
+ end
29
+ end
30
+
31
+ def self.parse_result(text)
32
+ r = {}
33
+ items = text.split(" ")
34
+ items.each do |item|
35
+ k, v = item.split("=")
36
+ r[k] = v
37
+ end
38
+ r
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,27 @@
1
+ module ActiveTax
2
+ class Tax
3
+ attr_accessor :state, :api_class
4
+
5
+ def self.rate(address={})
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)
8
+ end
9
+
10
+ def initialize(state)
11
+ self.state = state
12
+ end
13
+
14
+ def rate_from_address(address={})
15
+ self.state = address[:state] if address[:state]
16
+
17
+ case self.state.upcase
18
+ when "WA"
19
+ self.api_class = States::WA
20
+ else
21
+ raise StandardError, "API for #{self.state.upcase} not yet implemented in ActiveTax."
22
+ end
23
+
24
+ self.api_class.rate(address)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveTax
2
+ VERSION = "0.1.0"
3
+ end
data/lib/active_tax.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "active_tax/version"
2
+ require "active_tax/states/wa"
3
+ require "active_tax/tax"
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_tax
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Jamon Holmgren
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-09-26 00:00:00 Z
19
+ dependencies: []
20
+
21
+ 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.
22
+ email:
23
+ - jamon@clearsightstudio.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .DS_Store
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - active_tax.gemspec
38
+ - lib/active_tax.rb
39
+ - lib/active_tax/states/wa.rb
40
+ - lib/active_tax/tax.rb
41
+ - lib/active_tax/version.rb
42
+ homepage: https://github.com/jamonholmgren/active_tax
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.24
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: A Ruby gem for retrieving local sales tax rates from various government APIs.
75
+ test_files: []
76
+