Sha256: 980435701f632157c79910ecd281a101a3d5b9170fcdc8708034a75c2321f04f

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

module ParcelApi

  # Returns the shipping options and rates available depending on customer,
  # pick up and destination addresses and parcel dimensions and weight.
  # Both domestic and international.

  class ShippingOptions
    DOMESTIC_URL = '/ShippingOptions/2.0/domestic'
    INTERNATIONAL_URL = '/ShippingOptions/2.0/international'

    # Creates a new ParcelApi::ShippingOptions instance.

    def initialize(connection=nil)
      @connection ||= connection || ParcelApi::Client.connection
    end

    # Search for Domestic (NZ) Shipping Options
    # @param parcel_params [Hash] parcel parameters
    # @return [Array] return array of shipping options

    def get_domestic(parcel_params)
      response = @connection.get DOMESTIC_URL, params: parcel_params
      options = response.parsed.tap do |so|
        so.delete('success')
        so.delete('message_id')
      end
      RecursiveOpenStruct.new(options, recurse_over_arrays: true)
    end

    # Search for International Shipping Options
    # @param parcel_params [Hash] parcel parameters
    # @return [Array] return array of shipping options

    def get_international(parcel_params)
      response = @connection.get INTERNATIONAL_URL, params: parcel_params
      options = response.parsed.tap do |so|
        so.delete('success')
        so.delete('message_id')
      end
      RecursiveOpenStruct.new(options, recurse_over_arrays: true)
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
parcel_api-1.2.1 lib/parcel_api/shipping_options.rb
parcel_api-1.2.0 lib/parcel_api/shipping_options.rb
parcel_api-1.1.1 lib/parcel_api/shipping_options.rb
parcel_api-1.1.0 lib/parcel_api/shipping_options.rb
parcel_api-1.0.0 lib/parcel_api/shipping_options.rb