Skip to content
This repository was archived by the owner on Mar 7, 2018. It is now read-only.

Commit f91c1b8

Browse files
committed
Added dependency to the twitter gem so that the twitter widget can work with the 1.1 API.
1 parent 56b3ac9 commit f91c1b8

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

templates/project/Gemfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
source 'https://rubygems.org'
22

3-
gem 'dashing'
3+
gem 'dashing'
4+
5+
## Remove this if you don't need a twitter widget.
6+
gem 'twitter'

templates/project/jobs/twitter.rb

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
require 'net/http'
2-
require 'json'
1+
require 'twitter'
2+
3+
4+
#### Get your twitter keys & secrets:
5+
#### https://dev.twitter.com/docs/auth/tokens-devtwittercom
6+
Twitter.configure do |config|
7+
config.consumer_key = 'YOUR_CONSUMER_KEY'
8+
config.consumer_secret = 'YOUR_CONSUMER_SECRET'
9+
config.oauth_token = 'YOUR_OAUTH_TOKEN'
10+
config.oauth_token_secret = 'YOUR_OAUTH_SECRET'
11+
end
312

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

615
SCHEDULER.every '10m', :first_in => 0 do |job|
7-
http = Net::HTTP.new('search.twitter.com')
8-
response = http.request(Net::HTTP::Get.new("/search.json?q=#{search_term}"))
9-
tweets = JSON.parse(response.body)["results"]
10-
if tweets
11-
tweets.map! do |tweet|
12-
{ name: tweet['from_user'], body: tweet['text'], avatar: tweet['profile_image_url_https'] }
16+
begin
17+
tweets = Twitter.search("#{search_term}").results
18+
19+
if tweets
20+
tweets.map! do |tweet|
21+
{ name: tweet.user.name, body: tweet.text, avatar: tweet.user.profile_image_url_https }
22+
end
23+
send_event('twitter_mentions', comments: tweets)
1324
end
14-
15-
send_event('twitter_mentions', comments: tweets)
25+
rescue Twitter::Error
26+
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"
1627
end
1728
end

0 commit comments

Comments
 (0)