Class: Botolo::API::Blog
- Inherits:
-
Object
- Object
- Botolo::API::Blog
- Defined in:
- lib/botolo/api/blog.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Blog
constructor
A new instance of Blog.
- #promote_latest(hashtags = "") ⇒ Object
- #refresh_rss ⇒ Object
- #tweet_random_posts(limit = 3, hashtags = "") ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Blog
Returns a new instance of Blog.
7 8 9 10 |
# File 'lib/botolo/api/blog.rb', line 7 def initialize(={}) @url = [:url] @tweet = [:tweet_api] end |
Instance Method Details
#promote_latest(hashtags = "") ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/botolo/api/blog.rb', line 43 def promote_latest(="") return nil if @feed.nil? || @feed.size == 0 post = @feed[0] m = "\"#{post[:title]}\" (#{post[:link]}) #blog #sicurezza #informatica." $logger.debug "#{m} - #{m.length}" begin @tweet.tweet(m) rescue => e $logger.err("error tweeting #{m}: #{e.}") end end |
#refresh_rss ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/botolo/api/blog.rb', line 12 def refresh_rss rss = nil open("#{@url}/feed.xml") do |http| response = http.read rss = RSS::Parser.parse(response, false) end @feed = [] rss.items.each_with_index do |item, i| @feed << {:title=>item.title.content, :link=>item.link.href} end $logger.info "#{@feed.size} elements loaded from feed" end |
#tweet_random_posts(limit = 3, hashtags = "") ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/botolo/api/blog.rb', line 26 def tweet_random_posts(limit = 3, ="") return nil if @feed.nil? || @feed.size == 0 (0..limit-1).each do |l| post = @feed[SecureRandom.random_number(@feed.size)] m = "\"#{post[:title]}\" (#{post[:link]}) #{}" $logger.debug "#{m} - #{m.length}" begin @tweet.tweet(m) $logger.debug "tweet sent!" rescue => e $logger.err("error tweeting #{m}: #{e.}") end sleep(10) end end |