Class: Trackerific::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/trackerific/base.rb

Overview

Base class for Trackerific package tracking services.

Direct Known Subclasses

FedEx, UPS, USPS

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Base) initialize(options = {})

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.

Creates a new instance of Trackerific::Base with required options



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/trackerific/base.rb', line 6

def initialize(options = {})
  required = self.class.required_options
  # make sure all the required options exist
  required.each do |k|
    raise ArgumentError.new("Missing required parameter: #{k}") unless options.has_key?(k)
  end
  # make sure no invalid options exist
  options.each do |k, v|
    raise ArgumentError.new("Invalid parameter: #{k}") unless required.include?(k)
  end
  @options = options
end

Class Method Details

+ (Array, Regexp) package_id_matchers

An Array of Regexp that matches valid package identifiers for your service

Examples:

Override this method in your custom tracking service

module Trackerific
  class MyTrackingService < Base
    def self.package_id_matchers
      [ /^.Z/, /^[HK].{10}$/ ]  # matchers for UPS package identifiers
    end
  end
end

Returns:

  • (Array, Regexp)

    an array of regular expressions



50
51
52
# File 'lib/trackerific/base.rb', line 50

def self.package_id_matchers
  nil
end

+ (Array) required_options

An array of options that are required to create a new instance of this class

Examples:

Override this method in your custom tracking service to enforce some options

module Trackerific
  class MyTrackingService < Base
    def self.required_options
      [:all, :these, :are, :required]
    end
  end
end

Returns:

  • (Array)

    the required options



65
66
67
# File 'lib/trackerific/base.rb', line 65

def self.required_options
  []
end

Instance Method Details

- (Trackerific::Details) track_package(package_id)

Gets the tracking information for the package from the server

Examples:

Override this method in your custom tracking service to implement tracking

module Trackerific
  class MyTrackingService < Base
    def track_package
      # your tracking code here
      Trackerific::Details.new(
        "summary of tracking events",
        [Trackerific::Event.new(Time.now, "summary", "location")]
      )
    end
  end
end

Parameters:

  • package_id (String)

    the package identifier

Returns:



35
36
37
# File 'lib/trackerific/base.rb', line 35

def track_package(package_id)
  @package_id = package_id
end