Class: PBShipping::Shipment
- Inherits:
-
ShippingApiResource
- Object
- ApiObject
- ApiResource
- ShippingApiResource
- PBShipping::Shipment
- Defined in:
- lib/pbshipping/shipment.rb
Class Method Summary collapse
- .reprintLabelByShipmentId(auth_obj, shipmentId) ⇒ Object
- .retryByTransactionId(auth_obj, txid, originalTxid) ⇒ Object
Instance Method Summary collapse
-
#cancel(auth_obj, txid, carrier, cancelInitiator = nil) ⇒ Object
MANAGING RATES AND SHIPMENTS API: DELETE /shipment/shipmentId API signature: delete/shipments/…
- #cancelByShipmentId(auth_obj, txid, shipmentId, carrier, cancelInitiator = nil) ⇒ Object
-
#createAndPurchase(auth_obj, txid, includeDeliveryCommitment = nil, extraHdrs = nil, overwrite = true) ⇒ Object
MANAGING RATES AND SHIPMENTS API: POST /shipments/ API signature: post/shipments.
-
#getRates(auth_obj, txid, includeDeliveryCommitment = nil, extraHdrs = nil) ⇒ Object
MANAGING RATES AND SHIPMENTS API: POST /rates API signature: post/rates.
-
#reprintLabel(auth_obj, overwrite = true) ⇒ Object
MANAGING RATES AND SHIPMENTS API: GET /shipments/shipmentId API signature: get/shipments/…
-
#retry(auth_obj, txid, originalTxid, overwrite = true) ⇒ Object
MANAGING RATES AND SHIPMENTS API: GET /shipments?originalTransactionId API signature: get/shipments.
Methods inherited from ApiObject
#[], #[]=, #add_accessors, #as_json, convert_to_api_object, #create_accessor, #each, #initialize, #inspect, #key?, #keys, #metaclass, #respond_to?, #to_hash, #to_json, #to_s, #update, #values
Constructor Details
This class inherits a constructor from PBShipping::ApiObject
Class Method Details
Instance Method Details
#cancel(auth_obj, txid, carrier, cancelInitiator = nil) ⇒ Object
MANAGING RATES AND SHIPMENTS API: DELETE /shipment/shipmentId API signature: delete/shipments/…
Cancel/void a shipment, and submit the shipment label for refund.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/pbshipping/shipment.rb', line 159 def cancel(auth_obj, txid, carrier, cancelInitiator=nil) if self.key?(:shipmentId) == false raise MissingResourceAttribute.new(:shipmentId) end hdrs = { PBShipping::txid_attrname => txid } payload = { :carrier => carrier } if cancelInitiator != nil payload[:cancelInitiator] = cancelInitiator end api_sig = "delete/shipments/..." api_version = PBShipping::get_api_version(api_sig) api_path = "/shipments/" + self[:shipmentId] json_resp = PBShipping::api_request( auth_obj, :delete, api_version, api_path, hdrs, nil, payload) ApiObject.new(json_resp) end |
#cancelByShipmentId(auth_obj, txid, shipmentId, carrier, cancelInitiator = nil) ⇒ Object
176 177 178 179 |
# File 'lib/pbshipping/shipment.rb', line 176 def cancelByShipmentId(auth_obj, txid, shipmentId, carrier, cancelInitiator=nil) Shipment.new({:shipmentId => shipmentId}).cancel( auth_obj, txid, carrier, cancelInitiator) end |
#createAndPurchase(auth_obj, txid, includeDeliveryCommitment = nil, extraHdrs = nil, overwrite = true) ⇒ Object
MANAGING RATES AND SHIPMENTS API: POST /shipments/ API signature: post/shipments
Create a shipment and purchase a shipment label.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/pbshipping/shipment.rb', line 61 def createAndPurchase(auth_obj, txid, includeDeliveryCommitment=nil, extraHdrs=nil, overwrite=true) hdrs = { PBShipping::txid_attrname => txid } if extraHdrs != nil hdrs.update(extraHdrs) end if includeDeliveryCommitment == nil params = { :includeDeliveryCommitment => false } else params = { :includeDeliveryCommitment => includeDeliveryCommitment } end api_sig = "post/shipments" api_version = PBShipping::get_api_version(api_sig) api_path = "/shipments" json_resp = PBShipping::api_request( auth_obj, :post, api_version, api_path, hdrs, params, self) if overwrite == true self.update(json_resp) self else Shipment.new(json_resp) end end |
#getRates(auth_obj, txid, includeDeliveryCommitment = nil, extraHdrs = nil) ⇒ Object
MANAGING RATES AND SHIPMENTS API: POST /rates API signature: post/rates
Rate a shipment before a shipment label is purchased and printed.
By default, the returned result would overwrite the current state of the object. To avoid overwriting, set the input argument overwrite to False and a copy of the result would be generated and returned instead
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pbshipping/shipment.rb', line 34 def getRates(auth_obj, txid, includeDeliveryCommitment=nil, extraHdrs=nil) hdrs = { PBShipping::txid_attrname => txid } if extraHdrs != nil hdrs.update(extraHdrs) end if includeDeliveryCommitment == nil params = { :includeDeliveryCommitment => false } else params = { :includeDeliveryCommitment => includeDeliveryCommitment } end api_sig = "post/rates" api_version = PBShipping::get_api_version(api_sig) api_path = "/rates" json_resp = PBShipping::api_request( auth_obj, :post, api_version, api_path, hdrs, params, self) rate_list = [] json_resp[:rates].each { |rate| rate_list << Rate.new(rate) } return rate_list end |
#reprintLabel(auth_obj, overwrite = true) ⇒ Object
MANAGING RATES AND SHIPMENTS API: GET /shipments/shipmentId API signature: get/shipments/…
Reprint a shipment label. Note that the number of reprints of a shipment label will be scrutinized and restricted.
By default, the returned result would overwrite the current state of the object. To avoid overwriting, set the input argument overwrite to False and a copy of the result would be generated and returned instead
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/pbshipping/shipment.rb', line 99 def reprintLabel(auth_obj, overwrite=true) if self.key?(:shipmentId) == false raise MissingResourceAttribute.new(:shipmentId) end api_sig = "get/shipments/..." api_version = PBShipping::get_api_version(api_sig) api_path = "/shipments/" + self[:shipmentId] json_resp = PBShipping::api_request( auth_obj, :get, api_version, api_path, {}, {}, {}) if overwrite == true self.update(json_resp) self else Shipment.new(json_resp) end end |
#retry(auth_obj, txid, originalTxid, overwrite = true) ⇒ Object
MANAGING RATES AND SHIPMENTS API: GET /shipments?originalTransactionId API signature: get/shipments
Retry a shipment that was previously submitted with no successful response.
By default, the returned result would overwrite the current state of the object. To avoid overwriting, set the input argument overwrite to False and a copy of the result would be generated and returned instead
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/pbshipping/shipment.rb', line 132 def retry(auth_obj, txid, originalTxid, overwrite=true) hdrs = { PBShipping::txid_attrname => txid } params = {:originalTransactionId => originalTxid} api_sig = "get/shipments" api_version = PBShipping::get_api_version(api_sig) api_path = "/shipments" json_resp = PBShipping::api_request( auth_obj, :get, api_version, api_path, hdrs, params, {}) if overwrite == true self.update(json_resp) self else Shipment.new(json_resp) end end |