Class: LearnableNotifier
- Inherits:
-
Object
- Object
- LearnableNotifier
- Defined in:
- lib/learnable-notifier.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#options ⇒ Object
Returns the value of attribute options.
-
#rss_path ⇒ Object
Returns the value of attribute rss_path.
-
#sent ⇒ Object
Returns the value of attribute sent.
Instance Method Summary collapse
- #find_next_message ⇒ Object
-
#initialize(rss_path, api_key, options = {}) ⇒ LearnableNotifier
constructor
A new instance of LearnableNotifier.
- #send_message(title, message) ⇒ Object
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, = {}) self.rss_path = rss_path self. = { :application => 'Learnable forum', :storage => File.join(ENV['HOME'], '.learnable-notifier') }.merge() Prowler.configure do |config| config.api_key = api_key config.application = self.[:application] end self.sent = { self.rss_path => [] } if (File.exists?(self.[:storage]) && yaml = YAML.load_file(self.[:storage])) self.sent = yaml end end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/learnable-notifier.rb', line 8 def api_key @api_key end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/learnable-notifier.rb', line 8 def end |
#rss_path ⇒ Object
Returns the value of attribute rss_path.
8 9 10 |
# File 'lib/learnable-notifier.rb', line 8 def rss_path @rss_path end |
#sent ⇒ Object
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_message ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/learnable-notifier.rb', line 28 def 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) ("Message from Learnable", entry.title) self.sent[self.rss_path].push(entry.entry_id) end end File.open(self.[: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 (title, ) Prowler.notify title, end |