Created
April 16, 2011 20:24
-
-
Save eedrummer/923454 to your computer and use it in GitHub Desktop.
Automagic Twitter client for The Compleat Rubyist
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
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