dhl-get_quote 0.4.27 → 0.5.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/README.md +7 -6
- data/dhl-get_quote.gemspec +6 -1
- data/lib/dhl-get_quote.rb +30 -16
- data/lib/dhl/get_quote/errors.rb +11 -0
- data/lib/dhl/get_quote/request.rb +69 -14
- data/lib/dhl/get_quote/response.rb +16 -0
- data/lib/dhl/get_quote/version.rb +14 -1
- data/spec/lib/dhl/dh-get_quote_spec.rb +40 -49
- data/spec/lib/dhl/get_quote/request_spec.rb +178 -27
- data/spec/lib/dhl/get_quote/response_spec.rb +17 -0
- data/spec/spec_helper.rb +6 -0
- data/tpl/request.xml.erb +10 -1
- metadata +11 -8
data/README.md
CHANGED
|
@@ -127,18 +127,19 @@ You can also get the value directly:
|
|
|
127
127
|
|
|
128
128
|
#### Setting Duty
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
! Note, this a breaking change from 0.4.x
|
|
131
|
+
|
|
132
|
+
To set the duty on a shipment, use the dutiable!() method. It accepts the numeric value and an optional currency code. If not specified, the currency code default to US Dollars (USD).
|
|
131
133
|
|
|
132
134
|
```ruby
|
|
133
|
-
|
|
134
|
-
request.
|
|
135
|
+
# set the dutiable value at $100 in US Dollars
|
|
136
|
+
request.dutiable!(100.00, 'USD')
|
|
135
137
|
```
|
|
136
138
|
|
|
137
|
-
|
|
139
|
+
To remove a previously set duty, use the not_dutiable!() method.
|
|
138
140
|
|
|
139
141
|
```ruby
|
|
140
|
-
request.
|
|
141
|
-
request.dutiable(false)
|
|
142
|
+
request.not_dutiable!
|
|
142
143
|
```
|
|
143
144
|
|
|
144
145
|
You can query the current state with #dutiable?:
|
data/dhl-get_quote.gemspec
CHANGED
|
@@ -24,6 +24,11 @@ Gem::Specification.new do |gem|
|
|
|
24
24
|
gem.add_development_dependency 'rake', '10.0.4'
|
|
25
25
|
gem.add_development_dependency 'rspec', '2.13.0'
|
|
26
26
|
gem.add_development_dependency 'rspec-must', '0.0.1'
|
|
27
|
-
gem.add_development_dependency '
|
|
27
|
+
gem.add_development_dependency 'timecop', '~> 0.6.1'
|
|
28
|
+
# gem.add_development_dependency 'debugger'
|
|
29
|
+
|
|
30
|
+
if Dhl::GetQuote::PostInstallMessage
|
|
31
|
+
gem.post_install_message = Dhl::GetQuote::PostInstallMessage
|
|
32
|
+
end
|
|
28
33
|
|
|
29
34
|
end
|
data/lib/dhl-get_quote.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
1
3
|
require "dhl/get_quote/version"
|
|
2
4
|
require "dhl/get_quote/helper"
|
|
3
5
|
require "dhl/get_quote/errors"
|
|
@@ -44,13 +46,25 @@ class Dhl
|
|
|
44
46
|
end
|
|
45
47
|
end
|
|
46
48
|
|
|
47
|
-
def self.
|
|
49
|
+
def self.metric_measurements!
|
|
48
50
|
@@weight_unit = WEIGHT_UNIT_CODES[:kilograms]
|
|
51
|
+
@@dimensions_unit = DIMENSIONS_UNIT_CODES[:centimeters]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.us_measurements!
|
|
55
|
+
@@weight_unit = WEIGHT_UNIT_CODES[:pounds]
|
|
56
|
+
@@dimensions_unit = DIMENSIONS_UNIT_CODES[:inches]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def self.kilograms!
|
|
60
|
+
deprication_notice(:kilograms!, :metric)
|
|
61
|
+
metric_measurements!
|
|
49
62
|
end
|
|
50
63
|
def self.kilogrammes!; self.kilograms!; end
|
|
51
64
|
|
|
52
65
|
def self.pounds!
|
|
53
|
-
|
|
66
|
+
deprication_notice(:pounds!, :us)
|
|
67
|
+
us_measurements!
|
|
54
68
|
end
|
|
55
69
|
|
|
56
70
|
def self.weight_unit
|
|
@@ -58,30 +72,20 @@ class Dhl
|
|
|
58
72
|
end
|
|
59
73
|
|
|
60
74
|
def self.centimeters!
|
|
61
|
-
|
|
75
|
+
deprication_notice(:centimeters!, :metric)
|
|
76
|
+
metric_measurements!
|
|
62
77
|
end
|
|
63
78
|
def self.centimetres!; self.centimeters!; end
|
|
64
79
|
|
|
65
80
|
def self.inches!
|
|
66
|
-
|
|
81
|
+
deprication_notice(:inches!, :us)
|
|
82
|
+
us_measurements!
|
|
67
83
|
end
|
|
68
84
|
|
|
69
85
|
def self.dimensions_unit
|
|
70
86
|
@@dimensions_unit
|
|
71
87
|
end
|
|
72
88
|
|
|
73
|
-
def self.dutiable!
|
|
74
|
-
@@dutiable = true
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def self.not_dutiable!
|
|
78
|
-
@@dutiable = false
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def self.dutiable?
|
|
82
|
-
!!@@dutiable
|
|
83
|
-
end
|
|
84
|
-
|
|
85
89
|
def self.set_defaults
|
|
86
90
|
@@site_id = nil
|
|
87
91
|
@@password = nil
|
|
@@ -90,6 +94,16 @@ class Dhl
|
|
|
90
94
|
@@dutiable = false
|
|
91
95
|
@@test_mode = false
|
|
92
96
|
end
|
|
97
|
+
|
|
98
|
+
private
|
|
99
|
+
|
|
100
|
+
def self.deprication_notice(meth, m)
|
|
101
|
+
messages = {
|
|
102
|
+
:metric => "Method replaced by Dhl::GetQuote#metic_measurements!(). I am now setting your measurements to metric",
|
|
103
|
+
:us => "Method replaced by Dhl::GetQuote#us_measurements!(). I am now setting your measurements to US customary",
|
|
104
|
+
}
|
|
105
|
+
puts "!!!! Method \"##{meth}()\" is depricated. #{messages[m.to_sym]}."
|
|
106
|
+
end
|
|
93
107
|
end
|
|
94
108
|
end
|
|
95
109
|
|
data/lib/dhl/get_quote/errors.rb
CHANGED
|
@@ -9,5 +9,16 @@ class Dhl::GetQuote
|
|
|
9
9
|
class Upstream < StandardError
|
|
10
10
|
class UnknownError < Upstream; end
|
|
11
11
|
class ValidationFailureError < Upstream; end
|
|
12
|
+
class ConditionError < Upstream
|
|
13
|
+
attr_reader :code, :message
|
|
14
|
+
def initialize(code, message)
|
|
15
|
+
@code = code
|
|
16
|
+
@message = message
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_s
|
|
20
|
+
"#{code}: #{message}"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
12
23
|
end
|
|
13
24
|
end
|
|
@@ -4,7 +4,7 @@ require 'erb'
|
|
|
4
4
|
require 'set'
|
|
5
5
|
|
|
6
6
|
class Dhl::GetQuote::Request
|
|
7
|
-
attr_reader :site_id, :password, :from_country_code, :from_postal_code, :to_country_code, :to_postal_code
|
|
7
|
+
attr_reader :site_id, :password, :from_country_code, :from_postal_code, :to_country_code, :to_postal_code, :duty
|
|
8
8
|
attr_accessor :pieces
|
|
9
9
|
|
|
10
10
|
URLS = {
|
|
@@ -26,7 +26,7 @@ class Dhl::GetQuote::Request
|
|
|
26
26
|
|
|
27
27
|
@special_services_list = Set.new
|
|
28
28
|
|
|
29
|
-
@
|
|
29
|
+
@duty = false
|
|
30
30
|
|
|
31
31
|
@pieces = []
|
|
32
32
|
end
|
|
@@ -56,19 +56,27 @@ class Dhl::GetQuote::Request
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
def dutiable?
|
|
59
|
-
!!@
|
|
59
|
+
!!@duty
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
def dutiable(
|
|
63
|
-
@
|
|
62
|
+
def dutiable(value, currency_code="USD")
|
|
63
|
+
@duty = {
|
|
64
|
+
:declared_value => value.to_f,
|
|
65
|
+
:declared_currency => currency_code.slice(0,3).upcase
|
|
66
|
+
}
|
|
64
67
|
end
|
|
68
|
+
alias_method :dutiable!, :dutiable
|
|
65
69
|
|
|
66
|
-
def
|
|
67
|
-
|
|
70
|
+
def not_dutiable!
|
|
71
|
+
@duty = false
|
|
68
72
|
end
|
|
69
73
|
|
|
70
|
-
def
|
|
71
|
-
|
|
74
|
+
def payment_account_number(pac = nil)
|
|
75
|
+
if pac.to_s.size > 0
|
|
76
|
+
@payment_account_number = pac
|
|
77
|
+
else
|
|
78
|
+
@payment_account_number
|
|
79
|
+
end
|
|
72
80
|
end
|
|
73
81
|
|
|
74
82
|
def dimensions_unit
|
|
@@ -79,13 +87,33 @@ class Dhl::GetQuote::Request
|
|
|
79
87
|
@weight_unit ||= Dhl::GetQuote.weight_unit
|
|
80
88
|
end
|
|
81
89
|
|
|
82
|
-
def
|
|
90
|
+
def metric_measurements!
|
|
91
|
+
@weight_unit = Dhl::GetQuote::WEIGHT_UNIT_CODES[:kilograms]
|
|
83
92
|
@dimensions_unit = Dhl::GetQuote::DIMENSIONS_UNIT_CODES[:centimeters]
|
|
84
93
|
end
|
|
94
|
+
|
|
95
|
+
def us_measurements!
|
|
96
|
+
@weight_unit = Dhl::GetQuote::WEIGHT_UNIT_CODES[:pounds]
|
|
97
|
+
@dimensions_unit = Dhl::GetQuote::DIMENSIONS_UNIT_CODES[:inches]
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def centimeters!
|
|
101
|
+
deprication_notice(:centimeters!, :metric)
|
|
102
|
+
metric_measurements!
|
|
103
|
+
end
|
|
85
104
|
alias :centimetres! :centimeters!
|
|
86
105
|
|
|
87
106
|
def inches!
|
|
88
|
-
|
|
107
|
+
deprication_notice(:inches!, :us)
|
|
108
|
+
us_measurements!
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def metric_measurements?
|
|
112
|
+
centimeters? && kilograms?
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def us_measurements?
|
|
116
|
+
pounds? && inches?
|
|
89
117
|
end
|
|
90
118
|
|
|
91
119
|
def centimeters?
|
|
@@ -98,12 +126,14 @@ class Dhl::GetQuote::Request
|
|
|
98
126
|
end
|
|
99
127
|
|
|
100
128
|
def kilograms!
|
|
101
|
-
|
|
129
|
+
deprication_notice(:kilograms!, :metric)
|
|
130
|
+
metric_measurements!
|
|
102
131
|
end
|
|
103
132
|
alias :kilogrammes! :kilograms!
|
|
104
133
|
|
|
105
134
|
def pounds!
|
|
106
|
-
|
|
135
|
+
deprication_notice(:pounds!, :us)
|
|
136
|
+
us_measurements!
|
|
107
137
|
end
|
|
108
138
|
|
|
109
139
|
def pounds?
|
|
@@ -120,8 +150,23 @@ class Dhl::GetQuote::Request
|
|
|
120
150
|
ERB.new(File.new(xml_template_path).read, nil,'%<>-').result(binding)
|
|
121
151
|
end
|
|
122
152
|
|
|
153
|
+
# ready times are only 8a-5p(17h)
|
|
123
154
|
def ready_time(time=Time.now)
|
|
124
|
-
time.
|
|
155
|
+
if time.hour >= 17 || time.hour < 8
|
|
156
|
+
time.strftime("PT08H00M")
|
|
157
|
+
else
|
|
158
|
+
time.strftime("PT%HH%MM")
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# ready dates are only mon-fri
|
|
163
|
+
def ready_date(t=Time.now)
|
|
164
|
+
date = Date.parse(t.to_s)
|
|
165
|
+
if date.wday >= 5 && t.hour >= 17
|
|
166
|
+
date.send(:next_day, (8-date.wday))
|
|
167
|
+
else
|
|
168
|
+
date
|
|
169
|
+
end.strftime("%Y-%m-%d")
|
|
125
170
|
end
|
|
126
171
|
|
|
127
172
|
def post
|
|
@@ -180,4 +225,14 @@ protected
|
|
|
180
225
|
gem_root = spec.gem_dir
|
|
181
226
|
gem_root + "/tpl/request.xml.erb"
|
|
182
227
|
end
|
|
228
|
+
|
|
229
|
+
private
|
|
230
|
+
|
|
231
|
+
def deprication_notice(meth, m)
|
|
232
|
+
messages = {
|
|
233
|
+
:metric => "Method replaced by Dhl::GetQuote::Request#metic_measurements!(). I am now setting your measurements to metric",
|
|
234
|
+
:us => "Method replaced by Dhl::GetQuote::Request#us_measurements!(). I am now setting your measurements to US customary",
|
|
235
|
+
}
|
|
236
|
+
puts "!!!! Method \"##{meth}()\" is depricated. #{messages[m.to_sym]}."
|
|
237
|
+
end
|
|
183
238
|
end
|
|
@@ -23,6 +23,8 @@ class Dhl::GetQuote::Response
|
|
|
23
23
|
else
|
|
24
24
|
Dhl::GetQuote::Upstream::UnknownError.new(response_error_condition_data)
|
|
25
25
|
end
|
|
26
|
+
elsif condition_indicates_error?
|
|
27
|
+
@error = Dhl::GetQuote::Upstream::ConditionError.new(condition_error_code, condition_error_message)
|
|
26
28
|
else
|
|
27
29
|
load_costs(DEFAULT_CURRENCY_ROLE_TYPE_CODE)
|
|
28
30
|
end
|
|
@@ -90,6 +92,20 @@ protected
|
|
|
90
92
|
@response_error_condition_data ||= response_error_status_condition['ConditionData']
|
|
91
93
|
end
|
|
92
94
|
|
|
95
|
+
def condition_indicates_error?
|
|
96
|
+
@parsed_xml["DCTResponse"]["GetQuoteResponse"] &&
|
|
97
|
+
@parsed_xml["DCTResponse"]["GetQuoteResponse"]["Note"] &&
|
|
98
|
+
@parsed_xml["DCTResponse"]["GetQuoteResponse"]["Note"]["Condition"].is_a?(Hash)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def condition_error_code
|
|
102
|
+
@parsed_xml["DCTResponse"]["GetQuoteResponse"]["Note"]["Condition"]["ConditionCode"]
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def condition_error_message
|
|
106
|
+
@parsed_xml["DCTResponse"]["GetQuoteResponse"]["Note"]["Condition"]["ConditionData"].strip
|
|
107
|
+
end
|
|
108
|
+
|
|
93
109
|
def market_services
|
|
94
110
|
@market_services ||= begin
|
|
95
111
|
srv = @parsed_xml["DCTResponse"]["GetQuoteResponse"]["Srvs"]["Srv"]
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
class Dhl
|
|
2
2
|
class GetQuote
|
|
3
|
-
VERSION = "0.
|
|
3
|
+
VERSION = "0.5.0"
|
|
4
|
+
|
|
5
|
+
PostInstallMessage = <<EOS
|
|
6
|
+
|
|
7
|
+
*** NOTE Dhl-GetQuote ***
|
|
8
|
+
|
|
9
|
+
This version introduces the following changes from 0.4.x:
|
|
10
|
+
|
|
11
|
+
* #inches!, #pounds!, #kilograms! and #centimeters have been depricated.
|
|
12
|
+
Please use #us_measurements! or #metric_measurements!.
|
|
13
|
+
|
|
14
|
+
* dutiable() replaces dutiable! now requires arguments (dutiable value and currency).
|
|
15
|
+
|
|
16
|
+
EOS
|
|
4
17
|
end
|
|
5
18
|
end
|
|
@@ -94,83 +94,74 @@ describe Dhl::GetQuote do
|
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
describe "kilograms!" do
|
|
97
|
-
|
|
97
|
+
# silence deprication notices in tests
|
|
98
|
+
before(:each) { klass.stub!(:puts) }
|
|
98
99
|
|
|
99
|
-
it "must
|
|
100
|
-
klass.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
it "Dhl::GetQuote::Request must honor this" do
|
|
104
|
-
valid_request.weight_unit.must == "KG"
|
|
100
|
+
it "must call #metric_measurements!" do
|
|
101
|
+
klass.must_receive(:metric_measurements!)
|
|
102
|
+
klass.kilograms!
|
|
105
103
|
end
|
|
106
104
|
end
|
|
107
105
|
|
|
108
106
|
describe "pounds!" do
|
|
109
|
-
|
|
107
|
+
# silence deprication notices in tests
|
|
108
|
+
before(:each) { klass.stub!(:puts) }
|
|
110
109
|
|
|
111
|
-
it "must
|
|
112
|
-
klass.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
it "Dhl::GetQuote::Request must honor this" do
|
|
116
|
-
valid_request.weight_unit.must == "LB"
|
|
110
|
+
it "must call #us_measurements!" do
|
|
111
|
+
klass.must_receive(:us_measurements!)
|
|
112
|
+
klass.pounds!
|
|
117
113
|
end
|
|
118
114
|
end
|
|
119
115
|
|
|
120
116
|
describe "centimeters!" do
|
|
121
|
-
|
|
117
|
+
# silence deprication notices in tests
|
|
118
|
+
before(:each) { klass.stub!(:puts) }
|
|
122
119
|
|
|
123
|
-
it "must
|
|
124
|
-
klass.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
it "Dhl::GetQuote::Request must honor this" do
|
|
128
|
-
valid_request.dimensions_unit.must == "CM"
|
|
120
|
+
it "must call #metric_measurements!" do
|
|
121
|
+
klass.must_receive(:metric_measurements!)
|
|
122
|
+
klass.centimeters!
|
|
129
123
|
end
|
|
130
124
|
end
|
|
131
125
|
|
|
132
126
|
describe "inches!" do
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
it "must set class weight_unit to IN" do
|
|
136
|
-
klass.dimensions_unit.must == "IN"
|
|
137
|
-
end
|
|
127
|
+
# silence deprication notices in tests
|
|
128
|
+
before(:each) { klass.stub!(:puts) }
|
|
138
129
|
|
|
139
|
-
it "
|
|
140
|
-
|
|
130
|
+
it "must call #us_measurements!" do
|
|
131
|
+
klass.must_receive(:us_measurements!)
|
|
132
|
+
klass.inches!
|
|
141
133
|
end
|
|
142
134
|
end
|
|
143
135
|
|
|
144
|
-
describe "
|
|
145
|
-
before(:each)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
klass.dutiable?.must be_true
|
|
136
|
+
describe "us_measurements!" do
|
|
137
|
+
before(:each) { klass.metric_measurements! }
|
|
138
|
+
it "must set the weight and dimensions to LB and IN" do
|
|
139
|
+
klass.us_measurements!
|
|
140
|
+
klass.dimensions_unit.must == "IN"
|
|
141
|
+
klass.weight_unit.must == "LB"
|
|
151
142
|
end
|
|
152
143
|
|
|
153
|
-
it "Dhl::GetQuote::Request must honor this
|
|
154
|
-
|
|
155
|
-
|
|
144
|
+
it "Dhl::GetQuote::Request must honor this" do
|
|
145
|
+
klass.us_measurements!
|
|
146
|
+
valid_request.dimensions_unit.must == "IN"
|
|
147
|
+
valid_request.weight_unit.must == "LB"
|
|
156
148
|
end
|
|
157
149
|
end
|
|
158
150
|
|
|
159
|
-
describe "
|
|
160
|
-
before(:each)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
klass.dutiable?.must be_false
|
|
151
|
+
describe "metric_measurements!" do
|
|
152
|
+
before(:each) { klass.us_measurements! }
|
|
153
|
+
it "must set the weight and dimensions to KG and CM" do
|
|
154
|
+
klass.metric_measurements!
|
|
155
|
+
klass.dimensions_unit.must == "CM"
|
|
156
|
+
klass.weight_unit.must == "KG"
|
|
166
157
|
end
|
|
167
158
|
|
|
168
|
-
it "Dhl::GetQuote::Request must honor this
|
|
169
|
-
|
|
170
|
-
|
|
159
|
+
it "Dhl::GetQuote::Request must honor this" do
|
|
160
|
+
klass.metric_measurements!
|
|
161
|
+
valid_request.dimensions_unit.must == "CM"
|
|
162
|
+
valid_request.weight_unit.must == "KG"
|
|
171
163
|
end
|
|
172
164
|
end
|
|
173
|
-
|
|
174
165
|
end
|
|
175
166
|
end
|
|
176
167
|
|
|
@@ -98,12 +98,12 @@ describe Dhl::GetQuote::Request do
|
|
|
98
98
|
|
|
99
99
|
describe "#dutiable?" do
|
|
100
100
|
it "must be true if dutiable set to yes" do
|
|
101
|
-
subject.
|
|
101
|
+
subject.dutiable!(1.0, 'USD')
|
|
102
102
|
subject.dutiable?.must be_true
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
it "must be false if dutiable set to no" do
|
|
106
|
-
subject.
|
|
106
|
+
subject.not_dutiable!
|
|
107
107
|
subject.dutiable?.must be_false
|
|
108
108
|
end
|
|
109
109
|
|
|
@@ -112,30 +112,41 @@ describe Dhl::GetQuote::Request do
|
|
|
112
112
|
end
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
-
describe "#dutiable" do
|
|
116
|
-
it "must
|
|
117
|
-
subject.dutiable
|
|
115
|
+
describe "#dutiable!" do
|
|
116
|
+
it "must accept a value and currency code" do
|
|
117
|
+
subject.dutiable?.must be_false #sanity
|
|
118
|
+
|
|
119
|
+
subject.dutiable!(1.0, 'CAD')
|
|
120
|
+
|
|
118
121
|
subject.dutiable?.must be_true
|
|
122
|
+
|
|
123
|
+
subject.duty.must be_an_instance_of Hash
|
|
124
|
+
subject.duty[:declared_currency].must == 'CAD'
|
|
125
|
+
subject.duty[:declared_value].must == 1.0
|
|
119
126
|
end
|
|
120
127
|
|
|
121
|
-
it "must
|
|
122
|
-
subject.dutiable(
|
|
123
|
-
|
|
128
|
+
it "must use USD as the default currency code" do
|
|
129
|
+
subject.dutiable!(1.0)
|
|
130
|
+
|
|
131
|
+
subject.duty[:declared_currency].must == 'USD'
|
|
124
132
|
end
|
|
125
|
-
end
|
|
126
133
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
subject.dutiable?.must be_false #sanity
|
|
134
|
+
it "must upcase and truncate currency codes" do
|
|
135
|
+
subject.dutiable!(1.0, 'MxPe')
|
|
130
136
|
|
|
131
|
-
subject.
|
|
132
|
-
|
|
137
|
+
subject.duty[:declared_currency].must == 'MXP'
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it "must cast value to float" do
|
|
141
|
+
subject.dutiable!(1)
|
|
142
|
+
|
|
143
|
+
subject.duty[:declared_value].must == 1.0
|
|
133
144
|
end
|
|
134
145
|
end
|
|
135
146
|
|
|
136
147
|
describe "#not_dutiable!" do
|
|
137
148
|
it "must set dutiable() to false" do
|
|
138
|
-
subject.instance_variable_set(:@
|
|
149
|
+
subject.instance_variable_set(:@duty, {})
|
|
139
150
|
subject.dutiable?.must be_true #sanity
|
|
140
151
|
|
|
141
152
|
subject.not_dutiable!
|
|
@@ -167,21 +178,75 @@ describe Dhl::GetQuote::Request do
|
|
|
167
178
|
end
|
|
168
179
|
end
|
|
169
180
|
|
|
181
|
+
describe "#us_measurements!" do
|
|
182
|
+
it "should set the measurement units to us" do
|
|
183
|
+
subject.instance_variable_set(:@dimensions_unit, "CM")
|
|
184
|
+
subject.instance_variable_set(:@weight_unit, "KG")
|
|
185
|
+
|
|
186
|
+
subject.us_measurements!
|
|
187
|
+
|
|
188
|
+
subject.dimensions_unit.must == "IN"
|
|
189
|
+
subject.weight_unit.must == "LB"
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
describe "#metric_measurements!" do
|
|
194
|
+
it "must set the measurement units to metric" do
|
|
195
|
+
subject.instance_variable_set(:@dimensions_unit, "IN")
|
|
196
|
+
subject.instance_variable_set(:@weight_unit, "LB")
|
|
197
|
+
|
|
198
|
+
subject.metric_measurements!
|
|
199
|
+
|
|
200
|
+
subject.dimensions_unit.must == "CM"
|
|
201
|
+
subject.weight_unit.must == "KG"
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
describe "#metric_measurements?" do
|
|
206
|
+
it "must be true if measurements are in kg and cm" do
|
|
207
|
+
subject.metric_measurements!
|
|
208
|
+
|
|
209
|
+
subject.metric_measurements?.must be_true
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
it "must be false if measurements are not in kg and cm" do
|
|
213
|
+
subject.us_measurements!
|
|
214
|
+
|
|
215
|
+
subject.metric_measurements?.must be_false
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
describe "#us_measurements?" do
|
|
220
|
+
it "must be true if measurements are in ln and in" do
|
|
221
|
+
subject.us_measurements!
|
|
222
|
+
|
|
223
|
+
subject.us_measurements?.must be_true
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
it "must be false if measurements are not in lb and in" do
|
|
227
|
+
subject.metric_measurements!
|
|
228
|
+
|
|
229
|
+
subject.us_measurements?.must be_false
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
170
233
|
describe "#centimeters!" do
|
|
171
|
-
|
|
172
|
-
|
|
234
|
+
# silence deprication notices in tests
|
|
235
|
+
before(:each) { subject.stub!(:puts) }
|
|
173
236
|
|
|
237
|
+
it "must call #metric_measurements!" do
|
|
238
|
+
subject.must_receive(:metric_measurements!)
|
|
174
239
|
subject.centimeters!
|
|
175
|
-
subject.dimensions_unit.must == "CM"
|
|
176
240
|
end
|
|
177
241
|
end
|
|
178
242
|
|
|
179
243
|
describe "#inches!" do
|
|
180
|
-
|
|
181
|
-
|
|
244
|
+
# silence deprication notices in tests
|
|
245
|
+
before(:each) { subject.stub!(:puts) }
|
|
182
246
|
|
|
247
|
+
it "must call #us_measurements!" do
|
|
248
|
+
subject.must_receive(:us_measurements!)
|
|
183
249
|
subject.inches!
|
|
184
|
-
subject.dimensions_unit.must == "IN"
|
|
185
250
|
end
|
|
186
251
|
end
|
|
187
252
|
|
|
@@ -210,20 +275,22 @@ describe Dhl::GetQuote::Request do
|
|
|
210
275
|
end
|
|
211
276
|
|
|
212
277
|
describe "#kilograms!" do
|
|
213
|
-
|
|
214
|
-
|
|
278
|
+
# silence deprication notices in tests
|
|
279
|
+
before(:each) { subject.stub!(:puts) }
|
|
215
280
|
|
|
281
|
+
it "must call #metric_measurements!" do
|
|
282
|
+
subject.must_receive(:metric_measurements!)
|
|
216
283
|
subject.kilograms!
|
|
217
|
-
subject.weight_unit.must == "KG"
|
|
218
284
|
end
|
|
219
285
|
end
|
|
220
286
|
|
|
221
287
|
describe "#pounds!" do
|
|
222
|
-
|
|
223
|
-
|
|
288
|
+
# silence deprication notices in tests
|
|
289
|
+
before(:each) { subject.stub!(:puts) }
|
|
224
290
|
|
|
291
|
+
it "must call #us_measurements!" do
|
|
292
|
+
subject.must_receive(:us_measurements!)
|
|
225
293
|
subject.pounds!
|
|
226
|
-
subject.weight_unit.must == "LB"
|
|
227
294
|
end
|
|
228
295
|
end
|
|
229
296
|
|
|
@@ -255,6 +322,12 @@ describe Dhl::GetQuote::Request do
|
|
|
255
322
|
before(:each) do
|
|
256
323
|
subject.from('US', 84010)
|
|
257
324
|
subject.to('CA', 'T1H 0A1')
|
|
325
|
+
|
|
326
|
+
Timecop.freeze(Time.local(2013, 5, 15, 10, 5, 0))
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
after(:each) do
|
|
330
|
+
Timecop.return
|
|
258
331
|
end
|
|
259
332
|
|
|
260
333
|
let(:time) { Time.now }
|
|
@@ -479,4 +552,82 @@ eos
|
|
|
479
552
|
subject.instance_variable_get(:@test_mode).must be_false
|
|
480
553
|
end
|
|
481
554
|
end
|
|
555
|
+
|
|
556
|
+
describe "#ready_time" do
|
|
557
|
+
after(:each) do
|
|
558
|
+
Timecop.return
|
|
559
|
+
end
|
|
560
|
+
|
|
561
|
+
it "should conver the current time into a DHL timestamp" do
|
|
562
|
+
Timecop.freeze(Time.local(2013, 5, 15, 10, 5, 0))
|
|
563
|
+
|
|
564
|
+
subject.ready_time.must == 'PT10H05M'
|
|
565
|
+
end
|
|
566
|
+
|
|
567
|
+
context "the time is after 5pm" do
|
|
568
|
+
it "should provide a stamp for the 8am" do
|
|
569
|
+
Timecop.freeze(Time.local(2013, 5, 15, 19, 5, 0))
|
|
570
|
+
|
|
571
|
+
subject.ready_time.must == 'PT08H00M'
|
|
572
|
+
end
|
|
573
|
+
end
|
|
574
|
+
|
|
575
|
+
context "the time is before 8am" do
|
|
576
|
+
it "should provide a stamp for the 8am" do
|
|
577
|
+
Timecop.freeze(Time.local(2013, 5, 15, 6, 5, 0))
|
|
578
|
+
|
|
579
|
+
subject.ready_time.must == 'PT08H00M'
|
|
580
|
+
end
|
|
581
|
+
end
|
|
582
|
+
end
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
describe "#ready_date" do
|
|
586
|
+
after(:each) do
|
|
587
|
+
Timecop.return
|
|
588
|
+
end
|
|
589
|
+
|
|
590
|
+
it 'should provide an ISO date of the current or next business day' do
|
|
591
|
+
Timecop.freeze(Time.local(2013, 5, 15, 10, 5, 0))
|
|
592
|
+
|
|
593
|
+
subject.ready_date.must == '2013-05-15'
|
|
594
|
+
end
|
|
595
|
+
|
|
596
|
+
context 'the date is friday' do
|
|
597
|
+
context 'the time is before 5pm' do
|
|
598
|
+
it 'should return todays date' do
|
|
599
|
+
Timecop.freeze(Time.local(2013, 5, 31, 10, 4, 0))
|
|
600
|
+
|
|
601
|
+
subject.ready_date.must == '2013-05-31'
|
|
602
|
+
end
|
|
603
|
+
end
|
|
604
|
+
context 'the time is after 5pm' do
|
|
605
|
+
it 'should return todays date' do
|
|
606
|
+
Timecop.freeze(Time.local(2013, 5, 31, 19, 4, 0))
|
|
607
|
+
|
|
608
|
+
subject.ready_date.must == '2013-06-03'
|
|
609
|
+
end
|
|
610
|
+
end
|
|
611
|
+
end
|
|
612
|
+
end
|
|
613
|
+
|
|
614
|
+
describe "#payment_account_number" do
|
|
615
|
+
context "payment account number is passed" do
|
|
616
|
+
it "must set the pac to be the passed number" do
|
|
617
|
+
subject.payment_account_number('abc123')
|
|
618
|
+
|
|
619
|
+
subject.instance_variable_get(:@payment_account_number).must == 'abc123'
|
|
620
|
+
end
|
|
621
|
+
end
|
|
622
|
+
context "payment account number is not passes" do
|
|
623
|
+
it "must be nil if no pac is recorded" do
|
|
624
|
+
subject.payment_account_number.must be_nil
|
|
625
|
+
end
|
|
626
|
+
it "must return the pac if one was set previously" do
|
|
627
|
+
subject.instance_variable_set(:@payment_account_number, '123abc')
|
|
628
|
+
|
|
629
|
+
subject.payment_account_number.must == '123abc'
|
|
630
|
+
end
|
|
631
|
+
end
|
|
632
|
+
end
|
|
482
633
|
end
|
|
@@ -96,6 +96,23 @@ describe Dhl::GetQuote::Response do
|
|
|
96
96
|
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
+
context "Condition error" do
|
|
100
|
+
let(:r) { klass.new(conditon_error_response) }
|
|
101
|
+
it "must return a valid object" do
|
|
102
|
+
r.must be_an_instance_of(klass)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "must indicater an error" do
|
|
106
|
+
r.error?.must be_true
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "must set the error value appropriately" do
|
|
110
|
+
r.error.must be_an_instance_of Dhl::GetQuote::Upstream::ConditionError
|
|
111
|
+
r.error.message.must == "The declared value is missing."
|
|
112
|
+
r.error.code.must == "5021"
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
99
116
|
end
|
|
100
117
|
|
|
101
118
|
describe "#error?" do
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
require 'rspec'
|
|
2
2
|
require 'rspec/must'
|
|
3
3
|
|
|
4
|
+
require 'timecop'
|
|
5
|
+
|
|
4
6
|
RSpec.configure do |config|
|
|
5
7
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
6
8
|
config.run_all_when_everything_filtered = true
|
|
@@ -505,4 +507,8 @@ def mkt_srv_response
|
|
|
505
507
|
</Srvs>
|
|
506
508
|
</GetQuoteResponse>
|
|
507
509
|
</res:DCTResponse>'
|
|
510
|
+
end
|
|
511
|
+
|
|
512
|
+
def conditon_error_response
|
|
513
|
+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><res:DCTResponse xmlns:res='http://www.dhl.com' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation= 'http://www.dhl.com DCT-Response.xsd'><GetQuoteResponse><Response><ServiceHeader><MessageTime>2013-05-31T22:49:42.138+01:00</MessageTime><SiteID>Desere</SiteID></ServiceHeader></Response><Note><Condition><ConditionCode>5021</ConditionCode><ConditionData>The declared value is missing. </ConditionData></Condition></Note></GetQuoteResponse></res:DCTResponse>\n"
|
|
508
514
|
end
|
data/tpl/request.xml.erb
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
</From>
|
|
14
14
|
<BkgDetails>
|
|
15
15
|
<PaymentCountryCode><%= @from_country_code %></PaymentCountryCode>
|
|
16
|
-
<Date><%=
|
|
16
|
+
<Date><%= ready_date %></Date>
|
|
17
17
|
<ReadyTime><%= ready_time %></ReadyTime>
|
|
18
18
|
<ReadyTimeGMTOffset>+00:00</ReadyTimeGMTOffset>
|
|
19
19
|
<DimensionUnit><%= dimensions_unit %></DimensionUnit>
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
<Pieces>
|
|
22
22
|
<% pieces.each_with_index do |piece,i| %><%= piece.piece_id = i+1; piece.to_xml %><% end %>
|
|
23
23
|
</Pieces>
|
|
24
|
+
<% if @payment_account_number -%>
|
|
25
|
+
<PaymentAccountNumber><%= @payment_account_number %></PaymentAccountNumber>
|
|
26
|
+
<% end -%>
|
|
24
27
|
<IsDutiable><%= dutiable? ? "Y" : "N" %></IsDutiable>
|
|
25
28
|
<% if special_services.size>0 -%>
|
|
26
29
|
<QtdShp>
|
|
@@ -36,5 +39,11 @@
|
|
|
36
39
|
<CountryCode><%= @to_country_code %></CountryCode>
|
|
37
40
|
<Postalcode><%= @to_postal_code %></Postalcode>
|
|
38
41
|
</To>
|
|
42
|
+
<%- if dutiable? %>
|
|
43
|
+
<Dutiable>
|
|
44
|
+
<DeclaredCurrency><%= @duty[:declared_currency] %></DeclaredCurrency>
|
|
45
|
+
<DeclaredValue><%= @duty[:declared_value] %></DeclaredValue>
|
|
46
|
+
</Dutiable>
|
|
47
|
+
<% end %>
|
|
39
48
|
</GetQuote>
|
|
40
49
|
</p:DCTRequest>
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dhl-get_quote
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2013-
|
|
13
|
+
date: 2013-06-03 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: httparty
|
|
@@ -109,21 +109,21 @@ dependencies:
|
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
110
|
version: 0.0.1
|
|
111
111
|
- !ruby/object:Gem::Dependency
|
|
112
|
-
name:
|
|
112
|
+
name: timecop
|
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
|
114
114
|
none: false
|
|
115
115
|
requirements:
|
|
116
|
-
- -
|
|
116
|
+
- - ~>
|
|
117
117
|
- !ruby/object:Gem::Version
|
|
118
|
-
version:
|
|
118
|
+
version: 0.6.1
|
|
119
119
|
type: :development
|
|
120
120
|
prerelease: false
|
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
|
122
122
|
none: false
|
|
123
123
|
requirements:
|
|
124
|
-
- -
|
|
124
|
+
- - ~>
|
|
125
125
|
- !ruby/object:Gem::Version
|
|
126
|
-
version:
|
|
126
|
+
version: 0.6.1
|
|
127
127
|
description: Get shipping quotes from DHL
|
|
128
128
|
email:
|
|
129
129
|
- mnielsen@deseretbook.com
|
|
@@ -157,7 +157,10 @@ files:
|
|
|
157
157
|
- tpl/request.xml.erb
|
|
158
158
|
homepage: https://github.com/deseretbook/dhl-get_quote
|
|
159
159
|
licenses: []
|
|
160
|
-
post_install_message:
|
|
160
|
+
post_install_message: ! "\n*** NOTE Dhl-GetQuote ***\n\nThis version introduces the
|
|
161
|
+
following changes from 0.4.x:\n\n* #inches!, #pounds!, #kilograms! and #centimeters
|
|
162
|
+
have been depricated.\n Please use #us_measurements! or #metric_measurements!.\n\n*
|
|
163
|
+
dutiable() replaces dutiable! now requires arguments (dutiable value and currency).\n\n"
|
|
161
164
|
rdoc_options: []
|
|
162
165
|
require_paths:
|
|
163
166
|
- lib
|