Class: Trackerific::Service

Inherits:
Object
  • Object
show all
Includes:
OptionsHelper
Defined in:
lib/trackerific/service.rb

Overview

Base class for Trackerific services

Direct Known Subclasses

FedEx, UPS, USPS

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from OptionsHelper

#validate_options

Constructor Details

- (Service) 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::Service with required options



8
9
10
11
# File 'lib/trackerific/service.rb', line 8

def initialize(options = {})
  validate_options options, self.class.required_options
  @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 < Service
    def self.package_id_matchers
      [ /^.Z/, /^[HK].{10}$/ ]  # matchers for UPS package identifiers
    end
  end
end

Returns:

  • (Array, Regexp)

    an array of regular expressions



46
47
48
# File 'lib/trackerific/service.rb', line 46

def 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 < Service
    def self.required_options
      [:all, :these, :are, :required]
    end
  end
end

Returns:

  • (Array)

    the required options



61
62
63
# File 'lib/trackerific/service.rb', line 61

def 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 < Trackerific::Service
    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:



29
30
31
# File 'lib/trackerific/service.rb', line 29

def track_package(package_id)
  @package_id = package_id
end