Created
August 29, 2010 00:14
-
-
Save ashaw/555746 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'open-uri' | |
require 'crack/json' | |
class Tweep | |
def initialize(user) | |
@user = user | |
begin | |
u = open("http://api.twitter.com/1/users/show.json?screen_name=#{user}").read | |
rescue OpenURI::HTTPError | |
end | |
if data = Crack::JSON.parse(u) | |
data.collect {|k,v| | |
instance_variable_set("@#{k}",v) | |
} | |
end | |
end | |
def method_missing(method) | |
super unless instance_variables.include?("@#{method}") | |
instance_variable_get("@#{method}") | |
end | |
end | |
# irb(main):002:0> a = Tweep.new("a_l") | |
# irb(main):004:0> a.description | |
# => "politics n' code: Designer/Developer at TPM" | |
# irb(main):005:0> b = Tweep.new("tpmpolls") | |
# irb(main):006:0> b.description | |
# => "Live feed of incoming political poll data from the TPM Polling Team." | |
# irb(main):007:0> a.description | |
# => "politics n' code: Designer/Developer at TPM" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment