# File lib/twitter.rb, line 29 29: def self.api_endpoint 30: @api_endpoint ||= "api.twitter.com/#{API_VERSION}" 31: end
# File lib/twitter.rb, line 33 33: def self.api_endpoint=(value) 34: @api_endpoint = value 35: end
# File lib/twitter.rb, line 37 37: def self.firehose(options = {}) 38: perform_get("/statuses/public_timeline.json") 39: end
# File lib/twitter.rb, line 53 53: def self.follower_ids(id,options={}) 54: perform_get("/followers/ids/#{id}.json") 55: end
# File lib/twitter.rb, line 49 49: def self.friend_ids(id,options={}) 50: perform_get("/friends/ids/#{id}.json") 51: end
:per_page = max number of statues to get at once :page = which page of tweets you wish to get
# File lib/twitter.rb, line 63 63: def self.list_timeline(list_owner_username, slug, query = {}) 64: perform_get("/#{list_owner_username}/lists/#{slug}/statuses.json", :query => query) 65: end
# File lib/twitter.rb, line 45 45: def self.status(id,options={}) 46: perform_get("/statuses/show/#{id}.json") 47: end
# File lib/twitter.rb, line 74 74: def self.make_friendly(response) 75: raise_errors(response) 76: data = parse(response) 77: # Don't mash arrays of integers 78: if data && data.is_a?(Array) && data.first.is_a?(Integer) 79: data 80: else 81: mash(data) 82: end 83: end
Lame workaround for the fact that mash doesn’t hash correctly
# File lib/twitter.rb, line 120 120: def self.make_mash_with_consistent_hash(obj) 121: m = Hashie::Mash.new(obj) 122: def m.hash 123: inspect.hash 124: end 125: return m 126: end
# File lib/twitter.rb, line 109 109: def self.mash(obj) 110: if obj.is_a?(Array) 111: obj.map{|item| make_mash_with_consistent_hash(item)} 112: elsif obj.is_a?(Hash) 113: make_mash_with_consistent_hash(obj) 114: else 115: obj 116: end 117: end
# File lib/twitter.rb, line 105 105: def self.parse(response) 106: Yajl::Parser.parse(response.body) 107: end
# File lib/twitter.rb, line 69 69: def self.perform_get(uri, options = {}) 70: base_uri self.api_endpoint 71: make_friendly(get(uri, options)) 72: end
# File lib/twitter.rb, line 85 85: def self.raise_errors(response) 86: case response.code.to_i 87: when 400 88: data = parse(response) 89: raise RateLimitExceeded.new(data), "(#{response.code}): #{response.message} - #{data['error'] if data}" 90: when 401 91: data = parse(response) 92: raise Unauthorized.new(data), "(#{response.code}): #{response.message} - #{data['error'] if data}" 93: when 403 94: data = parse(response) 95: raise General.new(data), "(#{response.code}): #{response.message} - #{data['error'] if data}" 96: when 404 97: raise NotFound, "(#{response.code}): #{response.message}" 98: when 500 99: raise InformTwitter, "Twitter had an internal error. Please let them know in the group. (#{response.code}): #{response.message}" 100: when 502..503 101: raise Unavailable, "(#{response.code}): #{response.message}" 102: end 103: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.