Class: FriendlyShipping::Services::ShipEngineLTL::ParseQuoteResponse
- Inherits:
-
Object
- Object
- FriendlyShipping::Services::ShipEngineLTL::ParseQuoteResponse
- Extended by:
- Dry::Monads::Result::Mixin
- Defined in:
- lib/friendly_shipping/services/ship_engine_ltl/parse_quote_response.rb
Overview
Parses the rate quotes API response.
Class Method Summary collapse
-
.call(request:, response:) ⇒ Success<ApiResult<Array<Rate>>>, Failure<ApiResult<Array<String>>>
The parsed rates or errors.
Class Method Details
.call(request:, response:) ⇒ Success<ApiResult<Array<Rate>>>, Failure<ApiResult<Array<String>>>
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/friendly_shipping/services/ship_engine_ltl/parse_quote_response.rb', line 14 def call(request:, response:) parsed_json = JSON.parse(response.body) rates = build_rates(parsed_json) if rates.any? Success( ApiResult.new( rates, original_request: request, original_response: response ) ) else errors = parsed_json.fetch('errors', [{ 'message' => 'Unknown error' }]) Failure( ApiResult.new( errors.map { |e| e['message'] }, original_request: request, original_response: response ) ) end end |