namelessjon-twitter_oauth 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +76 -0
- data/Rakefile +38 -0
- data/VERSION +1 -0
- data/lib/twitter_oauth.rb +8 -0
- data/lib/twitter_oauth/account.rb +42 -0
- data/lib/twitter_oauth/blocks.rb +15 -0
- data/lib/twitter_oauth/client.rb +70 -0
- data/lib/twitter_oauth/direct_messages.rb +25 -0
- data/lib/twitter_oauth/favorites.rb +17 -0
- data/lib/twitter_oauth/friendships.rb +31 -0
- data/lib/twitter_oauth/notifications.rb +15 -0
- data/lib/twitter_oauth/search.rb +20 -0
- data/lib/twitter_oauth/status.rb +25 -0
- data/lib/twitter_oauth/timeline.rb +56 -0
- data/lib/twitter_oauth/user.rb +15 -0
- data/lib/twitter_oauth/utils.rb +34 -0
- data/test/client_test.rb +43 -0
- data/test/test_helper.rb +10 -0
- data/twitter_oauth.gemspec +39 -0
- metadata +124 -0
data/README.textile
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
h1. Twitter OAuth REST API client library for Ruby
|
2
|
+
|
3
|
+
To make authorized requests with the client library you'll need to [create a Twitter OAuth Application](http://twitter.com/oauth_clients/new).
|
4
|
+
|
5
|
+
See [sinitter](http://github.com/moomerman/sinitter/tree/master) for a full website integration example.
|
6
|
+
|
7
|
+
h2. Unauthorized request example
|
8
|
+
|
9
|
+
The Twitter API can be called to make public requests without needing any client credentials.
|
10
|
+
Most methods will not work in this mode but some of them do. An example to retrieve the public details
|
11
|
+
about a Twitter user is below.
|
12
|
+
|
13
|
+
<pre><code>client = TwitterOAuth::Client.new
|
14
|
+
|
15
|
+
puts client.show('twitter')
|
16
|
+
=> => {"status"=>{"truncated"=>false, "favorited"=>false, "text"=>"Update on service issues http://tinyurl.com/ca872j", "id"=>1357776683, "in_reply_to_user_id"=>nil, "in_reply_to_status_id"=>nil, "source"=>"<a href=\"http://twitterfeed.com\">twitterfeed</a>", "created_at"=>"Fri Mar 20 01:17:35 +0000 2009"}, "name"=>"Twitter", "profile_sidebar_fill_color"=>"CDFFFF", "profile_sidebar_border_color"=>"8a6447", "profile_background_tile"=>false, "profile_link_color"=>"0000ff", "url"=>"http://twitter.com", "favourites_count"=>0, "id"=>783214, "description"=>"Always wondering what everyone's doing.", "profile_text_color"=>"000000", "protected"=>false, "utc_offset"=>-28800, "screen_name"=>"twitter", "profile_background_color"=>"9ae4e8", "time_zone"=>"Pacific Time (US & Canada)", "followers_count"=>469150, "profile_background_image_url"=>"http://static.twitter.com/images/themes/theme1/bg.gif", "friends_count"=>30, "statuses_count"=>290, "location"=>"San Francisco, CA", "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/75075164/twitter_bird_profile_normal.png", "created_at"=>"Tue Feb 20 14:35:54 +0000 2007"}
|
17
|
+
</code></pre>
|
18
|
+
|
19
|
+
You can also access to the search API which is available in either authorized or unauthorized modes.
|
20
|
+
|
21
|
+
<pre><code>search = client.search('twitter')
|
22
|
+
search.results.size => 20
|
23
|
+
search.results.first.from_user => "josephpred"
|
24
|
+
search.results.first.text
|
25
|
+
=> "Useful public service Twitter account for those of you hitting Tahoe or just needing to cross the pass to Reno: @i80chains"
|
26
|
+
</code></pre>
|
27
|
+
|
28
|
+
h2. Authorized request example
|
29
|
+
|
30
|
+
To use the full power of the Twitter API you need to authorize your application and a valid Twitter user via OAuth.
|
31
|
+
An example showing how to update the status of an authorized user is below.
|
32
|
+
|
33
|
+
Firstly we need to create an instance of the client with your application client credentials you have been given by Twitter
|
34
|
+
when you set up your application.
|
35
|
+
|
36
|
+
<pre><code>client = TwitterOAuth::Client.new(
|
37
|
+
:consumer_key => 'YOUR_APP_CONSUMER_KEY',
|
38
|
+
:consumer_secret => 'YOURA_APP_CONSUMER_SECRET'
|
39
|
+
)
|
40
|
+
request_token = client.request_token(:oauth_callback => oauth_confirm_url)
|
41
|
+
#:oauth_callback required for web apps, since oauth gem by default forse PIN-based flow
|
42
|
+
#( see http://groups.google.com/group/twitter-development-talk/browse_thread/thread/472500cfe9e7cdb9/848f834227d3e64d )
|
43
|
+
|
44
|
+
|
45
|
+
request_token.authorize_url
|
46
|
+
=> http://twitter.com/oauth/authorize?oauth_token=TOKEN
|
47
|
+
</code></pre>
|
48
|
+
|
49
|
+
In your application your user would be redirected to Twitter to authorize the application at this point. You'll need to store
|
50
|
+
the request token (usually in the session) for later. The code continues below assuming the user has authorized your application.
|
51
|
+
|
52
|
+
<pre><code>access_token = client.authorize(
|
53
|
+
request_token.token,
|
54
|
+
request_token.secret,
|
55
|
+
:oauth_verifier => params[:oauth_verifier]
|
56
|
+
)
|
57
|
+
|
58
|
+
client.authorized?
|
59
|
+
=> true
|
60
|
+
|
61
|
+
client.update('checking out the twitter_oauth library') # sends a twitter status update
|
62
|
+
</code></pre>
|
63
|
+
|
64
|
+
Now if you keep hold of the access_token (usually in the database) for this user you won't need to re-authorize them next time. When you create an instance of the client you can just pass in the access token and secret that you have stored.
|
65
|
+
|
66
|
+
<pre><code>access_token = @user.access_token # assuming @user
|
67
|
+
client = TwitterOAuth::Client.new(
|
68
|
+
:consumer_key => 'YOUR_CONSUMER_KEY',
|
69
|
+
:consumer_secret => 'YOUR-CONSUMER-SECRET',
|
70
|
+
:token => access_token.token,
|
71
|
+
:secret => access_token.secret
|
72
|
+
)
|
73
|
+
|
74
|
+
client.authorized?
|
75
|
+
=> true
|
76
|
+
</code></pre>
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
require 'shoulda/tasks'
|
3
|
+
|
4
|
+
|
5
|
+
task :default => ["test:units"]
|
6
|
+
|
7
|
+
desc "Run basic tests"
|
8
|
+
Rake::TestTask.new("test:units") { |t|
|
9
|
+
t.pattern = 'test/**/*_test.rb'
|
10
|
+
t.verbose = true
|
11
|
+
t.warning = true
|
12
|
+
}
|
13
|
+
|
14
|
+
begin
|
15
|
+
require 'jeweler'
|
16
|
+
|
17
|
+
Jeweler::Tasks.new do |gem|
|
18
|
+
gem.name = 'namelessjon-twitter_oauth'
|
19
|
+
gem.summary = 'twitter_oauth is a Ruby library for talking to twitter using the new oauth method.'
|
20
|
+
gem.description = "A fork of twitter_oauth library. With added yajl (and that's it)"
|
21
|
+
gem.email = 'jonathan.stott@gmail.com'
|
22
|
+
gem.homepage = 'http://github.com/namelessjon/twitter_oauth'
|
23
|
+
gem.authors = ["Jonathan Stott", "Richard Taylor" ]
|
24
|
+
|
25
|
+
|
26
|
+
gem.add_dependency 'oauth', '>= 0.3.6'
|
27
|
+
gem.add_dependency 'yajl-ruby', '>= 0.6.5'
|
28
|
+
gem.add_dependency 'mime-types', '>= 1.15'
|
29
|
+
|
30
|
+
gem.add_development_dependency 'shoulda'
|
31
|
+
gem.add_development_dependency 'mocha'
|
32
|
+
end
|
33
|
+
|
34
|
+
Jeweler::GemcutterTasks.new
|
35
|
+
rescue LoadError
|
36
|
+
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
|
37
|
+
end
|
38
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.0
|
@@ -0,0 +1,42 @@
|
|
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 client info
|
12
|
+
def info
|
13
|
+
get('/account/verify_credentials.json')
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns the remaining number of API requests available to the requesting user before the API limit is reached for the current hour.
|
17
|
+
def rate_limit_status
|
18
|
+
get('/account/rate_limit_status.json')
|
19
|
+
end
|
20
|
+
|
21
|
+
# Updates profile background image. Takes a File object and optional tile argument.
|
22
|
+
# Returns extended user info object.
|
23
|
+
def update_profile_background_image(image, tile = false)
|
24
|
+
body, headers = http_multipart_data({:image => image, :tile => tile})
|
25
|
+
post('/account/update_profile_background_image.json', body, headers)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Updates profile avatar image. Takes a File object which should be an image.
|
29
|
+
# Returns extended user info object.
|
30
|
+
def update_profile_image(image)
|
31
|
+
body, headers = http_multipart_data({:image => image})
|
32
|
+
post('/account/update_profile_image.json', body, headers)
|
33
|
+
end
|
34
|
+
|
35
|
+
# colors hash must contain at least one or more of the following keys :profile_background_color, :profile_text_color, :profile_link_color, :profile_sidebar_fill_color, :profile_sidebar_border_color
|
36
|
+
# returns extended user info object.
|
37
|
+
def update_profile_colors(colors)
|
38
|
+
post('/account/update_profile_colors.json', colors)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'twitter_oauth/timeline'
|
2
|
+
require 'twitter_oauth/status'
|
3
|
+
require 'twitter_oauth/account'
|
4
|
+
require 'twitter_oauth/direct_messages'
|
5
|
+
require 'twitter_oauth/search'
|
6
|
+
require 'twitter_oauth/notifications'
|
7
|
+
require 'twitter_oauth/blocks'
|
8
|
+
require 'twitter_oauth/friendships'
|
9
|
+
require 'twitter_oauth/user'
|
10
|
+
require 'twitter_oauth/favorites'
|
11
|
+
require 'twitter_oauth/utils'
|
12
|
+
|
13
|
+
module TwitterOAuth
|
14
|
+
class Client
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
@consumer_key = options[:consumer_key]
|
18
|
+
@consumer_secret = options[:consumer_secret]
|
19
|
+
@token = options[:token]
|
20
|
+
@secret = options[:secret]
|
21
|
+
end
|
22
|
+
|
23
|
+
def authorize(token, secret, options = {})
|
24
|
+
request_token = OAuth::RequestToken.new(
|
25
|
+
consumer, token, secret
|
26
|
+
)
|
27
|
+
@access_token = request_token.get_access_token(options)
|
28
|
+
@token = @access_token.token
|
29
|
+
@secret = @access_token.secret
|
30
|
+
@access_token
|
31
|
+
end
|
32
|
+
|
33
|
+
def get(url)
|
34
|
+
oauth_response = access_token.get(url)
|
35
|
+
Yajl::Parser.parse(oauth_response.body)
|
36
|
+
end
|
37
|
+
|
38
|
+
def post(url, body = '', headers = {})
|
39
|
+
oauth_response = access_token.post(url, body, headers)
|
40
|
+
Yajl::Parser.parse(oauth_response.body)
|
41
|
+
end
|
42
|
+
|
43
|
+
def show(username)
|
44
|
+
get("/users/show/#{username}.json")
|
45
|
+
end
|
46
|
+
|
47
|
+
def request_token(options={})
|
48
|
+
consumer.get_request_token(options)
|
49
|
+
end
|
50
|
+
|
51
|
+
def authentication_request_token(options={})
|
52
|
+
consumer.options[:authorize_path] = '/oauth/authenticate'
|
53
|
+
request_token(options)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
def consumer
|
58
|
+
@consumer ||= OAuth::Consumer.new(
|
59
|
+
@consumer_key,
|
60
|
+
@consumer_secret,
|
61
|
+
{ :site=>"http://twitter.com" }
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
def access_token
|
66
|
+
@access_token ||= OAuth::AccessToken.new(consumer, @token, @secret)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,25 @@
|
|
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(page=1)
|
6
|
+
get("/direct_messages.json?page=#{page}")
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns a list of the 20 most recent direct messages sent by the authenticating user.
|
10
|
+
def sent_messages
|
11
|
+
get('/direct_messages/sent.json')
|
12
|
+
end
|
13
|
+
|
14
|
+
# Sends a new direct message to the specified user from the authenticating user.
|
15
|
+
def message(user, text)
|
16
|
+
post('/direct_messages/new.json', :user => user, :text => text)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Destroys the direct message specified in the required ID parameter.
|
20
|
+
def message_destroy(id)
|
21
|
+
post("/direct_messages/destroy/#{id}.json")
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module TwitterOAuth
|
2
|
+
class Client
|
3
|
+
|
4
|
+
def favorites(page=1)
|
5
|
+
get("/favorites.json?page=#{page}")
|
6
|
+
end
|
7
|
+
|
8
|
+
def favorite
|
9
|
+
post("/favorites/create/#{id}.json")
|
10
|
+
end
|
11
|
+
|
12
|
+
def unfavorite
|
13
|
+
post("/favorites/destroy/#{id}.json")
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module TwitterOAuth
|
2
|
+
class Client
|
3
|
+
|
4
|
+
def friends_ids(options={})
|
5
|
+
args = options.map{|k,v| "#{k}=#{v}"}.join('&')
|
6
|
+
get("/friends/ids.json?#{args}")
|
7
|
+
end
|
8
|
+
|
9
|
+
def followers_ids(options={})
|
10
|
+
args = options.map{|k,v| "#{k}=#{v}"}.join('&')
|
11
|
+
get("/followers/ids.json?#{args}")
|
12
|
+
end
|
13
|
+
|
14
|
+
# friend this user.
|
15
|
+
def friend(id)
|
16
|
+
post("/friendships/create/#{id}.json")
|
17
|
+
end
|
18
|
+
|
19
|
+
# unfriend.
|
20
|
+
def unfriend(id)
|
21
|
+
post("/friendships/destroy/#{id}.json")
|
22
|
+
end
|
23
|
+
|
24
|
+
# exists?.
|
25
|
+
def exists?(a, b)
|
26
|
+
oauth_response = access_token.get("/friendships/exists.json?user_a=#{a}&user_b=#{b}")
|
27
|
+
oauth_response.body.strip == 'true'
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'yajl/http_stream'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module TwitterOAuth
|
6
|
+
class Client
|
7
|
+
|
8
|
+
def search(q, options={})
|
9
|
+
options[:page] ||= 1
|
10
|
+
options[:per_page] ||= 20
|
11
|
+
uri = URI.parse("http://search.twitter.com/search.json?q=#{URI.escape(q)}&page=#{options[:page]}&rpp=#{options[:per_page]}&since_id=#{options[:since_id]}")
|
12
|
+
|
13
|
+
search_result = Yajl::HttpStream.get(uri)
|
14
|
+
search_result = OpenStruct.new(search_result)
|
15
|
+
search_result.results = search_result.results.collect{|x| OpenStruct.new(x)}
|
16
|
+
search_result
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module TwitterOAuth
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Returns a single status, specified by the id parameter below.
|
5
|
+
def status(id)
|
6
|
+
get("/statuses/show/#{id}.json")
|
7
|
+
end
|
8
|
+
|
9
|
+
# Updates the authenticating user's status.
|
10
|
+
def update(message, options={})
|
11
|
+
post('/statuses/update.json', options.merge(:status => message))
|
12
|
+
end
|
13
|
+
|
14
|
+
# Destroys the status specified by the required ID parameter
|
15
|
+
def status_destroy(id)
|
16
|
+
post("/statuses/destroy/#{id}.json")
|
17
|
+
end
|
18
|
+
|
19
|
+
# Retweets the tweet specified by the id parameter. Returns the original tweet with retweet details embedded.
|
20
|
+
def retweet(id)
|
21
|
+
post("/statuses/retweet/#{id}.json")
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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(options={})
|
6
|
+
args = options.map{|k,v| "#{k}=#{v}"}.join('&')
|
7
|
+
get("/statuses/public_timeline.json?#{args}")
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns the 20 most recent statuses, including retweets, posted by the authenticating user and that user's friends.
|
11
|
+
# This is the equivalent of /timeline/home on the Web.
|
12
|
+
def home_timeline(options={})
|
13
|
+
args = options.map{|k,v| "#{k}=#{v}"}.join('&')
|
14
|
+
get("/statuses/home_timeline.json?#{args}")
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns the 20 most recent statuses posted by the authenticating user and that user's friends.
|
18
|
+
def friends_timeline(options={})
|
19
|
+
args = options.map{|k,v| "#{k}=#{v}"}.join('&')
|
20
|
+
get("/statuses/friends_timeline.json?#{args}")
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns the 20 most recent statuses posted from the authenticating user.
|
24
|
+
def user_timeline(options={})
|
25
|
+
args = options.map{|k,v| "#{k}=#{v}"}.join('&')
|
26
|
+
get("/statuses/user_timeline.json?#{args}")
|
27
|
+
end
|
28
|
+
alias :user :user_timeline
|
29
|
+
|
30
|
+
# Returns the 20 most recent @replies (status updates prefixed with @username) for the authenticating user.
|
31
|
+
def mentions(options={})
|
32
|
+
args = options.map{|k,v| "#{k}=#{v}"}.join('&')
|
33
|
+
get("/statuses/mentions.json?#{args}")
|
34
|
+
end
|
35
|
+
alias :replies :mentions
|
36
|
+
|
37
|
+
# Returns the 20 most recent retweets posted by the authenticating user
|
38
|
+
def retweeted_by_me(options={})
|
39
|
+
args = options.map{|k,v| "#{k}=#{v}"}.join('&')
|
40
|
+
get("/statuses/retweeted_by_me.json?#{args}")
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns the 20 most recent retweets posted by the authenticating user's friends.
|
44
|
+
def retweeted_to_me(options={})
|
45
|
+
args = options.map{|k,v| "#{k}=#{v}"}.join('&')
|
46
|
+
get("/statuses/retweeted_to_me.json?#{args}")
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns the 20 most recent tweets of the authenticated user that have been retweeted by others.
|
50
|
+
def retweets_of_me(options={})
|
51
|
+
args = options.map{|k,v| "#{k}=#{v}"}.join('&')
|
52
|
+
get("/statuses/retweets_of_me.json?#{args}")
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module TwitterOAuth
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Returns the 100 last friends
|
5
|
+
def friends(page=1)
|
6
|
+
get("/statuses/friends.json?page=#{page}")
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns the 100 last followers
|
10
|
+
def followers(page=1)
|
11
|
+
get("/statuses/followers.json?page=#{page}")
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module TwitterOAuth
|
2
|
+
class Client
|
3
|
+
CRLF = "\r\n"
|
4
|
+
|
5
|
+
private
|
6
|
+
# Properly encodes images in form/multipart specification for upload via OAuth.
|
7
|
+
def http_multipart_data(params)
|
8
|
+
body = ""
|
9
|
+
headers = {}
|
10
|
+
|
11
|
+
boundary = Time.now.to_i.to_s(16)
|
12
|
+
|
13
|
+
headers["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
|
14
|
+
params.each do |key,value|
|
15
|
+
esc_key = OAuth::Helper.escape(key.to_s)
|
16
|
+
body << "--#{boundary}#{CRLF}"
|
17
|
+
|
18
|
+
if value.respond_to?(:read)
|
19
|
+
mime_type = MIME::Types.type_for(value.path)[0] || MIME::Types["application/octet-stream"][0]
|
20
|
+
body << "Content-Disposition: form-data; name=\"#{esc_key}\"; filename=\"#{File.basename(value.path)}\"#{CRLF}"
|
21
|
+
body << "Content-Type: #{mime_type.simplified}#{CRLF*2}"
|
22
|
+
body << value.read
|
23
|
+
else
|
24
|
+
body << "Content-Disposition: form-data; name=\"#{esc_key}\"#{CRLF*2}#{value}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
body << "--#{boundary}--#{CRLF*2}"
|
29
|
+
headers["Content-Length"] = body.size.to_s
|
30
|
+
|
31
|
+
return [ body, headers ]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/test/client_test.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/test_helper")
|
2
|
+
|
3
|
+
class ClientTest < Test::Unit::TestCase
|
4
|
+
include TwitterOAuth
|
5
|
+
|
6
|
+
context "A client instance" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@client = Client.new
|
10
|
+
end
|
11
|
+
|
12
|
+
should "be kind of TwitterOAuth" do
|
13
|
+
assert_kind_of TwitterOAuth::Client, @client
|
14
|
+
end
|
15
|
+
|
16
|
+
context "authentication_request_token" do
|
17
|
+
setup do
|
18
|
+
@consumer = stub("oauth consumer", :options => {})
|
19
|
+
@client.stubs(:request_token)
|
20
|
+
@client.stubs(:consumer).returns(@consumer)
|
21
|
+
end
|
22
|
+
|
23
|
+
should "sets consumers authorize path" do
|
24
|
+
@client.authentication_request_token
|
25
|
+
assert_equal @client.consumer.options[:authorize_path], '/oauth/authenticate'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when authorizing" do
|
30
|
+
setup do
|
31
|
+
@request_token = stub('a request token')
|
32
|
+
@access_token = stub_everything('access token')
|
33
|
+
@request_token.stubs(:get_access_token).returns(@access_token)
|
34
|
+
OAuth::RequestToken.stubs(:new).returns(@request_token)
|
35
|
+
end
|
36
|
+
|
37
|
+
should "return an access token" do
|
38
|
+
assert_equal @client.authorize("haha","haha"), @access_token
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{twitter_oauth}
|
5
|
+
s.version = "0.2.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Richard Taylor"]
|
9
|
+
s.date = %q{2009-03-20}
|
10
|
+
s.description = %q{twitter_oauth is a Ruby library for talking to twitter using the new oauth method.}
|
11
|
+
s.email = %q{moomerman@gmail.com}
|
12
|
+
s.files = ["README.textile", "lib/twitter_oauth", "lib/twitter_oauth.rb", "lib/twitter_oauth/client.rb", "lib/twitter_oauth/timeline.rb", "lib/twitter_oauth/account.rb", "lib/twitter_oauth/status.rb", "lib/twitter_oauth/direct_messages.rb", "lib/twitter_oauth/search.rb", "lib/twitter_oauth/blocks.rb" , "lib/twitter_oauth/friendships.rb", "lib/twitter_oauth/notifications.rb", "lib/twitter_oauth/user.rb", "lib/twitter_oauth/favorites.rb", "lib/twitter_oauth/utils.rb"]
|
13
|
+
s.has_rdoc = false
|
14
|
+
s.homepage = %q{http://github.com/moomerman/twitter_oauth}
|
15
|
+
s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{twitter_oauth}
|
18
|
+
s.rubygems_version = %q{1.3.1}
|
19
|
+
s.summary = %q{twitter_oauth is a Ruby library for talking to twitter using the new oauth method.}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 2
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<oauth>, [">= 0.3.1"])
|
27
|
+
s.add_runtime_dependency(%q<yajl-ruby>, [">= 0.6.5"])
|
28
|
+
s.add_runtime_dependency(%q<mime-types>, [">= 1.15"])
|
29
|
+
else
|
30
|
+
s.add_dependency(%q<oauth>, [">= 0.3.1"])
|
31
|
+
s.add_dependency(%q<yajl-ruby>, [">= 0.6.5"])
|
32
|
+
s.add_dependency(%q<mime-types>, [">= 1.15"])
|
33
|
+
end
|
34
|
+
else
|
35
|
+
s.add_dependency(%q<oauth>, [">= 0.3.1"])
|
36
|
+
s.add_dependency(%q<yajl-ruby>, [">= 0.6.5"])
|
37
|
+
s.add_dependency(%q<mime-types>, [">= 1.15"])
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: namelessjon-twitter_oauth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Stott
|
8
|
+
- Richard Taylor
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-11-25 00:00:00 +00:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: oauth
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.3.6
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: yajl-ruby
|
28
|
+
type: :runtime
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.6.5
|
35
|
+
version:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: mime-types
|
38
|
+
type: :runtime
|
39
|
+
version_requirement:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "1.15"
|
45
|
+
version:
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: shoulda
|
48
|
+
type: :development
|
49
|
+
version_requirement:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: mocha
|
58
|
+
type: :development
|
59
|
+
version_requirement:
|
60
|
+
version_requirements: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
description: A fork of twitter_oauth library. With added yajl (and that's it)
|
67
|
+
email: jonathan.stott@gmail.com
|
68
|
+
executables: []
|
69
|
+
|
70
|
+
extensions: []
|
71
|
+
|
72
|
+
extra_rdoc_files:
|
73
|
+
- README.textile
|
74
|
+
files:
|
75
|
+
- README.textile
|
76
|
+
- Rakefile
|
77
|
+
- VERSION
|
78
|
+
- lib/twitter_oauth.rb
|
79
|
+
- lib/twitter_oauth/account.rb
|
80
|
+
- lib/twitter_oauth/blocks.rb
|
81
|
+
- lib/twitter_oauth/client.rb
|
82
|
+
- lib/twitter_oauth/direct_messages.rb
|
83
|
+
- lib/twitter_oauth/favorites.rb
|
84
|
+
- lib/twitter_oauth/friendships.rb
|
85
|
+
- lib/twitter_oauth/notifications.rb
|
86
|
+
- lib/twitter_oauth/search.rb
|
87
|
+
- lib/twitter_oauth/status.rb
|
88
|
+
- lib/twitter_oauth/timeline.rb
|
89
|
+
- lib/twitter_oauth/user.rb
|
90
|
+
- lib/twitter_oauth/utils.rb
|
91
|
+
- test/client_test.rb
|
92
|
+
- test/test_helper.rb
|
93
|
+
- twitter_oauth.gemspec
|
94
|
+
has_rdoc: true
|
95
|
+
homepage: http://github.com/namelessjon/twitter_oauth
|
96
|
+
licenses: []
|
97
|
+
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options:
|
100
|
+
- --charset=UTF-8
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: "0"
|
108
|
+
version:
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: "0"
|
114
|
+
version:
|
115
|
+
requirements: []
|
116
|
+
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.3.5
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: twitter_oauth is a Ruby library for talking to twitter using the new oauth method.
|
122
|
+
test_files:
|
123
|
+
- test/client_test.rb
|
124
|
+
- test/test_helper.rb
|