Class: Trackerific::Services::UPS
- Includes:
- HTTParty
- Defined in:
- lib/trackerific/services/ups.rb
Overview
Provides package tracking support for UPS.
Class Method Summary collapse
-
.package_id_matchers ⇒ Array, Regexp
private
An Array of Regexp that matches valid UPS package IDs.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ UPS
constructor
A new instance of UPS.
-
#track(id) ⇒ Trackerific::Details
Tracks a UPS package.
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ UPS
Returns a new instance of UPS.
19 20 21 |
# File 'lib/trackerific/services/ups.rb', line 19 def initialize(={}) @options = end |
Class Method Details
.package_id_matchers ⇒ Array, Regexp
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.
An Array of Regexp that matches valid UPS package IDs
26 27 28 |
# File 'lib/trackerific/services/ups.rb', line 26 def self.package_id_matchers [ /^.Z/, /^[HK].{10}$/ ] end |
Instance Method Details
#track(id) ⇒ Trackerific::Details
Tracks a UPS package
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/trackerific/services/ups.rb', line 38 def track(id) @package_id = id # connect to UPS via HTTParty http_response = self.class.post('/Track', body: build_xml_request) # throw any HTTP errors http_response.error! unless http_response.code == 200 # Check the response for errors, return a Trackerific::Error, or parse # the response from UPS and return a Trackerific::Details case http_response['TrackResponse']['Response']['ResponseStatusCode'] when "0" then raise Trackerific::Error, parse_error_response(http_response) when "1" then return parse_success_response(http_response) else raise Trackerific::Error, "Invalid response code returned from server." end end |