Skip to content

Instantly share code, notes, and snippets.

@ignu
Created August 2, 2010 20:34
Show Gist options
  • Save ignu/505262 to your computer and use it in GitHub Desktop.
Save ignu/505262 to your computer and use it in GitHub Desktop.
require 'httparty'
require 'ruby-growl'
class FedEx
include HTTParty
format :html
class << self
@status, @location = nil, nil
def current_status
body = get("http://www.fedex.com/Tracking/Detail?ftc_start_url=&totalPieceNum=&backTo=&template_type=print&cntry_code=us&language=english&trackNum=#{@number}&pieceNum=&selectedTimeZone=localScanTime")
status = body.scan(/DIV CLASS="undeliveredstatustop" style="clear:both">(.+)<\/DIV>/).first.first
location = body.scan(/DIV CLASS="undeliveredstatus">(.+)<\/DIV>/).first.first
{:status=>status, :location=>location}
end
def notify_if_different(status)
puts 'checking...'
return if @status == status[:status] && @location == status[:location]
@status, @location = status[:status], status[:location]
alert
end
def alert
puts "Update: #{@status}: #{@location}"
growl = Growl.new("localhost", "ruby-growl", ["fedex"], ["fedex"], nil)
growl.notify("fedex", "FedEx Update", "#{@status}: #{@location}", 1, true)
end
def track(number)
@number = number
while true do
notify_if_different current_status
sleep 20
end
end
end
end
FedEx.track(440021480538)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment