Class: Trackerific::Services::FedEx
- Includes:
- HTTParty
- Defined in:
- lib/trackerific/services/fedex.rb
Class Method Summary collapse
-
.package_id_matchers ⇒ Array, Regexp
private
An Array of Regexp that matches valid FedEx package IDs.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ FedEx
constructor
A new instance of FedEx.
-
#track(package_id) ⇒ Trackerific::Details
Tracks a FedEx package.
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ FedEx
Returns a new instance of FedEx.
21 22 23 |
# File 'lib/trackerific/services/fedex.rb', line 21 def initialize(={}) @options = end |
Class Method Details
.package_id_matchers ⇒ Array, Regexp
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
An Array of Regexp that matches valid FedEx package IDs
17 18 19 |
# File 'lib/trackerific/services/fedex.rb', line 17 def self.package_id_matchers [ /^[0-9]{15}$/ ] end |
Instance Method Details
#track(package_id) ⇒ Trackerific::Details
Tracks a FedEx package
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/trackerific/services/fedex.rb', line 33 def track(package_id) # request tracking information from FedEx via HTTParty http_response = self.class.post "/GatewayDC", body: build_xml_request # raise any HTTP errors http_response.error! unless http_response.code == 200 # get the tracking information from the reply track_reply = http_response["FDXTrack2Reply"] # raise a Trackerific::Error if there is an error in the reply raise Trackerific::Error, track_reply["Error"]["Message"] unless track_reply["Error"].nil? # get the details from the reply details = track_reply["Package"] # convert them into Trackerific::Events events = [] details["Event"].each do |e| date = Time.parse("#{e["Date"]} #{e["Time"]}") desc = e["Description"] addr = e["Address"] loc = "#{addr["StateOrProvinceCode"]} #{addr["PostalCode"]}" events << Trackerific::Event.new(date, desc, loc) end # Return a Trackerific::Details containing all the events Trackerific::Details.new( details["TrackingNumber"], details["StatusDescription"], events ) end |