Browse files

move signature detail to special services

  • Loading branch information...
1 parent 7852ea7 commit 34aca2d73ffa74ff12b168558de7ad0df7a2360f @binarylogic committed Aug 21, 2010
View
36 README.rdoc
@@ -19,10 +19,6 @@ Install the gem from rubyforge:
sudo gem install shippinglogic
-Or from github:
-
- sudo gem install binarylogic-shippinglogic
-
Now just include it in your project and you are ready to go.
You can also install this as a plugin:
@@ -36,30 +32,26 @@ See below for usage examples.
What I think is unique about this library is it's usage / syntax:
fedex = Shippinglogic::FedEx.new(key, password, account, meter)
- tracking_details = fedex.track(:tracking_number => "XXXXXXXXXXXXXXXXX")
+ tracking = fedex.track(:tracking_number => "XXXXXXXXXXXXXXXXX")
# => A proxy object that delegates calls to an array of Shippinglogic::FedEx::Track::Event objects
- # this shows that the tracking object is a proxy for the underlying array
- tracking_details.tracking_number
+ tracking.tracking_number
# => "XXXXXXXXXXXXXXXXX"
- tracking_details.tracking_number = "YYYYYYYYYYYYYYYYYY"
+ tracking.tracking_number = "YYYYYYYYYYYYYYYYYY"
# => "YYYYYYYYYYYYYYYYYY"
- tracking_details.class
- # => Shippinglogic::FedEx::Track::Details
-
- tracking_details.status
+ tracking.status
# => "Delivered"
- tracking_details.signature_name
+ tracking.signature_name
# => "KKING"
- tracking_details.events.first
+ tracking.events.first
# => #<Shippinglogic::FedEx::Track::Event @postal_code="95817", @name="Delivered", @state="CA", @residential=false,
# @city="Sacramento", @type="DL", @country="US", @occured_at=Mon Dec 08 10:43:37 -0500 2008>
- tracking_details.first.name
+ tracking.events.first.name
# => "Delivered"
== Calls to the web services are lazy
@@ -75,21 +67,21 @@ This is similar to how ActiveRecord's association proxies work. When you call "u
You will notice above we assign the result of the 'track' method to a variable called 'tracking'. That object has more to it:
# Initializing
- tracking_details = fedex.track(:tracking_number => "XXXXXXXXXXXXX")
- tracking_details.tracking_number
+ tracking = fedex.track(:tracking_number => "XXXXXXXXXXXXX")
+ tracking.tracking_number
# => "XXXXXXXXXXXXX"
# Attribute accessors
- tracking_details.tracking_number = "YYYYYYYYYYYYYYY"
- tracking_details.tracking_number
+ tracking.tracking_number = "YYYYYYYYYYYYYYY"
+ tracking.tracking_number
# => "YYYYYYYYYYYYYYY"
# Mass attribute setting
- tracking_details.attributes = {:tracking_number => "ZZZZZZZZZZZZZZZZ"}
- tracking_details.tracking_number
+ tracking.attributes = {:tracking_number => "ZZZZZZZZZZZZZZZZ"}
+ tracking.tracking_number
# => "ZZZZZZZZZZZZZZZZ"
- tracking_details.attributes
+ tracking.attributes
# => {:tracking_number => "ZZZZZZZZZZZZZZZZ"}
== Available services and their features
View
3 Rakefile
@@ -10,12 +10,11 @@ begin
gem.email = "bjohnson@binarylogic.com"
gem.homepage = "http://github.com/binarylogic/shippinglogic"
gem.authors = ["Ben Johnson of Binary Logic"]
- gem.rubyforge_project = "shippinglogic"
gem.add_development_dependency "rspec"
gem.add_dependency "activesupport", ">= 2.2.0"
gem.add_dependency "httparty", ">= 0.4.4"
end
- Jeweler::RubyforgeTasks.new
+ Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
View
2 lib/shippinglogic/fedex/cancel.rb
@@ -5,7 +5,7 @@ class FedEx
# == Accessor methods / options
#
# * <tt>tracking_number</tt> - the tracking number
- # * <tt>deletion_control</tt> - one of DELETION_CONTROL (default: DELETE_ALL_PACKAGES)
+ # * <tt>deletion_control</tt> - one of Enumerations::DELETION_CONTROL (default: DELETE_ALL_PACKAGES)
#
# === Simple Example
#
View
2 lib/shippinglogic/fedex/error.rb
@@ -45,7 +45,7 @@ def initialize(request, response)
)
end
- super(errors.collect { |error| error[:message] }.to_sentence)
+ super(errors.collect { |error| error[:message].strip }.to_sentence)
end
def add_error(error, code = nil)
View
11 lib/shippinglogic/fedex/rate.rb
@@ -39,7 +39,7 @@ class FedEx
# multi package shipment is to increase the package_count option and keep the dimensions and weight the same for all packages. Then again,
# the documentation for the FedEx web services is terrible, so I could be wrong. Any tests I tried resulted in an error though.
#
- # * <tt>packaging_type</tt> - one of PACKAGE_TYPES. (default: YOUR_PACKAGING)
+ # * <tt>packaging_type</tt> - one of Enumerations::PACKAGE_TYPES. (default: YOUR_PACKAGING)
# * <tt>package_count</tt> - the number of packages in your shipment. (default: 1)
# * <tt>package_weight</tt> - a single packages weight.
# * <tt>package_weight_units</tt> - either LB or KG. (default: LB)
@@ -52,20 +52,20 @@ class FedEx
#
# * <tt>currency_type</tt> - the type of currency. (default: nil, because FedEx will default to your account preferences)
# * <tt>insured_value</tt> - the value you want to insure, if any. (default: nil)
- # * <tt>payment_type</tt> - one of PAYMENT_TYPES. (default: SENDER)
+ # * <tt>payment_type</tt> - one of Enumerations::PAYMENT_TYPES. (default: SENDER)
# * <tt>payor_account_number</tt> - if the account paying for this ship is different than the account you specified then
# you can specify that here. (default: your account number)
# * <tt>payor_country</tt> - the country code for the account number. (default: US)
#
# === Delivery options
#
# * <tt>ship_time</tt> - a Time object representing when you want to ship the package. (default: Time.now)
- # * <tt>service_type</tt> - one of SERVICE_TYPES, this is optional, leave this blank if you want a list of all
+ # * <tt>service_type</tt> - one of Enumerations::SERVICE_TYPES, this is optional, leave this blank if you want a list of all
# available services. (default: nil)
# * <tt>delivery_deadline</tt> - whether or not to include estimated transit times. (default: true)
- # * <tt>dropoff_type</tt> - one of DROP_OFF_TYPES. (default: REGULAR_PICKUP)
+ # * <tt>dropoff_type</tt> - one of Enumerations::DROP_OFF_TYPES. (default: REGULAR_PICKUP)
# * <tt>special_services_requested</tt> - any exceptions or special services FedEx needs to be aware of, this should be
- # one or more of SPECIAL_SERVICES. (default: nil)
+ # one or more of Enumerations::SPECIAL_SERVICES. (default: nil)
#
# === Misc options
#
@@ -195,6 +195,7 @@ def parse_response(response)
response[:rate_reply_details].collect do |details|
shipment_detail = details[:rated_shipment_details].is_a?(Array) ? details[:rated_shipment_details].first : details[:rated_shipment_details]
cost = shipment_detail[:shipment_rate_detail][:total_net_charge]
+
delivered_by = details[:delivery_timestamp] && Time.parse(details[:delivery_timestamp])
speed = case details[:service_type]
when /overnight/i
View
41 lib/shippinglogic/fedex/ship.rb
@@ -34,9 +34,9 @@ class FedEx
#
# === Label options
#
- # * <tt>label_format</tt> - one of LABEL_FORMATS. (default: COMMON2D)
- # * <tt>label_file_type</tt> - one of LABEL_FILE_TYPES. (default: PDF)
- # * <tt>label_stock_type</tt> - one of LABEL_STOCK_TYPES. (default: PAPER_8.5X11_TOP_HALF_LABEL)
+ # * <tt>label_format</tt> - one of Enumerations::LABEL_FORMATS. (default: COMMON2D)
+ # * <tt>label_file_type</tt> - one of Enumerations::LABEL_FILE_TYPES. (default: PDF)
+ # * <tt>label_stock_type</tt> - one of Enumerations::LABEL_STOCK_TYPES. (default: PAPER_8.5X11_TOP_HALF_LABEL)
#
# === Packaging options
#
@@ -45,7 +45,7 @@ class FedEx
# multi package shipment is to increase the package_count option and keep the dimensions and weight the same for all packages. Then again,
# the documentation for the FedEx web services is terrible, so I could be wrong. Any tests I tried resulted in an error though.
#
- # * <tt>packaging_type</tt> - one of PACKAGE_TYPES. (default: YOUR_PACKAGING)
+ # * <tt>packaging_type</tt> - one of Enumerations::PACKAGE_TYPES. (default: YOUR_PACKAGING)
# * <tt>package_count</tt> - the number of packages in your shipment. (default: 1)
# * <tt>package_weight</tt> - a single packages weight.
# * <tt>package_weight_units</tt> - either LB or KG. (default: LB)
@@ -58,25 +58,25 @@ class FedEx
#
# * <tt>currency_type</tt> - the type of currency. (default: nil, because FedEx will default to your account preferences)
# * <tt>insured_value</tt> - the value you want to insure, if any. (default: nil)
- # * <tt>payment_type</tt> - one of PAYMENT_TYPES. (default: SENDER)
+ # * <tt>payment_type</tt> - one of Enumerations::PAYMENT_TYPES. (default: SENDER)
# * <tt>payor_account_number</tt> - if the account paying for this ship is different than the account you specified then
# you can specify that here. (default: your account number)
# * <tt>payor_country</tt> - the country code for the account number. (default: US)
#
# === Delivery options
#
# * <tt>ship_time</tt> - a Time object representing when you want to ship the package. (default: Time.now)
- # * <tt>service_type</tt> - one of SERVICE_TYPES, this is optional, leave this blank if you want a list of all
+ # * <tt>service_type</tt> - one of Enumerations::SERVICE_TYPES, this is optional, leave this blank if you want a list of all
# available services. (default: nil)
- # * <tt>dropoff_type</tt> - one of DROP_OFF_TYPES. (default: REGULAR_PICKUP)
+ # * <tt>dropoff_type</tt> - one of Enumerations::DROP_OFF_TYPES. (default: REGULAR_PICKUP)
# * <tt>special_services_requested</tt> - any exceptions or special services FedEx needs to be aware of, this should be
- # one or more of SPECIAL_SERVICES. (default: nil)
- # * <tt>signature</tt> - one of SIGNATURE_OPTION_TYPES. (default: nil, which defaults to the service default)
+ # one or more of Enumerations::SPECIAL_SERVICES. (default: nil)
+ # * <tt>signature</tt> - one of Enumerations::SIGNATURE_OPTION_TYPES. (default: nil, which defaults to the service default)
#
# === Misc options
#
# * <tt>just_validate</tt> - will tell FedEx to ONLY validate the shipment, not actually create it. (default: false)
- # * <tt>rate_request_types</tt> - one or more of RATE_REQUEST_TYPES. (default: ACCOUNT)
+ # * <tt>rate_request_types</tt> - one or more of Enumerations::RATE_REQUEST_TYPES. (default: ACCOUNT)
#
# == Simple Example
#
@@ -178,7 +178,20 @@ def build_request
xml = b.tag!(just_validate ? "ValidateShipmentRequest" : "ProcessShipmentRequest", :xmlns => "http://fedex.com/ws/ship/v#{VERSION[:major]}") do
build_authentication(b)
build_version(b, "ship", VERSION[:major], VERSION[:intermediate], VERSION[:minor])
- b.SpecialServicesRequested special_services_requested.join(",") if special_services_requested.any?
+
+ if special_services_requested.any? || signature
+ b.SpecialServicesRequested do
+ if special_services_requested.any?
+ b.SpecialServiceTypes special_services_requested.join(",")
+ end
+
+ if signature
+ b.SignatureOptionDetail do
+ b.OptionType signature
+ end
+ end
+ end
+ end
b.RequestedShipment do
b.ShipTimestamp ship_time.xmlschema if ship_time
@@ -211,12 +224,6 @@ def build_request
b.LabelStockType label_stock_type if label_stock_type
end
- if signature
- b.SignatureOptionDetail do
- b.OptionType signature
- end
- end
-
b.RateRequestTypes rate_request_types.join(",")
build_package(b)
end
View
4 lib/shippinglogic/fedex/signature.rb
@@ -6,8 +6,8 @@ class FedEx
# == Accessor methods / options
#
# * <tt>tracking_number</tt> - the tracking number
- # * <tt>image_type</tt> - one of SIGNATURE_IMAGE_TYPES. (default: LETTER)
- # * <tt>image_file_type</tt> - one of LABEL_FILE_TYPES. (default: PDF)
+ # * <tt>image_type</tt> - one of Enumerations::SIGNATURE_IMAGE_TYPES. (default: LETTER)
+ # * <tt>image_file_type</tt> - one of Enumerations::LABEL_FILE_TYPES. (default: PDF)
# * <tt>fax_number</tt> - if image_type is set to FAX you must provide a fax number here. (default: nil)
#
# === Simple Example
View
8 lib/shippinglogic/fedex/track.rb
@@ -14,17 +14,17 @@ class FedEx
# fedex = Shippinglogic::FedEx.new(key, password, account, meter)
# tracking_details = fedex.track(:tracking_number => "my number")
#
- # tracking_details.status
+ # tracking.status
# # => "Delivered"
#
- # tracking_details.signature_name
+ # tracking.signature_name
# # => "KKING"
#
- # tracking_details.events.first
+ # tracking.events.first
# # => #<Shippinglogic::FedEx::Track::Event @postal_code="95817", @name="Delivered", @state="CA", @residential=false,
# # @city="Sacramento", @type="DL", @country="US", @occured_at=Mon Dec 08 10:43:37 -0500 2008>
#
- # tracking_details.events.first.name
+ # tracking.events.first.name
# # => "Delivered"
#
# === Note
View
14 spec/fedex/ship_spec.rb
@@ -23,15 +23,9 @@
end
it "should only validate the shipment" do
- pending
- DONT_SAVE = true
-
- @shipment.just_validate = true
-
- begin
- @shipment.rate.should == 'fdsf'
- rescue Shippinglogic::FedEx::Error => e
- raise e.request
- end
+ # An email from FedEx confirms that this service is only available in production,
+ # which makes no sense. So I can not test this, but the implmentation is
+ # exactly the same as shipping, and that works just fine. You would think a multi
+ # billion dollar company would have decent web services.
end
end

0 comments on commit 34aca2d

Please sign in to comment.