Module: Deliveries::Couriers::Dummy

Extended by:
Deliveries::Courier
Defined in:
lib/deliveries/couriers/dummy.rb

Class Method Summary collapse

Methods included from Deliveries::Courier

config, configure, configured?, live?, test?

Class Method Details

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



82
83
84
85
86
87
88
89
90
# File 'lib/deliveries/couriers/dummy.rb', line 82

def create_pickup(sender:, receiver:, parcels:, reference_code:, pickup_date: nil, **)
  Pickup.new courier_id: 'dummy',
             sender: sender,
             receiver: receiver,
             parcels: parcels,
             reference_code: reference_code,
             tracking_code: reference_code,
             pickup_date: pickup_date
end

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



72
73
74
75
76
77
78
79
80
# File 'lib/deliveries/couriers/dummy.rb', line 72

def create_shipment(sender:, receiver:, parcels:, reference_code:, shipment_date: nil, **)
  Shipment.new courier_id: 'dummy',
               sender: sender,
               receiver: receiver,
               parcels: parcels,
               reference_code: reference_code,
               tracking_code: reference_code,
               shipment_date: shipment_date
end

.get_collection_point(global_point_id:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/deliveries/couriers/dummy.rb', line 8

def get_collection_point(global_point_id:)
  point = CollectionPoint.parse_global_point_id global_point_id: global_point_id
  CollectionPoint.new name: 'Dummy',
                      email: '[email protected]',
                      phone: '555 555 555',
                      country: point.country.to_sym,
                      state: 'Bizkaia',
                      city: 'Erandio',
                      street: 'Axpe',
                      postcode: point.postcode,
                      courier_id: 'dummy',
                      point_id: point.point_id,
                      latitude: 43.312132,
                      longitude: -2.979586,
                      timetable: {
                        0 => [],
                        1 => [OpenStruct.new(open: '8:00', close: '14:00'),
                              OpenStruct.new(open: '16:00', close: '20:00')],
                        2 => [OpenStruct.new(open: '8:00', close: '14:00'),
                              OpenStruct.new(open: '16:00', close: '20:00')],
                        3 => [OpenStruct.new(open: '8:00', close: '14:00'),
                              OpenStruct.new(open: '16:00', close: '20:00')],
                        4 => [OpenStruct.new(open: '8:00', close: '14:00'),
                              OpenStruct.new(open: '16:00', close: '20:00')],
                        5 => [OpenStruct.new(open: '8:00', close: '15:00')],
                        6 => []
                      },
                      url_map: nil,
                      url_photo: nil
end

.get_collection_points(country:, postcode:) ⇒ Object



39
40
41
42
43
44
# File 'lib/deliveries/couriers/dummy.rb', line 39

def get_collection_points(country:, postcode:)
  [
    get_collection_point(global_point_id: "dummy~#{country}~#{postcode}~1"),
    get_collection_point(global_point_id: "dummy~#{country}~#{postcode}~2")
  ]
end

.get_labelObject



92
93
94
95
96
97
98
99
# File 'lib/deliveries/couriers/dummy.rb', line 92

def get_label(**)
  pdf = <<~PDF
    %PDF-1.0
    1 0 obj<</Pages 2 0 R>>endobj 2 0 obj<</Kids[3 0 R]/Count 1>>endobj 3 0 obj<</MediaBox[0 0 3 3]>>endobj
    trailer<</Root 1 0 R>>
  PDF
  Deliveries::Label.new(raw: pdf)
end

.get_labels(tracking_codes:, language: nil) ⇒ Object



101
102
103
# File 'lib/deliveries/couriers/dummy.rb', line 101

def get_labels(tracking_codes:, language: nil)
  get_label tracking_code: tracking_codes, language: language
end

.pickup_info(tracking_code:) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/deliveries/couriers/dummy.rb', line 59

def pickup_info(tracking_code:, **)
  TrackingInfo.new courier_id: 'dummy',
                   tracking_code: tracking_code,
                   status: :in_transit,
                   checkpoints: [
                     Checkpoint.new(status: :registered, location: 'Source city', tracked_at: 1.week.ago,
                                    description: 'Parcel taken'),
                     Checkpoint.new(status: :in_transit, location: 'Halfway city', tracked_at: 1.day.ago,
                                    description: 'There is some delay')
                   ],
                   url: 'https://google.com'
end

.shipment_info(tracking_code:) ⇒ Object



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

def shipment_info(tracking_code:, **)
  TrackingInfo.new courier_id: 'dummy',
                   tracking_code: tracking_code,
                   status: :in_transit,
                   checkpoints: [
                     Checkpoint.new(status: :registered, location: 'Source city', tracked_at: 1.week.ago,
                                    description: 'Parcel taken'),
                     Checkpoint.new(status: :in_transit, location: 'Halfway city', tracked_at: 1.day.ago,
                                    description: 'There is some delay')
                   ],
                   url: 'https://google.com'
end