Skip to content

Commit

Permalink
Removed Service class and added initialize_for_fedex_service method t…
Browse files Browse the repository at this point in the history
…o Base.
  • Loading branch information
jimmybaker committed Apr 15, 2008
1 parent c13ca3d commit 7620f89
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 48 deletions.
17 changes: 15 additions & 2 deletions lib/shipping/base.rb
Expand Up @@ -20,6 +20,8 @@ class Base
attr_accessor :weight, :weight_units, :insured_value, :declared_value, :transaction_type, :description
attr_accessor :measure_units, :measure_length, :measure_width, :measure_height
attr_accessor :package_total, :packaging_type, :service_type

attr_accessor :price, :discount_price, :eta, :time_in_transit

attr_accessor :ship_date, :dropoff_type, :pay_type, :currency_code, :image_type, :label_type

Expand All @@ -35,7 +37,7 @@ def initialize(options = {})
instance_variable_set("@#{method}", value)
end

case options[:service]
case options[:carrier]
when "fedex"
fedex
when "ups"
Expand All @@ -44,7 +46,6 @@ def initialize(options = {})
else
raise ShippingError, "unknown service"
end

end

# Initializes an instance of Shipping::FedEx with the same instance variables as the base object
Expand All @@ -56,6 +57,8 @@ def fedex
def ups
Shipping::UPS.new prepare_vars
end



def self.state_from_zip(zip)
zip = zip.to_i
Expand Down Expand Up @@ -171,5 +174,15 @@ def check_required
end

STATES = {"al" => "alabama", "ne" => "nebraska", "ak" => "alaska", "nv" => "nevada", "az" => "arizona", "nh" => "new hampshire", "ar" => "arkansas", "nj" => "new jersey", "ca" => "california", "nm" => "new mexico", "co" => "colorado", "ny" => "new york", "ct" => "connecticut", "nc" => "north carolina", "de" => "delaware", "nd" => "north dakota", "fl" => "florida", "oh" => "ohio", "ga" => "georgia", "ok" => "oklahoma", "hi" => "hawaii", "or" => "oregon", "id" => "idaho", "pa" => "pennsylvania", "il" => "illinois", "pr" => "puerto rico", "in" => "indiana", "ri" => "rhode island", "ia" => "iowa", "sc" => "south carolina", "ks" => "kansas", "sd" => "south dakota", "ky" => "kentucky", "tn" => "tennessee", "la" => "louisiana", "tx" => "texas", "me" => "maine", "ut" => "utah", "md" => "maryland", "vt" => "vermont", "ma" => "massachusetts", "va" => "virginia", "mi" => "michigan", "wa" => "washington", "mn" => "minnesota", "dc" => "district of columbia", "ms" => "mississippi", "wv" => "west virginia", "mo" => "missouri", "wi" => "wisconsin", "mt" => "montana", "wy" => "wyoming"}

def self.initialize_for_fedex_service(xml)
s = Shipping::Base.new
s.fedex
s.eta = REXML::XPath.first(xml, "DeliveryDate").text unless REXML::XPath.match(xml, "DeliveryDate").empty?
s.service_type = REXML::XPath.first(xml, "Service").text
s.discount_price = REXML::XPath.first(xml, "EstimatedCharges/DiscountedCharges/BaseCharge").text
s.price = REXML::XPath.first(xml, "EstimatedCharges/DiscountedCharges/NetCharge").text
return s
end
end
end
3 changes: 1 addition & 2 deletions lib/shipping/fedex.rb
Expand Up @@ -480,7 +480,6 @@ def get_available_services
end

def rate_available_services_request(carrier_code)
results = []
@data = String.new
b = Builder::XmlMarkup.new(:target => @data)
b.instruct!
Expand Down Expand Up @@ -514,7 +513,7 @@ def rate_available_services_request(carrier_code)
get_response @fedex_url

REXML::XPath.each(@response, "//Entry") { |el|
@services << Service.new('fedex', el)
@services << Shipping::Base.initialize_for_fedex_service(el)
}

end
Expand Down
44 changes: 0 additions & 44 deletions lib/shipping/service.rb

This file was deleted.

0 comments on commit 7620f89

Please sign in to comment.