Created
September 19, 2013 19:18
-
-
Save jenncoop/6628500 to your computer and use it in GitHub Desktop.
ShipIt Rates Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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