Skip to content

Instantly share code, notes, and snippets.

@eedrummer
Created April 16, 2011 20:24
Show Gist options
  • Save eedrummer/923454 to your computer and use it in GitHub Desktop.
Save eedrummer/923454 to your computer and use it in GitHub Desktop.
Automagic Twitter client for The Compleat Rubyist
require 'rest_client'
require 'json'
class Twitter
def initialize(username)
@username = username
end
def timeline
raw_json = RestClient.get "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=#{@username}"
json_array = JSON.parse raw_json
json_array.map {|tweet_hash| Tweet.new(tweet_hash)}
end
end
class Tweet
def initialize(tweet_hash)
@tweet_hash = tweet_hash
@tweet_hash.keys.each do |key|
self.singleton_class.class_eval do
define_method(key) do
@tweet_hash[key.to_s]
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment