shipppit-canada-post 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/rate_spec.rb ADDED
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+ require 'canada_post'
3
+ require 'canada_post/client'
4
+
5
+ describe CanadaPost::Client do
6
+
7
+ context 'missing required parameters' do
8
+ it 'does raise Rate exception' do
9
+ expect{ CanadaPost::Client.new }.to raise_error(CanadaPost::RateError)
10
+ end
11
+ end
12
+
13
+ context 'required parameters present' do
14
+ it 'does create a valid instance' do
15
+ expect( CanadaPost::Client.new(canada_post_credentials) ).to be_an_instance_of(CanadaPost::Client)
16
+ end
17
+ end
18
+
19
+ describe 'rate service' do
20
+ let(:canada_post) { CanadaPost::Client.new(canada_post_credentials) }
21
+ let(:simple_package) { { weight: {value: 2, units: "KG"} } }
22
+ let(:complex_package) { { weight: {value: 2, units: "KG"}, dimension: {length: 25, width: 15, height: 10, units: "CM"} } }
23
+ let(:mailing_tube) { { cylinder: true, weight: {value: 2, units: "KG"}, dimension: {length: 25, width: 15, height: 10, units: "CM"} } }
24
+ let(:shipper) { { postal_code: "M5X1B8", country_code: "CA" } }
25
+ let(:domestic_recipient) { { postal_code: "M5R1C6", country_code: "CA" } }
26
+ let(:us_recipient) { { postal_code: "10012", country_code: "US", residential: true } }
27
+ let(:intl_recipient) { { country_code: "GB" } }
28
+
29
+ context 'domestic shipment', :vcr do
30
+ let(:rates) {
31
+ canada_post.rate(shipper: shipper, recipient: domestic_recipient, package: simple_package) }
32
+ it 'does return a rate' do
33
+ expect(rates.first).to be_an_instance_of(CanadaPost::Rate)
34
+ end
35
+ it 'does return a cost' do
36
+ expect(rates.first.total_net_charge).not_to be_nil
37
+ end
38
+ it 'does return a service_code' do
39
+ expect(rates.first.service_code).not_to be_nil
40
+ end
41
+ it 'does return expected_transit_time' do
42
+ expect(rates.first.expected_transit_time).not_to be_nil
43
+ end
44
+ it 'does return guaranteed_delivery' do
45
+ expect(rates.first.guaranteed_delivery).not_to be_nil
46
+ end
47
+ it 'does return expected_delivery_date' do
48
+ expect(rates.first.expected_delivery_date).not_to be_nil
49
+ end
50
+ end
51
+
52
+ context 'with package options specified', :vcr do
53
+ let(:rates) {
54
+ canada_post.rate(shipper: shipper, recipient: domestic_recipient, package: mailing_tube) }
55
+ it 'does return a rate' do
56
+ expect(rates.first).to be_an_instance_of(CanadaPost::Rate)
57
+ end
58
+ end
59
+
60
+ context 'with service type specified', :vcr do
61
+ let(:rates) { canada_post.rate(shipper: shipper, recipient: domestic_recipient, package: simple_package, service_type: "DOM.RP") }
62
+
63
+ it 'returns a single rate' do
64
+ expect(rates.count).to eq 1
65
+ end
66
+
67
+ it 'has a service_type attribute' do
68
+ expect(rates.first.service_type).to eq("Regular Parcel")
69
+ end
70
+ end
71
+
72
+ context 'with no service type specified', :vcr do
73
+ let(:rates) { canada_post.rate(shipper: shipper, recipient: domestic_recipient, package: simple_package) }
74
+ it 'returns multiple rates' do
75
+ expect(rates.count).to be >= 1
76
+ end
77
+
78
+ context 'each rate' do
79
+ it 'has service type attribute' do
80
+ expect(rates.first).to respond_to(:service_type)
81
+ end
82
+ end
83
+ end
84
+
85
+ context 'when there are no valid services available', :vcr do
86
+ let(:bad_shipper) { shipper.merge(postal_code: '0') }
87
+ let(:rates) { canada_post.rate(shipper: bad_shipper, recipient: domestic_recipient, package: simple_package) }
88
+
89
+ it 'does raise Rate exception' do
90
+ expect{ rates }.to raise_error(CanadaPost::RateError)
91
+ end
92
+ end
93
+
94
+ end
95
+
96
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'canada_post'
3
+ require 'canada_post/shipment'
4
+ require 'canada_post/client'
5
+
6
+ describe CanadaPost::Request::Registration do
7
+ let(:canada_post_service) { CanadaPost::Client.new(canada_post_credentials) }
8
+ context 'missing required parameters' do
9
+ it 'does raise Rate exception' do
10
+ expect { CanadaPost::Client.new }.to raise_error(CanadaPost::RateError)
11
+ end
12
+ end
13
+
14
+ context 'required parameters present', :vcr do
15
+ it 'does create a valid instance' do
16
+ expect(CanadaPost::Client.new(canada_post_credentials)).to be_an_instance_of(CanadaPost::Client)
17
+ end
18
+
19
+ let(:registration) {
20
+ canada_post_service.registration_token
21
+ }
22
+
23
+ it 'should generate new token' do
24
+ expect(registration[:token_id]).not_to be_nil
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+ require 'canada_post'
3
+ require 'canada_post/shipment'
4
+ require 'canada_post/client'
5
+
6
+ describe CanadaPost::Shipment do
7
+ context 'missing required parameters' do
8
+ it 'does raise Rate exception' do
9
+ expect { CanadaPost::Client.new }.to raise_error(CanadaPost::RateError)
10
+ end
11
+ end
12
+
13
+ context 'required parameters present' do
14
+ it 'does create a valid instance' do
15
+ expect(CanadaPost::Client.new(canada_post_credentials)).to be_an_instance_of(CanadaPost::Client)
16
+ end
17
+ end
18
+
19
+ describe 'Shipment shipping service' do
20
+ let(:canada_post_service) { CanadaPost::Client.new(canada_post_credentials) }
21
+ let(:package) { {weight: 2, unpackaged: false, mailing_tube: false, dimensions: {length: 2, width: 2, height: 2}} }
22
+ let(:sender) { {name: 'nazrul', company: 'my company', phone: '34343434', shipping_point: 'H2B1A0', address_details: {address: 'test address road', city: 'MONTREAL', state: 'QC', country: 'CA', postal_code: 'H2B1A0'}} }
23
+ let(:destination) { {name: 'nazrul recp', company: 'your company', address_details: {address: 'test dest address', city: 'Ottawa', state: 'ON', country: 'CA', postal_code: 'K1P5Z9'}} }
24
+ let(:notification) { {email: 'user@gmail.com', on_shipment: 'true', on_exception: 'true', on_delivery: 'true'} }
25
+ let(:preferences) { {show_packing_instructions: 'true', show_postage_rate: 'false', show_insured_value: 'true'} }
26
+ let(:group_id) { {value: '5241557'} }
27
+ let(:mailing_date) { {value: "#{Date.today + 5}"} }
28
+ let(:service_code) { {value: 'DOM.EP'} }
29
+ let(:contract_number) { {value: '42708517'} }
30
+ let(:mobo) {
31
+ {
32
+ username: 'xxx',
33
+ password: 'password',
34
+ customer_number: '123456789',
35
+ contract_number: '987654321'
36
+ }
37
+ }
38
+
39
+ context 'create shipment', :vcr do
40
+ let(:shipping) {
41
+ canada_post_service.create(
42
+ sender: sender,
43
+ destination: destination,
44
+ package: package,
45
+ notification: notification,
46
+ preferences: preferences,
47
+ group_id: group_id[:value],
48
+ mailing_date: mailing_date[:value],
49
+ service_code: service_code[:value],
50
+ contract_number: contract_number[:value]
51
+ )
52
+ }
53
+
54
+ it 'Should create a shipping' do
55
+ expect(shipping[:create_shipping][:errors]).to be_nil
56
+ end
57
+
58
+ it 'Should get a shipping id' do
59
+ expect(shipping[:create_shipping][:shipment_info][:shipment_id]).not_to be_nil
60
+ end
61
+
62
+ it 'Should transmit shipping' do
63
+ expect(shipping[:transmit_shipping][:errors]).to be_nil
64
+ end
65
+
66
+ it 'Should create manifest link for shipping' do
67
+ expect(shipping[:transmit_shipping][:manifests]).not_to be_nil
68
+ end
69
+
70
+ let(:get_shipment) {
71
+ canada_post_service.details(shipping[:create_shipping][:shipment_info][:shipment_id])
72
+ }
73
+
74
+ it 'Should get shipping details' do
75
+ expect(get_shipment[:shipment_details]).not_to be_nil
76
+ end
77
+
78
+ it 'Should shipping status be transmitted' do
79
+ expect(get_shipment[:shipment_details][:shipment_status]).to eq 'transmitted'
80
+ end
81
+
82
+ let(:get_price) {
83
+ canada_post_service.get_price(shipping[:create_shipping][:shipment_info][:shipment_id])
84
+ }
85
+
86
+ it 'Should get shipping price' do
87
+ expect(get_price[:shipment_price]).not_to be_nil
88
+ end
89
+
90
+ let(:void_shipping) {
91
+ canada_post_service.void_shipment(shipping[:create_shipping][:shipment_info][:shipment_id])
92
+ }
93
+
94
+ it 'Should void' do
95
+ expect(void_shipping[:errors]).to be_nil
96
+ end
97
+
98
+ end
99
+
100
+ context "Create MOBO shipping (on behalf of)", :vcr do
101
+ let(:shipping) {
102
+ canada_post_service.create(
103
+ sender: sender,
104
+ destination: destination,
105
+ package: package,
106
+ mobo: mobo,
107
+ notification: notification,
108
+ preferences: preferences,
109
+ group_id: group_id[:value],
110
+ mailing_date: mailing_date[:value],
111
+ service_code: service_code[:value],
112
+ contract_number: contract_number[:value]
113
+ )
114
+ }
115
+
116
+ let(:get_shipment) {
117
+ canada_post_service.details(shipping[:create_shipping][:shipment_info][:shipment_id], mobo[:customer_number])
118
+ }
119
+
120
+ it 'Should create a shipping' do
121
+ expect(shipping[:create_shipping][:errors]).to be_nil
122
+ end
123
+
124
+ it 'Should get a MOBO shipping id' do
125
+ expect(shipping[:create_shipping][:shipment_info][:shipment_id]).not_to be_nil
126
+ end
127
+
128
+ it 'Should transmit MOBO shipping' do
129
+ expect(shipping[:transmit_shipping][:errors]).to be_nil
130
+ end
131
+
132
+ it 'Should get MOBO shipping details' do
133
+ expect(get_shipment[:shipment_details]).not_to be_nil
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,11 @@
1
+ require 'rspec'
2
+ require 'canada_post'
3
+ require 'support/vcr'
4
+ require 'support/credentials'
5
+
6
+ RSpec.configure do |c|
7
+ c.filter_run_excluding :production unless canada_post_production_credentials
8
+ c.expect_with :rspec do |expect_config|
9
+ expect_config.syntax = :expect
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ def canada_post_credentials
2
+ @canada_post_credentials ||= credentials["development"]
3
+ end
4
+
5
+ def canada_post_production_credentials
6
+ @canada_post_production_credentials ||= credentials["production"]
7
+ end
8
+
9
+ private
10
+
11
+ def credentials
12
+ @credentials ||= begin
13
+ YAML.load_file("#{File.dirname(__FILE__)}/../config/canada_post_credentials.yml")
14
+ end
15
+ end
16
+
@@ -0,0 +1,14 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ c.cassette_library_dir = File.expand_path('../../vcr', __FILE__)
5
+ c.hook_into :webmock
6
+ end
7
+
8
+ RSpec.configure do |c|
9
+ c.include CanadaPost::Helpers
10
+ c.around(:each, :vcr) do |example|
11
+ name = underscorize(example.metadata[:full_description].split(/\s+/, 2).join("/")).gsub(/[^\w\/]+/, "_")
12
+ VCR.use_cassette(name) { example.call }
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,197 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shipppit-canada-post
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Olivier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.13.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.13.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.6.7.1
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.6'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.6.7.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: activesupport
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '4.2'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '4.2'
61
+ - !ruby/object:Gem::Dependency
62
+ name: bundler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.7'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.7'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '10.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '10.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.4'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.4'
103
+ - !ruby/object:Gem::Dependency
104
+ name: webmock
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.22'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '1.22'
117
+ - !ruby/object:Gem::Dependency
118
+ name: vcr
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '3.0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '3.0'
131
+ description: Ruby wrapper for the Canada Post API V3
132
+ email:
133
+ - olivier@yafoy.com
134
+ executables: []
135
+ extensions: []
136
+ extra_rdoc_files: []
137
+ files:
138
+ - ".gitignore"
139
+ - Gemfile
140
+ - LICENSE.txt
141
+ - README.md
142
+ - Rakefile
143
+ - canada-post-api.gemspec
144
+ - lib/canada_post.rb
145
+ - lib/canada_post/client.rb
146
+ - lib/canada_post/credentials.rb
147
+ - lib/canada_post/helpers.rb
148
+ - lib/canada_post/rate.rb
149
+ - lib/canada_post/request/base.rb
150
+ - lib/canada_post/request/manifest.rb
151
+ - lib/canada_post/request/rate.rb
152
+ - lib/canada_post/request/registration.rb
153
+ - lib/canada_post/request/shipment.rb
154
+ - lib/canada_post/request/shipping.rb
155
+ - lib/canada_post/shipment.rb
156
+ - lib/canada_post/version.rb
157
+ - spec/config/canada_post_credentials.example.yml
158
+ - spec/manifest_spec.rb
159
+ - spec/rate_spec.rb
160
+ - spec/registration_spec.rb
161
+ - spec/shipping_spec.rb
162
+ - spec/spec_helper.rb
163
+ - spec/support/credentials.rb
164
+ - spec/support/vcr.rb
165
+ homepage: https://github.com/shipppit/shipppit-canada-post
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.4.3
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Canada Post API
189
+ test_files:
190
+ - spec/config/canada_post_credentials.example.yml
191
+ - spec/manifest_spec.rb
192
+ - spec/rate_spec.rb
193
+ - spec/registration_spec.rb
194
+ - spec/shipping_spec.rb
195
+ - spec/spec_helper.rb
196
+ - spec/support/credentials.rb
197
+ - spec/support/vcr.rb