This repository was archived by the owner on Mar 7, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +25
-11
lines changed Expand file tree Collapse file tree 2 files changed +25
-11
lines changed Original file line number Diff line number Diff line change 1
1
source 'https://rubygems.org'
2
2
3
- gem 'dashing'
3
+ gem 'dashing'
4
+
5
+ ## Remove this if you don't need a twitter widget.
6
+ gem 'twitter'
Original file line number Diff line number Diff line change 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
3
12
4
13
search_term = URI ::encode ( '#todayilearned' )
5
14
6
15
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 )
13
24
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"
16
27
end
17
28
end
You can’t perform that action at this time.
0 commit comments