jonathannelson-massauth 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +22 -0
- data/README.rdoc +37 -0
- data/lib/massauth.rb +10 -0
- data/lib/massauth/account_helpers.rb +29 -0
- data/lib/massauth/authorization.rb +33 -0
- data/lib/massauth/exceptions.rb +14 -0
- data/lib/massauth/message_helpers.rb +23 -0
- data/lib/massauth/search_helpers.rb +11 -0
- data/lib/massauth/status_helpers.rb +36 -0
- data/test/massauth_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +68 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 Jonathan Nelson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
22
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
= MassAuth
|
2
|
+
|
3
|
+
MassAuth is a Twitter OAuth client library
|
4
|
+
|
5
|
+
Requirements:
|
6
|
+
OAuth Gem - http://github.com/pelle/oauth/tree/master
|
7
|
+
Twitter Gem - http://github.com/jnunemaker/twitter/tree/master
|
8
|
+
|
9
|
+
MassAuth is a library to communicate with Twitter with the help of OAuth. There are both public and private request types. For public, you need just to create MASSAUTH::Base instance:
|
10
|
+
|
11
|
+
tconnection = MASSAUTH::Base.new
|
12
|
+
tconnection.user_info('username')
|
13
|
+
tconnection.search('keyword',page, per_page)
|
14
|
+
tconnection.public_timeline
|
15
|
+
|
16
|
+
To act on behalf of twitter user, you need consumer key and consumer secret:
|
17
|
+
|
18
|
+
tconnection = MASSAUTH::Base.new(:consumer_key => KEY, :consumer_secret => SECRET)
|
19
|
+
|
20
|
+
Then, you need to get request token:
|
21
|
+
|
22
|
+
request_token = tconnection.request_token
|
23
|
+
|
24
|
+
and redirect user to request_token.authorize_url
|
25
|
+
|
26
|
+
After that, get access token
|
27
|
+
|
28
|
+
session[:access_token] = tconnection.authorize(session[:request_token],session[:request_token_secret])
|
29
|
+
|
30
|
+
If you don't want to reauthenticate user every time he logs in, you can just store his access_token.token and access_token.secret somewhere.
|
31
|
+
|
32
|
+
NB: All methods raise MASSAUTH::TwitterOAuthError
|
33
|
+
|
34
|
+
|
35
|
+
== Copyright
|
36
|
+
|
37
|
+
Copyright (c) 2009 Jonathan Nelson. See LICENSE for details.
|
data/lib/massauth.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'oauth'
|
2
|
+
require 'json'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
require "massauth/exceptions"
|
6
|
+
require "massauth/account_helpers"
|
7
|
+
require "massauth/message_helpers"
|
8
|
+
require "massauth/status_helpers"
|
9
|
+
require "massauth/search_helpers"
|
10
|
+
require "massauth/authorization"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module MASSAUTH
|
2
|
+
class Base
|
3
|
+
|
4
|
+
def authorized?
|
5
|
+
response = access_token.get('/account/verify_credentials.json')
|
6
|
+
return response.class == Net::HTTPOK
|
7
|
+
end
|
8
|
+
|
9
|
+
def verify_credentials
|
10
|
+
response = access_token.get('/account/verify_credentials.json')
|
11
|
+
return_validated(response.body)
|
12
|
+
end
|
13
|
+
|
14
|
+
def rate_limit_status
|
15
|
+
response = access_token.get('/account/rate_limit_status.json')
|
16
|
+
return_validated(response.body)
|
17
|
+
end
|
18
|
+
|
19
|
+
def user_info(username)
|
20
|
+
response = access_token.get("/users/show/#{username}.json")
|
21
|
+
return_validated(response.body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_friendship_and_follow(username)
|
25
|
+
response = access_token.post('/friendships/create/#{username}.json',"follow=true")
|
26
|
+
return_validated(response.body)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module MASSAUTH
|
2
|
+
class Base
|
3
|
+
|
4
|
+
def initialize(options = {})
|
5
|
+
@consumer_key = options[:consumer_key]
|
6
|
+
@consumer_secret = options[:consumer_secret]
|
7
|
+
@token = options[:token]
|
8
|
+
@secret = options[:secret]
|
9
|
+
end
|
10
|
+
|
11
|
+
def authorize(token, secret)
|
12
|
+
request_token = OAuth::RequestToken.new(consumer, token, secret)
|
13
|
+
@access_token = request_token.get_access_token
|
14
|
+
@token = @access_token.token
|
15
|
+
@secret = @access_token.secret
|
16
|
+
@access_token
|
17
|
+
end
|
18
|
+
|
19
|
+
def request_token
|
20
|
+
consumer.get_request_token
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def consumer
|
25
|
+
@consumer ||= OAuth::Consumer.new(@consumer_key, @consumer_secret, :site =>"http://twitter.com" )
|
26
|
+
end
|
27
|
+
|
28
|
+
def access_token
|
29
|
+
@access_token ||= OAuth::AccessToken.new(consumer, @token, @secret)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MASSAUTH
|
2
|
+
class TwitterOAuthError < StandardError; end
|
3
|
+
|
4
|
+
class Base
|
5
|
+
def return_validated(response)
|
6
|
+
result = JSON.parse(response)
|
7
|
+
if result.is_a? Hash and result['error']
|
8
|
+
raise TwitterOAuthError, result['error']
|
9
|
+
else
|
10
|
+
result
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module TwitterOAuth
|
2
|
+
class Base
|
3
|
+
|
4
|
+
# Returns a list of the 20 most recent direct messages sent to the authenticating user.
|
5
|
+
def messages
|
6
|
+
response = access_token.get('/direct_messages.json')
|
7
|
+
return_validated(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
|
+
response = access_token.get('/direct_messages/sent.json')
|
13
|
+
return_validated(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
|
+
response = access_token.post('/direct_messages/new.json', :user => user, :text => text)
|
19
|
+
return_validated(response.body)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
module MASSAUTH
|
3
|
+
class Base
|
4
|
+
|
5
|
+
def status_by_id(id)
|
6
|
+
response = access_token.get("/statuses/show/#{id}.json")
|
7
|
+
return_validated(response.body)
|
8
|
+
end
|
9
|
+
|
10
|
+
def public_timeline
|
11
|
+
response = access_token.get('/statuses/public_timeline.json')
|
12
|
+
return_validated(response.body)
|
13
|
+
end
|
14
|
+
|
15
|
+
def friends_timeline
|
16
|
+
response = access_token.get('/statuses/friends_timeline.json')
|
17
|
+
return_validated(response.body)
|
18
|
+
end
|
19
|
+
|
20
|
+
def user_timeline
|
21
|
+
response = access_token.get('/statuses/user_timeline.json')
|
22
|
+
return_validated(response.body)
|
23
|
+
end
|
24
|
+
|
25
|
+
def update(message)
|
26
|
+
response = access_token.post('/statuses/update.json', :status => message)
|
27
|
+
return_validated(response.body)
|
28
|
+
end
|
29
|
+
|
30
|
+
def replies
|
31
|
+
response = access_token.get('/statuses/replies.json')
|
32
|
+
return_validated(response.body)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jonathannelson-massauth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Nelson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-29 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: |
|
18
|
+
jonathannelson@me.com
|
19
|
+
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files:
|
25
|
+
- README.rdoc
|
26
|
+
- LICENSE
|
27
|
+
files:
|
28
|
+
- README.rdoc
|
29
|
+
- lib/massauth
|
30
|
+
- lib/massauth/account_helpers.rb
|
31
|
+
- lib/massauth/authorization.rb
|
32
|
+
- lib/massauth/exceptions.rb
|
33
|
+
- lib/massauth/message_helpers.rb
|
34
|
+
- lib/massauth/search_helpers.rb
|
35
|
+
- lib/massauth/status_helpers.rb
|
36
|
+
- lib/massauth.rb
|
37
|
+
- test/massauth_test.rb
|
38
|
+
- test/test_helper.rb
|
39
|
+
- LICENSE
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/jonathannelson/massauth
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --inline-source
|
45
|
+
- --charset=UTF-8
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.2.0
|
64
|
+
signing_key:
|
65
|
+
specification_version: 2
|
66
|
+
summary: TODO
|
67
|
+
test_files: []
|
68
|
+
|