Class: Deliveries::Couriers::MondialRelay::Shipments::Create
- Inherits:
-
Object
- Object
- Deliveries::Couriers::MondialRelay::Shipments::Create
- Defined in:
- lib/deliveries/couriers/mondial_relay/shipments/create.rb,
lib/deliveries/couriers/mondial_relay/shipments/create/defaults.rb,
lib/deliveries/couriers/mondial_relay/shipments/create/format_params.rb
Defined Under Namespace
Modules: Defaults Classes: FormatParams
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(params:) ⇒ Create
constructor
A new instance of Create.
Constructor Details
#initialize(params:) ⇒ Create
Returns a new instance of Create.
8 9 10 |
# File 'lib/deliveries/couriers/mondial_relay/shipments/create.rb', line 8 def initialize(params:) self.params = params end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
6 7 8 |
# File 'lib/deliveries/couriers/mondial_relay/shipments/create.rb', line 6 def params @params end |
Instance Method Details
#execute ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/deliveries/couriers/mondial_relay/shipments/create.rb', line 12 def execute params['Security'] = Deliveries::Couriers::MondialRelay.calculate_security_param params # Call web service. response = MondialRelay.api_client.call :wsi2_creation_etiquette, message: params # If response returns OK stat code. response_result = response.body[:wsi2_creation_etiquette_response][:wsi2_creation_etiquette_result] if response_result && response_result[:stat] == '0' { tracking_code: response_result[:expedition_num], label_url: "http://www.mondialrelay.com#{response_result[:url_etiquette].gsub('format=A4', 'format=10x15')}" } else raise Deliveries::APIError.new( StatusCodes.(response_result[:stat].to_i), response_result[:stat] ) end end |