Skip to content

Instantly share code, notes, and snippets.

@robertolos
Last active October 5, 2015 09:59
Show Gist options
  • Save robertolos/b6ef398055fefae52a62 to your computer and use it in GitHub Desktop.
Save robertolos/b6ef398055fefae52a62 to your computer and use it in GitHub Desktop.
Shopify dashing - Twitter mentions
require 'twitter'
#### Get your twitter keys & secrets:
#### https://dev.twitter.com/docs/auth/tokens-devtwittercom
twitter = Twitter::REST::Client.new do |config|
config.consumer_key = 'YOUR_CONSUMER_KEY'
config.consumer_secret = 'YOUR_CONSUMER_SECRET_KEY'
config.access_token = 'YOUR_ACCESS_TOKEN'
config.access_token_secret = 'YOUR_ACCESS_TOKEN_SECRET'
end
SCHEDULER.every '1m', :first_in => 0 do |job|
begin
user = twitter.user
timeline = twitter.mentions_timeline
if timeline
mentions = timeline.map do |tweet|
media_url = false
if tweet.media?
media_url = tweet.media[0].media_url.to_s
end
{ name: tweet.user.name, body: tweet.text, avatar: tweet.user.profile_image_url_https.to_s, media: media_url }
end
send_event('twitter_mentions', {comments: mentions})
end
rescue Twitter::Error
puts "\e[33mThere was an error with Twitter\e[0m"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment