Class: IMAPToRSS::Handler
- Inherits:
-
Object
- Object
- IMAPToRSS::Handler
- Defined in:
- lib/imap_to_rss/handler.rb,
lib/imap_to_rss/test_case.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.
Defined Under Namespace
Classes: Amazon, HSBC, Itunes, UPS
Instance Attribute Summary collapse
-
#mail ⇒ Object
Returns the value of attribute mail.
-
#search ⇒ Object
IMAP SEARCH command keywords to search.
Class Method Summary collapse
-
.handlers ⇒ Object
List of found handlers.
-
.inherited(subclass) ⇒ Object
Collect handler subclasses.
Instance Method Summary collapse
-
#add_item(title, description, author, pub_date, link = nil, guid = nil, category = nil) ⇒ Object
Adds an item to the RSS feed with given parts.
-
#each_message(*args, &block) ⇒ Object
Delegates to IMAPToRSS#each_message.
-
#handle(uids) ⇒ Object
Guts of the handler, implement this yourself.
-
#log(*args) ⇒ Object
Delegates to IMAPToRSS.
-
#setup(imap_to_rss) ⇒ Object
Sets up delegators to IMAPToRSS.
Instance Attribute Details
#mail ⇒ Object
Returns the value of attribute mail.
14 15 16 |
# File 'lib/imap_to_rss/test_case.rb', line 14 def mail @mail end |
#search ⇒ Object
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
.handlers ⇒ Object
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, , 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, , 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 (*args, &block) @itor.(*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.
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 |