summaryrefslogtreecommitdiff
path: root/templates/project/jobs/twitter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'templates/project/jobs/twitter.rb')
-rw-r--r--templates/project/jobs/twitter.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/templates/project/jobs/twitter.rb b/templates/project/jobs/twitter.rb
new file mode 100644
index 0000000..9359a89
--- /dev/null
+++ b/templates/project/jobs/twitter.rb
@@ -0,0 +1,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 \ No newline at end of file