Skip to content

Instantly share code, notes, and snippets.

@kevinthompson
Last active August 18, 2022 13:39
Show Gist options
  • Save kevinthompson/c3023df8e2c904ad00d9 to your computer and use it in GitHub Desktop.
Save kevinthompson/c3023df8e2c904ad00d9 to your computer and use it in GitHub Desktop.
Litmus Example – Tweets in CSS
TWITTER_CONSUMER_KEY=""
TWITTER_CONSUMER_SECRET=""
TWITTER_SEARCH_STRING="#tedc15 -rt"
require 'sinatra'
require 'twitter'
helpers do
def twitter
@twitter ||= Twitter::REST::Client.new do |config|
config.consumer_key = ENV.fetch("TWITTER_CONSUMER_KEY")
config.consumer_secret = ENV.fetch("TWITTER_CONSUMER_SECRET")
end
end
end
get "/tweets.css" do
content_type "text/css"
tweets = twitter.search(ENV.fetch("TWITTER_SEARCH_STRING"))
tweets.take(15).map.with_index do |tweet, i|
<<-CSS
#tweet-#{i + 1} .copy {
content: "#{tweet.text}";
}
CSS
end
end
source 'https://rubygems.org'
gem 'sinatra'
gem 'twitter'
gem 'puma'
group 'development' do
gem 'foreman'
end
web: bundle exec ruby app.rb -p $PORT
@kevinthompson
Copy link
Author

View the full example in the litmus/example-css-tweets repo,
or deploy a version to heroku to test your own search terms.

Deploy

Copy link

ghost commented May 27, 2015

I truely love it. Great job! Seen your result in the Litmus example. Might use it someday. ;-)

Cheers.

@matthelbig
Copy link

Any way you can update this to include pulling down avatar photo, name, handle, and timestamp? 😄

@nola
Copy link

nola commented Jan 14, 2016

Awesome stuff! Where do you add the Cache-Control? Is it a part of the repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment