Skip to content

Instantly share code, notes, and snippets.

@chuckbergeron
Created August 14, 2013 01:50
Show Gist options
  • Save chuckbergeron/6227373 to your computer and use it in GitHub Desktop.
Save chuckbergeron/6227373 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'active_shipping'
include ActiveMerchant::Shipping
####### START: STORE THIS IN A CONFIG FILE
MyApp::Application.config.fedex_credentials = {
account: '1234567890',
password: '1234567890abcdefgh1234567890',
key: '1234567890abcde',
login: '12345678'
}
MyApp::Application.config.fedex_origin_address = {
country: 'CA',
postal_code: 'T2J 1W9'
}
####### END STORE IN CONFIGS
fedex = FedEx.new( MyApp::Application.config.fedex_credentials )
packages = [
Package.new( 7.86 * 16, # ounces or lbs
[ 33, 33, 1 ], # inches
:units => :imperial, # not grams, not centimetres
:value => 100,
:currency => "USD" )
]
origin = Location.new(:country => 'CA', :postal_code => 'V5N3B2')
destination = Location.new(:country => 'US', :postal_code => '90210')
response = fedex.find_rates(origin, destination, packages)
rates = response.rates.sort_by(&:price).collect {|rate| [rate.service_name, rate.price]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment