ups-ruby 0.14.1 → 0.23.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 +4 -4
- data/Gemfile.lock +4 -4
- data/lib/ups/builders/builder_base.rb +38 -24
- data/lib/ups/builders/international_invoice_builder.rb +12 -2
- data/lib/ups/builders/organisation_builder.rb +22 -0
- data/lib/ups/builders/package_builder.rb +69 -0
- data/lib/ups/builders/ship_confirm_builder.rb +40 -1
- data/lib/ups/builders/track_builder.rb +37 -0
- data/lib/ups/connection.rb +22 -0
- data/lib/ups/parsers/ship_accept_parser.rb +26 -0
- data/lib/ups/parsers/track_parser.rb +51 -0
- data/lib/ups/version.rb +2 -2
- data/lib/ups.rb +3 -0
- data/spec/stubs/rates_success_with_packaging_type.xml +187 -0
- data/spec/stubs/rates_success_with_packaging_type_and_dimensions.xml +185 -0
- data/spec/stubs/ship_accept_success_with_packaging_type.xml +69 -0
- data/spec/stubs/ship_accept_success_without_negotiated_price.xml +59 -0
- data/spec/stubs/ship_confirm_success_with_packaging_type.xml +33 -0
- data/spec/stubs/track_success.xml +105 -0
- data/spec/support/AccessRequest.xsd +12 -0
- data/spec/support/IF.xsd +352 -0
- data/spec/support/RateRequest.xsd +454 -1
- data/spec/support/ShipAcceptRequest.xsd +4 -15
- data/spec/support/ShipConfirmRequest.xsd +99 -367
- data/spec/support/shipping_options.rb +42 -0
- data/spec/support/xsd_validator.rb +1 -1
- data/spec/ups/builders/organisation_builder_spec.rb +51 -0
- data/spec/ups/builders/rate_builder_spec.rb +1 -0
- data/spec/ups/builders/ship_confirm_builder_spec.rb +2 -0
- data/spec/ups/connection/rates_standard_spec.rb +94 -1
- data/spec/ups/connection/ship_spec.rb +55 -1
- data/spec/ups/connection/track_spec.rb +47 -0
- metadata +15 -3
@@ -23,12 +23,21 @@ module ShippingOptions
|
|
23
23
|
city: 'London',
|
24
24
|
state: 'England',
|
25
25
|
postal_code: 'WC2H 8AG',
|
26
|
+
email_address: 'test@example.com',
|
26
27
|
country: 'GB'
|
27
28
|
}
|
28
29
|
end
|
29
30
|
|
30
31
|
def package
|
31
32
|
{
|
33
|
+
reference_number: {
|
34
|
+
value: 'GB393023098',
|
35
|
+
type: 'TN'
|
36
|
+
},
|
37
|
+
reference_number_2: {
|
38
|
+
value: '#3403',
|
39
|
+
type: 'IK'
|
40
|
+
},
|
32
41
|
weight: '0.5',
|
33
42
|
unit: 'KGS',
|
34
43
|
dimensions: {
|
@@ -42,6 +51,9 @@ module ShippingOptions
|
|
42
51
|
|
43
52
|
def large_package
|
44
53
|
{
|
54
|
+
reference_number: {
|
55
|
+
value: 'GB393023098'
|
56
|
+
},
|
45
57
|
weight: '1',
|
46
58
|
unit: 'KGS',
|
47
59
|
dimensions: {
|
@@ -53,6 +65,34 @@ module ShippingOptions
|
|
53
65
|
}
|
54
66
|
end
|
55
67
|
|
68
|
+
def package_with_carrier_packaging
|
69
|
+
{
|
70
|
+
weight: '1',
|
71
|
+
unit: 'KGS',
|
72
|
+
packaging_type:{
|
73
|
+
code: '01',
|
74
|
+
description: 'Tube'
|
75
|
+
}
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def package_with_carrier_packaging_and_dimensions
|
80
|
+
{
|
81
|
+
weight: '1',
|
82
|
+
unit: 'KGS',
|
83
|
+
dimensions: {
|
84
|
+
length: 40,
|
85
|
+
width: 30,
|
86
|
+
height: 20,
|
87
|
+
unit: 'CM'
|
88
|
+
},
|
89
|
+
packaging_type:{
|
90
|
+
code: '01',
|
91
|
+
description: 'Tube'
|
92
|
+
}
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
56
96
|
def reference_number
|
57
97
|
{
|
58
98
|
code: 'IK',
|
@@ -65,6 +105,8 @@ module ShippingOptions
|
|
65
105
|
invoice_number: '#P-1234',
|
66
106
|
invoice_date: '20170816',
|
67
107
|
reason_for_export: '',
|
108
|
+
terms_of_shipment: 'DDP',
|
109
|
+
declaration_statement: 'U.S Customs (Freeform text)',
|
68
110
|
currency_code: 'USD',
|
69
111
|
discount: '1',
|
70
112
|
freight_charge: '1',
|
@@ -2,7 +2,7 @@ require 'minitest/assertions'
|
|
2
2
|
|
3
3
|
module Minitest::Assertions
|
4
4
|
def assert_passes_validation(schema_path, xml_to_validate)
|
5
|
-
schema = Nokogiri::XML::Schema(File.
|
5
|
+
schema = Nokogiri::XML::Schema(File.open(schema_path))
|
6
6
|
document = Nokogiri::XML::Document.parse(xml_to_validate)
|
7
7
|
schema.validate(document)
|
8
8
|
end
|
@@ -18,4 +18,55 @@ describe UPS::Builders::OrganisationBuilder do
|
|
18
18
|
subject.opts[:skip_ireland_state_validation].must_equal false
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
describe "#to_xml" do
|
23
|
+
let(:ioss_id) { 'IOSS32341313' }
|
24
|
+
let(:vat_id) { 'GB800909000' }
|
25
|
+
|
26
|
+
let(:address_hash) do
|
27
|
+
{
|
28
|
+
address_line_1: 'Googleplex',
|
29
|
+
address_line_2: '1600 Amphitheatre Parkway',
|
30
|
+
city: 'Mountain View',
|
31
|
+
state: 'California',
|
32
|
+
postal_code: '94043',
|
33
|
+
country: 'US',
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:organisation_hash) do
|
38
|
+
{
|
39
|
+
company_name: 'Company LTD',
|
40
|
+
phone_number: '07452444345',
|
41
|
+
attention_name: 'John Smith',
|
42
|
+
sender_vat_number: vat_id,
|
43
|
+
sender_ioss_number: ioss_id,
|
44
|
+
email_address: 'john.smith@company.com',
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:opts) { organisation_hash.merge(address_hash) }
|
49
|
+
|
50
|
+
subject { Ox.dump UPS::Builders::OrganisationBuilder.new('SoldTo', opts).to_xml }
|
51
|
+
|
52
|
+
it 'populates the xml with the correct elements' do
|
53
|
+
subject.must_include '<CompanyName>Company LTD</CompanyName>'
|
54
|
+
subject.must_include '<PhoneNumber>07452444345</PhoneNumber>'
|
55
|
+
subject.must_include '<AttentionName>John Smith</AttentionName>'
|
56
|
+
subject.must_include '<Address>'
|
57
|
+
subject.must_include '<TaxIdentificationNumber>GB800909000</TaxIdentificationNumber>'
|
58
|
+
subject.must_include '<EMailAddress>john.smith@company.com</EMailAddress>'
|
59
|
+
subject.must_include '<VendorCollectIDNumber>IOSS32341313</VendorCollectIDNumber>'
|
60
|
+
subject.must_include '<VendorCollectIDTypeCode>0356</VendorCollectIDTypeCode>'
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'when there is no IOSS id' do
|
64
|
+
let(:ioss_id) { nil }
|
65
|
+
|
66
|
+
it 'does not send the VendorInfo element at all' do
|
67
|
+
subject.wont_include '<VendorInfo>'
|
68
|
+
subject.wont_include '<VendorCollectIDNumber>IOSS32341313</VendorCollectIDNumber>'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
21
72
|
end
|
@@ -17,6 +17,8 @@ class UPS::Builders::TestShipConfirmBuilder < Minitest::Test
|
|
17
17
|
builder.add_reference_number reference_number
|
18
18
|
builder.add_insurance_charge '5.00'
|
19
19
|
builder.add_shipment_delivery_confirmation '2'
|
20
|
+
builder.add_shipment_direct_delivery_only
|
21
|
+
builder.add_invoice_line_total('12', "GBP")
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
@@ -14,6 +14,7 @@ describe UPS::Connection do
|
|
14
14
|
|
15
15
|
let(:stub_path) { File.expand_path("../../../stubs", __FILE__) }
|
16
16
|
let(:server) { UPS::Connection.new(test_mode: true) }
|
17
|
+
let(:supplied_package) { package }
|
17
18
|
|
18
19
|
describe 'if requesting rates' do
|
19
20
|
subject do
|
@@ -22,7 +23,7 @@ describe UPS::Connection do
|
|
22
23
|
rate_builder.add_shipper shipper
|
23
24
|
rate_builder.add_ship_from shipper
|
24
25
|
rate_builder.add_ship_to ship_to
|
25
|
-
rate_builder.add_package
|
26
|
+
rate_builder.add_package supplied_package
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
@@ -96,6 +97,98 @@ describe UPS::Connection do
|
|
96
97
|
end
|
97
98
|
end
|
98
99
|
|
100
|
+
describe 'when ups packaging type is specified' do
|
101
|
+
let(:supplied_package) { package_with_carrier_packaging }
|
102
|
+
|
103
|
+
before do
|
104
|
+
Excon.stub(method: :post) do |params|
|
105
|
+
case params[:path]
|
106
|
+
when UPS::Connection::RATE_PATH
|
107
|
+
{ body: File.read("#{stub_path}/rates_success_with_packaging_type.xml"), status: 200 }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'returns rates' do
|
113
|
+
expect(subject.rated_shipments).wont_be_empty
|
114
|
+
expect(subject.rated_shipments).must_equal [
|
115
|
+
{
|
116
|
+
service_code: '07',
|
117
|
+
service_name: 'Express',
|
118
|
+
warnings: [
|
119
|
+
' The weight exceeds the limit for the UPS Letter/Envelope rate and will be rated using the weight. ',
|
120
|
+
' Your invoice may vary from the displayed reference rates '
|
121
|
+
],
|
122
|
+
total: '171.04'
|
123
|
+
},
|
124
|
+
{
|
125
|
+
service_code: '65',
|
126
|
+
service_name: 'Express Saver',
|
127
|
+
warnings: [
|
128
|
+
' The weight exceeds the limit for the UPS Letter/Envelope rate and will be rated using the weight. ',
|
129
|
+
' Your invoice may vary from the displayed reference rates '
|
130
|
+
],
|
131
|
+
total: '160.76'
|
132
|
+
},
|
133
|
+
{
|
134
|
+
service_code: '54',
|
135
|
+
service_name: 'Express Plus',
|
136
|
+
warnings: [
|
137
|
+
' The weight exceeds the limit for the UPS Letter/Envelope rate and will be rated using the weight. ',
|
138
|
+
' Your invoice may vary from the displayed reference rates '
|
139
|
+
],
|
140
|
+
total: '226.89'
|
141
|
+
}
|
142
|
+
]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe 'when both ups packaging type and dimensions are specified' do
|
147
|
+
let(:supplied_package) { package_with_carrier_packaging }
|
148
|
+
|
149
|
+
before do
|
150
|
+
Excon.stub(method: :post) do |params|
|
151
|
+
case params[:path]
|
152
|
+
when UPS::Connection::RATE_PATH
|
153
|
+
{ body: File.read("#{stub_path}/rates_success_with_packaging_type_and_dimensions.xml"), status: 200 }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'returns rates' do
|
159
|
+
expect(subject.rated_shipments).wont_be_empty
|
160
|
+
expect(subject.rated_shipments).must_equal [
|
161
|
+
{
|
162
|
+
service_code: '07',
|
163
|
+
service_name: 'Express',
|
164
|
+
warnings: [
|
165
|
+
' The weight exceeds the limit for the UPS Letter/Envelope rate and will be rated using the weight. ',
|
166
|
+
' Your invoice may vary from the displayed reference rates '
|
167
|
+
],
|
168
|
+
total: '170.27'
|
169
|
+
},
|
170
|
+
{
|
171
|
+
service_code: '65',
|
172
|
+
service_name: 'Express Saver',
|
173
|
+
warnings: [
|
174
|
+
' The weight exceeds the limit for the UPS Letter/Envelope rate and will be rated using the weight. ',
|
175
|
+
' Your invoice may vary from the displayed reference rates '
|
176
|
+
],
|
177
|
+
total: '160.76'
|
178
|
+
},
|
179
|
+
{
|
180
|
+
service_code: '54',
|
181
|
+
service_name: 'Express Plus',
|
182
|
+
warnings: [
|
183
|
+
' The weight exceeds the limit for the UPS Letter/Envelope rate and will be rated using the weight. ',
|
184
|
+
' Your invoice may vary from the displayed reference rates '
|
185
|
+
],
|
186
|
+
total: '226.89'
|
187
|
+
}
|
188
|
+
]
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
99
192
|
describe 'error rates response' do
|
100
193
|
describe 'with single error response' do
|
101
194
|
before do
|
@@ -15,6 +15,7 @@ describe UPS::Connection do
|
|
15
15
|
|
16
16
|
let(:stub_path) { File.expand_path("../../../stubs", __FILE__) }
|
17
17
|
let(:server) { UPS::Connection.new(test_mode: true) }
|
18
|
+
let(:ship_accept_stub_file) { 'ship_accept_success' }
|
18
19
|
|
19
20
|
describe 'if requesting a shipment' do
|
20
21
|
describe 'single package shipment' do
|
@@ -27,7 +28,7 @@ describe UPS::Connection do
|
|
27
28
|
}
|
28
29
|
when UPS::Connection::SHIP_ACCEPT_PATH
|
29
30
|
{
|
30
|
-
body: File.read("#{stub_path}
|
31
|
+
body: File.read("#{stub_path}/#{ship_accept_stub_file}.xml"), status: 200
|
31
32
|
}
|
32
33
|
end
|
33
34
|
end
|
@@ -80,6 +81,59 @@ describe UPS::Connection do
|
|
80
81
|
it 'should return the tracking number' do
|
81
82
|
subject.tracking_number.must_equal '1Z2220060292353829'
|
82
83
|
end
|
84
|
+
|
85
|
+
describe 'total shipment cost' do
|
86
|
+
describe 'with negotiated rates' do
|
87
|
+
it 'returns the total shipment cost' do
|
88
|
+
subject.total_charge.must_equal 115.14
|
89
|
+
subject.currency_code.must_equal 'USD'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'without negotiated rates' do
|
94
|
+
let(:ship_accept_stub_file) { 'ship_accept_success_without_negotiated_price' }
|
95
|
+
|
96
|
+
it 'returns the total shipment cost' do
|
97
|
+
subject.total_charge.must_equal 118.48
|
98
|
+
subject.currency_code.must_equal 'USD'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe 'when packaging type is specified' do
|
105
|
+
before do
|
106
|
+
Excon.stub(method: :post) do |params|
|
107
|
+
case params[:path]
|
108
|
+
when UPS::Connection::SHIP_CONFIRM_PATH
|
109
|
+
{
|
110
|
+
body: File.read("#{stub_path}/ship_confirm_success_with_packaging_type.xml"), status: 200
|
111
|
+
}
|
112
|
+
when UPS::Connection::SHIP_ACCEPT_PATH
|
113
|
+
{
|
114
|
+
body: File.read("#{stub_path}/ship_accept_success_with_packaging_type.xml"), status: 200
|
115
|
+
}
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
subject do
|
121
|
+
server.ship do |shipment_builder|
|
122
|
+
shipment_builder.add_access_request ENV['UPS_LICENSE_NUMBER'], ENV['UPS_USER_ID'], ENV['UPS_PASSWORD']
|
123
|
+
shipment_builder.add_shipper shipper
|
124
|
+
shipment_builder.add_ship_from shipper
|
125
|
+
shipment_builder.add_ship_to ship_to
|
126
|
+
shipment_builder.add_package package_with_carrier_packaging_and_dimensions
|
127
|
+
shipment_builder.add_payment_information ENV['UPS_ACCOUNT_NUMBER']
|
128
|
+
shipment_builder.add_service '07'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
let(:supplied_package) { package_with_carrier_packaging }
|
133
|
+
|
134
|
+
it 'should return the tracking number' do
|
135
|
+
subject.tracking_number.must_equal '1Z2R466A6790676189'
|
136
|
+
end
|
83
137
|
end
|
84
138
|
|
85
139
|
describe 'multi package shipment' do
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'support/shipping_options'
|
3
|
+
|
4
|
+
describe UPS::Connection do
|
5
|
+
include ShippingOptions
|
6
|
+
|
7
|
+
before do
|
8
|
+
Excon.defaults[:mock] = true
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
Excon.stubs.clear
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:stub_path) { File.expand_path("../../../stubs", __FILE__) }
|
16
|
+
let(:server) { UPS::Connection.new(test_mode: true) }
|
17
|
+
let(:supplied_package) { package }
|
18
|
+
|
19
|
+
describe 'if tracking shipment' do
|
20
|
+
subject do
|
21
|
+
server.track do |track_builder|
|
22
|
+
track_builder.add_access_request ENV['UPS_LICENSE_NUMBER'], ENV['UPS_USER_ID'], ENV['UPS_PASSWORD']
|
23
|
+
track_builder.add_tracking_number '1Z12345E6692804405'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'successful track response' do
|
28
|
+
before do
|
29
|
+
Excon.stub(method: :post) do |params|
|
30
|
+
case params[:path]
|
31
|
+
when UPS::Connection::TRACK_PATH
|
32
|
+
{ body: File.read("#{stub_path}/track_success.xml"), status: 200 }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns the tracking status' do
|
38
|
+
expect(subject.to_h).wont_be_empty
|
39
|
+
expect(subject.to_h).must_equal(
|
40
|
+
status_date: Date.parse('2010-06-10'),
|
41
|
+
status_type_description: 'DELIVERED',
|
42
|
+
status_type_code: 'D'
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ups-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.23.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Veeqo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ox
|
@@ -101,10 +101,12 @@ files:
|
|
101
101
|
- lib/ups/builders/international_invoice_builder.rb
|
102
102
|
- lib/ups/builders/international_invoice_product_builder.rb
|
103
103
|
- lib/ups/builders/organisation_builder.rb
|
104
|
+
- lib/ups/builders/package_builder.rb
|
104
105
|
- lib/ups/builders/rate_builder.rb
|
105
106
|
- lib/ups/builders/ship_accept_builder.rb
|
106
107
|
- lib/ups/builders/ship_confirm_builder.rb
|
107
108
|
- lib/ups/builders/shipper_builder.rb
|
109
|
+
- lib/ups/builders/track_builder.rb
|
108
110
|
- lib/ups/connection.rb
|
109
111
|
- lib/ups/data.rb
|
110
112
|
- lib/ups/data/canadian_states.rb
|
@@ -119,6 +121,7 @@ files:
|
|
119
121
|
- lib/ups/parsers/rates_parser.rb
|
120
122
|
- lib/ups/parsers/ship_accept_parser.rb
|
121
123
|
- lib/ups/parsers/ship_confirm_parser.rb
|
124
|
+
- lib/ups/parsers/track_parser.rb
|
122
125
|
- lib/ups/services.rb
|
123
126
|
- lib/ups/utils.rb
|
124
127
|
- lib/ups/version.rb
|
@@ -130,10 +133,18 @@ files:
|
|
130
133
|
- spec/stubs/rates_negotiated_success.xml
|
131
134
|
- spec/stubs/rates_success.xml
|
132
135
|
- spec/stubs/rates_success_single_rate.xml
|
136
|
+
- spec/stubs/rates_success_with_packaging_type.xml
|
137
|
+
- spec/stubs/rates_success_with_packaging_type_and_dimensions.xml
|
133
138
|
- spec/stubs/ship_accept_failure.xml
|
134
139
|
- spec/stubs/ship_accept_success.xml
|
140
|
+
- spec/stubs/ship_accept_success_with_packaging_type.xml
|
141
|
+
- spec/stubs/ship_accept_success_without_negotiated_price.xml
|
135
142
|
- spec/stubs/ship_confirm_failure.xml
|
136
143
|
- spec/stubs/ship_confirm_success.xml
|
144
|
+
- spec/stubs/ship_confirm_success_with_packaging_type.xml
|
145
|
+
- spec/stubs/track_success.xml
|
146
|
+
- spec/support/AccessRequest.xsd
|
147
|
+
- spec/support/IF.xsd
|
137
148
|
- spec/support/RateRequest.xsd
|
138
149
|
- spec/support/ShipAcceptRequest.xsd
|
139
150
|
- spec/support/ShipConfirmRequest.xsd
|
@@ -148,6 +159,7 @@ files:
|
|
148
159
|
- spec/ups/connection/rates_negotiated_spec.rb
|
149
160
|
- spec/ups/connection/rates_standard_spec.rb
|
150
161
|
- spec/ups/connection/ship_spec.rb
|
162
|
+
- spec/ups/connection/track_spec.rb
|
151
163
|
- spec/ups/connection_spec.rb
|
152
164
|
- ups.gemspec
|
153
165
|
homepage: https://github.com/veeqo/ups-ruby
|
@@ -169,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
181
|
- !ruby/object:Gem::Version
|
170
182
|
version: 1.3.6
|
171
183
|
requirements: []
|
172
|
-
rubygems_version: 3.0.
|
184
|
+
rubygems_version: 3.0.3.1
|
173
185
|
signing_key:
|
174
186
|
specification_version: 4
|
175
187
|
summary: UPS
|