taxbear 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c5c3cd196511c61c9ea3a229a656c4b2410ba38c
4
+ data.tar.gz: efcd41ff0ecb2f23e36c3a15fa2816d5334491e6
5
+ SHA512:
6
+ metadata.gz: ea32a31b082dc8f55b06f63c014f53ed282ec978e7129dc0dd18e516815a2a719bd4b2a1433b4dfab219b0e403af6012be8fc0ba639c289139c6cc3d8df1b6e3
7
+ data.tar.gz: d6b71f0c29625a45490ead5d71af9e729c3dda3de48d87859b4f3a3565177b657157dab5fe7424c69fc5a90cbb567199bead913051654c9afedf9cd38bb41fbc
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at jcypret@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in taxbear.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Taxbear
2
+
3
+ ## Installation
4
+
5
+ $ gem install taxbear
6
+
7
+ ## Usage
8
+
9
+ Lookup sales tax rates for a zip code:
10
+
11
+ ```bash
12
+ $ taxbear zip 72034
13
+ # +--------+----------+--------+-------------+--------+
14
+ # | Sales Tax Rates for 72034 |
15
+ # +--------+----------+--------+-------------+--------+
16
+ # | AR | FAULKNER | CONWAY | DISTRICT(S) | TOTAL |
17
+ # +--------+----------+--------+-------------+--------+
18
+ # | 6.500% | 0.500% | 1.750% | 0.000% | 8.750% |
19
+ # +--------+----------+--------+-------------+--------+
20
+ ```
21
+
22
+ ## Development
23
+
24
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
+
26
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/taxbear. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "taxbear"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/taxbear ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "taxbear"
4
+
5
+ Taxbear::CLI.start(ARGV)
data/lib/taxbear.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "taxbear/cli"
2
+ require "taxbear/exceptions"
3
+ require "taxbear/table_builder"
4
+ require "taxbear/taxjar"
5
+ require "taxbear/version"
6
+
7
+ module Taxbear
8
+ CONFIG_FILE = ENV["HOME"] + "/.taxbear"
9
+ end
@@ -0,0 +1,30 @@
1
+ require "thor"
2
+
3
+ module Taxbear
4
+ class CLI < Thor
5
+ desc "zip ZIPCODE", "displays sales tax rates for supplied zip code"
6
+ def zip(zipcode)
7
+ ensure_api_key_is_available
8
+
9
+ rates = Taxjar.get_rates_by_zipcode(zipcode)
10
+ TableBuilder.print_rates_for_zipcode(rates, zipcode)
11
+ rescue TaxjarError => e
12
+ print_error(e.message)
13
+ end
14
+
15
+ private
16
+
17
+ def ensure_api_key_is_available
18
+ unless File.exists?(CONFIG_FILE)
19
+ token = ask("What is your TaxJar API token?")
20
+ File.write(CONFIG_FILE, token)
21
+ token
22
+ end
23
+ end
24
+
25
+ def print_error(error)
26
+ error_message = "✘ #{error}"
27
+ puts set_color(error_message, :red)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ module Taxbear
2
+ class TaxjarError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,47 @@
1
+ require "terminal-table"
2
+
3
+ module Taxbear
4
+ class TableBuilder
5
+ # A class to build tables for outputing to STDOUT.
6
+
7
+ class << self
8
+ # Takes the rates and prints them as a nice table to STDOUT.
9
+ #
10
+ # @param rates [Hash] the rates
11
+ # @return [nil] returns nothing, prints to STDOUT
12
+ def print_rates_for_zipcode(rates, zipcode)
13
+ puts ""
14
+ puts Terminal::Table.new(
15
+ title: "Sales Tax Rates for #{zipcode}",
16
+ headings: align_each_cell_center(get_header_rows(rates)),
17
+ rows: [align_each_cell_center(format_rates(rates))]
18
+ )
19
+ puts ""
20
+ end
21
+
22
+ private
23
+
24
+ def align_each_cell_center(row)
25
+ row.map {|c| align_center(c)}
26
+ end
27
+
28
+ def align_center(value)
29
+ {value: value, alignment: :center}
30
+ end
31
+
32
+ def get_header_rows(rates)
33
+ [*rates.fetch_values("state", "county", "city"), "DISTRICT(S)", "TOTAL"]
34
+ end
35
+
36
+ def format_rates(rates)
37
+ rates
38
+ .fetch_values("state_rate", "county_rate", "city_rate", "combined_district_rate", "combined_rate")
39
+ .map {|r| format_rate(r)}
40
+ end
41
+
42
+ def format_rate(rate)
43
+ sprintf('%.3f', rate.to_f * 100) + "%"
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,37 @@
1
+ require "thor"
2
+ require "httparty"
3
+
4
+ module Taxbear
5
+ class Taxjar
6
+ # A class to interect with the TaxJar API.
7
+ include HTTParty
8
+
9
+ base_uri "https://api.taxjar.com/v2"
10
+
11
+ class << self
12
+ # Gets tax rates from TaxJar API based on zipcode.
13
+ #
14
+ # @param zipcode [Integer] the zip code
15
+ # @return [Hash] the rates returned by API
16
+ def get_rates_by_zipcode(zipcode)
17
+ response = get("/rates/#{zipcode}", {headers: headers})
18
+
19
+ if response.success?
20
+ response.fetch("rate")
21
+ else
22
+ raise TaxjarError, "Unable to get tax rates from TaxJar API."
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def headers
29
+ {"Authorization" => "Token token=#{api_token}"}
30
+ end
31
+
32
+ def api_token
33
+ File.read(CONFIG_FILE)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Taxbear
2
+ VERSION = "0.1.0"
3
+ end
data/taxbear.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'taxbear/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "taxbear"
8
+ spec.version = Taxbear::VERSION
9
+ spec.authors = ["Justin Cypret"]
10
+ spec.email = ["jcypret@gmail.com"]
11
+
12
+ spec.summary = %q{A CLI for interacting with the TaxJar API.}
13
+ spec.homepage = "https://github.com/jcypret/taxbear"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.11"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+
24
+ spec.add_dependency "thor", "~> 0.19"
25
+ spec.add_dependency "httparty", "~> 0.14"
26
+ spec.add_dependency "terminal-table"
27
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: taxbear
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Cypret
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-18 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
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.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.19'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.19'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.14'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.14'
83
+ - !ruby/object:Gem::Dependency
84
+ name: terminal-table
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - jcypret@gmail.com
100
+ executables:
101
+ - taxbear
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - exe/taxbear
115
+ - lib/taxbear.rb
116
+ - lib/taxbear/cli.rb
117
+ - lib/taxbear/exceptions.rb
118
+ - lib/taxbear/table_builder.rb
119
+ - lib/taxbear/taxjar.rb
120
+ - lib/taxbear/version.rb
121
+ - taxbear.gemspec
122
+ homepage: https://github.com/jcypret/taxbear
123
+ licenses: []
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.5.1
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: A CLI for interacting with the TaxJar API.
145
+ test_files: []