Created
August 24, 2009 21:01
-
-
Save joemsak/174175 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#view | |
<div id="twitter"> | |
<h3 class="hide">Recent Tweets</h3> | |
<ul> | |
<% @tweets.each do |tweet| -%> | |
<li class="tweet"> | |
<%= tweet.title.gsub!('simplifyadvance: ', '') %> | |
<strong class="date"><%= tweet.pubDate.strftime("%l:%M %p %b %e") %></strong> | |
</li> | |
<% end -%> | |
</ul> | |
<%= our_twitter_link %> | |
</div> | |
#model | |
class RssReader | |
def self.posts_for(feed_url, length=2, perform_validation=false) | |
posts = [] | |
begin | |
open(feed_url) do |rss| | |
posts = RSS::Parser.parse(rss, perform_validation).items | |
end | |
posts.each do |post| | |
post.title.gsub!(/(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?/ix) { |w| '<a href="' + w + '">' + w + '</a>' } | |
post.title.gsub!(/@(\w+)/, '<a class="twitter_name" href="http://www.twitter.com/\\1">@\\1</a>') | |
post.title.gsub!(/#(\w+)/, '<a class="twitter_hashtag" href="http://search.twitter.com/search?q=\\1">#\\1</a>') | |
end | |
posts[0..length - 1] if posts.size > length | |
rescue OpenURI::HTTPError => error | |
posts << [post.title = 'No posts available', post.pubDate = Time.now] | |
end | |
end | |
end | |
#controller | |
def setup_twitter_feed | |
@tweets = RssReader.posts_for("http://twitter.com/statuses/user_timeline/52242943.rss", 2) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment