Module: Deliveries::Couriers::Spring

Extended by:
Deliveries::Courier
Defined in:
lib/deliveries/couriers/spring.rb,
lib/deliveries/couriers/spring/address.rb,
lib/deliveries/couriers/spring/request.rb,
lib/deliveries/couriers/spring/labels/generate.rb,
lib/deliveries/couriers/spring/shipments/trace.rb,
lib/deliveries/couriers/spring/shipments/create.rb,
lib/deliveries/couriers/spring/shipments/create/defaults.rb,
lib/deliveries/couriers/spring/shipments/create/format_params.rb,
lib/deliveries/couriers/spring/shipments/trace/format_response.rb

Defined Under Namespace

Modules: Labels, Request, Shipments Classes: Address, Config

Constant Summary collapse

COURIER_ID =
:spring
ENDPOINT_LIVE =
'https://mtapi.net/'.freeze
ENDPOINT_TEST =
'https://mtapi.net/?testMode=1'.freeze

Class Method Summary collapse

Methods included from Deliveries::Courier

config, configure, configured?, get_collection_point, get_collection_points, live?, test?

Class Method Details

.create_pickup(sender:, receiver:, parcels:, reference_code:, pickup_date: nil) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/deliveries/couriers/spring.rb', line 68

def create_pickup(sender:, receiver:, parcels:, reference_code:, pickup_date: nil, **)
  delivery = Shipments::Create.new(
    sender: sender,
    receiver: receiver,
    parcels: parcels,
    reference_code: reference_code
  ).execute

  Deliveries::Pickup.new(delivery: delivery, pickup_date: pickup_date)
end

.create_shipment(sender:, receiver:, parcels:, reference_code:, shipment_date: nil) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/deliveries/couriers/spring.rb', line 57

def create_shipment(sender:, receiver:, parcels:, reference_code:, shipment_date: nil, **)
  delivery = Shipments::Create.new(
    sender: sender,
    receiver: receiver,
    parcels: parcels,
    reference_code: reference_code
  ).execute

  Deliveries::Shipment.new(delivery: delivery, shipment_date: shipment_date)
end

.get_label(tracking_code:) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/deliveries/couriers/spring.rb', line 36

def get_label(tracking_code:, **)
  decoded_label, url = Labels::Generate.new(
    tracking_code: tracking_code
  ).execute.values_at(:decoded_label, :url)

  Deliveries::Label.new(
    raw: decoded_label,
    url: url
  )
end

.get_labels(tracking_codes:) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/deliveries/couriers/spring.rb', line 47

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:) ⇒ Object



79
80
81
# File 'lib/deliveries/couriers/spring.rb', line 79

def pickup_info(tracking_code:, **)
  shipment_info(tracking_code: tracking_code)
end

.shipment_info(tracking_code:) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/deliveries/couriers/spring.rb', line 27

def shipment_info(tracking_code:, **)
  response = Shipments::Trace.new(
    tracking_code: tracking_code
  ).execute

  tracking_info_params = Shipments::Trace::FormatResponse.new(response: response).execute
  Deliveries::TrackingInfo.new(**tracking_info_params)
end