Class: AsakusaRssMonitor::RssMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/asakusa-rss-monitor/rss-monitor.rb

Instance Method Summary collapse

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]
  @as_info = config[:as_info]
end

Instance Method Details

#callObject



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)
  latest_time= checker.latest

  rss = RssGetter.new(:url => @rss_url)
  new_articles = rss.get_new_articles latest_time
  return unless new_articles.any?

  begin
    bot = PostBot.new(:as_info => @as_info)
    new_articles.each do |entry|
      bot.post perform(entry)
    end
  rescue => exception
    p exception
  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