Class: Everyx::PeriodicTasks::RSSNotifier

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

Overview

This class will fetch and parse a RSS feed. It will create an NServer alert with all the ‘titles’ of the entries whenever the feed updates.

Try not to run this one every minute, as it generally annoys the feed owner. 15 minutes is fairly “standard.”

You’ll have to set the uri before you schedule this.

Example:

rss = Everyx::PeriodicTasks::RSSNotifier.new
rss.uri = "http://www.slashdot.org/slash.rss"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRSSNotifier

Returns a new instance of RSSNotifier.



96
97
98
99
# File 'lib/everyx.rb', line 96

def initialize
  @uri = nil
  @last = nil
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



95
96
97
# File 'lib/everyx.rb', line 95

def uri
  @uri
end

Instance Method Details

#callObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/everyx.rb', line 101

def call
  rss = RSS::Parser.parse( open(@uri) {|s| s.read }, false )
  new = []
  first_new = nil
  rss.items.each do |item|
    if item.link != @last
      first_new = item.link unless first_new
      new << "* #{item.title}"
    else
      break
    end
  end

  @last = first_new if first_new

  if new.size > 0
    NServer::Client.try_notify( new.join("\n") )
  end
end