Sha256: 42693f7a223748e4ecb85d10d422661e460353ab764e6209a6d0580df431825c

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

module Unforlogistics
  module Core
    module Shipments
      def get_shipments(filters={})
        response = get_request('/shipments', filters)

        get_paging_response(response)
      end

      def get_shipment(code)
        get_request("/shipments/#{code}").body
      end

      def create_shipment(attrs={})
        response = post_request('/shipments', attrs)

        get_persistance_response(response)
      end

      def cancel_shipment(code)
        response = put_request("/shipments/#{code}/cancellation")

        get_persistance_response(response)
      end

      def quote_shipment(attrs={})
        response = post_request('/shipments/quote', attrs)
        results = response.body

        if response.headers.warning.nil?
          errors = []

          results.each do |result|
            result.price = BigDecimal.new(result.price)
            result.surcharge = BigDecimal.new(result.surcharge)
            result.total = BigDecimal.new(result.total)
          end
        else
          errors = response.headers.warning
        end

        OpenStruct.new({
          results: results,
          valid: errors.empty?,
          errors: errors
        })
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unforlogistics-api-0.13 lib/unforlogistics/core/shipments.rb
unforlogistics-api-0.12 lib/unforlogistics/core/shipments.rb