Skip to content

Instantly share code, notes, and snippets.

@ssalinas
Forked from zimbatm/README.md
Created June 19, 2014 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssalinas/68c54d9674e458029889 to your computer and use it in GitHub Desktop.
Save ssalinas/68c54d9674e458029889 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', '~> 5.0.0'

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.

SSL issues

If you have issues with SSL, you can bundle the SSL root certificates like this.

  1. Download http://curl.haxx.se/ca/cacert.pem and put it somewhere in your project
  2. In ruby, tell OpenSSL where to find the file:
ENV['SSL_CERT_FILE'] = File.expand_path('../cacert.pem', __FILE__)
require 'twitter'
# Make sure you have downloaded the file before
#ENV['SSL_CERT_FILE'] = File.expand_path('../cacert.pem', __FILE__)
twitter = Twitter::REST::Client.new do |config|
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
config.access_token = ENV['TWITTER_ACCESS_TOKEN']
config.access_token_secret = ENV['TWITTER_ACCESS_SECRET']
end
search_term = URI::encode('#todayilearned')
SCHEDULER.every '10m', :first_in => 0 do |job|
result = twitter.search(search_term)
tweets = result.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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment