Module: Deliveries::Couriers::Ups
- Extended by:
- Deliveries::Courier
- Defined in:
- lib/deliveries/couriers/ups.rb,
lib/deliveries/couriers/ups/json_request.rb,
lib/deliveries/couriers/ups/labels/generate.rb,
lib/deliveries/couriers/ups/shipments/trace.rb,
lib/deliveries/couriers/ups/shipments/create.rb,
lib/deliveries/couriers/ups/collection_points/search.rb
Defined Under Namespace
Modules: CollectionPoints, JsonRequest, Labels, Shipments Classes: Config
Constant Summary collapse
- COURIER_ID =
:ups
Class Method Summary collapse
- .create_pickup(sender:, receiver:, parcels:, reference_code:, pickup_date: nil, language: nil) ⇒ Object
- .create_shipment(sender:, receiver:, parcels:, reference_code:, collection_point:, shipment_date: nil, language: nil) ⇒ Object
- .get_collection_point(global_point_id:) ⇒ Object
- .get_collection_points(country:, postcode:) ⇒ Object
- .get_label(tracking_code:) ⇒ Object
- .get_labels(tracking_codes:) ⇒ Object
- .pickup_info(tracking_code:, language: nil) ⇒ Object
- .shipment_info(tracking_code:, language: nil) ⇒ Object
Methods included from Deliveries::Courier
config, configure, configured?, live?, test?
Class Method Details
.create_pickup(sender:, receiver:, parcels:, reference_code:, pickup_date: nil, language: nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/deliveries/couriers/ups.rb', line 71 def create_pickup(sender:, receiver:, parcels:, reference_code:, pickup_date: nil, language: nil, **) tracking_code, label = Shipments::Create.new( shipper: receiver, consignee: sender, parcels: parcels, reference_code: reference_code, type: :return, language: language ).execute.values_at(:tracking_code, :label) Deliveries::Pickup.new( courier_id: COURIER_ID, sender: sender, receiver: receiver, parcels: parcels, reference_code: reference_code, tracking_code: tracking_code, pickup_date: pickup_date, label: Label.new(raw: label) ) end |
.create_shipment(sender:, receiver:, parcels:, reference_code:, collection_point:, shipment_date: nil, language: nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/deliveries/couriers/ups.rb', line 48 def create_shipment(sender:, receiver:, parcels:, reference_code:, collection_point:, shipment_date: nil, language: nil, **) tracking_code, label = Shipments::Create.new( shipper: sender, consignee: receiver, parcels: parcels, reference_code: reference_code, type: :forward, collection_point: collection_point, language: language ).execute.values_at(:tracking_code, :label) Deliveries::Shipment.new( courier_id: COURIER_ID, sender: sender, receiver: receiver, parcels: parcels, reference_code: reference_code, tracking_code: tracking_code, shipment_date: shipment_date, label: Label.new(raw: label) ) end |
.get_collection_point(global_point_id:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/deliveries/couriers/ups.rb', line 25 def get_collection_point(global_point_id:) global_point = CollectionPoint.parse_global_point_id(global_point_id: global_point_id) points = CollectionPoints::Search.new( country: global_point.country, point_id: global_point.point_id ).execute raise Error, 'No collection point found by that point ID' if points.empty? CollectionPoint.new(**points.first) end |
.get_collection_points(country:, postcode:) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/deliveries/couriers/ups.rb', line 37 def get_collection_points(country:, postcode:) points = CollectionPoints::Search.new( country: country, postcode: postcode ).execute points.map do |arguments| CollectionPoint.new(**arguments) end end |
.get_label(tracking_code:) ⇒ Object
93 94 95 96 |
# File 'lib/deliveries/couriers/ups.rb', line 93 def get_label(tracking_code:, **) arguments = Labels::Generate.new(tracking_code: tracking_code).execute Label.new(**arguments) end |
.get_labels(tracking_codes:) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/deliveries/couriers/ups.rb', line 98 def get_labels(tracking_codes:, **) labels = Deliveries::Labels.new tracking_codes.each do |tracking_code| labels << get_label(tracking_code: tracking_code) end labels end |
.pickup_info(tracking_code:, language: nil) ⇒ Object
117 118 119 |
# File 'lib/deliveries/couriers/ups.rb', line 117 def pickup_info(tracking_code:, language: nil) shipment_info(tracking_code: tracking_code, language: language) end |
.shipment_info(tracking_code:, language: nil) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/deliveries/couriers/ups.rb', line 108 def shipment_info(tracking_code:, language: nil) checkpoints = Shipments::Trace.new(tracking_code: tracking_code, language: language).execute.map do |arguments| Checkpoint.new(**arguments) end TrackingInfo.new(courier_id: COURIER_ID, tracking_code: tracking_code, checkpoints: checkpoints, status: checkpoints.last&.status) end |