duty_calculator 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/duty_calculator.rb +3 -2
- data/lib/duty_calculator/calculation.rb +8 -2
- data/lib/duty_calculator/client.rb +1 -1
- data/lib/duty_calculator/configuration.rb +4 -2
- data/lib/duty_calculator/dootie.rb +19 -0
- data/lib/duty_calculator/error_messages.rb +4 -2
- data/lib/duty_calculator/version.rb +1 -1
- data/spec/duty_calculator/dootie_spec.rb +59 -0
- data/spec/vcr/dootie__status_codes_from_api_1.yml +49 -0
- data/spec/vcr/dootie__status_codes_from_api_2.yml +49 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acd45bb6bd3eb0e883c0661940510ecd5ca4eb69
|
4
|
+
data.tar.gz: d266474849fcd13a2bf9f133e3ccdccbc992fe32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecc1d5b1e5dbdb6415bd948f61b54ccef4a2401b68bdf89169bc86a18002a2e1c0aacf52ff5057019082ca40015c1d64d80688f92524fa60b5f95b13fe1e48a3
|
7
|
+
data.tar.gz: 51e901b315355add0af9686f533f4f893790fede47c5c8e8183a9fa929a71e6106e40c88ad2f2bccfde4256385c01987b0eb405f2fe3a56c2ba9627e590972b7
|
data/lib/duty_calculator.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
require "duty_calculator/version"
|
2
1
|
require "duty_calculator/configuration"
|
3
2
|
require "duty_calculator/currency"
|
4
3
|
require "duty_calculator/category"
|
5
4
|
require "duty_calculator/calculation"
|
6
|
-
require "duty_calculator/
|
5
|
+
require "duty_calculator/dootie"
|
7
6
|
require "duty_calculator/error_messages"
|
7
|
+
require "duty_calculator/response"
|
8
|
+
require "duty_calculator/version"
|
8
9
|
|
9
10
|
require "faraday"
|
10
11
|
require "faraday_middleware"
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "duty_calculator/client"
|
2
2
|
require "duty_calculator/response"
|
3
|
+
require "duty_calculator/dootie"
|
3
4
|
require "addressable/uri"
|
4
5
|
module DutyCalculator
|
5
6
|
class Calculation
|
@@ -37,12 +38,17 @@ module DutyCalculator
|
|
37
38
|
|
38
39
|
def self.get(params={})
|
39
40
|
transformed_params = transform_params(validate_params(params))
|
41
|
+
# initialize connection
|
40
42
|
conn = DutyCalculator::Client.new
|
43
|
+
|
41
44
|
resp = conn.get "#{DutyCalculator::Client.api_base}/calculation", transformed_params
|
42
45
|
hashed_resp = DutyCalculator::Response.new(resp.to_hash)
|
43
46
|
resp = Hashie::Mash.new(hashed_resp)
|
44
|
-
|
45
|
-
|
47
|
+
|
48
|
+
if resp.body["error"]
|
49
|
+
return DutyCalculator::Dootie.new({message: "[DutyCalculator][Error]:", error: resp.body["error"]})
|
50
|
+
end
|
51
|
+
|
46
52
|
resp.body.duty_calculation
|
47
53
|
end
|
48
54
|
end
|
@@ -10,7 +10,7 @@ module DutyCalculator
|
|
10
10
|
faraday.use Faraday::Response::ParseXml
|
11
11
|
faraday.use Faraday::Response::Mashify
|
12
12
|
faraday.use Faraday::Response::RaiseError unless DutyCalculator.configuration.debug
|
13
|
-
faraday.response :logger
|
13
|
+
faraday.response :logger, DutyCalculator.configuration.logger
|
14
14
|
|
15
15
|
faraday.adapter ::Faraday.default_adapter
|
16
16
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
require "yaml"
|
2
|
-
|
2
|
+
require 'logger'
|
3
3
|
require "duty_calculator"
|
4
4
|
|
5
5
|
module DutyCalculator
|
6
6
|
class Configuration
|
7
|
-
attr_accessor :api_root, :api_version, :api_key, :api_base, :sandbox, :debug
|
7
|
+
attr_accessor :api_root, :api_version, :api_key, :api_base, :sandbox, :debug, :logger
|
8
|
+
|
8
9
|
|
9
10
|
def initialize
|
10
11
|
defaults = load_defaults
|
@@ -12,6 +13,7 @@ module DutyCalculator
|
|
12
13
|
@api_version = defaults[:api_version]
|
13
14
|
@sandbox = defaults[:sandbox]
|
14
15
|
@debug = defaults[:debug]
|
16
|
+
@logger = ::Logger.new(STDOUT)
|
15
17
|
end
|
16
18
|
|
17
19
|
private
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module DutyCalculator
|
3
|
+
class Dootie < StandardError
|
4
|
+
def initialize(data=nil)
|
5
|
+
@data = data
|
6
|
+
@default_message = "[DutyCalculator][Error]: ¯\\_(ツ)_/¯"
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
msg = []
|
11
|
+
msg << @data[:message] || @default_message
|
12
|
+
msg << "Error Code: #{@data[:error][:code]}"
|
13
|
+
msg << DutyCalculator::ErrorMessages.for_code(@data[:error][:code]) if @data[:error][:code]
|
14
|
+
msg.to_s
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class NotImplemented < Dootie; end
|
19
|
+
end
|
@@ -10,7 +10,8 @@ module DutyCalculator
|
|
10
10
|
"4061" => "Account does not support called service: Classification service - get HS codes, duty & tax rates and import restrictions",
|
11
11
|
"4062" => "Account does not support called service: Documents service",
|
12
12
|
"4063" => "Account does not support called operation: Classification service - get DutyCalculator item ID",
|
13
|
-
"4064" => "Account does not support called operation: Reporting service",
|
13
|
+
"4064" => "Account does not support called operation: Reporting service",
|
14
|
+
"4401" => "Parameter is missing",
|
14
15
|
"4421" => "Bad parameter: shipping cost can't be empty",
|
15
16
|
"4422" => "Bad parameter: shipment weight can't be empty",
|
16
17
|
"4423" => "Bad parameter: imported weight can't be empty",
|
@@ -19,7 +20,8 @@ module DutyCalculator
|
|
19
20
|
"4426" => "Bad parameter: both category and description for reference <product reference> can't be empty",
|
20
21
|
"4427" => "Bad parameter: SKU for reference <product reference> can't be empty",
|
21
22
|
"4428" => "Bad parameter: HS code for reference <product reference> can't be empty",
|
22
|
-
"4429" => "Bad parameter: description for reference <product reference> can't be empty",
|
23
|
+
"4429" => "Bad parameter: description for reference <product reference> can't be empty",
|
24
|
+
"4701" => "Bad parameter: <parameter name> is invalid",
|
23
25
|
"4721" => "Classification for the selected import to country is not possible",
|
24
26
|
"4722" => "Bad parameter: country from code",
|
25
27
|
"4723" => "Bad parameter: country to code",
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module DutyCalculator
|
4
|
+
describe Dootie do
|
5
|
+
context "Status Codes From API" do
|
6
|
+
let(:params) do
|
7
|
+
{
|
8
|
+
from: "US",
|
9
|
+
to: "CA",
|
10
|
+
shipping_mode: "USPS",
|
11
|
+
insurance: 0.0,
|
12
|
+
currency: "USD",
|
13
|
+
origin: "US",
|
14
|
+
reference: "ORD12345",
|
15
|
+
preferential_rates: 0,
|
16
|
+
detailed_result: 1,
|
17
|
+
incl_hs_codes: 1,
|
18
|
+
shipping: 10.0,
|
19
|
+
cat: ["9999999999999999999992"],
|
20
|
+
hs: ["9019100020"],
|
21
|
+
country_of_hs_code: ["CN"],
|
22
|
+
desc: ["Hydrotherapy Spa Bath"],
|
23
|
+
weight: ["1.0"],
|
24
|
+
weight_unit: ["lb"],
|
25
|
+
value: [ "1234.00" ],
|
26
|
+
sku: [ "300101" ],
|
27
|
+
qty: [ 1 ],
|
28
|
+
commercial_importer: 0,
|
29
|
+
classify_by: 'cat',
|
30
|
+
}
|
31
|
+
end
|
32
|
+
it "returns a DutyCalculator error from code for bad api key" do
|
33
|
+
DutyCalculator.configure do |config|
|
34
|
+
config.api_key = ""
|
35
|
+
config.sandbox = true
|
36
|
+
config.debug = true
|
37
|
+
end
|
38
|
+
VCR.use_cassette('dootie__status_codes_from_api_1') do
|
39
|
+
duty_calculation = DutyCalculator::Calculation.get(params)
|
40
|
+
expect(duty_calculation.class).to eq(DutyCalculator::Dootie)
|
41
|
+
expect(duty_calculation.message).to include('Client id is invalid or missing')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
it "returns a DutyCalculator error about a bad category" do
|
45
|
+
DutyCalculator.configure do |config|
|
46
|
+
config.api_key = 'DUTY_CALC'
|
47
|
+
config.sandbox = true
|
48
|
+
config.debug = true
|
49
|
+
end
|
50
|
+
VCR.use_cassette('dootie__status_codes_from_api_2') do
|
51
|
+
duty_calculation = DutyCalculator::Calculation.get(params)
|
52
|
+
expect(duty_calculation.class).to eq(DutyCalculator::Dootie)
|
53
|
+
expect(duty_calculation.message).to include('4747')
|
54
|
+
expect(duty_calculation.message).to include('could not be autoclassified')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://www.dutycalculator.com/api2.1/sandbox/calculation?cat%5B%5D=9999999999999999999992&classify_by=cat&commercial_importer=0&country_of_hs_code%5B%5D=CN¤cy=USD&desc%5B%5D=Hydrotherapy%20Spa%20Bath&detailed_result=1&from=US&hs%5B%5D=9019100020&incl_hs_codes=1&insurance=0.0&origin=US&preferential_rates=0&qty%5B%5D=1&reference=ORD12345&shipping=10.0&shipping_mode=USPS&sku%5B%5D=300101&to=CA&value%5B%5D=1234.00&weight%5B%5D=1.0&weight_unit%5B%5D=lb
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.1
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 400
|
19
|
+
message: Bad Request
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx/1.6.1
|
23
|
+
Date:
|
24
|
+
- Wed, 01 Apr 2015 18:33:37 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/xml
|
27
|
+
Transfer-Encoding:
|
28
|
+
- chunked
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
X-Powered-By:
|
32
|
+
- PHP/5.5.9-1ubuntu4.5
|
33
|
+
Set-Cookie:
|
34
|
+
- DebugLevel=0; expires=Fri, 01-May-2015 18:33:37 GMT; Max-Age=2592000; path=/
|
35
|
+
- PHPSESSID=2r0e1sofgbpetuhrks0nm273o0; path=/
|
36
|
+
Expires:
|
37
|
+
- Thu, 19 Nov 1981 08:52:00 GMT
|
38
|
+
Cache-Control:
|
39
|
+
- no-store, no-cache, must-revalidate, post-check=0, pre-check=0
|
40
|
+
Pragma:
|
41
|
+
- no-cache
|
42
|
+
body:
|
43
|
+
encoding: UTF-8
|
44
|
+
string: |
|
45
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
46
|
+
<error><code>4046</code><message>Client id is invalid or missing</message></error>
|
47
|
+
http_version:
|
48
|
+
recorded_at: Wed, 01 Apr 2015 18:31:08 GMT
|
49
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,49 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://www.dutycalculator.com/api2.1/sandbox/DUTY_CALC/calculation?cat%5B%5D=9999999999999999999992&classify_by=cat&commercial_importer=0&country_of_hs_code%5B%5D=CN¤cy=USD&desc%5B%5D=Hydrotherapy%20Spa%20Bath&detailed_result=1&from=US&hs%5B%5D=9019100020&incl_hs_codes=1&insurance=0.0&origin=US&preferential_rates=0&qty%5B%5D=1&reference=ORD12345&shipping=10.0&shipping_mode=USPS&sku%5B%5D=300101&to=CA&value%5B%5D=1234.00&weight%5B%5D=1.0&weight_unit%5B%5D=lb
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.1
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 400
|
19
|
+
message: Bad Request
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx/1.6.1
|
23
|
+
Date:
|
24
|
+
- Wed, 01 Apr 2015 18:33:37 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/xml
|
27
|
+
Transfer-Encoding:
|
28
|
+
- chunked
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
X-Powered-By:
|
32
|
+
- PHP/5.5.9-1ubuntu4.5
|
33
|
+
Set-Cookie:
|
34
|
+
- DebugLevel=0; expires=Fri, 01-May-2015 18:33:37 GMT; Max-Age=2592000; path=/
|
35
|
+
- PHPSESSID=njctv8db05jj19cpk6p42qm621; path=/
|
36
|
+
Expires:
|
37
|
+
- Thu, 19 Nov 1981 08:52:00 GMT
|
38
|
+
Cache-Control:
|
39
|
+
- no-store, no-cache, must-revalidate, post-check=0, pre-check=0
|
40
|
+
Pragma:
|
41
|
+
- no-cache
|
42
|
+
body:
|
43
|
+
encoding: UTF-8
|
44
|
+
string: |
|
45
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
46
|
+
<error><code>4747</code><message>Reference 0 could not be autoclassified</message></error>
|
47
|
+
http_version:
|
48
|
+
recorded_at: Wed, 01 Apr 2015 18:31:08 GMT
|
49
|
+
recorded_with: VCR 2.9.3
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duty_calculator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Hanley
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-04-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -160,17 +160,21 @@ files:
|
|
160
160
|
- lib/duty_calculator/client.rb
|
161
161
|
- lib/duty_calculator/configuration.rb
|
162
162
|
- lib/duty_calculator/currency.rb
|
163
|
+
- lib/duty_calculator/dootie.rb
|
163
164
|
- lib/duty_calculator/error_messages.rb
|
164
165
|
- lib/duty_calculator/response.rb
|
165
166
|
- lib/duty_calculator/version.rb
|
166
167
|
- spec/duty_calculator/calculation_spec.rb
|
167
168
|
- spec/duty_calculator/configuration_spec.rb
|
168
169
|
- spec/duty_calculator/currency_spec.rb
|
170
|
+
- spec/duty_calculator/dootie_spec.rb
|
169
171
|
- spec/duty_calculator/response_spec.rb
|
170
172
|
- spec/spec_helper.rb
|
171
173
|
- spec/support/vcr.rb
|
172
174
|
- spec/vcr/calculate__nice_hash_for_multiple_products.yml
|
173
175
|
- spec/vcr/calculate__nice_hash_for_single_product.yml
|
176
|
+
- spec/vcr/dootie__status_codes_from_api_1.yml
|
177
|
+
- spec/vcr/dootie__status_codes_from_api_2.yml
|
174
178
|
homepage: https://github.com/tjhanley/duty-calculator
|
175
179
|
licenses:
|
176
180
|
- MIT
|
@@ -199,8 +203,11 @@ test_files:
|
|
199
203
|
- spec/duty_calculator/calculation_spec.rb
|
200
204
|
- spec/duty_calculator/configuration_spec.rb
|
201
205
|
- spec/duty_calculator/currency_spec.rb
|
206
|
+
- spec/duty_calculator/dootie_spec.rb
|
202
207
|
- spec/duty_calculator/response_spec.rb
|
203
208
|
- spec/spec_helper.rb
|
204
209
|
- spec/support/vcr.rb
|
205
210
|
- spec/vcr/calculate__nice_hash_for_multiple_products.yml
|
206
211
|
- spec/vcr/calculate__nice_hash_for_single_product.yml
|
212
|
+
- spec/vcr/dootie__status_codes_from_api_1.yml
|
213
|
+
- spec/vcr/dootie__status_codes_from_api_2.yml
|