pbshipping 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/LICENSE +20 -0
- data/README.md +185 -0
- data/lib/pbshipping.rb +173 -0
- data/lib/pbshipping/account.rb +45 -0
- data/lib/pbshipping/address.rb +55 -0
- data/lib/pbshipping/api_object.rb +131 -0
- data/lib/pbshipping/api_resource.rb +22 -0
- data/lib/pbshipping/authentication.rb +36 -0
- data/lib/pbshipping/carrier.rb +53 -0
- data/lib/pbshipping/country.rb +22 -0
- data/lib/pbshipping/customs.rb +26 -0
- data/lib/pbshipping/developer.rb +120 -0
- data/lib/pbshipping/error.rb +73 -0
- data/lib/pbshipping/manifest.rb +130 -0
- data/lib/pbshipping/merchant.rb +22 -0
- data/lib/pbshipping/parcel.rb +26 -0
- data/lib/pbshipping/rate.rb +32 -0
- data/lib/pbshipping/scandetails.rb +22 -0
- data/lib/pbshipping/shipment.rb +185 -0
- data/lib/pbshipping/shipping_api_resource.rb +26 -0
- data/lib/pbshipping/tracking.rb +53 -0
- data/lib/pbshipping/transactiondetails.rb +22 -0
- data/lib/pbshipping/version.rb +3 -0
- data/test/tc_address.rb +46 -0
- data/test/tc_manifest.rb +69 -0
- data/test/tc_merchant.rb +44 -0
- data/test/tc_shipment.rb +89 -0
- data/test/tc_transactionreport.rb +93 -0
- data/test/test_util.rb +222 -0
- data/test/ts_all_tests.rb +21 -0
- data/tutorial.rb +464 -0
- metadata +96 -0
@@ -0,0 +1,130 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016 Pitney Bowes Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the MIT License (the "License"); you may not use this file
|
5
|
+
# except in compliance with the License. You may obtain a copy of the License
|
6
|
+
# in the LICENSE file or at
|
7
|
+
# https://opensource.org/licenses/MIT
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
# File: manifest.rb
|
16
|
+
# Description: manifest management functions
|
17
|
+
#
|
18
|
+
|
19
|
+
module PBShipping
|
20
|
+
class Manifest < ShippingApiResource
|
21
|
+
|
22
|
+
#
|
23
|
+
# MANAGING MANIFESTS
|
24
|
+
# API: POST /manifests
|
25
|
+
# API signature: post/manifests
|
26
|
+
#
|
27
|
+
# Create a USPS scan form
|
28
|
+
#
|
29
|
+
# By default, the returned result would overwrite the current state
|
30
|
+
# of the object. To avoid overwriting, set the input argument
|
31
|
+
# overwrite to False and a copy of the result would be generated and
|
32
|
+
# returned instead
|
33
|
+
#
|
34
|
+
def create(auth_obj, txid, overwrite=true)
|
35
|
+
if self.key?(:carrier) == false
|
36
|
+
raise MissingResourceAttribute.new(:carrier)
|
37
|
+
elsif self.key?(:parcelTrackingNumbers) == false
|
38
|
+
raise MissingResourceAttribute.new(:parcelTrackingNumbers)
|
39
|
+
elsif self.key?(:submissionDate) == false
|
40
|
+
raise MissingResourceAttribute.new(:submissionDate)
|
41
|
+
elsif self.key?(:fromAddress) == false
|
42
|
+
raise MissingResourceAttribute.new(:fromAddress)
|
43
|
+
end
|
44
|
+
hdrs = { PBShipping::txid_attrname => txid }
|
45
|
+
payload = {
|
46
|
+
:carrier => self[:carrier],
|
47
|
+
:parcelTrackingNumbers => self[:parcelTrackingNumbers],
|
48
|
+
:submissionDate => self[:submissionDate],
|
49
|
+
:fromAddress => self[:fromAddress]
|
50
|
+
}
|
51
|
+
api_sig = "post/manifests"
|
52
|
+
api_version = PBShipping::get_api_version(api_sig)
|
53
|
+
api_path = "/manifests"
|
54
|
+
json_resp = PBShipping::api_request(
|
55
|
+
auth_obj, :post, api_version, api_path, hdrs, {}, payload)
|
56
|
+
if overwrite == true
|
57
|
+
self.update(json_resp)
|
58
|
+
self
|
59
|
+
else
|
60
|
+
Manifest.new(json_resp)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# MANAGING MANIFESTS
|
66
|
+
# API: GET /manifests/{manifestId}
|
67
|
+
# API signature: get/manifests/...
|
68
|
+
#
|
69
|
+
# Reprint the USPS scan form
|
70
|
+
#
|
71
|
+
# By default, the returned result would overwrite the current state
|
72
|
+
# of the object. To avoid overwriting, set the input argument
|
73
|
+
# overwrite to False and a copy of the result would be generated and
|
74
|
+
# returned instead
|
75
|
+
#
|
76
|
+
def reprint(auth_obj, overwrite=true)
|
77
|
+
if self.key?(:manifestId) == false
|
78
|
+
raise MissingResourceAttribute.new(:manifestId)
|
79
|
+
end
|
80
|
+
api_sig = "get/manifests/..."
|
81
|
+
api_version = PBShipping::get_api_version(api_sig)
|
82
|
+
api_path = "/manifests/" + self[:manifestId]
|
83
|
+
json_resp = PBShipping::api_request(
|
84
|
+
auth_obj, :get, api_version, api_path, {}, {}, {})
|
85
|
+
if overwrite == true
|
86
|
+
self.update(json_resp)
|
87
|
+
self
|
88
|
+
else
|
89
|
+
Manifest.new(json_resp)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.reprintById(auth_obj, manifestId)
|
94
|
+
Manifest.new({:manifestId => manifestId}).reprint(auth_obj)
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# MANAGING MANIFESTS
|
99
|
+
# API: GET /manifests
|
100
|
+
# API signature: get/manifests/
|
101
|
+
#
|
102
|
+
# Retry a manifest request that was previously submitted with no successful
|
103
|
+
# response
|
104
|
+
#
|
105
|
+
# By default, the returned result would overwrite the current state
|
106
|
+
# of the object. To avoid overwriting, set the input argument
|
107
|
+
# overwrite to False and a copy of the result would be generated and
|
108
|
+
# returned instead
|
109
|
+
#
|
110
|
+
def retry(auth_obj, txid, originalTxid, overwrite=true)
|
111
|
+
hdrs = { PBShipping::txid_attrname => txid }
|
112
|
+
params = { :originalTransactionId => originalTxid }
|
113
|
+
api_sig = "get/manifests"
|
114
|
+
api_version = PBShipping::get_api_version(api_sig)
|
115
|
+
api_path = "/manifests"
|
116
|
+
json_resp = PBShipping::api_request(
|
117
|
+
auth_obj, :get, api_version, api_path, hdrs, params, {})
|
118
|
+
if overwrite == true
|
119
|
+
self.update(json_resp)
|
120
|
+
self
|
121
|
+
else
|
122
|
+
Manifest.new(json_resp)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.retryByTransactionId(auth_obj, txid, originalTxid)
|
127
|
+
Manifest.new().retry(auth_obj, txid, originalTxid)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016 Pitney Bowes Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the MIT License (the "License"); you may not use this file
|
5
|
+
# except in compliance with the License. You may obtain a copy of the License
|
6
|
+
# in the LICENSE file or at
|
7
|
+
# https://opensource.org/licenses/MIT
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
# File: merchant.rb
|
16
|
+
# Description: merchant account class
|
17
|
+
#
|
18
|
+
|
19
|
+
module PBShipping
|
20
|
+
class Merchant < ShippingApiResource
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016 Pitney Bowes Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the MIT License (the "License"); you may not use this file
|
5
|
+
# except in compliance with the License. You may obtain a copy of the License
|
6
|
+
# in the LICENSE file or at
|
7
|
+
# https://opensource.org/licenses/MIT
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
# File: parcel.rb
|
16
|
+
# Description: parcel class
|
17
|
+
#
|
18
|
+
|
19
|
+
module PBShipping
|
20
|
+
class Parcel < ShippingApiResource
|
21
|
+
end
|
22
|
+
class ParcelDimension < ShippingApiResource
|
23
|
+
end
|
24
|
+
class ParcelWeight < ShippingApiResource
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016 Pitney Bowes Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the MIT License (the "License"); you may not use this file
|
5
|
+
# except in compliance with the License. You may obtain a copy of the License
|
6
|
+
# in the LICENSE file or at
|
7
|
+
# https://opensource.org/licenses/MIT
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
# File: rate.rb
|
16
|
+
# Description: shipping rate class
|
17
|
+
#
|
18
|
+
|
19
|
+
module PBShipping
|
20
|
+
class Rate < ShippingApiResource
|
21
|
+
end
|
22
|
+
class DeliveryCommitment < ShippingApiResource
|
23
|
+
end
|
24
|
+
class Discount < ShippingApiResource
|
25
|
+
end
|
26
|
+
class SpecialService < ShippingApiResource
|
27
|
+
end
|
28
|
+
class Surcharge < ShippingApiResource
|
29
|
+
end
|
30
|
+
class Tax < ShippingApiResource
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016 Pitney Bowes Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the MIT License (the "License"); you may not use this file
|
5
|
+
# except in compliance with the License. You may obtain a copy of the License
|
6
|
+
# in the LICENSE file or at
|
7
|
+
# https://opensource.org/licenses/MIT
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
# File: scandetails.rb
|
16
|
+
# Description: SCAN form details object
|
17
|
+
#
|
18
|
+
|
19
|
+
module PBShipping
|
20
|
+
class ScanDetails < ShippingApiResource
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016 Pitney Bowes Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the MIT License (the "License"); you may not use this file
|
5
|
+
# except in compliance with the License. You may obtain a copy of the License
|
6
|
+
# in the LICENSE file or at
|
7
|
+
# https://opensource.org/licenses/MIT
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
# File: shipment.rb
|
16
|
+
# Description: shipment rate quote, creation, and other functions
|
17
|
+
#
|
18
|
+
|
19
|
+
module PBShipping
|
20
|
+
class Shipment < ShippingApiResource
|
21
|
+
|
22
|
+
#
|
23
|
+
# MANAGING RATES AND SHIPMENTS
|
24
|
+
# API: POST /rates
|
25
|
+
# API signature: post/rates
|
26
|
+
#
|
27
|
+
# Rate a shipment before a shipment label is purchased and printed.
|
28
|
+
#
|
29
|
+
# By default, the returned result would overwrite the current state
|
30
|
+
# of the object. To avoid overwriting, set the input argument
|
31
|
+
# overwrite to False and a copy of the result would be generated and
|
32
|
+
# returned instead
|
33
|
+
#
|
34
|
+
def getRates(auth_obj, txid, includeDeliveryCommitment=nil, extraHdrs=nil)
|
35
|
+
hdrs = { PBShipping::txid_attrname => txid }
|
36
|
+
if extraHdrs != nil
|
37
|
+
hdrs.update(extraHdrs)
|
38
|
+
end
|
39
|
+
if includeDeliveryCommitment == nil
|
40
|
+
params = { :includeDeliveryCommitment => false }
|
41
|
+
else
|
42
|
+
params = { :includeDeliveryCommitment => includeDeliveryCommitment }
|
43
|
+
end
|
44
|
+
api_sig = "post/rates"
|
45
|
+
api_version = PBShipping::get_api_version(api_sig)
|
46
|
+
api_path = "/rates"
|
47
|
+
json_resp = PBShipping::api_request(
|
48
|
+
auth_obj, :post, api_version, api_path, hdrs, params, self)
|
49
|
+
rate_list = []
|
50
|
+
json_resp[:rates].each { |rate| rate_list << Rate.new(rate) }
|
51
|
+
return rate_list
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# MANAGING RATES AND SHIPMENTS
|
56
|
+
# API: POST /shipments/
|
57
|
+
# API signature: post/shipments
|
58
|
+
#
|
59
|
+
# Create a shipment and purchase a shipment label.
|
60
|
+
#
|
61
|
+
def createAndPurchase(auth_obj, txid, includeDeliveryCommitment=nil,
|
62
|
+
extraHdrs=nil, overwrite=true)
|
63
|
+
hdrs = { PBShipping::txid_attrname => txid }
|
64
|
+
if extraHdrs != nil
|
65
|
+
hdrs.update(extraHdrs)
|
66
|
+
end
|
67
|
+
if includeDeliveryCommitment == nil
|
68
|
+
params = { :includeDeliveryCommitment => false }
|
69
|
+
else
|
70
|
+
params = { :includeDeliveryCommitment => includeDeliveryCommitment }
|
71
|
+
end
|
72
|
+
api_sig = "post/shipments"
|
73
|
+
api_version = PBShipping::get_api_version(api_sig)
|
74
|
+
api_path = "/shipments"
|
75
|
+
json_resp = PBShipping::api_request(
|
76
|
+
auth_obj, :post, api_version, api_path, hdrs, params, self)
|
77
|
+
if overwrite == true
|
78
|
+
self.update(json_resp)
|
79
|
+
self
|
80
|
+
else
|
81
|
+
Shipment.new(json_resp)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# MANAGING RATES AND SHIPMENTS
|
87
|
+
# API: GET /shipments/{shipmentId}
|
88
|
+
# API signature: get/shipments/...
|
89
|
+
#
|
90
|
+
# Reprint a shipment label.
|
91
|
+
# Note that the number of reprints of a shipment label will be scrutinized
|
92
|
+
# and restricted.
|
93
|
+
#
|
94
|
+
# By default, the returned result would overwrite the current state
|
95
|
+
# of the object. To avoid overwriting, set the input argument
|
96
|
+
# overwrite to False and a copy of the result would be generated and
|
97
|
+
# returned instead
|
98
|
+
#
|
99
|
+
def reprintLabel(auth_obj, overwrite=true)
|
100
|
+
if self.key?(:shipmentId) == false
|
101
|
+
raise MissingResourceAttribute.new(:shipmentId)
|
102
|
+
end
|
103
|
+
api_sig = "get/shipments/..."
|
104
|
+
api_version = PBShipping::get_api_version(api_sig)
|
105
|
+
api_path = "/shipments/" + self[:shipmentId]
|
106
|
+
json_resp = PBShipping::api_request(
|
107
|
+
auth_obj, :get, api_version, api_path, {}, {}, {})
|
108
|
+
if overwrite == true
|
109
|
+
self.update(json_resp)
|
110
|
+
self
|
111
|
+
else
|
112
|
+
Shipment.new(json_resp)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.reprintLabelByShipmentId(auth_obj, shipmentId)
|
117
|
+
Shipment.new({:shipmentId => shipmentId}).reprintLabel(auth_obj)
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
121
|
+
# MANAGING RATES AND SHIPMENTS
|
122
|
+
# API: GET /shipments?originalTransactionId
|
123
|
+
# API signature: get/shipments
|
124
|
+
#
|
125
|
+
# Retry a shipment that was previously submitted with no successful response.
|
126
|
+
#
|
127
|
+
# By default, the returned result would overwrite the current state
|
128
|
+
# of the object. To avoid overwriting, set the input argument
|
129
|
+
# overwrite to False and a copy of the result would be generated and
|
130
|
+
# returned instead
|
131
|
+
#
|
132
|
+
def retry(auth_obj, txid, originalTxid, overwrite=true)
|
133
|
+
hdrs = { PBShipping::txid_attrname => txid }
|
134
|
+
params = {:originalTransactionId => originalTxid}
|
135
|
+
api_sig = "get/shipments"
|
136
|
+
api_version = PBShipping::get_api_version(api_sig)
|
137
|
+
api_path = "/shipments"
|
138
|
+
json_resp = PBShipping::api_request(
|
139
|
+
auth_obj, :get, api_version, api_path, hdrs, params, {})
|
140
|
+
if overwrite == true
|
141
|
+
self.update(json_resp)
|
142
|
+
self
|
143
|
+
else
|
144
|
+
Shipment.new(json_resp)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def self.retryByTransactionId(auth_obj, txid, originalTxid)
|
149
|
+
Shipment.new().retry(auth_obj, txid, originalTxid)
|
150
|
+
end
|
151
|
+
|
152
|
+
#
|
153
|
+
# MANAGING RATES AND SHIPMENTS
|
154
|
+
# API: DELETE /shipment/{shipmentId}
|
155
|
+
# API signature: delete/shipments/...
|
156
|
+
#
|
157
|
+
# Cancel/void a shipment, and submit the shipment label for refund.
|
158
|
+
#
|
159
|
+
def cancel(auth_obj, txid, carrier, cancelInitiator=nil)
|
160
|
+
if self.key?(:shipmentId) == false
|
161
|
+
raise MissingResourceAttribute.new(:shipmentId)
|
162
|
+
end
|
163
|
+
hdrs = { PBShipping::txid_attrname => txid }
|
164
|
+
payload = { :carrier => carrier }
|
165
|
+
if cancelInitiator != nil
|
166
|
+
payload[:cancelInitiator] = cancelInitiator
|
167
|
+
end
|
168
|
+
api_sig = "delete/shipments/..."
|
169
|
+
api_version = PBShipping::get_api_version(api_sig)
|
170
|
+
api_path = "/shipments/" + self[:shipmentId]
|
171
|
+
json_resp = PBShipping::api_request(
|
172
|
+
auth_obj, :delete, api_version, api_path, hdrs, nil, payload)
|
173
|
+
ApiObject.new(json_resp)
|
174
|
+
end
|
175
|
+
|
176
|
+
def cancelByShipmentId(auth_obj, txid, shipmentId, carrier, cancelInitiator=nil)
|
177
|
+
Shipment.new({:shipmentId => shipmentId}).cancel(
|
178
|
+
auth_obj, txid, carrier, cancelInitiator)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
class ShipmentOptions < ShippingApiResource
|
182
|
+
end
|
183
|
+
class ShipmentLabel < ShippingApiResource
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016 Pitney Bowes Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the MIT License (the "License"); you may not use this file
|
5
|
+
# except in compliance with the License. You may obtain a copy of the License
|
6
|
+
# in the LICENSE file or at
|
7
|
+
# https://opensource.org/licenses/MIT
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
# File: shipping_api_resource.rb
|
16
|
+
# Description: shipping api resource base class
|
17
|
+
#
|
18
|
+
|
19
|
+
module PBShipping
|
20
|
+
class ShippingApiResource < ApiResource
|
21
|
+
end
|
22
|
+
class Document < ShippingApiResource
|
23
|
+
end
|
24
|
+
class Parameter < ShippingApiResource
|
25
|
+
end
|
26
|
+
end
|