moomerman-twitter_oauth 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/twitter_oauth/account.rb +18 -0
- data/lib/twitter_oauth/client.rb +47 -0
- data/lib/twitter_oauth/direct_messages.rb +23 -0
- data/lib/twitter_oauth/statuses.rb +41 -0
- metadata +5 -1
@@ -0,0 +1,18 @@
|
|
1
|
+
module TwitterOAuth
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful;
|
5
|
+
# returns a 401 status code and an error message if not.
|
6
|
+
def authorized?
|
7
|
+
oauth_response = access_token.get('/account/verify_credentials.json')
|
8
|
+
return oauth_response.class == Net::HTTPOK
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns the remaining number of API requests available to the requesting user before the API limit is reached for the current hour.
|
12
|
+
def rate_limit_status
|
13
|
+
oauth_response = access_token.get('/account/rate_limit_status.json')
|
14
|
+
JSON.parse(oauth_response.body)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'twitter_oauth/account'
|
2
|
+
require 'twitter_oauth/statuses'
|
3
|
+
require 'twitter_oauth/direct_messages'
|
4
|
+
|
5
|
+
module TwitterOAuth
|
6
|
+
class Client
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@username = options[:username]
|
10
|
+
@token = options[:token]
|
11
|
+
@secret = options[:secret]
|
12
|
+
end
|
13
|
+
|
14
|
+
def authorize(token, secret)
|
15
|
+
request_token = OAuth::RequestToken.new(
|
16
|
+
consumer, token, secret
|
17
|
+
)
|
18
|
+
@access_token = request_token.get_access_token
|
19
|
+
@token = @access_token.token
|
20
|
+
@secret = @access_token.secret
|
21
|
+
@access_token
|
22
|
+
end
|
23
|
+
|
24
|
+
def show(username = @username)
|
25
|
+
oauth_response = access_token.get("/users/show/#{username}.json")
|
26
|
+
JSON.parse(oauth_response.body)
|
27
|
+
end
|
28
|
+
|
29
|
+
def request_token
|
30
|
+
consumer.get_request_token
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def consumer
|
35
|
+
@consumer ||= OAuth::Consumer.new(
|
36
|
+
CLIENT_KEY,
|
37
|
+
CLIENT_SECRET,
|
38
|
+
{ :site=>"http://twitter.com" }
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def access_token
|
43
|
+
@access_token ||= OAuth::AccessToken.new(consumer, @token, @secret)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module TwitterOAuth
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Returns a list of the 20 most recent direct messages sent to the authenticating user.
|
5
|
+
def messages
|
6
|
+
oauth_response = access_token.get('/direct_messages.json')
|
7
|
+
JSON.parse(oauth_response.body)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns a list of the 20 most recent direct messages sent by the authenticating user.
|
11
|
+
def sent_messages
|
12
|
+
oauth_response = access_token.get('/direct_messages/sent.json')
|
13
|
+
JSON.parse(oauth_response.body)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Sends a new direct message to the specified user from the authenticating user.
|
17
|
+
def message(user, text)
|
18
|
+
oauth_response = access_token.post('/direct_messages/new.json', :user => user, :text => text)
|
19
|
+
JSON.parse(oauth_response.body)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module TwitterOAuth
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Returns the 20 most recent statuses from non-protected users who have set a custom user icon.
|
5
|
+
def public_timeline
|
6
|
+
oauth_response = access_token.get('/statuses/public_timeline.json')
|
7
|
+
JSON.parse(oauth_response.body)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns the 20 most recent statuses posted by the authenticating user and that user's friends.
|
11
|
+
def friends_timeline
|
12
|
+
oauth_response = access_token.get('/statuses/friends_timeline.json')
|
13
|
+
JSON.parse(oauth_response.body)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns the 20 most recent statuses posted from the authenticating user.
|
17
|
+
def user
|
18
|
+
oauth_response = access_token.get('/statuses/user_timeline.json')
|
19
|
+
JSON.parse(oauth_response.body)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns a single status, specified by the id parameter below.
|
23
|
+
def status(id)
|
24
|
+
oauth_response = access_token.get("/statuses/show/#{id}.json")
|
25
|
+
JSON.parse(oauth_response.body)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Updates the authenticating user's status.
|
29
|
+
def update(message)
|
30
|
+
oauth_response = access_token.post('/statuses/update.json', :status => message)
|
31
|
+
JSON.parse(oauth_response.body)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns the 20 most recent @replies (status updates prefixed with @username) for the authenticating user.
|
35
|
+
def replies
|
36
|
+
oauth_response = access_token.get('/statuses/replies.json')
|
37
|
+
JSON.parse(oauth_response.body)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moomerman-twitter_oauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Taylor
|
@@ -44,6 +44,10 @@ files:
|
|
44
44
|
- README.textile
|
45
45
|
- lib/twitter_oauth
|
46
46
|
- lib/twitter_oauth.rb
|
47
|
+
- lib/twitter_oauth/client.rb
|
48
|
+
- lib/twitter_oauth/account.rb
|
49
|
+
- lib/twitter_oauth/statuses.rb
|
50
|
+
- lib/twitter_oauth/direct_messages.rb
|
47
51
|
has_rdoc: false
|
48
52
|
homepage: http://github.com/moomerman/twitter_oauth
|
49
53
|
post_install_message:
|