Class: IMAPToRSS::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/imap_to_rss/handler.rb

Overview

Base message handler class. Subclass this to define your own handlers, and override the #initialize and #handle methods.

To have the handler automatically be picked up by IMAPToRSS, place it in the imap_to_rss/handler/ directory.

Direct Known Subclasses

Amazon, HSBC, UPS

Defined Under Namespace

Classes: Amazon, HSBC, UPS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#searchObject

IMAP SEARCH command keywords to search



16
17
18
# File 'lib/imap_to_rss/handler.rb', line 16

def search
  @search
end

Class Method Details

.handlersObject

List of found handlers



30
31
32
# File 'lib/imap_to_rss/handler.rb', line 30

def self.handlers
  @handlers
end

.inherited(subclass) ⇒ Object

Collect handler subclasses



23
24
25
# File 'lib/imap_to_rss/handler.rb', line 23

def self.inherited(subclass)
  @handlers << subclass
end

Instance Method Details

#add_item(title, description, author, pub_date, link = nil, guid = nil, category = nil) ⇒ Object

Adds an item to the RSS feed with given parts. Returns the created item



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/imap_to_rss/handler.rb', line 50

def add_item(title, description, author, pub_date, link = nil, guid = nil,
             category = nil)
  pub_date = case pub_date
             when Time then
               pub_date
             when Date, DateTime then
               Time.parse pub_date.to_s
             else
               Time.parse pub_date
             end

  item = IMAPToRSS::RSSItem.new title, description, author, pub_date, link,
                                guid, category

  @itor.rss_items << item

  item
end

#each_message(*args, &block) ⇒ Object

Delegates to IMAPToRSS#each_message



72
73
74
# File 'lib/imap_to_rss/handler.rb', line 72

def each_message(*args, &block)
  @itor.each_message(*args, &block)
end

#handle(uids) ⇒ Object

Guts of the handler, implement this yourself. It should call #add_item for each message found.

See IMAPToRSS::Handler::UPS for a simple handler, IMAPToRSS::Handler::Amazon for a complex one.

Raises:

  • (NotImplementedError)


83
84
85
# File 'lib/imap_to_rss/handler.rb', line 83

def handle(uids)
  raise NotImplementedError, 'write me'
end

#log(*args) ⇒ Object

Delegates to IMAPToRSS



90
91
92
# File 'lib/imap_to_rss/handler.rb', line 90

def log(*args)
  @itor.log(*args)
end

#setup(imap_to_rss) ⇒ Object

Sets up delegators to IMAPToRSS



97
98
99
100
# File 'lib/imap_to_rss/handler.rb', line 97

def setup(imap_to_rss)
  @itor = imap_to_rss
  @imap = imap_to_rss.imap
end