purolator_ruby 0.0.6 → 0.0.7
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 +4 -4
- data/lib/purolator_ruby.rb +8 -1
- data/lib/purolator_ruby/client.rb +19 -8
- data/lib/purolator_ruby/create_shipment_response.rb +15 -0
- data/lib/purolator_ruby/environment_credentials.rb +22 -10
- data/lib/purolator_ruby/get_documents_payload.rb +28 -0
- data/lib/purolator_ruby/get_documents_response.rb +13 -0
- data/lib/purolator_ruby/purolator_response.rb +36 -0
- data/lib/purolator_ruby/request.rb +45 -0
- data/lib/purolator_ruby/validate_city_postal_code_zip_payload.rb +27 -0
- data/lib/purolator_ruby/validate_city_postal_code_zip_response.rb +13 -0
- data/lib/purolator_ruby/version.rb +1 -1
- data/lib/purolator_ruby/wsdl_location.rb +35 -0
- data/spec/fixtures/ServiceAvailabilityService.wsdl +1055 -0
- data/spec/fixtures/ShippingDocumentsService.wsdl +704 -0
- data/spec/fixtures/vcr_cassettes/get_documents.yml +55 -0
- data/spec/fixtures/vcr_cassettes/shipping_service_integration.yml +5 -5
- data/spec/fixtures/vcr_cassettes/shipping_service_integration_2.yml +60 -0
- data/spec/fixtures/vcr_cassettes/validate_address.yml +56 -0
- data/spec/fixtures/vcr_cassettes/validate_address_invalid.yml +57 -0
- data/spec/purolator_ruby/client_spec.rb +39 -12
- data/spec/purolator_ruby/create_shipment_response_spec.rb +57 -0
- data/spec/purolator_ruby/get_documents_payload_spec.rb +16 -0
- data/spec/purolator_ruby/get_documents_response_spec.rb +40 -0
- data/spec/purolator_ruby/integration/create_shipment_spec.rb +53 -0
- data/spec/purolator_ruby/integration/get_documents_spec.rb +29 -0
- data/spec/purolator_ruby/integration/validate_address_spec.rb +51 -0
- data/spec/purolator_ruby/validate_city_postal_code_zip_payload_spec.rb +31 -0
- data/spec/purolator_ruby/wsdl_location_spec.rb +37 -0
- data/spec/spec_helper.rb +9 -0
- metadata +38 -5
- data/lib/purolator_ruby/create_shipment_request.rb +0 -55
- data/spec/purolator_ruby/create_shipment_request_spec.rb +0 -64
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Integration create shipment" do
|
4
|
+
|
5
|
+
before { setup_env }
|
6
|
+
|
7
|
+
let(:client) { PurolatorRuby::Client.new }
|
8
|
+
|
9
|
+
context "valid payload" do
|
10
|
+
|
11
|
+
let(:payload) do
|
12
|
+
{
|
13
|
+
sender_address: sender_address,
|
14
|
+
receiver_address: receiver_address,
|
15
|
+
shipping_date: Date.today,
|
16
|
+
weight: '10',
|
17
|
+
pieces: 1,
|
18
|
+
reference: 'ref 45'
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
it "succesfully communicates with ShippingService and returns shipment pin" do
|
23
|
+
VCR.use_cassette('shipping_service_integration') do
|
24
|
+
response = client.call(:create_shipment, payload)
|
25
|
+
expect(response.shipment_pin).to eq('329018602238')
|
26
|
+
expect(response.status).to eq(:ok)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
context "invalid payload" do
|
33
|
+
let(:payload) do
|
34
|
+
{
|
35
|
+
sender_address: sender_address,
|
36
|
+
receiver_address: receiver_address,
|
37
|
+
shipping_date: Date.new(2014, 01, 01),
|
38
|
+
weight: '10',
|
39
|
+
pieces: 1,
|
40
|
+
reference: '12'
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
it "has status error" do
|
46
|
+
VCR.use_cassette('shipping_service_integration_2') do
|
47
|
+
response = client.call(:create_shipment, payload)
|
48
|
+
expect(response.status).to eq(:error)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Get Documents integration" do
|
4
|
+
|
5
|
+
before { setup_env }
|
6
|
+
|
7
|
+
let(:client) { PurolatorRuby::Client.new }
|
8
|
+
|
9
|
+
context "valid payload" do
|
10
|
+
|
11
|
+
let(:payload) do
|
12
|
+
{
|
13
|
+
pin: '42',
|
14
|
+
document_type: 'DomesticBillOfLading'
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
it "gets document url" do
|
19
|
+
VCR.use_cassette('get_documents') do
|
20
|
+
response = client.call(:get_documents, payload)
|
21
|
+
|
22
|
+
expect(response.status).to eq(:ok)
|
23
|
+
expect(response.url).to eq('https://eshiponline.purolator.com/ShipOnline/shipment/getLabel.ashx?TEMP_TYPE=STUB&REPORT_NAME=GenericDummyReport.pdf&REPORT_NAME=GenericDummyReport.pdf')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Integration Validate Address" do
|
4
|
+
|
5
|
+
before { setup_env }
|
6
|
+
|
7
|
+
let(:client) { PurolatorRuby::Client.new }
|
8
|
+
|
9
|
+
context "valid payload" do
|
10
|
+
|
11
|
+
let(:payload) do
|
12
|
+
{
|
13
|
+
city: 'Ottawa',
|
14
|
+
province: 'ON',
|
15
|
+
country: 'CA',
|
16
|
+
postal_code: 'K1Y 0M5',
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
it "validates address" do
|
21
|
+
VCR.use_cassette('validate_address') do
|
22
|
+
response = client.call(:validate_city_postal_code_zip, payload)
|
23
|
+
|
24
|
+
expect(response.status).to eq(:ok)
|
25
|
+
expect(response.valid?).to eq(true)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context "invalid payload" do
|
32
|
+
let(:payload) do
|
33
|
+
{
|
34
|
+
city: 'Berlin',
|
35
|
+
province: 'ON',
|
36
|
+
country: 'CA',
|
37
|
+
postal_code: '1'
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
it "validates address" do
|
42
|
+
VCR.use_cassette('validate_address_invalid') do
|
43
|
+
response = client.call(:validate_city_postal_code_zip, payload)
|
44
|
+
|
45
|
+
expect(response.valid?).to eq(false)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PurolatorRuby::ValidateCityPostalCodeZipPayload do
|
4
|
+
|
5
|
+
let(:payload) do
|
6
|
+
{
|
7
|
+
city: 'Ottawa',
|
8
|
+
province: 'ON',
|
9
|
+
postal_code: 'K1Y 0M5',
|
10
|
+
country: 'CA'
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { described_class.new(payload) }
|
15
|
+
|
16
|
+
it "has a to_h method" do
|
17
|
+
expect(subject.to_h).to eq(
|
18
|
+
{
|
19
|
+
'Addresses' => {
|
20
|
+
'ShortAddress' => {
|
21
|
+
'City' => 'Ottawa',
|
22
|
+
'Province' => 'ON',
|
23
|
+
'PostalCode' => 'K1Y 0M5',
|
24
|
+
'Country' => 'CA'
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PurolatorRuby::WsdlLocation do
|
4
|
+
|
5
|
+
let(:test_root) { File.expand_path(File.join(File.dirname(__FILE__), '..')) }
|
6
|
+
let(:credentials) { double(wsdl_location: test_root, soap_header_v15: 'v15', soap_header_v13: 'v13') }
|
7
|
+
|
8
|
+
subject { described_class.new(credentials: credentials) }
|
9
|
+
|
10
|
+
it "can tell location for wsdl based on method" do
|
11
|
+
expect(subject.location_for(:create_shipment))
|
12
|
+
.to eq(File.join(test_root, 'ShippingService.wsdl'))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can tell location for validation service" do
|
16
|
+
expect(subject.location_for(:validate_city_postal_code_zip))
|
17
|
+
.to eq(File.join(test_root, 'ServiceAvailabilityService.wsdl'))
|
18
|
+
end
|
19
|
+
|
20
|
+
it "can tell soap_header for create shipment" do
|
21
|
+
expect(subject.soap_header_for(:create_shipment)).to eq('v15')
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can tell soap_header for validation service" do
|
25
|
+
expect(subject.soap_header_for(:validate_city_postal_code_zip)).to eq('v13')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "can tell location for get_documents service" do
|
29
|
+
expect(subject.location_for(:get_documents))
|
30
|
+
.to eq(File.join(test_root, 'ShippingDocumentsService.wsdl'))
|
31
|
+
end
|
32
|
+
|
33
|
+
it "can tell soap_header for get_documents service" do
|
34
|
+
expect(subject.soap_header_for(:get_documents)).to eq('v13')
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -28,3 +28,12 @@ def receiver_address
|
|
28
28
|
{'Name' => 'Fake Name', 'StreetNumber' => '5', 'StreetName' => 'Douglas Road','City' => 'Burnaby', 'Province' => 'BC', 'Country' => 'CA', 'PostalCode' => 'V5C1A1',
|
29
29
|
'PhoneNumber' => {'CountryCode' => '1', 'AreaCode' => '604', 'Phone' => '2982181'}}}
|
30
30
|
end
|
31
|
+
|
32
|
+
def setup_env
|
33
|
+
ENV['PLUROLATOR_RUBY_WSDL_LOCATION'] = File.expand_path 'spec/fixtures/'
|
34
|
+
ENV['PLUROLATOR_RUBY_DEVELOPER_KEY'] = "f1096de28f3d43d6a27872cc0c3c39a9"
|
35
|
+
ENV['PLUROLATOR_RUBY_DEVELOPER_PASSWORD'] = "10Wl)dh}"
|
36
|
+
ENV['PLUROLATOR_RUBY_CLIENT_ID'] = "9999999999"
|
37
|
+
ENV['PLUROLATOR_RUBY_ACCOUNT_NUMBER'] = "9999999999"
|
38
|
+
ENV['PLUROLATOR_RUBY_BILLING_NUMBER'] = "9999999999"
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: purolator_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boris Filipov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -151,17 +151,37 @@ files:
|
|
151
151
|
- lib/purolator_ruby.rb
|
152
152
|
- lib/purolator_ruby/client.rb
|
153
153
|
- lib/purolator_ruby/create_shipment_payload.rb
|
154
|
-
- lib/purolator_ruby/
|
154
|
+
- lib/purolator_ruby/create_shipment_response.rb
|
155
155
|
- lib/purolator_ruby/environment_credentials.rb
|
156
|
+
- lib/purolator_ruby/get_documents_payload.rb
|
157
|
+
- lib/purolator_ruby/get_documents_response.rb
|
158
|
+
- lib/purolator_ruby/purolator_response.rb
|
159
|
+
- lib/purolator_ruby/request.rb
|
160
|
+
- lib/purolator_ruby/validate_city_postal_code_zip_payload.rb
|
161
|
+
- lib/purolator_ruby/validate_city_postal_code_zip_response.rb
|
156
162
|
- lib/purolator_ruby/version.rb
|
163
|
+
- lib/purolator_ruby/wsdl_location.rb
|
157
164
|
- purolator_ruby.gemspec
|
158
165
|
- spec/.DS_Store
|
166
|
+
- spec/fixtures/ServiceAvailabilityService.wsdl
|
167
|
+
- spec/fixtures/ShippingDocumentsService.wsdl
|
159
168
|
- spec/fixtures/ShippingService.wsdl
|
169
|
+
- spec/fixtures/vcr_cassettes/get_documents.yml
|
160
170
|
- spec/fixtures/vcr_cassettes/shipping_service_integration.yml
|
171
|
+
- spec/fixtures/vcr_cassettes/shipping_service_integration_2.yml
|
172
|
+
- spec/fixtures/vcr_cassettes/validate_address.yml
|
173
|
+
- spec/fixtures/vcr_cassettes/validate_address_invalid.yml
|
161
174
|
- spec/purolator_ruby/client_spec.rb
|
162
175
|
- spec/purolator_ruby/create_shipment_payload_spec.rb
|
163
|
-
- spec/purolator_ruby/
|
176
|
+
- spec/purolator_ruby/create_shipment_response_spec.rb
|
164
177
|
- spec/purolator_ruby/environment_credentials_spec.rb
|
178
|
+
- spec/purolator_ruby/get_documents_payload_spec.rb
|
179
|
+
- spec/purolator_ruby/get_documents_response_spec.rb
|
180
|
+
- spec/purolator_ruby/integration/create_shipment_spec.rb
|
181
|
+
- spec/purolator_ruby/integration/get_documents_spec.rb
|
182
|
+
- spec/purolator_ruby/integration/validate_address_spec.rb
|
183
|
+
- spec/purolator_ruby/validate_city_postal_code_zip_payload_spec.rb
|
184
|
+
- spec/purolator_ruby/wsdl_location_spec.rb
|
165
185
|
- spec/spec_helper.rb
|
166
186
|
- spec/support/ShippingService.wsdl
|
167
187
|
homepage: http://github.com/Redelas/purolator_ruby
|
@@ -190,11 +210,24 @@ specification_version: 4
|
|
190
210
|
summary: Ruby wrapper around the Purolator E-Ship services.
|
191
211
|
test_files:
|
192
212
|
- spec/.DS_Store
|
213
|
+
- spec/fixtures/ServiceAvailabilityService.wsdl
|
214
|
+
- spec/fixtures/ShippingDocumentsService.wsdl
|
193
215
|
- spec/fixtures/ShippingService.wsdl
|
216
|
+
- spec/fixtures/vcr_cassettes/get_documents.yml
|
194
217
|
- spec/fixtures/vcr_cassettes/shipping_service_integration.yml
|
218
|
+
- spec/fixtures/vcr_cassettes/shipping_service_integration_2.yml
|
219
|
+
- spec/fixtures/vcr_cassettes/validate_address.yml
|
220
|
+
- spec/fixtures/vcr_cassettes/validate_address_invalid.yml
|
195
221
|
- spec/purolator_ruby/client_spec.rb
|
196
222
|
- spec/purolator_ruby/create_shipment_payload_spec.rb
|
197
|
-
- spec/purolator_ruby/
|
223
|
+
- spec/purolator_ruby/create_shipment_response_spec.rb
|
198
224
|
- spec/purolator_ruby/environment_credentials_spec.rb
|
225
|
+
- spec/purolator_ruby/get_documents_payload_spec.rb
|
226
|
+
- spec/purolator_ruby/get_documents_response_spec.rb
|
227
|
+
- spec/purolator_ruby/integration/create_shipment_spec.rb
|
228
|
+
- spec/purolator_ruby/integration/get_documents_spec.rb
|
229
|
+
- spec/purolator_ruby/integration/validate_address_spec.rb
|
230
|
+
- spec/purolator_ruby/validate_city_postal_code_zip_payload_spec.rb
|
231
|
+
- spec/purolator_ruby/wsdl_location_spec.rb
|
199
232
|
- spec/spec_helper.rb
|
200
233
|
- spec/support/ShippingService.wsdl
|
@@ -1,55 +0,0 @@
|
|
1
|
-
module PurolatorRuby
|
2
|
-
|
3
|
-
CreateShipmentResponse = Struct.new(:status, :shipment_pin, :payload, :errors)
|
4
|
-
|
5
|
-
class CreateShipmentRequest
|
6
|
-
|
7
|
-
attr_reader :client, :payload_opts
|
8
|
-
|
9
|
-
def initialize(options)
|
10
|
-
@client = options.fetch(:client)
|
11
|
-
_opts = options.dup
|
12
|
-
_opts.delete(:client)
|
13
|
-
@payload_opts = _opts.merge(account_number: client.account_number, billing_number: client.billing_number)
|
14
|
-
end
|
15
|
-
|
16
|
-
def send!
|
17
|
-
send.tap do |resp|
|
18
|
-
if resp.status == :error
|
19
|
-
puts resp
|
20
|
-
raise ArgumentError, resp.errors
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def send
|
26
|
-
payload = shipment_payload
|
27
|
-
|
28
|
-
if payload.valid?
|
29
|
-
response = client.call(:create_shipment, message: payload.to_h)
|
30
|
-
.body
|
31
|
-
.fetch(:create_shipment_response)
|
32
|
-
|
33
|
-
if response[:shipment_pin]
|
34
|
-
CreateShipmentResponse.new(:ok, response[:shipment_pin][:value], payload, nil)
|
35
|
-
else
|
36
|
-
begin
|
37
|
-
errors = response[:response_information][:errors].map {|k, v| v[:description]}
|
38
|
-
rescue TypeError
|
39
|
-
errors = response[:response_information][:errors].map(&:to_s)
|
40
|
-
end
|
41
|
-
CreateShipmentResponse.new(:error, nil, payload, errors)
|
42
|
-
end
|
43
|
-
else
|
44
|
-
CreateShipmentResponse.new(:error, nil, payload, payload.errors)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
def shipment_payload
|
50
|
-
CreateShipmentPayload.new(payload_opts)
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PurolatorRuby::CreateShipmentRequest do
|
4
|
-
|
5
|
-
before do
|
6
|
-
ENV['PLUROLATOR_RUBY_WSDL_LOCATION'] = File.expand_path 'spec/fixtures/ShippingService.wsdl'
|
7
|
-
ENV['PLUROLATOR_RUBY_DEVELOPER_KEY'] = "f1096de28f3d43d6a27872cc0c3c39a9"
|
8
|
-
ENV['PLUROLATOR_RUBY_DEVELOPER_PASSWORD'] = "10Wl)dh}"
|
9
|
-
ENV['PLUROLATOR_RUBY_CLIENT_ID'] = "9999999999"
|
10
|
-
ENV['PLUROLATOR_RUBY_ACCOUNT_NUMBER'] = "9999999999"
|
11
|
-
ENV['PLUROLATOR_RUBY_BILLING_NUMBER'] = "9999999999"
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:client) { PurolatorRuby::Client.new }
|
15
|
-
|
16
|
-
context "valid api input" do
|
17
|
-
subject do
|
18
|
-
described_class.new(
|
19
|
-
client: client,
|
20
|
-
sender_address: sender_address,
|
21
|
-
receiver_address: receiver_address,
|
22
|
-
shipping_date: Date.today,
|
23
|
-
weight: '10',
|
24
|
-
pieces: 1,
|
25
|
-
reference: 'ref 45')
|
26
|
-
end
|
27
|
-
|
28
|
-
it "succesfully communicates with ShippingService and returns shipment pin" do
|
29
|
-
VCR.use_cassette('shipping_service_integration') do
|
30
|
-
response = subject.send!
|
31
|
-
expect(response.shipment_pin).to eq('329018601172')
|
32
|
-
expect(response.status).to eq(:ok)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "invalid input" do
|
38
|
-
subject do
|
39
|
-
described_class.new(client: client)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "raises ArgumentError when called with a bang" do
|
43
|
-
expect { subject.send!.status }.to raise_error(ArgumentError)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "displays missing attributes" do
|
47
|
-
response = subject.send
|
48
|
-
expect(response.errors.join(' ')).to include('sender_address')
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "invalid but from soap side" do
|
53
|
-
subject do
|
54
|
-
described_class.new(client: client, sender_address: sender_address, receiver_address: receiver_address, shipping_date: Date.new(2014,01,01), weight: '0', pieces: 0, reference: '1')
|
55
|
-
end
|
56
|
-
|
57
|
-
it "raises ArgumentError" do
|
58
|
-
VCR.use_cassette('shipping_service_integration_2') do
|
59
|
-
expect { subject.send!.status }.to raise_error(ArgumentError)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|