dhl 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile +0 -18
- data/README.md +1 -0
- data/dhl.gemspec +3 -2
- data/lib/dhl.rb +2 -1
- data/lib/dhl/client.rb +12 -8
- data/lib/dhl/error.rb +6 -0
- data/lib/dhl/error/generic.rb +19 -0
- data/lib/dhl/tracking.rb +9 -0
- data/lib/dhl/tracking/event.rb +22 -0
- data/lib/dhl/tracking/request.rb +35 -0
- data/lib/dhl/tracking/response.rb +30 -0
- data/lib/dhl/tracking/shipment_info.rb +10 -0
- data/lib/dhl/version.rb +1 -1
- data/spec/fixtures/dhl_cassettes/tracking/5223281416.yml +770 -0
- data/spec/fixtures/dhl_cassettes/tracking/5223300596.yml +521 -0
- data/spec/fixtures/dhl_cassettes/tracking/6676848301.yml +315 -0
- data/spec/fixtures/dhl_cassettes/tracking/6676848415.yml +588 -0
- data/spec/fixtures/dhl_cassettes/tracking/9786162326.yml +547 -0
- data/spec/lib/dhl/client_spec.rb +38 -15
- data/spec/spec_helper.rb +1 -1
- metadata +37 -7
- data/lib/dhl/tracking_request.rb +0 -32
data/spec/lib/dhl/client_spec.rb
CHANGED
@@ -5,46 +5,69 @@ require_relative '../../spec_helper'
|
|
5
5
|
describe Dhl::Client do
|
6
6
|
|
7
7
|
let(:client) { Dhl.client(username: 'username', password: 'password', account: 123456789) }
|
8
|
+
subject { response }
|
8
9
|
|
9
10
|
after do
|
10
11
|
VCR.eject_cassette
|
11
12
|
end
|
12
13
|
|
13
14
|
describe '#request_shipment' do
|
14
|
-
before
|
15
|
-
VCR.insert_cassette 'shipment', record: :new_episodes
|
16
|
-
end
|
15
|
+
before { VCR.insert_cassette 'shipment', record: :new_episodes }
|
17
16
|
|
18
17
|
let(:shipment_request) { Dhl::ShipmentRequest.new }
|
19
18
|
let(:shipper) { FactoryGirl.build(:contact) }
|
20
19
|
let(:recipient) { FactoryGirl.build(:contact) }
|
21
20
|
let(:packages) { shipment_request.packages }
|
22
21
|
let(:shipment) { FactoryGirl.build(:shipment) }
|
22
|
+
let(:response) { client.request_shipment(shipment_request) }
|
23
23
|
|
24
24
|
it "should return a PDF shipping label" do
|
25
25
|
shipment_request.shipper = shipper
|
26
26
|
shipment_request.recipient = recipient
|
27
27
|
shipment.pickup_time = (Time.now + 86400)
|
28
28
|
shipment_request.shipment = shipment
|
29
|
-
|
30
29
|
packages.add(50, 10, 15, 20, 'Ref 1')
|
31
30
|
packages.add(100, 40, 45, 35, 'Ref 2')
|
32
31
|
|
33
|
-
response
|
34
|
-
response[:tracking_numbers].should == ["JD012038742880323158", "JD012038742880323159"]
|
32
|
+
response[:tracking_number].should == '9085882330'
|
35
33
|
File.exists?('labels/9085882330.pdf').should be_true
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
describe '#track' do
|
38
|
+
context 'the shipment has been fully delivered' do
|
39
|
+
before { VCR.insert_cassette 'tracking/5223281416', record: :new_episodes}
|
40
|
+
let(:response) { client.track "5223281416" }
|
41
|
+
|
42
|
+
its(:shipment_info) { should_not be_nil }
|
43
|
+
it { should have_at_least(1).event }
|
44
|
+
it { should be_delivered }
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'the shipment is not yet delivered' do
|
48
|
+
before { VCR.insert_cassette 'tracking/6676848301', record: :new_episodes}
|
49
|
+
let(:response) { client.track "6676848301" }
|
50
|
+
it { should_not be_delivered }
|
51
|
+
end
|
52
|
+
|
53
|
+
# More VCR cassettes for testing purposes
|
54
|
+
context 'the shipment has been fully delivered' do
|
55
|
+
before { VCR.insert_cassette 'tracking/9786162326', record: :new_episodes}
|
56
|
+
let(:response) { client.track "9786162326" }
|
57
|
+
it { should be_delivered }
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'the shipment has been fully delivered' do
|
61
|
+
before { VCR.insert_cassette 'tracking/5223300596', record: :new_episodes}
|
62
|
+
let(:response) { client.track "5223300596" }
|
63
|
+
it { should be_delivered }
|
64
|
+
end
|
43
65
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
66
|
+
context 'the shipment has been fully delivered' do
|
67
|
+
before { VCR.insert_cassette 'tracking/6676848415', record: :new_episodes}
|
68
|
+
let(:response) { client.track "6676848415" }
|
69
|
+
it { should be_delivered }
|
70
|
+
end
|
71
|
+
end
|
49
72
|
|
50
73
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -15,6 +15,7 @@ RSpec.configure do |config|
|
|
15
15
|
# --seed 1234
|
16
16
|
config.order = 'random'
|
17
17
|
|
18
|
+
# Deletes all existing shipping labels when done
|
18
19
|
config.after(:all) do
|
19
20
|
FileUtils.rm_rf('labels')
|
20
21
|
end
|
@@ -34,7 +35,6 @@ require 'rspec/autorun'
|
|
34
35
|
require 'webmock/rspec'
|
35
36
|
require 'vcr'
|
36
37
|
|
37
|
-
#VCR config
|
38
38
|
VCR.configure do |config|
|
39
39
|
config.cassette_library_dir = 'spec/fixtures/dhl_cassettes'
|
40
40
|
config.hook_into :webmock
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dhl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Mencarini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: savon
|
@@ -86,28 +86,42 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ~>
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 2.
|
89
|
+
version: 2.5.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 2.
|
96
|
+
version: 2.5.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: webmock
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ~>
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 1.
|
103
|
+
version: 1.11.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ~>
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 1.
|
110
|
+
version: 1.11.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.9.12
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.9.12
|
111
125
|
description: 'A wrapper for DHL SOAP interface. '
|
112
126
|
email:
|
113
127
|
- a.mencarini@freegoweb.it
|
@@ -127,16 +141,27 @@ files:
|
|
127
141
|
- lib/dhl/client.rb
|
128
142
|
- lib/dhl/configuration.rb
|
129
143
|
- lib/dhl/contact.rb
|
144
|
+
- lib/dhl/error.rb
|
145
|
+
- lib/dhl/error/generic.rb
|
130
146
|
- lib/dhl/examples.rb
|
131
147
|
- lib/dhl/package.rb
|
132
148
|
- lib/dhl/packages.rb
|
133
149
|
- lib/dhl/shipment.rb
|
134
150
|
- lib/dhl/shipment_request.rb
|
135
|
-
- lib/dhl/
|
151
|
+
- lib/dhl/tracking.rb
|
152
|
+
- lib/dhl/tracking/event.rb
|
153
|
+
- lib/dhl/tracking/request.rb
|
154
|
+
- lib/dhl/tracking/response.rb
|
155
|
+
- lib/dhl/tracking/shipment_info.rb
|
136
156
|
- lib/dhl/version.rb
|
137
157
|
- spec/factories/contact_factory.rb
|
138
158
|
- spec/factories/shipment_factory.rb
|
139
159
|
- spec/fixtures/dhl_cassettes/shipment.yml
|
160
|
+
- spec/fixtures/dhl_cassettes/tracking/5223281416.yml
|
161
|
+
- spec/fixtures/dhl_cassettes/tracking/5223300596.yml
|
162
|
+
- spec/fixtures/dhl_cassettes/tracking/6676848301.yml
|
163
|
+
- spec/fixtures/dhl_cassettes/tracking/6676848415.yml
|
164
|
+
- spec/fixtures/dhl_cassettes/tracking/9786162326.yml
|
140
165
|
- spec/lib/dhl/client_spec.rb
|
141
166
|
- spec/lib/dhl/contact_spec.rb
|
142
167
|
- spec/lib/dhl/packages_spec.rb
|
@@ -172,6 +197,11 @@ test_files:
|
|
172
197
|
- spec/factories/contact_factory.rb
|
173
198
|
- spec/factories/shipment_factory.rb
|
174
199
|
- spec/fixtures/dhl_cassettes/shipment.yml
|
200
|
+
- spec/fixtures/dhl_cassettes/tracking/5223281416.yml
|
201
|
+
- spec/fixtures/dhl_cassettes/tracking/5223300596.yml
|
202
|
+
- spec/fixtures/dhl_cassettes/tracking/6676848301.yml
|
203
|
+
- spec/fixtures/dhl_cassettes/tracking/6676848415.yml
|
204
|
+
- spec/fixtures/dhl_cassettes/tracking/9786162326.yml
|
175
205
|
- spec/lib/dhl/client_spec.rb
|
176
206
|
- spec/lib/dhl/contact_spec.rb
|
177
207
|
- spec/lib/dhl/packages_spec.rb
|
data/lib/dhl/tracking_request.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
module Dhl
|
2
|
-
class TrackingRequest
|
3
|
-
|
4
|
-
attr_accessor :tracking_number
|
5
|
-
|
6
|
-
# Accepts and array of tracking numbers
|
7
|
-
def initialize(numbers)
|
8
|
-
@tracking_numbers = numbers
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_hash
|
12
|
-
{
|
13
|
-
tracking_request: {
|
14
|
-
request: {
|
15
|
-
service_header: {
|
16
|
-
message_time: Time.now.strftime('%Y-%m-%dT%H:%M:%S%:z'),
|
17
|
-
message_reference: '1234567890123456789012345678' # Ref between 28 and 32 characters
|
18
|
-
}
|
19
|
-
},
|
20
|
-
a_w_b_number: {
|
21
|
-
array_of_a_w_b_number_item: @tracking_numbers
|
22
|
-
},
|
23
|
-
# lp_number: nil, # Inactive in API
|
24
|
-
level_of_details: 'LAST_CHECK_POINT_ONLY', # ALL_CHECK_POINTS for complete tracking
|
25
|
-
pieces_enabled: 'B' # B for Both, S for shipment details only, P for piece details only
|
26
|
-
}
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|