Sha256: 26fd1783bf71293673855c1e68591e5e707ca3345aa71d026b57d0667154d11b

Contents?: true

Size: 727 Bytes

Versions: 1

Compression:

Stored size: 727 Bytes

Contents

# frozen_string_literal: true

require 'friendly_shipping/bad_request'

module FriendlyShipping
  module Services
    class ShipEngine
      class ParseVoidResponse
        extend Dry::Monads::Result::Mixin

        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(
              ApiFailure.new(message, original_request: request, original_response: response)
            )
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
friendly_shipping-0.3.0 lib/friendly_shipping/services/ship_engine/parse_void_response.rb