Created
July 19, 2010 19:49
-
-
Save jpinnix/481896 to your computer and use it in GitHub Desktop.
Include recent tweets in a Rails app
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
#lib/tasks/download_twitter_feed.rake | |
desc "Download Twitter Feed" | |
task :download_twitter_feed do | |
require 'open-uri' | |
etag_cache = open( "#{RAILS_ROOT}/public/system/etag_cache.txt" ).read | |
begin | |
open( "http://twitter.com/statuses/user_timeline/callannlane.xml", "If-None-Match" => etag_cache ) do |feed| | |
open("#{RAILS_ROOT}/public/system/tweets.xml","w").write(feed.read) | |
open("#{RAILS_ROOT}/public/system/etag_cache.txt","w").write(feed.meta['etag']) | |
Rake::Task["remove_specific_cached_pages"].execute | |
puts "File has changed." | |
end | |
rescue OpenURI::HTTPError | |
puts "No file available or file has not changed." | |
end | |
end |
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
#lib/tasks/remove_specific_cached_pages.rake | |
desc "Remove specific cached pages" | |
task :remove_specific_cached_pages do | |
home_path = "#{RAILS_ROOT}/public/pages/home.html" | |
File.delete(home_path) if File.exist?(home_path) | |
puts "Cached pages removed." | |
end |
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
# app/models/twitterer.rb | |
class Twitterer | |
include HappyMapper | |
element :id, Integer | |
element :name, String | |
element :screen_name, String | |
element :location, String | |
element :description, String | |
element :profile_image_url, String | |
element :url, String | |
element :protected, Boolean | |
element :followers_count, Integer | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Due to changes with Twitter API, this no longer works.