after_ship 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +69 -32
- data/after_ship.gemspec +4 -4
- data/lib/after_ship/checkpoint.rb +35 -28
- data/lib/after_ship/core/attributes.rb +14 -0
- data/lib/after_ship/core/date_utils.rb +76 -0
- data/lib/after_ship/core/error.rb +29 -0
- data/lib/after_ship/core/error_handler.rb +67 -0
- data/lib/after_ship/core/request.rb +131 -0
- data/lib/after_ship/core/version.rb +4 -0
- data/lib/after_ship/courier.rb +45 -0
- data/lib/after_ship/tracking.rb +78 -6
- data/lib/after_ship.rb +158 -214
- data/spec/integration/after_ship_spec.rb +40 -0
- data/spec/request_stubs.rb +30 -97
- data/spec/requests/couriers.json +50 -0
- data/spec/requests/tracking/created.json +53 -0
- data/spec/requests/tracking/{delivered_ok.json → delivered.json} +79 -65
- data/spec/requests/trackings.json +654 -0
- data/spec/units/after_ship_spec.rb +104 -0
- data/spec/units/checkpoint_spec.rb +135 -0
- data/spec/units/courier_spec.rb +41 -0
- data/spec/{lib → units}/date_utils_spec.rb +17 -9
- data/spec/units/error_handler_spec.rb +168 -0
- data/spec/units/request_spec.rb +190 -0
- data/spec/units/tracking_spec.rb +276 -0
- metadata +39 -25
- data/lib/after_ship/version.rb +0 -3
- data/lib/attributes.rb +0 -12
- data/lib/date_utils.rb +0 -61
- data/spec/lib/after_ship_spec.rb +0 -137
- data/spec/lib/checkpoint_spec.rb +0 -139
- data/spec/lib/tracking_spec.rb +0 -89
- data/spec/requests/tracking/delivered_wild.json +0 -653
- data/spec/requests/tracking/in_transit.json +0 -443
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe AfterShip::Request do
|
4
|
+
let(:response_401) do
|
5
|
+
'
|
6
|
+
{
|
7
|
+
"meta": {
|
8
|
+
"code": 401,
|
9
|
+
"message": "Invalid API Key.",
|
10
|
+
"type": "Unauthorized"
|
11
|
+
},
|
12
|
+
"data": {}
|
13
|
+
}
|
14
|
+
'
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:response_200) do
|
18
|
+
'
|
19
|
+
{
|
20
|
+
"meta": {
|
21
|
+
"code": 200
|
22
|
+
},
|
23
|
+
"data": {
|
24
|
+
"tracking": {
|
25
|
+
"slug": "ups"
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
'
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:typhoeus_response_timeout) do
|
33
|
+
typhoeus_response = double('Typhoeus response')
|
34
|
+
allow(typhoeus_response).to receive(:timed_out?).and_return(true)
|
35
|
+
allow(typhoeus_response).to receive(:effective_url)
|
36
|
+
.and_return('http://bla.bla/')
|
37
|
+
typhoeus_response
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:typhoeus_response_401) do
|
41
|
+
typhoeus_response = double('Typhoeus response')
|
42
|
+
allow(typhoeus_response).to receive(:timed_out?).and_return(false)
|
43
|
+
allow(typhoeus_response).to receive(:body).and_return(response_401)
|
44
|
+
typhoeus_response
|
45
|
+
end
|
46
|
+
|
47
|
+
let(:typhoeus_response_200) do
|
48
|
+
typhoeus_response = double('Typhoeus response')
|
49
|
+
allow(typhoeus_response).to receive(:timed_out?).and_return(false)
|
50
|
+
allow(typhoeus_response).to receive(:body).and_return(response_200)
|
51
|
+
typhoeus_response
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'initialize with missing :api_key raises an error' do
|
55
|
+
expect { AfterShip::Request.new(url: 'http://bla.bla/', method: :get) }
|
56
|
+
.to raise_error(KeyError)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'initialize with missing :url raises an error' do
|
60
|
+
expect { AfterShip::Request.new(api_key: 'key', method: :get) }
|
61
|
+
.to raise_error(KeyError)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'initialize with missing :method raises an error' do
|
65
|
+
expect { AfterShip::Request.new(api_key: 'key', url: 'http://bla.bla/') }
|
66
|
+
.to raise_error(KeyError)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'get' do
|
70
|
+
allow_any_instance_of(AfterShip::Request)
|
71
|
+
.to receive(:typhoeus_response).and_return(typhoeus_response_200)
|
72
|
+
|
73
|
+
args = { api_key: 'key', url: 'http://bla.bla/' }
|
74
|
+
response = AfterShip::Request.get(args)
|
75
|
+
expected = {
|
76
|
+
meta: {
|
77
|
+
code: 200
|
78
|
+
},
|
79
|
+
data: {
|
80
|
+
tracking: {
|
81
|
+
slug: 'ups'
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
expect(response).to eq(expected)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'post' do
|
90
|
+
allow_any_instance_of(AfterShip::Request)
|
91
|
+
.to receive(:typhoeus_response).and_return(typhoeus_response_200)
|
92
|
+
|
93
|
+
args = { api_key: 'key', url: 'http://bla.bla/' }
|
94
|
+
response = AfterShip::Request.post(args)
|
95
|
+
expected = {
|
96
|
+
meta: {
|
97
|
+
code: 200
|
98
|
+
},
|
99
|
+
data: {
|
100
|
+
tracking: {
|
101
|
+
slug: 'ups'
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
expect(response).to eq(expected)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'put' do
|
110
|
+
allow_any_instance_of(AfterShip::Request)
|
111
|
+
.to receive(:typhoeus_response).and_return(typhoeus_response_200)
|
112
|
+
|
113
|
+
args = { api_key: 'key', url: 'http://bla.bla/' }
|
114
|
+
response = AfterShip::Request.put(args)
|
115
|
+
expected = {
|
116
|
+
meta: {
|
117
|
+
code: 200
|
118
|
+
},
|
119
|
+
data: {
|
120
|
+
tracking: {
|
121
|
+
slug: 'ups'
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
expect(response).to eq(expected)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'response raises an error on timeout' do
|
130
|
+
allow_any_instance_of(AfterShip::Request)
|
131
|
+
.to receive(:typhoeus_response).and_return(typhoeus_response_timeout)
|
132
|
+
|
133
|
+
args = { api_key: 'key', url: 'http://bla.bla/', method: :get }
|
134
|
+
request = AfterShip::Request.new(args)
|
135
|
+
|
136
|
+
expect { request.response }.to raise_error(AfterShip::Error::Timeout)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'response loads data and raises an error' do
|
140
|
+
allow_any_instance_of(AfterShip::Request)
|
141
|
+
.to receive(:typhoeus_response).and_return(typhoeus_response_401)
|
142
|
+
|
143
|
+
args = { api_key: 'key', url: 'http://bla.bla/', method: :get }
|
144
|
+
request = AfterShip::Request.new(args)
|
145
|
+
|
146
|
+
expect { request.response }.to raise_error(AfterShip::Error::Unauthorized)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'response without a block' do
|
150
|
+
allow_any_instance_of(AfterShip::Request)
|
151
|
+
.to receive(:typhoeus_response).and_return(typhoeus_response_200)
|
152
|
+
|
153
|
+
args = { api_key: 'key', url: 'http://bla.bla/', method: :get }
|
154
|
+
request = AfterShip::Request.new(args)
|
155
|
+
expected = {
|
156
|
+
meta: {
|
157
|
+
code: 200
|
158
|
+
},
|
159
|
+
data: {
|
160
|
+
tracking: {
|
161
|
+
slug: 'ups'
|
162
|
+
}
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
expect(request.response).to eq(expected)
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'response with a block' do
|
170
|
+
allow_any_instance_of(AfterShip::Request)
|
171
|
+
.to receive(:typhoeus_response).and_return(typhoeus_response_200)
|
172
|
+
|
173
|
+
args = { api_key: 'key', url: 'http://bla.bla/', method: :get }
|
174
|
+
request = AfterShip::Request.new(args) do |response|
|
175
|
+
response[:data][:tracking]
|
176
|
+
end
|
177
|
+
expected = {
|
178
|
+
slug: 'ups'
|
179
|
+
}
|
180
|
+
|
181
|
+
expect(request.response).to eq(expected)
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'typhoeus_response' do
|
185
|
+
allow_any_instance_of(Typhoeus::Request).to receive(:run)
|
186
|
+
args = { api_key: 'key', url: 'http://bla.bla/', method: :get }
|
187
|
+
request = AfterShip::Request.new(args)
|
188
|
+
expect { request.send(:typhoeus_response) }.to_not raise_error
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,276 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe AfterShip::Tracking do
|
4
|
+
context 'Attributes' do
|
5
|
+
it 'created_at' do
|
6
|
+
data = { created_at: '2014-10-30T10:05:48' }
|
7
|
+
tracking = AfterShip::Tracking.new(data)
|
8
|
+
expect(tracking.created_at).to be_a(DateTime)
|
9
|
+
expect(tracking.created_at.to_s).to eq('2014-10-30T10:05:48+00:00')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'updated_at' do
|
13
|
+
data = { updated_at: '2014-10-30T10:05:48' }
|
14
|
+
tracking = AfterShip::Tracking.new(data)
|
15
|
+
expect(tracking.updated_at).to be_a(DateTime)
|
16
|
+
expect(tracking.updated_at.to_s).to eq('2014-10-30T10:05:48+00:00')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'id' do
|
20
|
+
data = { id: '5457a109bb8bce546b7abafa' }
|
21
|
+
tracking = AfterShip::Tracking.new(data)
|
22
|
+
expect(tracking.id).to eq('5457a109bb8bce546b7abafa')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'tracking_number' do
|
26
|
+
data = { tracking_number: '1ZA2207X0444990982' }
|
27
|
+
tracking = AfterShip::Tracking.new(data)
|
28
|
+
expect(tracking.tracking_number).to eq('1ZA2207X0444990982')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'tracking_postal_code' do
|
32
|
+
data = { tracking_postal_code: '???' }
|
33
|
+
tracking = AfterShip::Tracking.new(data)
|
34
|
+
expect(tracking.tracking_postal_code).to eq('???')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'tracking_ship_date' do
|
38
|
+
data = { tracking_ship_date: '20141124' }
|
39
|
+
tracking = AfterShip::Tracking.new(data)
|
40
|
+
expect(tracking.tracking_ship_date).to be_a(Date)
|
41
|
+
expect(tracking.tracking_ship_date.to_s)
|
42
|
+
.to eq('2014-11-24')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'tracking_account_number' do
|
46
|
+
data = { tracking_account_number: '???' }
|
47
|
+
tracking = AfterShip::Tracking.new(data)
|
48
|
+
expect(tracking.tracking_account_number).to eq('???')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'slug' do
|
52
|
+
data = { slug: 'ups' }
|
53
|
+
tracking = AfterShip::Tracking.new(data)
|
54
|
+
expect(tracking.slug).to eq('ups')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'courier' do
|
58
|
+
data = { slug: 'ups' }
|
59
|
+
tracking = AfterShip::Tracking.new(data)
|
60
|
+
expect(tracking.courier).to eq('UPS')
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'active' do
|
64
|
+
data = { active: false }
|
65
|
+
tracking = AfterShip::Tracking.new(data)
|
66
|
+
expect(tracking.active).to eq(false)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'android' do
|
70
|
+
data = { android: [] }
|
71
|
+
tracking = AfterShip::Tracking.new(data)
|
72
|
+
expect(tracking.android).to eq([])
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'custom_fields' do
|
76
|
+
data = { custom_fields: [] }
|
77
|
+
tracking = AfterShip::Tracking.new(data)
|
78
|
+
expect(tracking.custom_fields).to eq([])
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'customer_name' do
|
82
|
+
data = { customer_name: nil }
|
83
|
+
tracking = AfterShip::Tracking.new(data)
|
84
|
+
expect(tracking.customer_name).to eq(nil)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'delivery_time' do
|
88
|
+
data = { delivery_time: 4 }
|
89
|
+
tracking = AfterShip::Tracking.new(data)
|
90
|
+
expect(tracking.delivery_time).to eq(4)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'destination_country_iso3' do
|
94
|
+
data = { destination_country_iso3: 'USA' }
|
95
|
+
tracking = AfterShip::Tracking.new(data)
|
96
|
+
expect(tracking.destination_country_iso3).to eq('USA')
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'emails' do
|
100
|
+
data = { emails: [] }
|
101
|
+
tracking = AfterShip::Tracking.new(data)
|
102
|
+
expect(tracking.emails).to eq([])
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'expected_delivery' do
|
106
|
+
data = { expected_delivery: '2014-10-30T10:05:48+00:00' }
|
107
|
+
tracking = AfterShip::Tracking.new(data)
|
108
|
+
expect(tracking.expected_delivery).to be_a(DateTime)
|
109
|
+
expect(tracking.expected_delivery.to_s)
|
110
|
+
.to eq('2014-10-30T10:05:48+00:00')
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'ios' do
|
114
|
+
data = { ios: [] }
|
115
|
+
tracking = AfterShip::Tracking.new(data)
|
116
|
+
expect(tracking.ios).to eq([])
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'order_id' do
|
120
|
+
data = { order_id: 'order-id' }
|
121
|
+
tracking = AfterShip::Tracking.new(data)
|
122
|
+
expect(tracking.order_id).to eq('order-id')
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'order_id_path' do
|
126
|
+
data = { order_id_path: '???' }
|
127
|
+
tracking = AfterShip::Tracking.new(data)
|
128
|
+
expect(tracking.order_id_path).to eq('???')
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'origin_country_iso3' do
|
132
|
+
data = { origin_country_iso3: 'IND' }
|
133
|
+
tracking = AfterShip::Tracking.new(data)
|
134
|
+
expect(tracking.origin_country_iso3).to eq('IND')
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'unique_token' do
|
138
|
+
data = { unique_token: 'bk6ysTW1U' }
|
139
|
+
tracking = AfterShip::Tracking.new(data)
|
140
|
+
expect(tracking.unique_token).to eq('bk6ysTW1U')
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'shipment_package_count' do
|
144
|
+
data = { shipment_package_count: 1 }
|
145
|
+
tracking = AfterShip::Tracking.new(data)
|
146
|
+
expect(tracking.shipment_package_count).to eq(1)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'shipment_type' do
|
150
|
+
data = { shipment_type: 'UPS SAVER' }
|
151
|
+
tracking = AfterShip::Tracking.new(data)
|
152
|
+
expect(tracking.shipment_type).to eq('UPS SAVER')
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'shipment_weight' do
|
156
|
+
data = { shipment_weight: 1 }
|
157
|
+
tracking = AfterShip::Tracking.new(data)
|
158
|
+
expect(tracking.shipment_weight).to eq(1)
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'shipment_weight_unit' do
|
162
|
+
data = { shipment_weight_unit: 'kg' }
|
163
|
+
tracking = AfterShip::Tracking.new(data)
|
164
|
+
expect(tracking.shipment_weight_unit).to eq('kg')
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'signed_by' do
|
168
|
+
data = { signed_by: 'A GUPTA (OFFICE)' }
|
169
|
+
tracking = AfterShip::Tracking.new(data)
|
170
|
+
expect(tracking.signed_by).to eq('A GUPTA (OFFICE)')
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'smses' do
|
174
|
+
data = { smses: [] }
|
175
|
+
tracking = AfterShip::Tracking.new(data)
|
176
|
+
expect(tracking.smses).to eq([])
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'source' do
|
180
|
+
data = { source: 'api' }
|
181
|
+
tracking = AfterShip::Tracking.new(data)
|
182
|
+
expect(tracking.source).to eq('api')
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'tag' do
|
186
|
+
data = { tag: 'Delivered' }
|
187
|
+
tracking = AfterShip::Tracking.new(data)
|
188
|
+
expect(tracking.tag).to eq('Delivered')
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'status' do
|
192
|
+
data = { tag: 'Delivered' }
|
193
|
+
tracking = AfterShip::Tracking.new(data)
|
194
|
+
expect(tracking.status).to eq('Delivered')
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'title' do
|
198
|
+
data = { title: '1ZA2207X0444990982' }
|
199
|
+
tracking = AfterShip::Tracking.new(data)
|
200
|
+
expect(tracking.title).to eq('1ZA2207X0444990982')
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'tracked_count' do
|
204
|
+
data = { tracked_count: 3 }
|
205
|
+
tracking = AfterShip::Tracking.new(data)
|
206
|
+
expect(tracking.tracked_count).to eq(3)
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'checkpoints' do
|
210
|
+
data = {
|
211
|
+
checkpoints: [
|
212
|
+
{
|
213
|
+
slug: 'ups'
|
214
|
+
}
|
215
|
+
]
|
216
|
+
}
|
217
|
+
tracking = AfterShip::Tracking.new(data)
|
218
|
+
expect(tracking.checkpoints.size).to eq(1)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'status' do
|
223
|
+
it 'Pending' do
|
224
|
+
data = { tag: 'Pending' }
|
225
|
+
tracking = AfterShip::Tracking.new(data)
|
226
|
+
expect(tracking.status).to eq('Pending')
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'InfoReceived' do
|
230
|
+
data = { tag: 'InfoReceived' }
|
231
|
+
tracking = AfterShip::Tracking.new(data)
|
232
|
+
expect(tracking.status).to eq('Info Received')
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'InTransit' do
|
236
|
+
data = { tag: 'InTransit' }
|
237
|
+
tracking = AfterShip::Tracking.new(data)
|
238
|
+
expect(tracking.status).to eq('In Transit')
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'OutForDelivery' do
|
242
|
+
data = { tag: 'OutForDelivery' }
|
243
|
+
tracking = AfterShip::Tracking.new(data)
|
244
|
+
expect(tracking.status).to eq('Out for Delivery')
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'AttemptFail' do
|
248
|
+
data = { tag: 'AttemptFail' }
|
249
|
+
tracking = AfterShip::Tracking.new(data)
|
250
|
+
expect(tracking.status).to eq('Attempt Failed')
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'Delivered' do
|
254
|
+
data = { tag: 'Delivered' }
|
255
|
+
tracking = AfterShip::Tracking.new(data)
|
256
|
+
expect(tracking.status).to eq('Delivered')
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'Exception' do
|
260
|
+
data = { tag: 'Exception' }
|
261
|
+
tracking = AfterShip::Tracking.new(data)
|
262
|
+
expect(tracking.status).to eq('Exception')
|
263
|
+
end
|
264
|
+
|
265
|
+
it 'Expired' do
|
266
|
+
data = { tag: 'Expired' }
|
267
|
+
tracking = AfterShip::Tracking.new(data)
|
268
|
+
expect(tracking.status).to eq('Expired')
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'error' do
|
272
|
+
data = { tag: 'error' }
|
273
|
+
expect { AfterShip::Tracking.new(data) }.to raise_error(KeyError)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: after_ship
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oldrich Vetesnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
47
|
+
version: '1.20'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
54
|
+
version: '1.20'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
75
|
+
version: '0.27'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
82
|
+
version: '0.27'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: pry
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,19 +170,28 @@ files:
|
|
170
170
|
- after_ship.gemspec
|
171
171
|
- lib/after_ship.rb
|
172
172
|
- lib/after_ship/checkpoint.rb
|
173
|
+
- lib/after_ship/core/attributes.rb
|
174
|
+
- lib/after_ship/core/date_utils.rb
|
175
|
+
- lib/after_ship/core/error.rb
|
176
|
+
- lib/after_ship/core/error_handler.rb
|
177
|
+
- lib/after_ship/core/request.rb
|
178
|
+
- lib/after_ship/core/version.rb
|
179
|
+
- lib/after_ship/courier.rb
|
173
180
|
- lib/after_ship/tracking.rb
|
174
|
-
-
|
175
|
-
- lib/attributes.rb
|
176
|
-
- lib/date_utils.rb
|
177
|
-
- spec/lib/after_ship_spec.rb
|
178
|
-
- spec/lib/checkpoint_spec.rb
|
179
|
-
- spec/lib/date_utils_spec.rb
|
180
|
-
- spec/lib/tracking_spec.rb
|
181
|
+
- spec/integration/after_ship_spec.rb
|
181
182
|
- spec/request_stubs.rb
|
182
|
-
- spec/requests/
|
183
|
-
- spec/requests/tracking/
|
184
|
-
- spec/requests/tracking/
|
183
|
+
- spec/requests/couriers.json
|
184
|
+
- spec/requests/tracking/created.json
|
185
|
+
- spec/requests/tracking/delivered.json
|
186
|
+
- spec/requests/trackings.json
|
185
187
|
- spec/spec_helper.rb
|
188
|
+
- spec/units/after_ship_spec.rb
|
189
|
+
- spec/units/checkpoint_spec.rb
|
190
|
+
- spec/units/courier_spec.rb
|
191
|
+
- spec/units/date_utils_spec.rb
|
192
|
+
- spec/units/error_handler_spec.rb
|
193
|
+
- spec/units/request_spec.rb
|
194
|
+
- spec/units/tracking_spec.rb
|
186
195
|
homepage: https://github.com/ollie/after_ship
|
187
196
|
licenses:
|
188
197
|
- MIT
|
@@ -203,18 +212,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
212
|
version: '0'
|
204
213
|
requirements: []
|
205
214
|
rubyforge_project:
|
206
|
-
rubygems_version: 2.4.
|
215
|
+
rubygems_version: 2.4.4
|
207
216
|
signing_key:
|
208
217
|
specification_version: 4
|
209
|
-
summary: A smallish library to talking to AfterShip via
|
218
|
+
summary: A smallish library to talking to AfterShip via v4 API.
|
210
219
|
test_files:
|
211
|
-
- spec/
|
212
|
-
- spec/lib/checkpoint_spec.rb
|
213
|
-
- spec/lib/date_utils_spec.rb
|
214
|
-
- spec/lib/tracking_spec.rb
|
220
|
+
- spec/integration/after_ship_spec.rb
|
215
221
|
- spec/request_stubs.rb
|
216
|
-
- spec/requests/
|
217
|
-
- spec/requests/tracking/
|
218
|
-
- spec/requests/tracking/
|
222
|
+
- spec/requests/couriers.json
|
223
|
+
- spec/requests/tracking/created.json
|
224
|
+
- spec/requests/tracking/delivered.json
|
225
|
+
- spec/requests/trackings.json
|
219
226
|
- spec/spec_helper.rb
|
227
|
+
- spec/units/after_ship_spec.rb
|
228
|
+
- spec/units/checkpoint_spec.rb
|
229
|
+
- spec/units/courier_spec.rb
|
230
|
+
- spec/units/date_utils_spec.rb
|
231
|
+
- spec/units/error_handler_spec.rb
|
232
|
+
- spec/units/request_spec.rb
|
233
|
+
- spec/units/tracking_spec.rb
|
220
234
|
has_rdoc:
|
data/lib/after_ship/version.rb
DELETED
data/lib/attributes.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# Extracted attributes loading.
|
2
|
-
module Attributes
|
3
|
-
# Loop through the data hash and for each key call a setter with the value.
|
4
|
-
#
|
5
|
-
# @param data [Hash]
|
6
|
-
def load_attributes(data)
|
7
|
-
data.each do |attribute, value|
|
8
|
-
setter = "#{ attribute }="
|
9
|
-
send(setter, value) if respond_to?(setter)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
data/lib/date_utils.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# Simple utility class for parsing dates and datetimes.
|
2
|
-
class DateUtils
|
3
|
-
# Date:
|
4
|
-
#
|
5
|
-
# +YYYY-MM-DD+
|
6
|
-
DATE_REGEX = /
|
7
|
-
\A
|
8
|
-
\d{4}-\d{2}-\d{2}
|
9
|
-
\Z
|
10
|
-
/x
|
11
|
-
|
12
|
-
# Datetime without zone:
|
13
|
-
#
|
14
|
-
# +YYYY-MM-DDTHH:MM:SS+
|
15
|
-
DATETIME_REGEX = /
|
16
|
-
\A
|
17
|
-
\d{4}-\d{2}-\d{2}
|
18
|
-
T
|
19
|
-
\d{2}:\d{2}:\d{2}
|
20
|
-
\Z
|
21
|
-
/x
|
22
|
-
|
23
|
-
# Datetime with zone:
|
24
|
-
#
|
25
|
-
# +YYYY-MM-DDTHH:MM:SSZ+
|
26
|
-
# +YYYY-MM-DDTHH:MM:SS+HH:MM+
|
27
|
-
# +YYYY-MM-DDTHH:MM:SS-HH:MM+
|
28
|
-
DATETIME_WITH_ZONE_REGEX = /
|
29
|
-
\A
|
30
|
-
\d{4}-\d{2}-\d{2}
|
31
|
-
T
|
32
|
-
\d{2}:\d{2}:\d{2}
|
33
|
-
(Z|[+-]\d{2}:\d{2})
|
34
|
-
\Z
|
35
|
-
/x
|
36
|
-
|
37
|
-
# Try to parse a date or datetime from a string.
|
38
|
-
#
|
39
|
-
# @param value [String]
|
40
|
-
# Empty String,
|
41
|
-
# YYYY-MM-DD,
|
42
|
-
# YYYY-MM-DDTHH:MM:SS,
|
43
|
-
# YYYY-MM-DDTHH:MM:SSZ,
|
44
|
-
# YYYY-MM-DDTHH:MM:SS+HH:MM or
|
45
|
-
# YYYY-MM-DDTHH:MM:SS-HH:MM.
|
46
|
-
#
|
47
|
-
def self.parse(value)
|
48
|
-
case value
|
49
|
-
when ''
|
50
|
-
nil
|
51
|
-
when nil
|
52
|
-
nil
|
53
|
-
when DATE_REGEX
|
54
|
-
Date.parse(value)
|
55
|
-
when DATETIME_REGEX, DATETIME_WITH_ZONE_REGEX
|
56
|
-
DateTime.parse(value)
|
57
|
-
else
|
58
|
-
fail ArgumentError, "Invalid expected_delivery date #{ value.inspect }"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|