-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
twitter.rb
63 lines (48 loc) · 1.62 KB
/
twitter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'forwardable'
require 'rubygems'
gem 'oauth', '~> 0.3.5'
require 'oauth'
gem 'hashie', '~> 0.1.3'
require 'hashie'
gem 'httparty', '~> 0.4.3'
require 'httparty'
module Twitter
class TwitterError < StandardError
attr_reader :data
def initialize(data)
@data = data
super
end
end
class RateLimitExceeded < TwitterError; end
class Unauthorized < TwitterError; end
class General < TwitterError; end
class Unavailable < StandardError; end
class InformTwitter < StandardError; end
class NotFound < StandardError; end
def self.firehose
response = HTTParty.get('http://twitter.com/statuses/public_timeline.json', :format => :json)
response.map { |tweet| Hashie::Mash.new(tweet) }
end
def self.user(id)
response = HTTParty.get("http://twitter.com/users/show/#{id}.json", :format => :json)
Hashie::Mash.new(response)
end
def self.status(id)
response = HTTParty.get("http://twitter.com/statuses/show/#{id}.json", :format => :json)
Hashie::Mash.new(response)
end
def self.friend_ids(id)
HTTParty.get("http://twitter.com/friends/ids/#{id}.json", :format => :json)
end
def self.follower_ids(id)
HTTParty.get("http://twitter.com/followers/ids/#{id}.json", :format => :json)
end
end
directory = File.expand_path(File.dirname(__FILE__))
require File.join(directory, 'twitter', 'oauth')
require File.join(directory, 'twitter', 'httpauth')
require File.join(directory, 'twitter', 'request')
require File.join(directory, 'twitter', 'base')
require File.join(directory, 'twitter', 'search')
require File.join(directory, 'twitter', 'trends')