Skip to content

Instantly share code, notes, and snippets.

@zimbatm zimbatm/README.md forked from jeroenbegyn/README.md
Last active Dec 28, 2015

Embed
What would you like to do?
Fixes compatibility issues with the version 5.0.0 of the twitter gem.

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
@koragan

This comment has been minimized.

Copy link

koragan commented Jul 18, 2014

For "ENV['SSL_CERT_FILE'] = File.expand_path('../cacert.pem', FILE)" to work, be sure to save the file in your 'Source Files' folder. Do not put it in any subfolder (inside Source Files) or the path '../cacert.pem' will not work.

Also, be sure your twitter gem is updated, "gem 'twitter', '~> 5.0.0'" is not correct. At the time of this post, the gem is at 5.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.