Skip to content

Instantly share code, notes, and snippets.

@jenncoop
Created September 19, 2013 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jenncoop/6628500 to your computer and use it in GitHub Desktop.
Save jenncoop/6628500 to your computer and use it in GitHub Desktop.
ShipIt Rates Class
class Rates
# options should include:
# => height
# => length
# => width
# => weight
# => origin_post_code
# => origin_country
# => destination_post_code
# => destination_country
def initialize(carrier_code, options = {})
@carrier_code = carrier_code
data = build_active_shipping_data(options)
@rates = get_rates(data)
end
private
#TODO: create Carrier model
def get_rates(data)
case @carrier_code
when @carrier_code == "FE"
#do stuff
when @carrier_code == "CP"
#do stuff
when @carrier_code == "UPS"
#do stuff
end
end
def build_active_shipping_data(options)
#extract data from options
#geocode location data (postal code) to retrieve city and province
@package_AS = ActiveMerchant::Shipping::Package.new(weight,[height,length,width])
@origin = ActiveMerchant::Shipping::Location.new(:country => origin_country, :province => origin_province, :city => origin_city, :zip => origin_post_code)
@destination = ActiveMerchant::Shipping::Location.new(:country => destination_country, :province => destination_province, :city => destination_city, :zip => destination_post_code)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment