taxbear 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +4 -0
- data/README.md +14 -2
- data/lib/taxbear.rb +1 -1
- data/lib/taxbear/cli.rb +34 -9
- data/lib/taxbear/config.rb +32 -0
- data/lib/taxbear/exceptions.rb +2 -2
- data/lib/taxbear/table_builder.rb +7 -4
- data/lib/taxbear/taxjar.rb +18 -5
- data/lib/taxbear/version.rb +1 -1
- data/taxbear.gemspec +3 -0
- metadata +45 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee7df243ec9b37ad77afa11cae811c5d8b59bf0a
|
4
|
+
data.tar.gz: 553a58b8a16626dc983fc7047de87d923c1964dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01f20233998f3540f4e1c7de846848b52d22f4ea26df7f74e8e25b0ca0ce3b4ba4fce48f063290a55c4de7b5ad4aaca04822f382828415814ca4b5e2428951c2
|
7
|
+
data.tar.gz: 4e08d0850ebfd51d3022908e5dadace182de29c77b4db93cf4e43e0c6a2c0da8cf17fbb68f90b261f16df91b2f8c6a7bb76b49b13e45e30d24484510d424f490
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,26 @@
|
|
1
1
|
# Taxbear
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/taxbear.svg)](https://badge.fury.io/rb/taxbear)
|
4
|
+
[![Build Status](https://travis-ci.org/jcypret/taxbear.svg?branch=master)](https://travis-ci.org/jcypret/taxbear)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/jcypret/taxbear/badges/gpa.svg)](https://codeclimate.com/github/jcypret/taxbear)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/jcypret/taxbear/badges/coverage.svg)](https://codeclimate.com/github/jcypret/taxbear/coverage)
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
7
|
-
|
10
|
+
```bash
|
11
|
+
$ gem install taxbear
|
12
|
+
```
|
8
13
|
|
9
14
|
## Usage
|
10
15
|
|
11
|
-
|
16
|
+
(1) Set your TaxJar API token:
|
17
|
+
|
18
|
+
```bash
|
19
|
+
$ taxbear login
|
20
|
+
#=> What is your TaxJar API token?
|
21
|
+
```
|
22
|
+
|
23
|
+
(2) Lookup sales tax rates for a zip code:
|
12
24
|
|
13
25
|
```bash
|
14
26
|
$ taxbear zip 72034
|
data/lib/taxbear.rb
CHANGED
data/lib/taxbear/cli.rb
CHANGED
@@ -2,27 +2,52 @@ require "thor"
|
|
2
2
|
|
3
3
|
module Taxbear
|
4
4
|
class CLI < Thor
|
5
|
+
desc "login", "Set API key used to authenticate with TaxJar"
|
6
|
+
def login
|
7
|
+
valid_token = false
|
8
|
+
while !valid_token
|
9
|
+
token = ask("What is your TaxJar API token?")
|
10
|
+
valid_token = Taxjar.validate_token(token)
|
11
|
+
say_nope if !valid_token
|
12
|
+
end
|
13
|
+
Config.save_token(token)
|
14
|
+
print_success "Success! You are now ready to access the TaxJar API."
|
15
|
+
end
|
16
|
+
|
5
17
|
desc "zip [ZIPCODE]", "Display sales tax rates for specified zip code"
|
6
18
|
def zip(zipcode)
|
7
|
-
ensure_api_key_is_available
|
8
19
|
rates = Taxjar.get_rates_by_zipcode(zipcode)
|
9
20
|
TableBuilder.print_rates_for_zipcode(rates, zipcode)
|
10
|
-
rescue
|
21
|
+
rescue => e
|
11
22
|
print_error(e.message)
|
12
23
|
end
|
13
24
|
|
14
25
|
private
|
15
26
|
|
16
|
-
def ensure_api_key_is_available
|
17
|
-
unless File.exists?(CONFIG_FILE)
|
18
|
-
token = ask("What is your TaxJar API token?")
|
19
|
-
File.write(CONFIG_FILE, token)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
27
|
def print_error(error)
|
24
28
|
error_message = "✘ #{error}"
|
25
29
|
puts set_color(error_message, :red)
|
26
30
|
end
|
31
|
+
|
32
|
+
def print_success(message)
|
33
|
+
success_message = "✔︎ #{message}"
|
34
|
+
puts set_color(success_message, :green)
|
35
|
+
end
|
36
|
+
|
37
|
+
def say_nope
|
38
|
+
print_error(random_no)
|
39
|
+
end
|
40
|
+
|
41
|
+
def random_no
|
42
|
+
[
|
43
|
+
"Nope, that's not correct.",
|
44
|
+
"Sorry, not quite right.",
|
45
|
+
"Maybe you should check the website? https://app.taxjar.com/smartcalcs",
|
46
|
+
"A for effort… but no.",
|
47
|
+
"I'll give you a hint, it's a bunch of random unguessable letters/numbers.",
|
48
|
+
"Good try, but unfortunately wrong.",
|
49
|
+
"Hmm… that doesn't seem to be working. Maybe something different?"
|
50
|
+
].sample
|
51
|
+
end
|
27
52
|
end
|
28
53
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Taxbear
|
2
|
+
class Config
|
3
|
+
# This class manages the configuration file stored on the user's computer.
|
4
|
+
|
5
|
+
class << self
|
6
|
+
# Checks whether the Taxbear config file exists on the users computer.
|
7
|
+
#
|
8
|
+
# @return [Boolean] whether the config file exists
|
9
|
+
def exists?
|
10
|
+
File.exist?(config_file)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns the TaxJar API token loaded from the users config file.
|
14
|
+
#
|
15
|
+
# @return [String] the TaxJar API token
|
16
|
+
def get_token
|
17
|
+
File.read(config_file)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Saves the token to a .taxbear config file in the users home directory.
|
21
|
+
def save_token(token)
|
22
|
+
File.write(config_file, token)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def config_file
|
28
|
+
File.join(Dir.home, "/.taxbear")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/taxbear/exceptions.rb
CHANGED
@@ -10,13 +10,16 @@ module Taxbear
|
|
10
10
|
# @param rates [Hash] the rates
|
11
11
|
# @return [nil] returns nothing, prints to STDOUT
|
12
12
|
def print_rates_for_zipcode(rates, zipcode)
|
13
|
-
|
14
|
-
|
13
|
+
output = ""
|
14
|
+
output << "\n"
|
15
|
+
output << Terminal::Table.new(
|
15
16
|
title: "Sales Tax Rates for #{zipcode}",
|
16
17
|
headings: align_each_cell_center(get_header_rows(rates)),
|
17
18
|
rows: [align_each_cell_center(format_rates(rates))]
|
18
|
-
)
|
19
|
-
|
19
|
+
).to_s
|
20
|
+
output << "\n\n"
|
21
|
+
|
22
|
+
puts output
|
20
23
|
end
|
21
24
|
|
22
25
|
private
|
data/lib/taxbear/taxjar.rb
CHANGED
@@ -14,7 +14,8 @@ module Taxbear
|
|
14
14
|
# @param zipcode [Integer] the zip code
|
15
15
|
# @return [Hash] the rates returned by API
|
16
16
|
def get_rates_by_zipcode(zipcode)
|
17
|
-
|
17
|
+
require_api_key()
|
18
|
+
response = get("/rates/#{zipcode}", {headers: auth_header})
|
18
19
|
|
19
20
|
if response.success?
|
20
21
|
response.fetch("rate")
|
@@ -23,14 +24,26 @@ module Taxbear
|
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
27
|
+
# Takes a tokens and returns whether the token is valid.
|
28
|
+
#
|
29
|
+
# @param token [String] the token
|
30
|
+
# @return [Boolean] whether token is valid
|
31
|
+
def validate_token(token)
|
32
|
+
get("/categories", headers: auth_header(token)).success?
|
33
|
+
end
|
34
|
+
|
26
35
|
private
|
27
36
|
|
28
|
-
def
|
29
|
-
|
37
|
+
def require_api_key
|
38
|
+
raise_unauthorized unless Config.exists?
|
39
|
+
end
|
40
|
+
|
41
|
+
def raise_unauthorized
|
42
|
+
raise TaxjarUnauthorized, "You must have a TaxJar API key set to access rates. Use `taxbear login`."
|
30
43
|
end
|
31
44
|
|
32
|
-
def
|
33
|
-
|
45
|
+
def auth_header(token = Config.get_token)
|
46
|
+
{"Authorization" => "Token token=#{token}"}
|
34
47
|
end
|
35
48
|
end
|
36
49
|
end
|
data/lib/taxbear/version.rb
CHANGED
data/taxbear.gemspec
CHANGED
@@ -20,6 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.11"
|
21
21
|
spec.add_development_dependency "rake", "~> 10.0"
|
22
22
|
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
spec.add_development_dependency "webmock", "~> 2.1.0"
|
24
|
+
spec.add_development_dependency "aruba", "~> 0.14.2"
|
25
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
23
26
|
|
24
27
|
spec.add_dependency "thor", "~> 0.19"
|
25
28
|
spec.add_dependency "httparty", "~> 0.14"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taxbear
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Cypret
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,48 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: aruba
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.14.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.14.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: codeclimate-test-reporter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
55
97
|
- !ruby/object:Gem::Dependency
|
56
98
|
name: thor
|
57
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,6 +157,7 @@ files:
|
|
115
157
|
- exe/taxbear
|
116
158
|
- lib/taxbear.rb
|
117
159
|
- lib/taxbear/cli.rb
|
160
|
+
- lib/taxbear/config.rb
|
118
161
|
- lib/taxbear/exceptions.rb
|
119
162
|
- lib/taxbear/table_builder.rb
|
120
163
|
- lib/taxbear/taxjar.rb
|