Class: PackageTracker::Client
- Inherits:
-
Object
- Object
- PackageTracker::Client
- Defined in:
- lib/package_tracker/client.rb
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Instance Method Summary collapse
-
#initialize(credentials = {}) ⇒ Client
constructor
A new instance of Client.
- #production_mode! ⇒ Object
- #test_mode! ⇒ Object
- #testing? ⇒ Boolean
- #track(tracking_number, carrier = nil) ⇒ Object
Constructor Details
#initialize(credentials = {}) ⇒ Client
Returns a new instance of Client.
6 7 8 |
# File 'lib/package_tracker/client.rb', line 6 def initialize(credentials={}) @credentials = credentials end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
3 4 5 |
# File 'lib/package_tracker/client.rb', line 3 def credentials @credentials end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
4 5 6 |
# File 'lib/package_tracker/client.rb', line 4 def mode @mode end |
Instance Method Details
#production_mode! ⇒ Object
34 35 36 |
# File 'lib/package_tracker/client.rb', line 34 def production_mode! @mode == "production" end |
#test_mode! ⇒ Object
30 31 32 |
# File 'lib/package_tracker/client.rb', line 30 def test_mode! @mode = "testing" end |
#testing? ⇒ Boolean
26 27 28 |
# File 'lib/package_tracker/client.rb', line 26 def testing? @mode == "testing" end |
#track(tracking_number, carrier = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/package_tracker/client.rb', line 10 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 |