summaryrefslogtreecommitdiff
path: root/templates/project/jobs/twitter.rb
blob: 9359a89f7c2c91bb25b67d2fa88fa92a435fdc25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require 'net/http'
require 'json'

search_term = URI::encode('#todayilearned')

SCHEDULER.every '10m', :first_in => 0 do |job|
  http = Net::HTTP.new('search.twitter.com')
  response = http.request(Net::HTTP::Get.new("/search.json?q=#{search_term}"))
  tweets = JSON.parse(response.body)["results"]
  if tweets
    tweets.map! do |tweet| 
      { name: tweet['from_user'], body: tweet['text'], avatar: tweet['profile_image_url_https'] }
    end
  
    send_event('twitter_mentions', comments: tweets)
  end
end