Class: IMAPToRSS::Handler::UPS

Inherits:
IMAPToRSS::Handler show all
Defined in:
lib/imap_to_rss/handler/ups.rb

Overview

Turns messages from UPS into links to the tracking page

Instance Attribute Summary

Attributes inherited from IMAPToRSS::Handler

#mail, #search

Instance Method Summary collapse

Methods inherited from IMAPToRSS::Handler

#add_item, #each_message, handlers, inherited, #log, #setup

Constructor Details

#initializeUPS

Selects messages with ups in the From header



11
12
13
# File 'lib/imap_to_rss/handler/ups.rb', line 11

def initialize
  @search = 'FROM', 'ups'
end

Instance Method Details

#handle(uids) ⇒ Object

Scans uids for UPS tracking numbers and turns them into RSS items



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/imap_to_rss/handler/ups.rb', line 18

def handle(uids)
  each_message uids, 'text/plain' do |uid, mail|
    mail.body =~ /Tracking Number:\s+(\w+)/

    tracking_number = $1

    next false unless $1

    url = "http://wwwapps.ups.com/WebTracking/processRequest?tracknum=#{tracking_number}"

    description = %{Package shipped: <a href="#{url}">#{tracking_number}</a>}

    add_item mail.subject, description, mail.from, mail.date, url,
             mail.message_id, 'UPS'
  end
end