Class: Deliveries::Couriers::Spring::Labels::Generate

Inherits:
Object
  • Object
show all
Defined in:
lib/deliveries/couriers/spring/labels/generate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tracking_code:) ⇒ Generate

Returns a new instance of Generate.



8
9
10
# File 'lib/deliveries/couriers/spring/labels/generate.rb', line 8

def initialize(tracking_code:)
  self.tracking_code = tracking_code
end

Instance Attribute Details

#tracking_codeObject

Returns the value of attribute tracking_code.



6
7
8
# File 'lib/deliveries/couriers/spring/labels/generate.rb', line 6

def tracking_code
  @tracking_code
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/deliveries/couriers/spring/labels/generate.rb', line 12

def execute
  params = {
    Apikey: Deliveries::Couriers::Spring.config(:api_key),
    Command: 'GetShipmentLabel',
    Shipment: {
      LabelFormat: 'PDF',
      TrackingNumber: tracking_code
    }
  }

  response = Deliveries::Couriers::Spring::Request.execute(params: params)

  {
    url: response[:Shipment][:CarrierTrackingUrl],
    decoded_label: Base64.decode64(response[:Shipment][:LabelImage]).force_encoding('binary')
  }
end