Module: Trackerific::Services

Defined in:
lib/trackerific/services.rb,
lib/trackerific/services/ups.rb,
lib/trackerific/services/base.rb,
lib/trackerific/services/usps.rb,
lib/trackerific/services/fedex.rb,
lib/trackerific/services/mock_service.rb

Defined Under Namespace

Classes: Base, FedEx, MockService, UPS, USPS

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](name) ⇒ Object

Finds a service by the given name

Parameters:

  • name (Symbol)

    The name of the service

Returns:

  • A descendant of Trackerific::Services::Base or nil for no match



10
11
12
# File 'lib/trackerific/services.rb', line 10

def [](name)
  @services[name]
end

.[]=(name, _class) ⇒ Object

Registers a service by the given name and class

Parameters:



18
19
20
21
22
23
24
25
26
# File 'lib/trackerific/services.rb', line 18

def []=(name, _class)
  unless _class.superclass == Trackerific::Services::Base
    raise ArgumentError,
      "Expected a Trackerific::Services::Base, got #{_class.inspect}",
      caller
  end

  @services[name] = _class
end

.find_by_package_id(id) ⇒ Array, Trackerific::Services::Base

Finds the tracking service(s) that are capable of tracking the given package ID capable of tracking the given ID.

Examples:

Find out which service providers can track a FedEx ID

Trackerific::Services.find_by_package_id "183689015000001"

Parameters:

  • id (String)

    The package identifier

Returns:



36
37
38
# File 'lib/trackerific/services.rb', line 36

def find_by_package_id(id)
  @services.map {|n,s| s if s.can_track?(id) }.compact
end

Instance Method Details

#track(id) ⇒ Trackerific::Details

Gets the tracking information for the package from the server

Parameters:

  • id (String)

    The package identifier

Returns:

Raises:

  • (NotImplementedError)


40
41
42
43
# File 'lib/trackerific/services/base.rb', line 40

def track(id)
  raise NotImplementedError,
    "You must implement this method in your service", caller
end