summaryrefslogtreecommitdiff
path: root/templates
diff options
context:
space:
mode:
authorpushmatrix <daniel.beauchamp@gmail.com>2013-06-14 18:14:02 +0200
committerpushmatrix <daniel.beauchamp@gmail.com>2013-06-14 18:14:02 +0200
commitf91c1b8962860eaeaa428d3ea75ebf61ced9ec6a (patch)
tree9b3b86293b6f56ab5b9ea6c5efaac89bbb3d533b /templates
parent56b3ac96521c2630fde811b0f5fdf045a4ab7ff3 (diff)
Added dependency to the twitter gem so that the twitter widget can work with the 1.1 API.
Diffstat (limited to 'templates')
-rw-r--r--templates/project/Gemfile5
-rw-r--r--templates/project/jobs/twitter.rb31
2 files changed, 25 insertions, 11 deletions
diff --git a/templates/project/Gemfile b/templates/project/Gemfile
index 8f1b17a..e6ccd84 100644
--- a/templates/project/Gemfile
+++ b/templates/project/Gemfile
@@ -1,3 +1,6 @@
source 'https://rubygems.org'
-gem 'dashing' \ No newline at end of file
+gem 'dashing'
+
+## Remove this if you don't need a twitter widget.
+gem 'twitter' \ No newline at end of file
diff --git a/templates/project/jobs/twitter.rb b/templates/project/jobs/twitter.rb
index 9359a89..5e70f30 100644
--- a/templates/project/jobs/twitter.rb
+++ b/templates/project/jobs/twitter.rb
@@ -1,17 +1,28 @@
-require 'net/http'
-require 'json'
+require 'twitter'
+
+
+#### Get your twitter keys & secrets:
+#### https://dev.twitter.com/docs/auth/tokens-devtwittercom
+Twitter.configure do |config|
+ config.consumer_key = 'YOUR_CONSUMER_KEY'
+ config.consumer_secret = 'YOUR_CONSUMER_SECRET'
+ config.oauth_token = 'YOUR_OAUTH_TOKEN'
+ config.oauth_token_secret = 'YOUR_OAUTH_SECRET'
+end
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'] }
+ begin
+ tweets = Twitter.search("#{search_term}").results
+
+ if tweets
+ tweets.map! do |tweet|
+ { name: tweet.user.name, body: tweet.text, avatar: tweet.user.profile_image_url_https }
+ end
+ send_event('twitter_mentions', comments: tweets)
end
-
- send_event('twitter_mentions', comments: tweets)
+ rescue Twitter::Error
+ puts "\e[33mFor the twitter widget to work, you need to put in your twitter API keys in the jobs/twitter.rb file.\e[0m"
end
end \ No newline at end of file