aus_post_api 1.0.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.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +147 -0
- data/Rakefile +32 -0
- data/aus_post_api.gemspec +14 -0
- data/lib/aus_post_api.rb +7 -0
- data/lib/aus_post_api/dce.rb +15 -0
- data/lib/aus_post_api/dce/endpoint.rb +80 -0
- data/lib/aus_post_api/dce/validate_australian_address.rb +12 -0
- data/lib/aus_post_api/endpoint.rb +66 -0
- data/lib/aus_post_api/endpoint/attributes.rb +54 -0
- data/lib/aus_post_api/pac.rb +83 -0
- data/lib/aus_post_api/pac/country.rb +9 -0
- data/lib/aus_post_api/pac/domestic_letter_size.rb +9 -0
- data/lib/aus_post_api/pac/domestic_letter_thickness.rb +9 -0
- data/lib/aus_post_api/pac/domestic_letter_weight.rb +9 -0
- data/lib/aus_post_api/pac/domestic_parcel_size.rb +9 -0
- data/lib/aus_post_api/pac/domestic_parcel_type.rb +9 -0
- data/lib/aus_post_api/pac/domestic_parcel_weight.rb +9 -0
- data/lib/aus_post_api/pac/domestic_postcode_search.rb +12 -0
- data/lib/aus_post_api/pac/endpoint.rb +76 -0
- data/lib/aus_post_api/pac/international_letter_weight.rb +9 -0
- data/lib/aus_post_api/pac/international_parcel_weight.rb +9 -0
- data/lib/aus_post_api/pac/postage_letter_domestic_calculate.rb +12 -0
- data/lib/aus_post_api/pac/postage_letter_domestic_service.rb +11 -0
- data/lib/aus_post_api/pac/postage_letter_international_calculate.rb +12 -0
- data/lib/aus_post_api/pac/postage_letter_international_service.rb +11 -0
- data/lib/aus_post_api/pac/postage_parcel_domestic_calculate.rb +13 -0
- data/lib/aus_post_api/pac/postage_parcel_domestic_service.rb +12 -0
- data/lib/aus_post_api/pac/postage_parcel_international_calculate.rb +12 -0
- data/lib/aus_post_api/pac/postage_parcel_international_service.rb +11 -0
- data/lib/aus_post_api/uri_handler.rb +35 -0
- data/spec/aus_post_api/dce/endpoint_spec.rb +86 -0
- data/spec/aus_post_api/dce/validate_australian_address_spec.rb +18 -0
- data/spec/aus_post_api/dce_spec.rb +33 -0
- data/spec/aus_post_api/endpoint/attributes_spec.rb +35 -0
- data/spec/aus_post_api/endpoint_spec.rb +43 -0
- data/spec/aus_post_api/pac/country_spec.rb +8 -0
- data/spec/aus_post_api/pac/domestic_letter_size_spec.rb +8 -0
- data/spec/aus_post_api/pac/domestic_letter_thickness_spec.rb +8 -0
- data/spec/aus_post_api/pac/domestic_letter_weight_spec.rb +8 -0
- data/spec/aus_post_api/pac/domestic_parcel_size_spec.rb +8 -0
- data/spec/aus_post_api/pac/domestic_parcel_type_spec.rb +8 -0
- data/spec/aus_post_api/pac/domestic_parcel_weight_spec.rb +8 -0
- data/spec/aus_post_api/pac/endpoint_spec.rb +109 -0
- data/spec/aus_post_api/pac/international_letter_weight_spec.rb +8 -0
- data/spec/aus_post_api/pac/international_parcel_weight_spec.rb +8 -0
- data/spec/aus_post_api/pac/postage_letter_domestic_calculate_spec.rb +19 -0
- data/spec/aus_post_api/pac/postage_letter_domestic_service_spec.rb +15 -0
- data/spec/aus_post_api/pac/postage_letter_international_calculate_spec.rb +20 -0
- data/spec/aus_post_api/pac/postage_letter_international_service_spec.rb +13 -0
- data/spec/aus_post_api/pac/postage_parcel_domestic_calculate_spec.rb +24 -0
- data/spec/aus_post_api/pac/postage_parcel_domestic_service_spec.rb +17 -0
- data/spec/aus_post_api/pac/postage_parcel_international_calculate_spec.rb +15 -0
- data/spec/aus_post_api/pac/postage_parcel_international_service_spec.rb +8 -0
- data/spec/aus_post_api/pac/postcode_search_spec.rb +17 -0
- data/spec/aus_post_api/pac_spec.rb +101 -0
- data/spec/aus_post_api/uri_handler_spec.rb +14 -0
- data/spec/shared_examples/shared_examples_for_endpoint_classes.rb +37 -0
- data/spec/spec_helper.rb +41 -0
- metadata +136 -0
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AusPostAPI::DCE::Endpoint do
|
4
|
+
describe "Implementation" do
|
5
|
+
context "no `api_uri` method is defined" do
|
6
|
+
it "should raise an error" do
|
7
|
+
dce_endpoint = Class.new(AusPostAPI::DCE::Endpoint).new({}, dce_config)
|
8
|
+
|
9
|
+
expect { dce_endpoint.uri }.to(
|
10
|
+
raise_error(AusPostAPI::DCE::Endpoint::ImplementationError)
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "an `api_uri` method is defined" do
|
16
|
+
it "should not raise an error" do
|
17
|
+
dce_endpoint = Class.new(AusPostAPI::DCE::Endpoint) do
|
18
|
+
def api_uri
|
19
|
+
'api_uri'
|
20
|
+
end
|
21
|
+
end.new({}, dce_config)
|
22
|
+
|
23
|
+
expect { dce_endpoint.uri }.to_not raise_error
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "Configuration" do
|
29
|
+
before do
|
30
|
+
stub_const('DCEEndpoint', Class.new(AusPostAPI::DCE::Endpoint) {
|
31
|
+
def api_uri; 'api_uri'; end
|
32
|
+
})
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "Format" do
|
36
|
+
context "no format is provided" do
|
37
|
+
it "should raise an error" do
|
38
|
+
no_format_config = dce_config
|
39
|
+
no_format_config.delete(:FORMAT)
|
40
|
+
|
41
|
+
dce_endpoint = DCEEndpoint.new({}, no_format_config)
|
42
|
+
|
43
|
+
expect { dce_endpoint.uri }.to(
|
44
|
+
raise_error(AusPostAPI::DCE::Endpoint::NoFormatProvidedError)
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "an invalid format is provided" do
|
50
|
+
it "should raise an error" do
|
51
|
+
dce_endpoint = DCEEndpoint.new({}, dce_config.merge(FORMAT: :invalid))
|
52
|
+
|
53
|
+
expect { dce_endpoint.uri }.to(
|
54
|
+
raise_error(AusPostAPI::DCE::Endpoint::InvalidFormatError)
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "no USERNAME is provided" do
|
61
|
+
it "should raise an error" do
|
62
|
+
no_username_config = dce_config
|
63
|
+
no_username_config.delete(:USERNAME)
|
64
|
+
|
65
|
+
dce_endpoint = DCEEndpoint.new({}, no_username_config)
|
66
|
+
|
67
|
+
expect { dce_endpoint.headers }.to(
|
68
|
+
raise_error(AusPostAPI::DCE::Endpoint::NoHeaderProvidedError)
|
69
|
+
)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "no PASSWORD is provided" do
|
74
|
+
it "should raise an error" do
|
75
|
+
no_password_config = dce_config
|
76
|
+
no_password_config.delete(:PASSWORD)
|
77
|
+
|
78
|
+
dce_endpoint = DCEEndpoint.new({}, no_password_config)
|
79
|
+
|
80
|
+
expect { dce_endpoint.headers }.to(
|
81
|
+
raise_error(AusPostAPI::DCE::Endpoint::NoHeaderProvidedError)
|
82
|
+
)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AusPostAPI::DCE::ValidateAustralianAddress do
|
4
|
+
skip "There are no test credentials for this endpoint" do
|
5
|
+
let(:required_attributes) {
|
6
|
+
{
|
7
|
+
addressline1: '111',
|
8
|
+
suburb: "Melbourne",
|
9
|
+
postcode: "3000",
|
10
|
+
state: "VIC",
|
11
|
+
country: "AU"
|
12
|
+
}
|
13
|
+
}
|
14
|
+
let(:optional_attributes) { { addressline2: 'Bourke St' } }
|
15
|
+
|
16
|
+
it_behaves_like 'an endpoint'
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.shared_examples_for "a DCE endpoint wrapper" do |wrapped_api_class|
|
4
|
+
let(:api_instance) { instance_double(wrapped_api_class) }
|
5
|
+
let(:api_method) { convert_class_to_method(wrapped_api_class) }
|
6
|
+
let(:params) { { test: :param } }
|
7
|
+
let(:config) { { test: :config } }
|
8
|
+
|
9
|
+
it "should call execute on the appropriate api class" do
|
10
|
+
expect(wrapped_api_class).to receive(:new).with(params, config) { api_instance }
|
11
|
+
expect(api_instance).to receive(:execute)
|
12
|
+
|
13
|
+
AusPostAPI::DCE.new(config).send(api_method, params)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def convert_class_to_method(klass)
|
18
|
+
klass = klass.to_s.gsub(/AusPostAPI::DCE/, '')
|
19
|
+
|
20
|
+
# underscores -> camel case
|
21
|
+
klass
|
22
|
+
.to_s
|
23
|
+
.gsub(/.*::/, '')
|
24
|
+
.split(/(?=[A-Z])/)
|
25
|
+
.map(&:downcase)
|
26
|
+
.join('_')
|
27
|
+
end
|
28
|
+
|
29
|
+
describe AusPostAPI::DCE do
|
30
|
+
describe "#validate_australian_address" do
|
31
|
+
it_behaves_like 'a DCE endpoint wrapper', AusPostAPI::DCE::ValidateAustralianAddress
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative "../../../lib/aus_post_api/endpoint/attributes"
|
2
|
+
|
3
|
+
describe "Including the attributes module on a class" do
|
4
|
+
it "should allow attributes to be specified using the required_attributes method" do
|
5
|
+
test = Class.new do
|
6
|
+
include AusPostAPI::Endpoint::Attributes
|
7
|
+
|
8
|
+
required_attributes :one, :two
|
9
|
+
end.new
|
10
|
+
|
11
|
+
expect(test.required_attributes).to eql([:one, :two])
|
12
|
+
|
13
|
+
test.one = 1
|
14
|
+
test.two = 2
|
15
|
+
|
16
|
+
expect(test.one).to eql(1)
|
17
|
+
expect(test.two).to eql(2)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should allow attributes to be specified using the optional_attributes method" do
|
21
|
+
test = Class.new do
|
22
|
+
include AusPostAPI::Endpoint::Attributes
|
23
|
+
|
24
|
+
optional_attributes :one, :two
|
25
|
+
end.new
|
26
|
+
|
27
|
+
expect(test.optional_attributes).to eql([:one, :two])
|
28
|
+
|
29
|
+
test.one = 1
|
30
|
+
test.two = 2
|
31
|
+
|
32
|
+
expect(test.one).to eql(1)
|
33
|
+
expect(test.two).to eql(2)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative '../../lib/aus_post_api/endpoint'
|
2
|
+
|
3
|
+
describe AusPostAPI::Endpoint do
|
4
|
+
before do
|
5
|
+
stub_const "NullUriHandler", Class.new { def self.call(uri, headers); nil; end }
|
6
|
+
stub_const "AusPost::API::Attributes", Module.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#execute" do
|
10
|
+
context "no `uri` or `headers` methods defined" do
|
11
|
+
it "should raise an error" do
|
12
|
+
test = AusPostAPI::Endpoint.new({}, {}, NullUriHandler)
|
13
|
+
|
14
|
+
expect { test.execute }.to raise_error(
|
15
|
+
AusPostAPI::Endpoint::ImplementationError
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "only the `uri` method defined" do
|
21
|
+
it "should raise an error" do
|
22
|
+
test = AusPostAPI::Endpoint.new({}, {}, NullUriHandler)
|
23
|
+
|
24
|
+
def test.uri; "uri"; end
|
25
|
+
|
26
|
+
expect { test.execute }.to raise_error(
|
27
|
+
AusPostAPI::Endpoint::ImplementationError
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "both the `uri` and the `headers` method defined" do
|
33
|
+
it "should not raise an error" do
|
34
|
+
test = AusPostAPI::Endpoint.new({}, {}, NullUriHandler)
|
35
|
+
|
36
|
+
def test.uri; "uri"; end
|
37
|
+
def test.headers; "headers"; end
|
38
|
+
|
39
|
+
expect { test.execute }.to_not raise_error
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AusPostAPI::PAC::Endpoint do
|
4
|
+
describe "Implementation" do
|
5
|
+
context "no `api_uri` method is defined" do
|
6
|
+
it "should raise an error" do
|
7
|
+
pac_endpoint = Class.new(AusPostAPI::PAC::Endpoint).new({}, json_config)
|
8
|
+
|
9
|
+
expect { pac_endpoint.uri }.to(
|
10
|
+
raise_error(AusPostAPI::PAC::Endpoint::ImplementationError)
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "an `api_uri` method is defined" do
|
16
|
+
it "should not raise an error" do
|
17
|
+
pac_endpoint = Class.new(AusPostAPI::PAC::Endpoint) do
|
18
|
+
def api_uri
|
19
|
+
'api_uri'
|
20
|
+
end
|
21
|
+
end.new({}, json_config)
|
22
|
+
|
23
|
+
expect { pac_endpoint.uri }.to_not raise_error
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "Configuration" do
|
29
|
+
before do
|
30
|
+
stub_const('PACEndpoint', Class.new(AusPostAPI::PAC::Endpoint) {
|
31
|
+
def api_uri; 'api_uri'; end
|
32
|
+
})
|
33
|
+
end
|
34
|
+
|
35
|
+
context "no format is provided" do
|
36
|
+
it "should raise an error" do
|
37
|
+
no_format_config = json_config
|
38
|
+
no_format_config.delete(:FORMAT)
|
39
|
+
|
40
|
+
pac_endpoint = PACEndpoint.new({}, no_format_config)
|
41
|
+
|
42
|
+
expect { pac_endpoint.uri }.to(
|
43
|
+
raise_error(AusPostAPI::PAC::Endpoint::NoFormatProvidedError)
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "an invalid format is provided" do
|
49
|
+
it "should raise an error" do
|
50
|
+
pac_endpoint = PACEndpoint.new({}, json_config.merge(FORMAT: :invalid))
|
51
|
+
|
52
|
+
expect { pac_endpoint.uri }.to(
|
53
|
+
raise_error(AusPostAPI::PAC::Endpoint::InvalidFormatError)
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "no PAC_AUTH_KEY is provided" do
|
59
|
+
context "the TEST config is false" do
|
60
|
+
it "should raise an error" do
|
61
|
+
no_auth_key_config = json_config.merge(TEST: false)
|
62
|
+
no_auth_key_config.delete(:PAC_AUTH_KEY)
|
63
|
+
|
64
|
+
pac_endpoint = PACEndpoint.new({}, no_auth_key_config)
|
65
|
+
|
66
|
+
expect { pac_endpoint.headers }.to(
|
67
|
+
raise_error(AusPostAPI::PAC::Endpoint::NoAuthKeyProvidedError)
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "the TEST config is true" do
|
73
|
+
it "should not raise an error" do
|
74
|
+
no_auth_key_config = json_config.merge(TEST: true)
|
75
|
+
no_auth_key_config.delete(:PAC_AUTH_KEY)
|
76
|
+
|
77
|
+
pac_endpoint = PACEndpoint.new({}, no_auth_key_config)
|
78
|
+
|
79
|
+
expect { pac_endpoint.headers }.to_not raise_error
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "a PAC_AUTH_KEY is provided" do
|
85
|
+
context "the TEST config is false" do
|
86
|
+
it "should not raise an error" do
|
87
|
+
no_auth_key_config =
|
88
|
+
|
89
|
+
pac_endpoint = PACEndpoint.new({}, json_config.merge(
|
90
|
+
TEST: false, PAC_AUTH_KEY: :abc
|
91
|
+
))
|
92
|
+
|
93
|
+
expect { pac_endpoint.headers }.to_not raise_error
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "the TEST config is true" do
|
98
|
+
it "should not raise an error" do
|
99
|
+
|
100
|
+
pac_endpoint = PACEndpoint.new({}, json_config.merge(
|
101
|
+
TEST: true, PAC_AUTH_KEY: :abc
|
102
|
+
))
|
103
|
+
|
104
|
+
expect { pac_endpoint.headers }.to_not raise_error
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AusPostAPI::PAC::PostageLetterDomesticCalculate do
|
4
|
+
let(:required_attributes) {
|
5
|
+
{
|
6
|
+
service_code: 'AUS_LETTER_REGULAR_LARGE',
|
7
|
+
weight: 100
|
8
|
+
}
|
9
|
+
}
|
10
|
+
let(:optional_attributes) {
|
11
|
+
{
|
12
|
+
option_code: 'AUS_SERVICE_OPTION_REGISTERED_POST',
|
13
|
+
suboption_code: 'AUS_SERVICE_OPTION_DELIVERY_CONFIRMATION',
|
14
|
+
extra_cover: 1000,
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
it_behaves_like 'an endpoint'
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AusPostAPI::PAC::PostageLetterDomesticService do
|
4
|
+
let(:required_attributes) {
|
5
|
+
{
|
6
|
+
length: 100,
|
7
|
+
width: 100,
|
8
|
+
thickness: 20,
|
9
|
+
weight: 100
|
10
|
+
}
|
11
|
+
}
|
12
|
+
let(:optional_attributes) { {} }
|
13
|
+
|
14
|
+
it_behaves_like 'an endpoint'
|
15
|
+
end
|