module MxdTracker::Mxd
Constants
- BASE_URL
Public Class Methods
attribute_information(tracking_hash)
click to toggle source
# File lib/mxd_tracker/mxd.rb, line 12 def self.attribute_information(tracking_hash) raise "No ZipCode" if missing_key_attributes(tracking_hash) zip_code = tracking_hash[:zip_code] info = {} info[:tracking_attribute] = get_tracking_attribute(tracking_hash) value = tracking_hash[info[:tracking_attribute]] info[:path] = construct_path(info[:tracking_attribute], value, zip_code) info end
shipment_status(tracking_hash={})
click to toggle source
# File lib/mxd_tracker/mxd.rb, line 6 def self.shipment_status(tracking_hash={}) attribute_info = attribute_information(tracking_hash) path = attribute_info[:path] MxdTracker::Scraper.get_status(path, tracking_hash[:zip_code]) end
Private Class Methods
construct_path(tracking_attribute, value, zip_code)
click to toggle source
# File lib/mxd_tracker/mxd.rb, line 24 def self.construct_path(tracking_attribute, value, zip_code) sanitized_zip_code = sanitize_zip_code(zip_code) raise "Invalid ZipCode" unless sanitized_zip_code if tracking_attribute == :tracking_number "/trackShipmentByIdAndZipOnly.htm?trackingId=#{value}&zip_code=#{sanitized_zip_code}" elsif tracking_attribute == :waybill_number "/trackShipmentByWbAndZipOnly.htm?wayBill=#{value}&zip_code=#{sanitized_zip_code}" elsif tracking_attribute == :order_number "/trackShipmentByRefAndZip.htm?refno=#{value}&zipCode=#{sanitized_zip_code}" else "/trackShipmentByPhoneAndZip.htm?zip=#{sanitized_zip_code}&phone=#{value}" end end
get_tracking_attribute(tracking_hash)
click to toggle source
# File lib/mxd_tracker/mxd.rb, line 42 def self.get_tracking_attribute(tracking_hash) if tracking_hash.key?(:tracking_number) return :tracking_number elsif tracking_hash.key?(:waybill_number) return :waybill_number elsif tracking_hash.key?(:order_number) return :order_number elsif tracking_hash.key?(:phone_number) return :phone_number else raise "No valid attribute to search on" end end
missing_key_attributes(tracking_hash)
click to toggle source
# File lib/mxd_tracker/mxd.rb, line 38 def self.missing_key_attributes(tracking_hash) tracking_hash.empty? || !tracking_hash.key?(:zip_code) end
sanitize_zip_code(zip_code)
click to toggle source
# File lib/mxd_tracker/mxd.rb, line 56 def self.sanitize_zip_code(zip_code) # MXD urls expect only five digit numeric zip codes sanitized_zip_code = zip_code.to_s.gsub(/\D+/, '').strip[0...5] if sanitized_zip_code.try(:to_i) && sanitized_zip_code.length == 5 sanitized_zip_code else false end end