Module: Trackerific
- Defined in:
- lib/trackerific.rb,
lib/trackerific/event.rb,
lib/trackerific/error.rb,
lib/trackerific/details.rb,
lib/trackerific/service.rb,
lib/trackerific/services/ups.rb,
lib/trackerific/configuration.rb,
lib/trackerific/services/usps.rb,
lib/trackerific/services/fedex.rb
Overview
Trackerific provides package tracking to Rails apps.
Defined Under Namespace
Classes: Configuration, Details, Error, Event, FedEx, Service, UPS, USPS
Class Method Summary (collapse)
-
+ (Trackerific::Configuration) configuration
Private
Stores the configuration options for Trackerific.
-
+ (Trackerific::Configuration) configure {|configuration| ... }
Configures Trackerific.
-
+ (Trackerific::Service) service_get(name)
Private
Gets a Trackerific::Service class.
-
+ (Array, Symbol) services
Private
Gets a list of all Trackerific services.
Instance Method Summary (collapse)
-
- (Trackerific::Details) track_package(package_id)
Tracks a package by determining its service from the package id.
-
- (Trackerific::Base) tracking_service(package_id)
Checks a string for a valid package tracking service.
Class Method Details
+ (Trackerific::Configuration) configuration
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.
Stores the configuration options for Trackerific
34 35 36 |
# File 'lib/trackerific/configuration.rb', line 34 def configuration @configuration ||= Trackerific::Configuration.new end |
+ (Trackerific::Configuration) configure {|configuration| ... }
Configures Trackerific
44 45 46 47 |
# File 'lib/trackerific/configuration.rb', line 44 def configure yield configuration configuration end |
+ (Trackerific::Service) service_get(name)
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.
Gets a Trackerific::Service class
31 32 33 34 35 36 |
# File 'lib/trackerific.rb', line 31 def service_get(name) services.each do |service| return Trackerific.const_get(service) if name == service.to_s.downcase.to_sym end return nil end |
+ (Array, Symbol) services
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.
Gets a list of all Trackerific services
20 21 22 23 24 25 |
# File 'lib/trackerific.rb', line 20 def services # a service is any Trackerific class that descends from Trackerific::Service Trackerific.constants.reject { |const| const unless Trackerific.const_get(const).superclass == Trackerific::Service } end |
Instance Method Details
- (Trackerific::Details) track_package(package_id)
Tracks a package by determining its service from the package id
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/trackerific.rb', line 74 def track_package(package_id) # find the service that will be able to track this package service = tracking_service package_id raise Trackerific::Error "Cannot find a service to track package id #{package_id}" if service.nil? # get the name of the service service_name = service.to_s.split('::')[1].downcase # get the default configuration for the service = Trackerific.configuration.send service_name # track the package service.new().track_package package_id end |
- (Trackerific::Base) tracking_service(package_id)
Checks a string for a valid package tracking service
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/trackerific.rb', line 47 def tracking_service(package_id) # loop through all the services Trackerific.services.each do |service| # get the class associated with this service cls = Trackerific.const_get(service) # loop through all the packge id regular expressions cls.package_id_matchers.each do |matcher| # return this class if the regular expression matches return cls if package_id =~ matcher end end # if we've made it this far, nothing matched nil end |