Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ What I think is unique about this library is it's usage / syntax:

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>
# @city="Sacramento", @type="DL", @country="US", @occurred_at=Mon Dec 08 10:43:37 -0500 2008>

tracking.events.first.name
# => "Delivered"
Expand Down Expand Up @@ -139,7 +139,7 @@ Then your results:
- @tracking_details.events.each do |event|
.event
.name= event.name
.occured_at= event.occured_at.to_s(:long)
.occurred_at= event.occurred_at.to_s(:long)
.location== #{event.city}, #{event.state} #{event.postal_code}, #{event.country}
.residential= event.residential ? "Yes" : "No"

Expand Down
6 changes: 3 additions & 3 deletions lib/shippinglogic/fedex/track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FedEx
#
# 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>
# # @city="Sacramento", @type="DL", @country="US", @occurred_at=Mon Dec 08 10:43:37 -0500 2008>
#
# tracking.events.first.name
# # => "Delivered"
Expand All @@ -36,7 +36,7 @@ class FedEx
class Track < Service
class Details
# Each tracking result is an object of this class
class Event; attr_accessor :name, :type, :occured_at, :city, :state, :postal_code, :country, :residential; end
class Event; attr_accessor :name, :type, :occurred_at, :city, :state, :postal_code, :country, :residential; end

attr_accessor :origin_city,
:origin_state,
Expand Down Expand Up @@ -82,7 +82,7 @@ def initialize(response)
event = Event.new
event.name = details[:event_description]
event.type = details[:event_type]
event.occured_at = Time.parse(details[:timestamp])
event.occurred_at = Time.parse(details[:timestamp])
event.city = details[:address][:city]
event.state = details[:address][:state_or_province_code]
event.postal_code = details[:address][:postal_code]
Expand Down
1 change: 1 addition & 0 deletions lib/shippinglogic/ups.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "shippinglogic/ups/enumerations"
require "shippinglogic/ups/service"
require "shippinglogic/ups/cancel"
require "shippinglogic/ups/rate"
Expand Down
2 changes: 1 addition & 1 deletion lib/shippinglogic/ups/enumerations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Enumerations
"2b" => "Medium Express Box",
"2c" => "Large Express Box"
}

