Class: FriendlyShipping::Services::RL::ParseCreateBOLResponse
- Inherits:
-
Object
- Object
- FriendlyShipping::Services::RL::ParseCreateBOLResponse
- Extended by:
- Dry::Monads::Result::Mixin
- Defined in:
- lib/friendly_shipping/services/rl/parse_create_bol_response.rb
Overview
Parses the response from the R+L API when creating a Bill of Lading (BOL).
Class Method Summary collapse
-
.call(request:, response:) ⇒ Result<ApiResult<ShipmentInformation>>
Shipment info with the BOL document attached.
Class Method Details
.call(request:, response:) ⇒ Result<ApiResult<ShipmentInformation>>
Returns shipment info with the BOL document attached.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/friendly_shipping/services/rl/parse_create_bol_response.rb', line 14 def call(request:, response:) parsed_json = JSON.parse(response.body) shipment_info = ShipmentInformation.new( pro_number: parsed_json['ProNumber'], pickup_request_number: parsed_json['PickupRequestNumber'] ) if shipment_info.valid? Success( ApiResult.new( shipment_info, original_request: request, original_response: response ) ) else errors = parsed_json.fetch('Errors', [{ 'ErrorMessage' => 'Unknown error' }]) Failure( ApiResult.new( errors.map { |e| e['ErrorMessage'] }, original_request: request, original_response: response ) ) end end |