Class: Deliveries::Couriers::MondialRelay::Labels::Generate
- Inherits:
-
Object
- Object
- Deliveries::Couriers::MondialRelay::Labels::Generate
- Defined in:
- lib/deliveries/couriers/mondial_relay/labels/generate.rb
Instance Attribute Summary collapse
-
#language ⇒ Object
Returns the value of attribute language.
-
#tracking_codes ⇒ Object
Returns the value of attribute tracking_codes.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(tracking_codes:, language:) ⇒ Generate
constructor
A new instance of Generate.
Constructor Details
#initialize(tracking_codes:, language:) ⇒ Generate
Returns a new instance of Generate.
8 9 10 11 |
# File 'lib/deliveries/couriers/mondial_relay/labels/generate.rb', line 8 def initialize(tracking_codes:, language:) self.tracking_codes = [tracking_codes].flatten.join(';') self.language = language.to_s.upcase end |
Instance Attribute Details
#language ⇒ Object
Returns the value of attribute language.
6 7 8 |
# File 'lib/deliveries/couriers/mondial_relay/labels/generate.rb', line 6 def language @language end |
#tracking_codes ⇒ Object
Returns the value of attribute tracking_codes.
6 7 8 |
# File 'lib/deliveries/couriers/mondial_relay/labels/generate.rb', line 6 def tracking_codes @tracking_codes end |
Instance Method Details
#execute ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/deliveries/couriers/mondial_relay/labels/generate.rb', line 13 def execute params = { 'Enseigne' => Deliveries::Couriers::MondialRelay.config(:mondial_relay_merchant), 'Expeditions' => tracking_codes, 'Langue' => language } # Calculate security parameters. params['Security'] = Deliveries::Couriers::MondialRelay.calculate_security_param params response = MondialRelay.api_client.call :wsi3_get_etiquettes, message: params response_stat = response.body.dig(:wsi3_get_etiquettes_response, :wsi3_get_etiquettes_result, :stat) if response_stat == '0' # Get path for 10x15 format. "http://www.mondialrelay.com#{response.body.dig(:wsi3_get_etiquettes_response, :wsi3_get_etiquettes_result, :url_pdf_10x15)}" else raise Deliveries::APIError.new( StatusCodes.(response_stat.to_i), response_stat ) end end |