Class: FriendlyShipping::Services::ShipEngine::ParseRatesResponse
- Inherits:
-
Object
- Object
- FriendlyShipping::Services::ShipEngine::ParseRatesResponse
- Extended by:
- Dry::Monads::Result::Mixin
- Defined in:
- lib/friendly_shipping/services/ship_engine/parse_rates_response.rb
Overview
Parses the rates API response.
Class Method Summary collapse
-
.call(request:, response:, options:) ⇒ Success<ApiResult<Array<Rate>>>, Failure<ApiResult<String>>
The parsed rates or error.
Class Method Details
.call(request:, response:, options:) ⇒ Success<ApiResult<Array<Rate>>>, Failure<ApiResult<String>>
Returns the parsed rates or error.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/friendly_shipping/services/ship_engine/parse_rates_response.rb', line 15 def call(request:, response:, options:) 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 error = parsed_json.dig("rate_response", "errors", 0, "message") || "Unknown error" Failure( ApiResult.new( error, original_request: request, original_response: response ) ) end end |