Module: Stamps::Client::Rate

Included in:
Stamps::Client
Defined in:
lib/stamps/client/rate.rb

Overview

Produces a list of rates for all available USPS services based on the ZIP Code or the foreign country being shipped to for a given package weight and size.

Examples:

Stamps.get_rates(
  :from_zip_code => '45440',
  :to_zip_code   => '45458',
  :weight_oz     => '8.0',
  :ship_date     => '2011-06-01'
 )

Instance Method Summary collapse

Instance Method Details

#get_rate(params = {}) ⇒ Object



35
36
37
38
# File 'lib/stamps/client/rate.rb', line 35

def get_rate(params = {})
  rates  = get_rates(params)
  rates.is_a?(Array) ? rates.first : rates
end

#get_rates(params = {}) ⇒ Object

Produces a list of rates matching the criteria provided in the parameters



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/stamps/client/rate.rb', line 22

def get_rates(params = {})
  rates = Stamps::Mapping::Rates.new({
    :authenticator => authenticator_token,
    :rate          => Stamps::Mapping::Rate.new(params)
  })
  response = request('GetRates', rates)
  if response[:get_rates_response].nil?
    response
  else
    response[:get_rates_response][:rates].nil? ? [] : [response[:get_rates_response][:rates][:rate]].flatten
  end
end