Skip to content

Instantly share code, notes, and snippets.

@netconstructor
Forked from jeroenbegyn/README.md
Created June 21, 2013 11:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netconstructor/5830670 to your computer and use it in GitHub Desktop.
Save netconstructor/5830670 to your computer and use it in GitHub Desktop.

Description

Simple Dashing widget (and associated job) to display a Twitter search. Uses Twitter API v1.1.

##Dependencies

twitter

Add it to dashing's gemfile:

gem 'twitter'

and run bundle install. Everything should work now :)

##Usage

Put the twitter-search.rb file in your /jobs folder.

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="twitter_mentions" data-view="Comments" data-title="Search Tweets" style="background-color: #71388a"></div>
</li>

##Settings

You'll need to add the twitter configs for your desired account to the job.

Tweets are fetched every 10 minutes, but you can change that by editing the job schedule.

require 'twitter'
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_TOKEN_SECRET'
end
search_term = URI::encode('#todayilearned')
SCHEDULER.every '10m', :first_in => 0 do |job|
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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment