Class: LearnableNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/learnable-notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rss_path, api_key, options = {}) ⇒ LearnableNotifier



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/learnable-notifier.rb', line 10

def initialize(rss_path, api_key, options = {})
  self.rss_path = rss_path
  self.options = {
    :application => 'Learnable forum',
    :storage => File.join(ENV['HOME'], '.learnable-notifier')
  }.merge(options)

  Prowler.configure do |config|
    config.api_key = api_key
    config.application = self.options[:application]
  end

  self.sent = { self.rss_path => [] }
  if (File.exists?(self.options[:storage]) && yaml = YAML.load_file(self.options[:storage]))
    self.sent = yaml
  end
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



8
9
10
# File 'lib/learnable-notifier.rb', line 8

def api_key
  @api_key
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/learnable-notifier.rb', line 8

def options
  @options
end

#rss_pathObject

Returns the value of attribute rss_path.



8
9
10
# File 'lib/learnable-notifier.rb', line 8

def rss_path
  @rss_path
end

#sentObject

Returns the value of attribute sent.



8
9
10
# File 'lib/learnable-notifier.rb', line 8

def sent
  @sent
end

Instance Method Details

#find_next_messageObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/learnable-notifier.rb', line 28

def find_next_message
  next_guid = nil
  feed = Feedzirra::Feed.fetch_and_parse("#{rss_path}?type=rss")
  feed.entries.each do |entry|
    unless self.sent[self.rss_path].include?(entry.entry_id)
      send_message("Message from Learnable", entry.title) 
      self.sent[self.rss_path].push(entry.entry_id)
    end
  end
  
  File.open(self.options[:storage], 'w') do |fh|
    YAML.dump(self.sent, fh)
  end
end

#send_message(title, message) ⇒ Object



43
44
45
# File 'lib/learnable-notifier.rb', line 43

def send_message(title, message)
  Prowler.notify title, message
end