active_shipping 1.7.2 → 1.7.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 +1 -0
- data/README.md +1 -0
- data/dev.yml +1 -3
- data/lib/active_shipping/carriers.rb +1 -0
- data/lib/active_shipping/carriers/australia_post.rb +250 -0
- data/lib/active_shipping/version.rb +1 -1
- data/test/credentials.yml +3 -0
- data/test/fixtures/json/australia_post/calculate_domestic.json +13 -0
- data/test/fixtures/json/australia_post/calculate_domestic_2.json +19 -0
- data/test/fixtures/json/australia_post/calculate_international.json +12 -0
- data/test/fixtures/json/australia_post/calculate_international_2.json +15 -0
- data/test/fixtures/json/australia_post/error_message.json +5 -0
- data/test/fixtures/json/australia_post/service_domestic.json +117 -0
- data/test/fixtures/json/australia_post/service_domestic_2.json +117 -0
- data/test/fixtures/json/australia_post/service_international.json +76 -0
- data/test/fixtures/json/australia_post/service_international_2.json +59 -0
- data/test/remote/australia_post_test.rb +140 -0
- data/test/test_helper.rb +13 -1
- data/test/unit/carriers/australia_post_test.rb +181 -0
- metadata +25 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79c6b3362e5819936e2a22e145f561bef37dbd4f
|
4
|
+
data.tar.gz: 3e0b2fcd0aa37da3733796632bdf92864e538e52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dadab7eeb70c6123fdaaa4a0215755a5e9337a5e51c6bc82ba29ca357d9caa493a9bd64c070ca85c8e5e2500df47109beeb9c11c7e787c34973b3a8b9376f13
|
7
|
+
data.tar.gz: eeacbd47303bd524f268877a386477b67fe8ac2987cf7c4a722a90abc3535409de6ffcdb508072992b9c75e6d620c0d3c759edac1dc50229b05f2a4a63e998f1
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -23,6 +23,7 @@ Active Shipping is currently being used and improved in a production environment
|
|
23
23
|
* [Shipwire](http://www.shipwire.com)
|
24
24
|
* [Stamps](http://www.stamps.com)
|
25
25
|
* [Kunaki](http://www.kunaki.com)
|
26
|
+
* [Australia Post](http://auspost.com.au/)
|
26
27
|
|
27
28
|
## Installation
|
28
29
|
|
data/dev.yml
CHANGED
@@ -33,3 +33,4 @@ ActiveShipping::Carriers.register :NewZealandPost, 'active_shipping/carriers/n
|
|
33
33
|
ActiveShipping::Carriers.register :CanadaPostPWS, 'active_shipping/carriers/canada_post_pws'
|
34
34
|
ActiveShipping::Carriers.register :Stamps, 'active_shipping/carriers/stamps'
|
35
35
|
ActiveShipping::Carriers.register :Correios, 'active_shipping/carriers/correios'
|
36
|
+
ActiveShipping::Carriers.register :AustraliaPost, 'active_shipping/carriers/australia_post'
|
@@ -0,0 +1,250 @@
|
|
1
|
+
require 'active_support/core_ext/object/to_query'
|
2
|
+
|
3
|
+
module ActiveShipping
|
4
|
+
class AustraliaPost < Carrier
|
5
|
+
cattr_reader :name
|
6
|
+
@@name = 'Australia Post'
|
7
|
+
|
8
|
+
HOST = 'digitalapi.auspost.com.au'
|
9
|
+
|
10
|
+
PARCEL_ENDPOINTS = {
|
11
|
+
service: {
|
12
|
+
domestic: '/postage/parcel/domestic/service.json',
|
13
|
+
international: '/postage/parcel/international/service.json'
|
14
|
+
},
|
15
|
+
calculate: {
|
16
|
+
domestic: '/postage/parcel/domestic/calculate.json',
|
17
|
+
international: '/postage/parcel/international/calculate.json'
|
18
|
+
}
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
def requirements
|
22
|
+
[:api_key]
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_rates(origin, destination, packages, options = {})
|
26
|
+
packages = Array(packages)
|
27
|
+
|
28
|
+
service_requests = packages.map do |package|
|
29
|
+
service_request = ServiceRequest.new(origin, destination, package, options)
|
30
|
+
|
31
|
+
service_request.parse(commit(service_request.url))
|
32
|
+
service_request
|
33
|
+
end
|
34
|
+
|
35
|
+
combined_response = CombinedResponse.new(origin, destination, packages, service_requests)
|
36
|
+
|
37
|
+
RateResponse.new(true, 'success', combined_response.params, combined_response.options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def calculate_rates(origin, destination, packages, service_code, options = {})
|
41
|
+
packages = Array(packages)
|
42
|
+
|
43
|
+
calculate_requests = packages.map do |package|
|
44
|
+
calculate_request = CalculateRequest.new(origin, destination, package, service_code, options)
|
45
|
+
|
46
|
+
calculate_request.parse(commit(calculate_request.url))
|
47
|
+
calculate_request
|
48
|
+
end
|
49
|
+
|
50
|
+
combined_response = CombinedResponse.new(origin, destination, packages, calculate_requests)
|
51
|
+
|
52
|
+
RateResponse.new(true, 'success', combined_response.params, combined_response.options)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def commit(request_url)
|
58
|
+
ssl_get(request_url, headers)
|
59
|
+
|
60
|
+
rescue ActiveUtils::ResponseError, ActiveShipping::ResponseError => e
|
61
|
+
data = JSON.parse(e.response.body)
|
62
|
+
error_message = data['error'] && data['error']['errorMessage'] ? data['error']['errorMessage'] : 'unknown'
|
63
|
+
|
64
|
+
RateResponse.new(false, error_message, data)
|
65
|
+
end
|
66
|
+
|
67
|
+
def headers
|
68
|
+
{
|
69
|
+
'Content-type' => 'application/json',
|
70
|
+
'auth-key' => @options[:api_key]
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
class CombinedResponse
|
75
|
+
|
76
|
+
def initialize(origin, destination, packages, requests)
|
77
|
+
@requests = requests
|
78
|
+
@origin = origin
|
79
|
+
@destination = destination
|
80
|
+
@packages = packages
|
81
|
+
end
|
82
|
+
|
83
|
+
def options
|
84
|
+
{
|
85
|
+
rates: rates,
|
86
|
+
raw_responses: @requests.map(&:raw_response),
|
87
|
+
request: @requests.map(&:url)
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
def params
|
92
|
+
{
|
93
|
+
responses: @requests.map(&:response)
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def rate_options(rates)
|
100
|
+
{
|
101
|
+
service_name: rates.first[:service_name],
|
102
|
+
service_code: rates.first[:service_code],
|
103
|
+
total_price: rates.sum { |rate| rate[:total_price] },
|
104
|
+
currency: 'AUD',
|
105
|
+
delivery_time_text: rates.first[:delivery_time_text]
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
def rates
|
110
|
+
rates = @requests.map(&:rates).flatten
|
111
|
+
|
112
|
+
rates.group_by { |rate| rate[:service_name] }.map do |service_name, service_rates|
|
113
|
+
next unless service_rates.size == @packages.size
|
114
|
+
|
115
|
+
AustraliaPostRateEstimate.new(@origin, @destination, AustraliaPost.name, service_name, rate_options(service_rates))
|
116
|
+
end.compact
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
class AustraliaPostRequest
|
122
|
+
attr_reader :raw_response
|
123
|
+
attr_reader :response
|
124
|
+
attr_reader :rates
|
125
|
+
|
126
|
+
def initialize(origin, destination, package, options)
|
127
|
+
@origin = Location.from(origin)
|
128
|
+
@destination = Location.from(destination)
|
129
|
+
@package = package
|
130
|
+
@rates = []
|
131
|
+
@options = options
|
132
|
+
end
|
133
|
+
|
134
|
+
def url
|
135
|
+
endpoint = domestic_destination? ? @endpoints[:domestic] : @endpoints[:international]
|
136
|
+
params = domestic_destination? ? domestic_params : international_params
|
137
|
+
|
138
|
+
URI::HTTPS.build(host: HOST, path: endpoint, query: params.to_query).to_s
|
139
|
+
end
|
140
|
+
|
141
|
+
def parse(data)
|
142
|
+
@raw_response = data
|
143
|
+
@response = JSON.parse(data)
|
144
|
+
end
|
145
|
+
|
146
|
+
protected
|
147
|
+
|
148
|
+
def domestic_destination?
|
149
|
+
@destination.country_code == 'AU'
|
150
|
+
end
|
151
|
+
|
152
|
+
def domestic_params
|
153
|
+
{
|
154
|
+
length: @package.cm(:length),
|
155
|
+
width: @package.cm(:width),
|
156
|
+
height: @package.cm(:height),
|
157
|
+
weight: @package.weight.in_kg.to_f.round(2),
|
158
|
+
from_postcode: @origin.postal_code,
|
159
|
+
to_postcode: @destination.postal_code
|
160
|
+
}
|
161
|
+
end
|
162
|
+
|
163
|
+
def international_params
|
164
|
+
{
|
165
|
+
weight: @package.weight.in_kg.to_f.round(2),
|
166
|
+
country_code: @destination.country_code
|
167
|
+
}
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
class ServiceRequest < AustraliaPostRequest
|
173
|
+
|
174
|
+
def initialize(origin, destination, package, options)
|
175
|
+
super
|
176
|
+
@endpoints = PARCEL_ENDPOINTS[:service]
|
177
|
+
end
|
178
|
+
|
179
|
+
def parse(data)
|
180
|
+
super
|
181
|
+
|
182
|
+
@rates = response['services']['service'].map do |service|
|
183
|
+
{
|
184
|
+
service_name: service['name'],
|
185
|
+
service_code: service['code'],
|
186
|
+
total_price: service['price'].to_f,
|
187
|
+
currency: 'AUD'
|
188
|
+
}
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
class CalculateRequest < AustraliaPostRequest
|
195
|
+
attr_reader :service_code
|
196
|
+
|
197
|
+
def initialize(origin, destination, package, service_code, options)
|
198
|
+
super(origin, destination, package, options)
|
199
|
+
|
200
|
+
@service_code = service_code
|
201
|
+
@endpoints = PARCEL_ENDPOINTS[:calculate]
|
202
|
+
end
|
203
|
+
|
204
|
+
def parse(data)
|
205
|
+
super
|
206
|
+
postage_result = response['postage_result']
|
207
|
+
|
208
|
+
@rates = [{
|
209
|
+
service_name: postage_result['service'],
|
210
|
+
service_code: service_code,
|
211
|
+
total_price: postage_result['total_cost'].to_f,
|
212
|
+
currency: 'AUD',
|
213
|
+
delivery_time_text: postage_result['delivery_time']
|
214
|
+
}]
|
215
|
+
end
|
216
|
+
|
217
|
+
private
|
218
|
+
|
219
|
+
def calculate_params
|
220
|
+
{
|
221
|
+
service_code: @service_code,
|
222
|
+
option_code: @options[:option_code],
|
223
|
+
suboption_code: @options[:suboption_code],
|
224
|
+
extra_cover: @options[:extra_cover]
|
225
|
+
}.
|
226
|
+
# INFO: equivalent of .compact
|
227
|
+
select { |_, value| !value.nil? }
|
228
|
+
end
|
229
|
+
|
230
|
+
def domestic_params
|
231
|
+
super.merge(calculate_params)
|
232
|
+
end
|
233
|
+
|
234
|
+
def international_params
|
235
|
+
super.merge(calculate_params)
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
239
|
+
|
240
|
+
class AustraliaPostRateEstimate < RateEstimate
|
241
|
+
attr_reader :delivery_time_text
|
242
|
+
|
243
|
+
def initialize(origin, destination, carrier, service_name, options = {})
|
244
|
+
super
|
245
|
+
@delivery_time_text = options[:delivery_time_text]
|
246
|
+
end
|
247
|
+
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
data/test/credentials.yml
CHANGED
@@ -65,6 +65,9 @@ stamps:
|
|
65
65
|
username: <%= ENV['ACTIVESHIPPING_STAMPS_USERNAME'] %>
|
66
66
|
password: <%= ENV['ACTIVESHIPPING_STAMPS_PASSWORD'] %>
|
67
67
|
|
68
|
+
australia_post:
|
69
|
+
api_key: <%= ENV['ACTIVESHIPPING_AUSTRALIA_POST_API_KEY'] %>
|
70
|
+
|
68
71
|
# fedex_freight:
|
69
72
|
# account: FedExFreightAccountNumber
|
70
73
|
# shipping_address1: FedExShippingAddress1
|
@@ -0,0 +1,13 @@
|
|
1
|
+
{
|
2
|
+
"postage_result": {
|
3
|
+
"service": "Express Post",
|
4
|
+
"delivery_time": "Guaranteed Next Business Day within the Express Post network (If posted on any business day Monday to Friday in accordance with the conditions set out on the item).",
|
5
|
+
"total_cost": "10.20",
|
6
|
+
"costs": {
|
7
|
+
"cost": {
|
8
|
+
"item": "Express Post",
|
9
|
+
"cost": "10.20"
|
10
|
+
}
|
11
|
+
}
|
12
|
+
}
|
13
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"postage_result": {
|
3
|
+
"service": "Express Post",
|
4
|
+
"delivery_time": "Guaranteed Next Business Day within the Express Post network (If posted on any business day Monday to Friday in accordance with the conditions set out on the item).",
|
5
|
+
"total_cost": "14.70",
|
6
|
+
"costs": {
|
7
|
+
"cost": [{
|
8
|
+
"item": "Express Post",
|
9
|
+
"cost": "10.20"
|
10
|
+
}, {
|
11
|
+
"item": "Standard Service",
|
12
|
+
"cost": "0.00"
|
13
|
+
}, {
|
14
|
+
"item": "Extra Cover",
|
15
|
+
"cost": "4.50"
|
16
|
+
}]
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
@@ -0,0 +1,117 @@
|
|
1
|
+
{
|
2
|
+
"services": {
|
3
|
+
"service": [{
|
4
|
+
"code": "AUS_PARCEL_EXPRESS",
|
5
|
+
"name": "Express Post",
|
6
|
+
"price": "28.55",
|
7
|
+
"max_extra_cover": 300,
|
8
|
+
"options": {
|
9
|
+
"option": [{
|
10
|
+
"code": "AUS_SERVICE_OPTION_STANDARD",
|
11
|
+
"name": "Standard Service",
|
12
|
+
"suboptions": {
|
13
|
+
"option": {
|
14
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
15
|
+
"name": "Extra Cover",
|
16
|
+
"max_extra_cover": 300
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}, {
|
20
|
+
"code": "AUS_SERVICE_OPTION_SIGNATURE_ON_DELIVERY",
|
21
|
+
"name": "Signature on Delivery",
|
22
|
+
"suboptions": {
|
23
|
+
"option": {
|
24
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
25
|
+
"name": "Extra Cover",
|
26
|
+
"max_extra_cover": 5000
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}]
|
30
|
+
}
|
31
|
+
}, {
|
32
|
+
"code": "AUS_PARCEL_EXPRESS_SATCHEL_3KG",
|
33
|
+
"name": "Express Post Medium (3Kg) Satchel",
|
34
|
+
"price": "14.80",
|
35
|
+
"max_extra_cover": 300,
|
36
|
+
"options": {
|
37
|
+
"option": [{
|
38
|
+
"code": "AUS_SERVICE_OPTION_STANDARD",
|
39
|
+
"name": "Standard Service",
|
40
|
+
"suboptions": {
|
41
|
+
"option": {
|
42
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
43
|
+
"name": "Extra Cover",
|
44
|
+
"max_extra_cover": 300
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}, {
|
48
|
+
"code": "AUS_SERVICE_OPTION_SIGNATURE_ON_DELIVERY",
|
49
|
+
"name": "Signature on Delivery",
|
50
|
+
"suboptions": {
|
51
|
+
"option": {
|
52
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
53
|
+
"name": "Extra Cover",
|
54
|
+
"max_extra_cover": 5000
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}]
|
58
|
+
}
|
59
|
+
}, {
|
60
|
+
"code": "AUS_PARCEL_REGULAR",
|
61
|
+
"name": "Parcel Post",
|
62
|
+
"price": "16.15",
|
63
|
+
"max_extra_cover": 300,
|
64
|
+
"options": {
|
65
|
+
"option": [{
|
66
|
+
"code": "AUS_SERVICE_OPTION_STANDARD",
|
67
|
+
"name": "Standard Service",
|
68
|
+
"suboptions": {
|
69
|
+
"option": {
|
70
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
71
|
+
"name": "Extra Cover",
|
72
|
+
"max_extra_cover": 300
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}, {
|
76
|
+
"code": "AUS_SERVICE_OPTION_SIGNATURE_ON_DELIVERY",
|
77
|
+
"name": "Signature on Delivery",
|
78
|
+
"suboptions": {
|
79
|
+
"option": {
|
80
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
81
|
+
"name": "Extra Cover",
|
82
|
+
"max_extra_cover": 5000
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}]
|
86
|
+
}
|
87
|
+
}, {
|
88
|
+
"code": "AUS_PARCEL_REGULAR_SATCHEL_3KG",
|
89
|
+
"name": "Parcel Post Medium Satchel",
|
90
|
+
"price": "13.40",
|
91
|
+
"max_extra_cover": 300,
|
92
|
+
"options": {
|
93
|
+
"option": [{
|
94
|
+
"code": "AUS_SERVICE_OPTION_STANDARD",
|
95
|
+
"name": "Standard Service",
|
96
|
+
"suboptions": {
|
97
|
+
"option": {
|
98
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
99
|
+
"name": "Extra Cover",
|
100
|
+
"max_extra_cover": 300
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}, {
|
104
|
+
"code": "AUS_SERVICE_OPTION_SIGNATURE_ON_DELIVERY",
|
105
|
+
"name": "Signature on Delivery",
|
106
|
+
"suboptions": {
|
107
|
+
"option": {
|
108
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
109
|
+
"name": "Extra Cover",
|
110
|
+
"max_extra_cover": 5000
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}]
|
114
|
+
}
|
115
|
+
}]
|
116
|
+
}
|
117
|
+
}
|
@@ -0,0 +1,117 @@
|
|
1
|
+
{
|
2
|
+
"services": {
|
3
|
+
"service": [{
|
4
|
+
"code": "AUS_PARCEL_EXPRESS",
|
5
|
+
"name": "Express Post",
|
6
|
+
"price": "10.20",
|
7
|
+
"max_extra_cover": 300,
|
8
|
+
"options": {
|
9
|
+
"option": [{
|
10
|
+
"code": "AUS_SERVICE_OPTION_STANDARD",
|
11
|
+
"name": "Standard Service",
|
12
|
+
"suboptions": {
|
13
|
+
"option": {
|
14
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
15
|
+
"name": "Extra Cover",
|
16
|
+
"max_extra_cover": 300
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}, {
|
20
|
+
"code": "AUS_SERVICE_OPTION_SIGNATURE_ON_DELIVERY",
|
21
|
+
"name": "Signature on Delivery",
|
22
|
+
"suboptions": {
|
23
|
+
"option": {
|
24
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
25
|
+
"name": "Extra Cover",
|
26
|
+
"max_extra_cover": 5000
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}]
|
30
|
+
}
|
31
|
+
}, {
|
32
|
+
"code": "AUS_PARCEL_EXPRESS_SATCHEL_500G",
|
33
|
+
"name": "Express Post Small Satchel",
|
34
|
+
"price": "10.55",
|
35
|
+
"max_extra_cover": 300,
|
36
|
+
"options": {
|
37
|
+
"option": [{
|
38
|
+
"code": "AUS_SERVICE_OPTION_STANDARD",
|
39
|
+
"name": "Standard Service",
|
40
|
+
"suboptions": {
|
41
|
+
"option": {
|
42
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
43
|
+
"name": "Extra Cover",
|
44
|
+
"max_extra_cover": 300
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}, {
|
48
|
+
"code": "AUS_SERVICE_OPTION_SIGNATURE_ON_DELIVERY",
|
49
|
+
"name": "Signature on Delivery",
|
50
|
+
"suboptions": {
|
51
|
+
"option": {
|
52
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
53
|
+
"name": "Extra Cover",
|
54
|
+
"max_extra_cover": 5000
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}]
|
58
|
+
}
|
59
|
+
}, {
|
60
|
+
"code": "AUS_PARCEL_REGULAR",
|
61
|
+
"name": "Parcel Post",
|
62
|
+
"price": "7.45",
|
63
|
+
"max_extra_cover": 300,
|
64
|
+
"options": {
|
65
|
+
"option": [{
|
66
|
+
"code": "AUS_SERVICE_OPTION_STANDARD",
|
67
|
+
"name": "Standard Service",
|
68
|
+
"suboptions": {
|
69
|
+
"option": {
|
70
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
71
|
+
"name": "Extra Cover",
|
72
|
+
"max_extra_cover": 300
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}, {
|
76
|
+
"code": "AUS_SERVICE_OPTION_SIGNATURE_ON_DELIVERY",
|
77
|
+
"name": "Signature on Delivery",
|
78
|
+
"suboptions": {
|
79
|
+
"option": {
|
80
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
81
|
+
"name": "Extra Cover",
|
82
|
+
"max_extra_cover": 5000
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}]
|
86
|
+
}
|
87
|
+
}, {
|
88
|
+
"code": "AUS_PARCEL_REGULAR_SATCHEL_500G",
|
89
|
+
"name": "Parcel Post Small Satchel",
|
90
|
+
"price": "8.25",
|
91
|
+
"max_extra_cover": 300,
|
92
|
+
"options": {
|
93
|
+
"option": [{
|
94
|
+
"code": "AUS_SERVICE_OPTION_STANDARD",
|
95
|
+
"name": "Standard Service",
|
96
|
+
"suboptions": {
|
97
|
+
"option": {
|
98
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
99
|
+
"name": "Extra Cover",
|
100
|
+
"max_extra_cover": 300
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}, {
|
104
|
+
"code": "AUS_SERVICE_OPTION_SIGNATURE_ON_DELIVERY",
|
105
|
+
"name": "Signature on Delivery",
|
106
|
+
"suboptions": {
|
107
|
+
"option": {
|
108
|
+
"code": "AUS_SERVICE_OPTION_EXTRA_COVER",
|
109
|
+
"name": "Extra Cover",
|
110
|
+
"max_extra_cover": 5000
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}]
|
114
|
+
}
|
115
|
+
}]
|
116
|
+
}
|
117
|
+
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
{
|
2
|
+
"services": {
|
3
|
+
"service": [{
|
4
|
+
"code": "INT_PARCEL_COR_OWN_PACKAGING",
|
5
|
+
"name": "Courier",
|
6
|
+
"price": "154.17",
|
7
|
+
"max_extra_cover": 5000,
|
8
|
+
"options": {
|
9
|
+
"option": [{
|
10
|
+
"code": "INT_TRACKING",
|
11
|
+
"name": "Tracking"
|
12
|
+
}, {
|
13
|
+
"code": "INT_SMS_TRACK_ADVICE",
|
14
|
+
"name": "SMS track advice"
|
15
|
+
}, {
|
16
|
+
"code": "INT_EXTRA_COVER",
|
17
|
+
"name": "Extra Cover"
|
18
|
+
}]
|
19
|
+
}
|
20
|
+
}, {
|
21
|
+
"code": "INT_PARCEL_EXP_OWN_PACKAGING",
|
22
|
+
"name": "Express",
|
23
|
+
"price": "89.17",
|
24
|
+
"max_extra_cover": 5000,
|
25
|
+
"options": {
|
26
|
+
"option": [{
|
27
|
+
"code": "INT_TRACKING",
|
28
|
+
"name": "Tracking"
|
29
|
+
}, {
|
30
|
+
"code": "INT_SIGNATURE_ON_DELIVERY",
|
31
|
+
"name": "Signature on delivery"
|
32
|
+
}, {
|
33
|
+
"code": "INT_SMS_TRACK_ADVICE",
|
34
|
+
"name": "SMS track advice"
|
35
|
+
}, {
|
36
|
+
"code": "INT_EXTRA_COVER",
|
37
|
+
"name": "Extra Cover"
|
38
|
+
}]
|
39
|
+
}
|
40
|
+
}, {
|
41
|
+
"code": "INT_PARCEL_STD_OWN_PACKAGING",
|
42
|
+
"name": "Standard",
|
43
|
+
"price": "84.17",
|
44
|
+
"max_extra_cover": 5000,
|
45
|
+
"options": {
|
46
|
+
"option": [{
|
47
|
+
"code": "INT_TRACKING",
|
48
|
+
"name": "Tracking"
|
49
|
+
}, {
|
50
|
+
"code": "INT_EXTRA_COVER",
|
51
|
+
"name": "Extra Cover"
|
52
|
+
}, {
|
53
|
+
"code": "INT_SIGNATURE_ON_DELIVERY",
|
54
|
+
"name": "Signature on delivery"
|
55
|
+
}, {
|
56
|
+
"code": "INT_SMS_TRACK_ADVICE",
|
57
|
+
"name": "SMS track advice"
|
58
|
+
}]
|
59
|
+
}
|
60
|
+
}, {
|
61
|
+
"code": "INT_PARCEL_SEA_OWN_PACKAGING",
|
62
|
+
"name": "Economy Sea",
|
63
|
+
"price": "46.80",
|
64
|
+
"max_extra_cover": 5000,
|
65
|
+
"options": {
|
66
|
+
"option": [{
|
67
|
+
"code": "INT_EXTRA_COVER",
|
68
|
+
"name": "Extra Cover"
|
69
|
+
}, {
|
70
|
+
"code": "INT_SIGNATURE_ON_DELIVERY",
|
71
|
+
"name": "Signature on delivery"
|
72
|
+
}]
|
73
|
+
}
|
74
|
+
}]
|
75
|
+
}
|
76
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
{
|
2
|
+
"services": {
|
3
|
+
"service": [{
|
4
|
+
"code": "INT_PARCEL_EXP_OWN_PACKAGING",
|
5
|
+
"name": "Express",
|
6
|
+
"price": "82.87",
|
7
|
+
"max_extra_cover": 5000,
|
8
|
+
"options": {
|
9
|
+
"option": [{
|
10
|
+
"code": "INT_TRACKING",
|
11
|
+
"name": "Tracking"
|
12
|
+
}, {
|
13
|
+
"code": "INT_SIGNATURE_ON_DELIVERY",
|
14
|
+
"name": "Signature on delivery"
|
15
|
+
}, {
|
16
|
+
"code": "INT_SMS_TRACK_ADVICE",
|
17
|
+
"name": "SMS track advice"
|
18
|
+
}, {
|
19
|
+
"code": "INT_EXTRA_COVER",
|
20
|
+
"name": "Extra Cover"
|
21
|
+
}]
|
22
|
+
}
|
23
|
+
}, {
|
24
|
+
"code": "INT_PARCEL_STD_OWN_PACKAGING",
|
25
|
+
"name": "Standard",
|
26
|
+
"price": "71.20",
|
27
|
+
"max_extra_cover": 5000,
|
28
|
+
"options": {
|
29
|
+
"option": [{
|
30
|
+
"code": "INT_TRACKING",
|
31
|
+
"name": "Tracking"
|
32
|
+
}, {
|
33
|
+
"code": "INT_EXTRA_COVER",
|
34
|
+
"name": "Extra Cover"
|
35
|
+
}, {
|
36
|
+
"code": "INT_SIGNATURE_ON_DELIVERY",
|
37
|
+
"name": "Signature on delivery"
|
38
|
+
}, {
|
39
|
+
"code": "INT_SMS_TRACK_ADVICE",
|
40
|
+
"name": "SMS track advice"
|
41
|
+
}]
|
42
|
+
}
|
43
|
+
}, {
|
44
|
+
"code": "INT_PARCEL_SEA_OWN_PACKAGING",
|
45
|
+
"name": "Economy Sea",
|
46
|
+
"price": "41.54",
|
47
|
+
"max_extra_cover": 5000,
|
48
|
+
"options": {
|
49
|
+
"option": [{
|
50
|
+
"code": "INT_EXTRA_COVER",
|
51
|
+
"name": "Extra Cover"
|
52
|
+
}, {
|
53
|
+
"code": "INT_SIGNATURE_ON_DELIVERY",
|
54
|
+
"name": "Signature on delivery"
|
55
|
+
}]
|
56
|
+
}
|
57
|
+
}]
|
58
|
+
}
|
59
|
+
}
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RemoteAustraliaPostTest < Minitest::Test
|
4
|
+
include ActiveShipping::Test::Credentials
|
5
|
+
include ActiveShipping::Test::Fixtures
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@carrier = AustraliaPost.new(credentials(:australia_post))
|
9
|
+
@sydney = location_fixtures[:sydney]
|
10
|
+
@melbourne = location_fixtures[:melbourne]
|
11
|
+
@ottawa = location_fixtures[:ottawa]
|
12
|
+
rescue NoCredentialsFound => e
|
13
|
+
skip(e.message)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_valid_credentials
|
17
|
+
assert @carrier.valid_credentials?
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_service_domestic_simple_request
|
21
|
+
response = @carrier.find_rates(@sydney, @melbourne, package_fixtures[:wii])
|
22
|
+
|
23
|
+
assert response.is_a?(RateResponse)
|
24
|
+
assert response.success?
|
25
|
+
assert response.rates.any?
|
26
|
+
assert response.rates.first.is_a?(RateEstimate)
|
27
|
+
assert_equal 1, response.params["responses"].size
|
28
|
+
assert_equal 1, response.request.size
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_service_domestic_combined_request
|
32
|
+
response = @carrier.find_rates(@sydney, @melbourne, package_fixtures.values_at(:book, :small_half_pound))
|
33
|
+
|
34
|
+
assert response.is_a?(RateResponse)
|
35
|
+
assert response.success?
|
36
|
+
assert response.rates.any?
|
37
|
+
assert response.rates.first.is_a?(RateEstimate)
|
38
|
+
assert_equal 2, response.params["responses"].size
|
39
|
+
assert_equal 2, response.request.size
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_service_international_simple_request
|
43
|
+
response = @carrier.find_rates(@sydney, @ottawa, package_fixtures[:wii])
|
44
|
+
|
45
|
+
assert response.is_a?(RateResponse)
|
46
|
+
assert response.success?
|
47
|
+
assert response.rates.any?
|
48
|
+
assert response.rates.first.is_a?(RateEstimate)
|
49
|
+
assert_equal 1, response.params["responses"].size
|
50
|
+
assert_equal 1, response.request.size
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_service_domestic_combined_request
|
54
|
+
response = @carrier.find_rates(@sydney, @ottawa, package_fixtures.values_at(:book, :small_half_pound))
|
55
|
+
|
56
|
+
assert response.is_a?(RateResponse)
|
57
|
+
assert response.success?
|
58
|
+
assert response.rates.any?
|
59
|
+
assert response.rates.first.is_a?(RateEstimate)
|
60
|
+
assert_equal 2, response.params["responses"].size
|
61
|
+
assert_equal 2, response.request.size
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_service_domestic_response_error
|
65
|
+
error = assert_raises(ActiveShipping::ResponseError) do
|
66
|
+
@carrier.find_rates(@sydney, @melbourne, package_fixtures[:largest_gold_bar])
|
67
|
+
end
|
68
|
+
|
69
|
+
assert_equal 'The maximum weight of a parcel is 22 kg.', error.message
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_service_international_response_error
|
73
|
+
error = assert_raises(ActiveShipping::ResponseError) do
|
74
|
+
@carrier.find_rates(@sydney, @ottawa, package_fixtures[:largest_gold_bar])
|
75
|
+
end
|
76
|
+
|
77
|
+
assert_equal 'The maximum weight of a parcel is 20 kg.', error.message
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_calculate_domestic_simple_request
|
81
|
+
response = @carrier.calculate_rates(@sydney, @melbourne, package_fixtures[:wii], 'AUS_PARCEL_EXPRESS')
|
82
|
+
|
83
|
+
assert response.is_a?(RateResponse)
|
84
|
+
assert response.success?
|
85
|
+
assert response.rates.any?
|
86
|
+
assert response.rates.first.is_a?(RateEstimate)
|
87
|
+
assert_equal 1, response.params["responses"].size
|
88
|
+
assert_equal 1, response.request.size
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_calculate_domestic_combined_request
|
92
|
+
response = @carrier.calculate_rates(@sydney, @melbourne, package_fixtures.values_at(:book, :small_half_pound), 'AUS_PARCEL_EXPRESS')
|
93
|
+
|
94
|
+
assert response.is_a?(RateResponse)
|
95
|
+
assert response.success?
|
96
|
+
assert response.rates.any?
|
97
|
+
assert response.rates.first.is_a?(RateEstimate)
|
98
|
+
assert_equal 2, response.params["responses"].size
|
99
|
+
assert_equal 2, response.request.size
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_calculate_international_simple_request
|
103
|
+
response = @carrier.calculate_rates(@sydney, @ottawa, package_fixtures[:wii], 'INT_PARCEL_COR_OWN_PACKAGING')
|
104
|
+
|
105
|
+
assert response.is_a?(RateResponse)
|
106
|
+
assert response.success?
|
107
|
+
assert response.rates.any?
|
108
|
+
assert response.rates.first.is_a?(RateEstimate)
|
109
|
+
assert_equal 1, response.params["responses"].size
|
110
|
+
assert_equal 1, response.request.size
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_calculate_domestic_combined_request
|
114
|
+
response = @carrier.calculate_rates(@sydney, @ottawa, package_fixtures.values_at(:book, :small_half_pound), 'INT_PARCEL_COR_OWN_PACKAGING')
|
115
|
+
|
116
|
+
assert response.is_a?(RateResponse)
|
117
|
+
assert response.success?
|
118
|
+
assert response.rates.any?
|
119
|
+
assert response.rates.first.is_a?(RateEstimate)
|
120
|
+
assert_equal 2, response.params["responses"].size
|
121
|
+
assert_equal 2, response.request.size
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_calculate_domestic_response_error
|
125
|
+
error = assert_raises(ActiveShipping::ResponseError) do
|
126
|
+
@carrier.calculate_rates(@sydney, @melbourne, package_fixtures[:wii], 'INT_PARCEL_COR_OWN_PACKAGING')
|
127
|
+
end
|
128
|
+
|
129
|
+
assert_equal 'Please enter a valid Service code.', error.message
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_calculate_international_response_error
|
133
|
+
error = assert_raises(ActiveShipping::ResponseError) do
|
134
|
+
@carrier.calculate_rates(@sydney, @ottawa, package_fixtures[:wii], 'AUS_PARCEL_EXPRESS')
|
135
|
+
end
|
136
|
+
|
137
|
+
assert_equal 'Please enter a valid Service code.', error.message
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -245,7 +245,19 @@ module ActiveShipping::Test
|
|
245
245
|
:city => 'Groningen',
|
246
246
|
:address1 => 'Aquamarijnstraat 349',
|
247
247
|
:postal_code => '9743 PJ',
|
248
|
-
:state => 'Groningen')
|
248
|
+
:state => 'Groningen'),
|
249
|
+
:sydney => Location.new(
|
250
|
+
:country => 'AUS',
|
251
|
+
:city => 'Sydney',
|
252
|
+
:state => 'NSW',
|
253
|
+
:address1 => '192 George Street',
|
254
|
+
:postal_code => '2000'),
|
255
|
+
:melbourne => Location.new(
|
256
|
+
:country => 'AUS',
|
257
|
+
:city => 'Melbourne',
|
258
|
+
:state => 'VIC',
|
259
|
+
:address1 => '192 George Street',
|
260
|
+
:postal_code => '3108')
|
249
261
|
}
|
250
262
|
end
|
251
263
|
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AustraliaPostTest < Minitest::Test
|
4
|
+
include ActiveShipping::Test::Fixtures
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@carrier = AustraliaPost.new(api_key: '4d9dc0f0-dda0-012e-066f-000c29b44ac0')
|
8
|
+
@sydney = location_fixtures[:sydney]
|
9
|
+
@melbourne = location_fixtures[:melbourne]
|
10
|
+
@ottawa = location_fixtures[:ottawa]
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_service_domestic_simple_request
|
14
|
+
url = 'https://digitalapi.auspost.com.au/postage/parcel/domestic/service.json?from_postcode=2000&height=2&length=19&to_postcode=3108&weight=0.25&width=14'
|
15
|
+
@carrier.expects(:commit).with(url).returns(json_fixture('australia_post/service_domestic'))
|
16
|
+
@carrier.find_rates(@sydney, @melbourne, package_fixtures[:book])
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_service_domestic_combined_request
|
20
|
+
url_1 = 'https://digitalapi.auspost.com.au/postage/parcel/domestic/service.json?from_postcode=2000&height=2&length=19&to_postcode=3108&weight=0.25&width=14'
|
21
|
+
url_2 = 'https://digitalapi.auspost.com.au/postage/parcel/domestic/service.json?from_postcode=2000&height=2.54&length=2.54&to_postcode=3108&weight=0.23&width=2.54'
|
22
|
+
@carrier.expects(:commit).with(url_1).returns(json_fixture('australia_post/service_domestic'))
|
23
|
+
@carrier.expects(:commit).with(url_2).returns(json_fixture('australia_post/service_domestic_2'))
|
24
|
+
@carrier.find_rates(@sydney, @melbourne, package_fixtures.values_at(:book, :small_half_pound))
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_service_domestic_simple_response
|
28
|
+
@carrier.expects(:commit).returns(json_fixture('australia_post/service_domestic'))
|
29
|
+
response = @carrier.find_rates(@sydney, @melbourne, package_fixtures[:book])
|
30
|
+
prices = [2855, 1480, 1615, 1340]
|
31
|
+
assert_equal prices, response.rates.map(&:price)
|
32
|
+
service_codes = ['AUS_PARCEL_EXPRESS', 'AUS_PARCEL_EXPRESS_SATCHEL_3KG', 'AUS_PARCEL_REGULAR', 'AUS_PARCEL_REGULAR_SATCHEL_3KG']
|
33
|
+
assert_equal service_codes, response.rates.map(&:service_code)
|
34
|
+
service_names = ['Express Post', 'Express Post Medium (3Kg) Satchel', 'Parcel Post', 'Parcel Post Medium Satchel']
|
35
|
+
assert_equal service_names, response.rates.map(&:service_name)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_service_domestic_combined_response
|
39
|
+
@carrier.expects(:commit).returns(json_fixture('australia_post/service_domestic'))
|
40
|
+
@carrier.expects(:commit).returns(json_fixture('australia_post/service_domestic_2'))
|
41
|
+
response = @carrier.find_rates(@sydney, @melbourne, package_fixtures.values_at(:book, :small_half_pound))
|
42
|
+
prices = [3875, 2360]
|
43
|
+
assert_equal prices, response.rates.map(&:price)
|
44
|
+
service_codes = ['AUS_PARCEL_EXPRESS', 'AUS_PARCEL_REGULAR']
|
45
|
+
assert_equal service_codes, response.rates.map(&:service_code)
|
46
|
+
service_names = ['Express Post', 'Parcel Post']
|
47
|
+
assert_equal service_names, response.rates.map(&:service_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_service_international_simple_request
|
51
|
+
url = 'https://digitalapi.auspost.com.au/postage/parcel/international/service.json?country_code=CA&weight=0.25'
|
52
|
+
@carrier.expects(:commit).with(url).returns(json_fixture('australia_post/service_international'))
|
53
|
+
@carrier.find_rates(@sydney, @ottawa, package_fixtures[:book])
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_service_international_combined_request
|
57
|
+
url_1 = 'https://digitalapi.auspost.com.au/postage/parcel/international/service.json?country_code=CA&weight=0.25'
|
58
|
+
url_2 = 'https://digitalapi.auspost.com.au/postage/parcel/international/service.json?country_code=CA&weight=0.23'
|
59
|
+
@carrier.expects(:commit).with(url_1).returns(json_fixture('australia_post/service_international'))
|
60
|
+
@carrier.expects(:commit).with(url_2).returns(json_fixture('australia_post/service_international_2'))
|
61
|
+
@carrier.find_rates(@sydney, @ottawa, package_fixtures.values_at(:book, :small_half_pound))
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_service_international_simple_response
|
65
|
+
@carrier.expects(:commit).returns(json_fixture('australia_post/service_international'))
|
66
|
+
response = @carrier.find_rates(@sydney, @ottawa, package_fixtures[:book])
|
67
|
+
prices = [15417, 8917, 8417, 4680]
|
68
|
+
assert_equal prices, response.rates.map(&:price)
|
69
|
+
service_codes = ['INT_PARCEL_COR_OWN_PACKAGING', 'INT_PARCEL_EXP_OWN_PACKAGING', 'INT_PARCEL_STD_OWN_PACKAGING', 'INT_PARCEL_SEA_OWN_PACKAGING']
|
70
|
+
assert_equal service_codes, response.rates.map(&:service_code)
|
71
|
+
service_names = ['Courier', 'Express', 'Standard', 'Economy Sea']
|
72
|
+
assert_equal service_names, response.rates.map(&:service_name)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_service_international_combined_response
|
76
|
+
@carrier.expects(:commit).returns(json_fixture('australia_post/service_international'))
|
77
|
+
@carrier.expects(:commit).returns(json_fixture('australia_post/service_international_2'))
|
78
|
+
response = @carrier.find_rates(@sydney, @melbourne, package_fixtures.values_at(:book, :small_half_pound))
|
79
|
+
prices = [17204, 15537, 8834]
|
80
|
+
assert_equal prices, response.rates.map(&:price)
|
81
|
+
service_codes = ['INT_PARCEL_EXP_OWN_PACKAGING', 'INT_PARCEL_STD_OWN_PACKAGING', 'INT_PARCEL_SEA_OWN_PACKAGING']
|
82
|
+
assert_equal service_codes, response.rates.map(&:service_code)
|
83
|
+
service_names = ['Express', 'Standard', 'Economy Sea']
|
84
|
+
assert_equal service_names, response.rates.map(&:service_name)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_service_response_error
|
88
|
+
error = assert_raises(ActiveShipping::ResponseError) do
|
89
|
+
raise_error = ActiveShipping::ResponseError.new
|
90
|
+
raise_error.expects(:response).returns(OpenStruct.new(body: json_fixture('australia_post/error_message')))
|
91
|
+
@carrier.expects(:ssl_get).raises raise_error
|
92
|
+
@carrier.find_rates(@sydney, @melbourne, package_fixtures[:book])
|
93
|
+
end
|
94
|
+
assert_equal 'Please enter From postcode.', error.response.message
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_calculate_domestic_simple_request
|
98
|
+
url = 'https://digitalapi.auspost.com.au/postage/parcel/domestic/calculate.json?from_postcode=2000&height=2&length=19&service_code=AUS_PARCEL_EXPRESS&to_postcode=3108&weight=0.25&width=14'
|
99
|
+
@carrier.expects(:commit).with(url).returns(json_fixture('australia_post/calculate_domestic'))
|
100
|
+
@carrier.calculate_rates(@sydney, @melbourne, package_fixtures[:book], 'AUS_PARCEL_EXPRESS')
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_calculate_domestic_combined_request
|
104
|
+
url_1 = 'https://digitalapi.auspost.com.au/postage/parcel/domestic/calculate.json?from_postcode=2000&height=2&length=19&service_code=AUS_PARCEL_EXPRESS&to_postcode=3108&weight=0.25&width=14'
|
105
|
+
url_2 = 'https://digitalapi.auspost.com.au/postage/parcel/domestic/calculate.json?from_postcode=2000&height=2.54&length=2.54&service_code=AUS_PARCEL_EXPRESS&to_postcode=3108&weight=0.23&width=2.54'
|
106
|
+
@carrier.expects(:commit).with(url_1).returns(json_fixture('australia_post/calculate_domestic'))
|
107
|
+
@carrier.expects(:commit).with(url_2).returns(json_fixture('australia_post/calculate_domestic_2'))
|
108
|
+
@carrier.calculate_rates(@sydney, @melbourne, package_fixtures.values_at(:book, :small_half_pound), 'AUS_PARCEL_EXPRESS')
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_calculate_domestic_simple_response
|
112
|
+
@carrier.expects(:commit).returns(json_fixture('australia_post/calculate_domestic'))
|
113
|
+
response = @carrier.calculate_rates(@sydney, @melbourne, package_fixtures[:book], 'AUS_PARCEL_EXPRESS')
|
114
|
+
prices = [1020]
|
115
|
+
assert_equal prices, response.rates.map(&:price)
|
116
|
+
service_codes = ['AUS_PARCEL_EXPRESS']
|
117
|
+
assert_equal service_codes, response.rates.map(&:service_code)
|
118
|
+
service_names = ['Express Post']
|
119
|
+
assert_equal service_names, response.rates.map(&:service_name)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_calculate_domestic_combined_response
|
123
|
+
@carrier.expects(:commit).returns(json_fixture('australia_post/calculate_domestic'))
|
124
|
+
@carrier.expects(:commit).returns(json_fixture('australia_post/calculate_domestic_2'))
|
125
|
+
response = @carrier.calculate_rates(@sydney, @melbourne, package_fixtures.values_at(:book, :small_half_pound), 'AUS_PARCEL_EXPRESS')
|
126
|
+
prices = [2490]
|
127
|
+
assert_equal prices, response.rates.map(&:price)
|
128
|
+
service_codes = ['AUS_PARCEL_EXPRESS']
|
129
|
+
assert_equal service_codes, response.rates.map(&:service_code)
|
130
|
+
service_names = ['Express Post']
|
131
|
+
assert_equal service_names, response.rates.map(&:service_name)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_calculate_international_simple_request
|
135
|
+
url = 'https://digitalapi.auspost.com.au/postage/parcel/international/calculate.json?country_code=CA&service_code=INT_PARCEL_COR_OWN_PACKAGING&weight=0.25'
|
136
|
+
@carrier.expects(:commit).with(url).returns(json_fixture('australia_post/calculate_international'))
|
137
|
+
@carrier.calculate_rates(@sydney, @ottawa, package_fixtures[:book], 'INT_PARCEL_COR_OWN_PACKAGING')
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_calculate_international_combined_request
|
141
|
+
url_1 = 'https://digitalapi.auspost.com.au/postage/parcel/international/calculate.json?country_code=CA&service_code=INT_PARCEL_COR_OWN_PACKAGING&weight=0.25'
|
142
|
+
url_2 = 'https://digitalapi.auspost.com.au/postage/parcel/international/calculate.json?country_code=CA&service_code=INT_PARCEL_COR_OWN_PACKAGING&weight=0.23'
|
143
|
+
@carrier.expects(:commit).with(url_1).returns(json_fixture('australia_post/calculate_international'))
|
144
|
+
@carrier.expects(:commit).with(url_2).returns(json_fixture('australia_post/calculate_international_2'))
|
145
|
+
@carrier.calculate_rates(@sydney, @ottawa, package_fixtures.values_at(:book, :small_half_pound), 'INT_PARCEL_COR_OWN_PACKAGING')
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_calculate_international_simple_response
|
149
|
+
@carrier.expects(:commit).returns(json_fixture('australia_post/calculate_international'))
|
150
|
+
response = @carrier.calculate_rates(@sydney, @ottawa, package_fixtures[:book], 'INT_PARCEL_COR_OWN_PACKAGING')
|
151
|
+
prices = [8736]
|
152
|
+
assert_equal prices, response.rates.map(&:price)
|
153
|
+
service_codes = ['INT_PARCEL_COR_OWN_PACKAGING']
|
154
|
+
assert_equal service_codes, response.rates.map(&:service_code)
|
155
|
+
service_names = ['Courier']
|
156
|
+
assert_equal service_names, response.rates.map(&:service_name)
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_calculate_international_combined_response
|
160
|
+
@carrier.expects(:commit).returns(json_fixture('australia_post/calculate_international'))
|
161
|
+
@carrier.expects(:commit).returns(json_fixture('australia_post/calculate_international_2'))
|
162
|
+
response = @carrier.calculate_rates(@sydney, @melbourne, package_fixtures.values_at(:book, :small_half_pound), 'INT_PARCEL_COR_OWN_PACKAGING')
|
163
|
+
prices = [17472]
|
164
|
+
assert_equal prices, response.rates.map(&:price)
|
165
|
+
service_codes = ['INT_PARCEL_COR_OWN_PACKAGING']
|
166
|
+
assert_equal service_codes, response.rates.map(&:service_code)
|
167
|
+
service_names = ['Courier']
|
168
|
+
assert_equal service_names, response.rates.map(&:service_name)
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_calculate_response_error
|
172
|
+
error = assert_raises(ActiveShipping::ResponseError) do
|
173
|
+
raise_error = ActiveShipping::ResponseError.new
|
174
|
+
raise_error.expects(:response).returns(OpenStruct.new(body: json_fixture('australia_post/error_message')))
|
175
|
+
@carrier.expects(:ssl_get).raises raise_error
|
176
|
+
@carrier.calculate_rates(@sydney, @melbourne, package_fixtures[:book], 'AUS_PARCEL_EXPRESS')
|
177
|
+
end
|
178
|
+
assert_equal 'Please enter From postcode.', error.response.message
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_shipping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James MacAulay
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-
|
14
|
+
date: 2016-06-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: quantified
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- lib/active_shipping.rb
|
186
186
|
- lib/active_shipping/carrier.rb
|
187
187
|
- lib/active_shipping/carriers.rb
|
188
|
+
- lib/active_shipping/carriers/australia_post.rb
|
188
189
|
- lib/active_shipping/carriers/benchmark_carrier.rb
|
189
190
|
- lib/active_shipping/carriers/bogus_carrier.rb
|
190
191
|
- lib/active_shipping/carriers/canada_post.rb
|
@@ -222,6 +223,15 @@ files:
|
|
222
223
|
- test/credentials.yml
|
223
224
|
- test/fixtures/files/label1.pdf
|
224
225
|
- test/fixtures/files/ups-shipping-label.gif
|
226
|
+
- test/fixtures/json/australia_post/calculate_domestic.json
|
227
|
+
- test/fixtures/json/australia_post/calculate_domestic_2.json
|
228
|
+
- test/fixtures/json/australia_post/calculate_international.json
|
229
|
+
- test/fixtures/json/australia_post/calculate_international_2.json
|
230
|
+
- test/fixtures/json/australia_post/error_message.json
|
231
|
+
- test/fixtures/json/australia_post/service_domestic.json
|
232
|
+
- test/fixtures/json/australia_post/service_domestic_2.json
|
233
|
+
- test/fixtures/json/australia_post/service_international.json
|
234
|
+
- test/fixtures/json/australia_post/service_international_2.json
|
225
235
|
- test/fixtures/json/newzealandpost/domestic_book.json
|
226
236
|
- test/fixtures/json/newzealandpost/domestic_default.json
|
227
237
|
- test/fixtures/json/newzealandpost/domestic_error.json
|
@@ -364,6 +374,7 @@ files:
|
|
364
374
|
- test/fixtures/xml/usps/world_rate_request_without_value.xml
|
365
375
|
- test/fixtures/xml/usps_returns/external_return_label_response.xml
|
366
376
|
- test/fixtures/xml/usps_returns/external_return_label_response_failure.xml
|
377
|
+
- test/remote/australia_post_test.rb
|
367
378
|
- test/remote/canada_post_pws_platform_test.rb
|
368
379
|
- test/remote/canada_post_pws_test.rb
|
369
380
|
- test/remote/canada_post_test.rb
|
@@ -378,6 +389,7 @@ files:
|
|
378
389
|
- test/remote/usps_returns_test.rb
|
379
390
|
- test/remote/usps_test.rb
|
380
391
|
- test/test_helper.rb
|
392
|
+
- test/unit/carriers/australia_post_test.rb
|
381
393
|
- test/unit/carriers/benchmark_test.rb
|
382
394
|
- test/unit/carriers/canada_post_pws_rating_test.rb
|
383
395
|
- test/unit/carriers/canada_post_pws_register_test.rb
|
@@ -431,6 +443,15 @@ test_files:
|
|
431
443
|
- test/credentials.yml
|
432
444
|
- test/fixtures/files/label1.pdf
|
433
445
|
- test/fixtures/files/ups-shipping-label.gif
|
446
|
+
- test/fixtures/json/australia_post/calculate_domestic.json
|
447
|
+
- test/fixtures/json/australia_post/calculate_domestic_2.json
|
448
|
+
- test/fixtures/json/australia_post/calculate_international.json
|
449
|
+
- test/fixtures/json/australia_post/calculate_international_2.json
|
450
|
+
- test/fixtures/json/australia_post/error_message.json
|
451
|
+
- test/fixtures/json/australia_post/service_domestic.json
|
452
|
+
- test/fixtures/json/australia_post/service_domestic_2.json
|
453
|
+
- test/fixtures/json/australia_post/service_international.json
|
454
|
+
- test/fixtures/json/australia_post/service_international_2.json
|
434
455
|
- test/fixtures/json/newzealandpost/domestic_book.json
|
435
456
|
- test/fixtures/json/newzealandpost/domestic_default.json
|
436
457
|
- test/fixtures/json/newzealandpost/domestic_error.json
|
@@ -573,6 +594,7 @@ test_files:
|
|
573
594
|
- test/fixtures/xml/usps/world_rate_request_without_value.xml
|
574
595
|
- test/fixtures/xml/usps_returns/external_return_label_response.xml
|
575
596
|
- test/fixtures/xml/usps_returns/external_return_label_response_failure.xml
|
597
|
+
- test/remote/australia_post_test.rb
|
576
598
|
- test/remote/canada_post_pws_platform_test.rb
|
577
599
|
- test/remote/canada_post_pws_test.rb
|
578
600
|
- test/remote/canada_post_test.rb
|
@@ -587,6 +609,7 @@ test_files:
|
|
587
609
|
- test/remote/usps_returns_test.rb
|
588
610
|
- test/remote/usps_test.rb
|
589
611
|
- test/test_helper.rb
|
612
|
+
- test/unit/carriers/australia_post_test.rb
|
590
613
|
- test/unit/carriers/benchmark_test.rb
|
591
614
|
- test/unit/carriers/canada_post_pws_rating_test.rb
|
592
615
|
- test/unit/carriers/canada_post_pws_register_test.rb
|