# delivery options
DROPOFF_TYPES = {
"01" => "Daily Pickup",
Expand Down
50 changes: 25 additions & 25 deletions lib/shippinglogic/ups/rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,26 @@ class UPS
# rates.first
# #<Shippinglogic::UPS::Rate::Service:0x10354d108 @currency="USD", @speed=nil,
# @rate=#<BigDecimal:10353ac10,'0.1885E2',18(18)>, @type="Ground", @name="Ground">
#
#
# # to show accessor methods
# rates.first.name
# # => "Ground"
class Rate < Service
def self.path
"/Rate"
end

# Each rate result is an object of this class
class Service; attr_accessor :name, :type, :speed, :rate, :currency; end

# shipper options
attribute :shipper_name, :string
attribute :shipper_streets, :string
attribute :shipper_city, :string
attribute :shipper_state, :string
attribute :shipper_postal_code, :string
attribute :shipper_country, :string, :modifier => :country_code

# recipient options
attribute :recipient_name, :string
attribute :recipient_streets, :string
Expand All @@ -104,7 +104,7 @@ class Service; attr_accessor :name, :type, :speed, :rate, :currency; end
attribute :recipient_postal_code, :string
attribute :recipient_country, :string, :modifier => :country_code
attribute :recipient_residential, :boolean, :default => false

# packaging options
attribute :packaging_type, :string, :default => "00"
attribute :package_count, :integer, :default => 1
Expand All @@ -114,84 +114,84 @@ class Service; attr_accessor :name, :type, :speed, :rate, :currency; end
attribute :package_width, :float
attribute :package_height, :float
attribute :package_dimension_units, :string, :default => "IN"

# monetary options
attribute :currency_type, :string
attribute :insured_value, :decimal
attribute :payor_account_number, :string, :default => lambda { |shipment| shipment.base.account }

# delivery options
attribute :service_type, :string
attribute :dropoff_type, :string, :default => "01"
attribute :saturday, :boolean, :default => false

# misc options
attribute :documents_only, :boolean, :default => false

private
def target
@target ||= parse_response(request(build_request))
end

def build_request
b = builder
build_authentication(b)
b.instruct!

b.RatingServiceSelectionRequest do
b.Request do
b.RequestAction "Rate"
b.RequestOption service_type ? "Rate" : "Shop"
end

b.PickupType do
b.Code dropoff_type
end

b.Shipment do
b.Shipper do
b.Name shipper_name
b.ShipperNumber payor_account_number
build_address(b, :shipper)
end

b.ShipTo do
b.CompanyName recipient_name
build_address(b, :recipient)
end

if service_type
b.Service do
b.Code service_type
end
end

b.DocumentsOnly if documents_only

package_count.times do |i|
b.Package do
b.PackagingType do
b.Code packaging_type
end

b.Dimensions do
b.UnitOfMeasurement do
b.Code package_dimension_units
end

b.Length "%.2f" % package_length
b.Width "%.2f" % package_width
b.Height "%.2f" % package_height
end

b.PackageWeight do
b.UnitOfMeasurement do
b.Code package_weight_units
end

b.Weight "%.1f" % package_weight
end

b.PackageServiceOptions do
if insured_value
b.InsuredValue do
Expand All @@ -202,17 +202,17 @@ def build_request
end
end
end

b.ShipmentServiceOptions do
b.SaturdayDelivery if saturday
end
end
end
end

def parse_response(response)
return [] if !response[:rated_shipment]

response[:rated_shipment].collect do |details|
service = Service.new
service.name = Enumerations::SERVICE_TYPES[details[:service][:code]]
Expand Down
39 changes: 19 additions & 20 deletions lib/shippinglogic/ups/track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class UPS
#
# tracking_details.status
# # => "Delivered"
#
#
# tracking_details.signature_name
# # => "KKING"
#
#
# tracking_details.events.first
# # => #<Shippinglogic::UPS::Track::Event @postal_code="95817", @name="Delivered", @state="CA",
# # @city="Sacramento", @type="Delivered", @country="US", @occured_at=Mon Dec 08 10:43:37 -0500 2008>
#
# # @city="Sacramento", @type="Delivered", @country="US", @occurred_at=Mon Dec 08 10:43:37 -0500 2008>
#
# tracking_details.events.first.name
# # => "Delivered"
#
Expand All @@ -37,48 +37,47 @@ class Track < Service
def self.path
"/Track"
end

class Details
# Each tracking result is an object of this class
class Event; attr_accessor :name, :type, :occured_at, :city, :state, :postal_code, :country; end
class Event; attr_accessor :name, :type, :occurred_at, :city, :state, :postal_code, :country; end

attr_accessor :origin_city, :origin_state, :origin_country,
:destination_city, :destination_state, :destination_country,
:signature_name, :service_type, :status, :delivery_at,
:events

def initialize(response)
details = response[:shipment]

if origin = details.fetch(:shipper, {})[:address]
self.origin_city = origin[:city]
self.origin_state = origin[:state_province_code]
self.origin_country = origin[:country_code]
end

if destination = details.fetch(:ship_to, {})[:address]
self.destination_city = destination[:city]
self.destination_state = destination[:state_province_code]
self.destination_country = destination[:country_code]
end

package = details[:package]
events = package[:activity].is_a?(Array) ? package[:activity] : [package[:activitiy]].compact
last_event = events.first
delivery = events.detect{|e| e[:status][:status_type][:code] == "D" }

self.signature_name = last_event && last_event[:signed_for_by_name]
self.service_type = details[:service][:description]
self.status = last_event && last_event[:status][:status_type][:description]
self.delivery_at = delivery && Time.parse(delivery[:date] + delivery[:time])

self.events = events.collect do |details|
event = Event.new
status = details[:status][:status_type]
event.name = status[:description]
event.type = status[:code]
#FIXME The proper spelling is "occurred", not "occured."
event.occured_at = Time.parse(details[:date] + details[:time])
event.occurred_at = Time.parse(details[:date] + details[:time])
location = details[:activity_location][:address]
event.city = location[:city]
event.state = location[:state_province_code]
Expand All @@ -88,28 +87,28 @@ def initialize(response)
end
end
end

attribute :tracking_number, :string

private
# The parent class Service requires that we define this method. This is our kicker. This method is only
# called when we need to deal with information from UPS. Notice the caching into the @target variable.
def target
@target ||= Details.new(request(build_request))
end

# Just building some XML to send off to UPS. UPS requires this particualar format.
def build_request
b = builder
build_authentication(b)
b.instruct!

b.TrackRequest do
b.Request do
b.RequestAction "Track"
b.RequestOption "activity"
end

b.TrackingNumber tracking_number
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/fedex/track_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
event = track_details.events.first
event.name.should == "Delivered"
event.type.should == "DL"
event.occured_at.should == Time.parse("Mon Dec 08 10:43:37 -0500 2008")
event.occurred_at.should == Time.parse("Mon Dec 08 10:43:37 -0500 2008")
event.city.should == "Sacramento"
event.state.should == "CA"
event.postal_code.should == "95817"
Expand Down