Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed Service class and added initialize_for_fedex_service method t…

…o Base.
  • Loading branch information...
commit 7620f898b454891741d949abbc839a4f55f4af06 1 parent c13ca3d
@jimmybaker jimmybaker authored
View
17 lib/shipping/base.rb
@@ -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
@@ -35,7 +37,7 @@ def initialize(options = {})
instance_variable_set("@#{method}", value)
end
- case options[:service]
+ case options[:carrier]
when "fedex"
fedex
when "ups"
@@ -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
@@ -56,6 +57,8 @@ def fedex
def ups
Shipping::UPS.new prepare_vars
end
+
+
def self.state_from_zip(zip)
zip = zip.to_i
@@ -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
View
3  lib/shipping/fedex.rb
@@ -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!
@@ -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
View
44 lib/shipping/service.rb
@@ -1,44 +0,0 @@
-module Shipping
-
- class Service
-
- attr_accessor :price, :eta, :type, :carrier, :discount_price, :number_of_packages
-
- def initialize(options={})
- options.each do |k, v|
- instance_variable_set("@#{k}", v)
- end
- end
-
- def initialize(carrier, xml)
- case carrier
- when 'fedex'
- initialize_for_fedex(xml)
- when 'ups'
- initialize_for_ups(xml)
- when 'usps'
-
- end
- end
-
- private
- def initialize_for_fedex(xml)
- begin
- @carrier = 'fedex'
- @eta = REXML::XPath.first(xml, "DeliveryDate").text unless REXML::XPath.match(xml, "DeliveryDate").empty?
- @type = REXML::XPath.first(xml, "Service").text
- @discount_price = REXML::XPath.first(xml, "EstimatedCharges/DiscountedCharges/BaseCharge").text
- @price = REXML::XPath.first(xml, "EstimatedCharges/DiscountedCharges/NetCharge").text
- rescue Exception => e
- puts e.message
- end
- end
-
- def initialize_for_ups(xml)
-
- end
-
-
- end
-
-end
Please sign in to comment.
Something went wrong with that request. Please try again.