Sha256: e706da5c2433644f91854494a76142475be03ab5cae427ba4a5646aa8ea725ee

Contents?: true

Size: 834 Bytes

Versions: 5

Compression:

Stored size: 834 Bytes

Contents

module ShipCompliant
  # == ShipCompliant::CommitSalesOrderResult
  #
  # Wraps the response of +CommitSalesOrder+ and provides methods to quickly
  # access shipments, and the committed shipment keys.
  class CommitSalesOrderResult < Struct.new(:response)
    include BaseResult

    # Returns an array of shipment objects.
    # 
    #   puts result.shipments #=> [
    #     {
    #       key: 'SHIPMENT-KEY',
    #       is_committed: true/false
    #     }
    #   ]
    def shipments
      Array.wrap(response[:shipments][:shipment_commit_response])
    end

    # Gets the keys for committed shipments.
    #
    #   puts result.committed_shipments #=> ['SHIPMENT-1', 'SHIPMENT-2', ...]
    def committed_shipments
      shipments
        .select { |s| s[:is_committed] == true }
        .map { |s| s[:key] }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ship_compliant-0.2.1 lib/ship_compliant/commit_sales_order_result.rb
ship_compliant-0.2.0 lib/ship_compliant/commit_sales_order_result.rb
ship_compliant-0.1.2 lib/ship_compliant/commit_sales_order_result.rb
ship_compliant-0.1.1 lib/ship_compliant/commit_sales_order_result.rb
ship_compliant-0.1.0 lib/ship_compliant/commit_sales_order_result.rb