Sha256: 0fbe4372b2630c93e743303e123356a09d246dbd0c480b6f8d36bfb96231849b

Contents?: true

Size: 997 Bytes

Versions: 2

Compression:

Stored size: 997 Bytes

Contents

module PackageTracker
  class Client
    attr_accessor :credentials
    attr_reader :mode

    def initialize(credentials={})
      @credentials = credentials
    end

    def track(tracking_number, carrier=nil)
      # Fed Ex
      if carrier == :fedex || Carriers::FedEx.match(tracking_number)
        Carriers::FedEx.track(tracking_number, :credentials => @credentials[:fedex], :testing => testing?)
      # UPS
      elsif carrier == :ups || Carriers::UPS.match(tracking_number)
        Carriers::UPS.track(tracking_number, :credentials => @credentials[:ups], :testing => testing?)
      # USPS 
      elsif carrier == :usps || Carriers::USPS.match(tracking_number)
        raise CarrierNotFoundError, "Need to impliment USPS"
      # DHL
      else
        raise CarrierNotFoundError
      end
    end
        
    def testing?
      @mode == "testing"
    end
    
    def test_mode!
      @mode = "testing"
    end
    
    def production_mode!
      @mode == "production"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
package_tracker-0.0.3 lib/package_tracker/client.rb
package_tracker-0.0.2 lib/package_tracker/client.rb