Class: AsakusaRssMonitor::RssMonitor
- Inherits:
-
Object
- Object
- AsakusaRssMonitor::RssMonitor
- Defined in:
- lib/asakusa-rss-monitor/rss-monitor.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(config) ⇒ RssMonitor
constructor
A new instance of RssMonitor.
- #perform(rss_entry) ⇒ Object
Constructor Details
#initialize(config) ⇒ RssMonitor
Returns a new instance of RssMonitor.
11 12 13 14 15 |
# File 'lib/asakusa-rss-monitor/rss-monitor.rb', line 11 def initialize(config) @check_file = config[:check_file] @rss_url = config[:rss_url] @bot_config = config[:bot_config] end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/asakusa-rss-monitor/rss-monitor.rb', line 17 def call checker = DateChecker.new(:file_name => @check_file) last_time= checker.last_time rss = RssGetter.new(:url => @rss_url) new_articles = rss.get_new_articles last_time return unless new_articles.any? begin bot = PostBot.new(:bot_config => @bot_config) new_articles.each do |entry| bot.post perform(entry) end rescue => exception p exception return end # rss.get_new_entries returns articles by ascending order checker.update new_articles.last.date end |
#perform(rss_entry) ⇒ Object
38 39 40 |
# File 'lib/asakusa-rss-monitor/rss-monitor.rb', line 38 def perform(rss_entry) "New Article - #{rss_entry.date}\n#{rss_entry.title}\n #{rss_entry.link} " end |