Skip to content

Instantly share code, notes, and snippets.

@tobinharris
Created May 17, 2010 19:05
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 tobinharris/404099 to your computer and use it in GitHub Desktop.
Save tobinharris/404099 to your computer and use it in GitHub Desktop.
#
# Simple way of grabbing tweets for Rails
# http://tobin@tobinharris.com
# Example on the home page of http://yuml.me
#
require 'rexml/document'
require 'open-uri'
include REXML
class TwitterController < ApplicationController
def tweets
unless fragment_exist?("tweets", :time_to_live=>10.minutes)
# search for yUML but don't show RTs and tweets from @yuml
url = 'http://search.twitter.com/search.atom?q=yuml+-RT+-%40yuml+-from:yuml'
@doc = Document.new(open(url, "UserAgent" => "Ruby-Twitter Reader").read)
@tweets = []
# convert result into neat Hash
REXML::XPath.each(@doc.root, '//entry') do |entry|
@tweets << {:title=>entry.elements['content'].text, :link=>entry.elements['link'].attributes['href'], :author=>entry.elements['author'].elements['name'].text, :published=>entry.elements['published'].text.to_time }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment