Class: FriendlyShipping::Services::ShipEngine::ParseVoidResponse

Inherits:
Object
  • Object
show all
Extended by:
Dry::Monads::Result::Mixin
Defined in:
lib/friendly_shipping/services/ship_engine/parse_void_response.rb

Overview

Parses the API response for voiding a label.

Class Method Summary collapse

Class Method Details

.call(request:, response:) ⇒ Success<ApiResult<String>>, Failure<ApiResult<String>>

Returns the success or failure message.

Parameters:

  • request (Request)

    the request to attach to the API result

  • response (Response)

    the response to parse

Returns:

  • (Success<ApiResult<String>>, Failure<ApiResult<String>>)

    the success or failure message



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/friendly_shipping/services/ship_engine/parse_void_response.rb', line 13

def self.call(request:, response:)
  parsed_json = JSON.parse(response.body)
  approved, message = parsed_json["approved"], parsed_json["message"]
  if approved
    Success(
      ApiResult.new(message, original_request: request, original_response: response)
    )
  else
    Failure(
      ApiResult.new(message, original_request: request, original_response: response)
    )
  end
end