jarodluebbert-twitter_oauth 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) Richard Taylor
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,82 @@
1
+ h1. Twitter OAuth REST API client library for Ruby
2
+
3
+ h2. Install the gem
4
+
5
+ sudo gem install twitter_oauth # (via gemcutter)
6
+
7
+ h2. Using the gem
8
+
9
+ To make authorized requests with the client library you'll need to "create a Twitter OAuth Application":http://twitter.com/oauth_clients/new.
10
+
11
+ See "sinitter":http://github.com/moomerman/sinitter/tree/master for a full website integration example.
12
+
13
+ h2. Unauthorized request example
14
+
15
+ The Twitter API can be called to make public requests without needing any client credentials.
16
+ Most methods will not work in this mode but some of them do. An example to retrieve the public details
17
+ about a Twitter user is below.
18
+
19
+ <pre><code>client = TwitterOAuth::Client.new
20
+
21
+ puts client.show('twitter')
22
+ => => {"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"}
23
+ </code></pre>
24
+
25
+ You can also access to the search API which is available in either authorized or unauthorized modes.
26
+
27
+ <pre><code>search = client.search('twitter')
28
+ search.results.size => 20
29
+ search.results.first.from_user => "josephpred"
30
+ search.results.first.text
31
+ => "Useful public service Twitter account for those of you hitting Tahoe or just needing to cross the pass to Reno: @i80chains"
32
+ </code></pre>
33
+
34
+ h2. Authorized request example
35
+
36
+ To use the full power of the Twitter API you need to authorize your application and a valid Twitter user via OAuth.
37
+ An example showing how to update the status of an authorized user is below.
38
+
39
+ Firstly we need to create an instance of the client with your application client credentials you have been given by Twitter
40
+ when you set up your application.
41
+
42
+ <pre><code>client = TwitterOAuth::Client.new(
43
+ :consumer_key => 'YOUR_APP_CONSUMER_KEY',
44
+ :consumer_secret => 'YOURA_APP_CONSUMER_SECRET'
45
+ )
46
+ request_token = client.request_token(:oauth_callback => oauth_confirm_url)
47
+ #:oauth_callback required for web apps, since oauth gem by default force PIN-based flow
48
+ #( see http://groups.google.com/group/twitter-development-talk/browse_thread/thread/472500cfe9e7cdb9/848f834227d3e64d )
49
+
50
+
51
+ request_token.authorize_url
52
+ => http://twitter.com/oauth/authorize?oauth_token=TOKEN
53
+ </code></pre>
54
+
55
+ In your application your user would be redirected to Twitter to authorize the application at this point. You'll need to store
56
+ the request token (usually in the session) for later. The code continues below assuming the user has authorized your application.
57
+
58
+ <pre><code>access_token = client.authorize(
59
+ request_token.token,
60
+ request_token.secret,
61
+ :oauth_verifier => params[:oauth_verifier]
62
+ )
63
+
64
+ client.authorized?
65
+ => true
66
+
67
+ client.update('checking out the twitter_oauth library') # sends a twitter status update
68
+ </code></pre>
69
+
70
+ 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.
71
+
72
+ <pre><code>access_token = @user.access_token # assuming @user
73
+ client = TwitterOAuth::Client.new(
74
+ :consumer_key => 'YOUR_CONSUMER_KEY',
75
+ :consumer_secret => 'YOUR-CONSUMER-SECRET',
76
+ :token => access_token.token,
77
+ :secret => access_token.secret
78
+ )
79
+
80
+ client.authorized?
81
+ => true
82
+ </code></pre>
@@ -0,0 +1,8 @@
1
+ require 'oauth'
2
+ require 'yaml'
3
+ require 'mime/types'
4
+
5
+ require 'twitter_oauth/client'
6
+
7
+ module TwitterOAuth
8
+ end
@@ -0,0 +1,53 @@
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
+ # Sets values that users are able to set under the "Account" tab of their settings page.
42
+ # Valid parameters are:
43
+ # :name Full name associated with the profile. Maximum of 20 characters.
44
+ # :url URL associated with the profile. Will be prepended with "http://" if not present. Maximum of 100 characters.
45
+ # :location The city or country describing where the user of the account is located. The contents are not normalized
46
+ # or geocoded in any way. Maximum of 30 characters.
47
+ # :description A description of the user owning the account. Maximum of 160 characters.
48
+ def update_profile(params)
49
+ post('/account/update_profile', params)
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,33 @@
1
+ module TwitterOAuth
2
+ class Client
3
+
4
+ # Blocks the user specified in the ID parameter as the authenticating user.
5
+ # Destroys a friendship to the blocked user if it exists.
6
+ # Returns the blocked user in the requested format when successful.
7
+ def block(id)
8
+ post("/blocks/create/#{id}.json")
9
+ end
10
+
11
+ # Un-blocks the user specified in the ID parameter for the authenticating user.
12
+ # Returns the un-blocked user in the requested format when successful.
13
+ def unblock(id)
14
+ post("/blocks/destroy/#{id}.json")
15
+ end
16
+
17
+ # Returns if the authenticating user is blocking a target user.
18
+ def blocked?(id)
19
+ get("/blocks/exists/#{id}.json")
20
+ end
21
+
22
+ # Returns an array of user objects that the authenticating user is blocking.
23
+ def blocking
24
+ get("/blocks/blocking.json")
25
+ end
26
+
27
+ # Returns an array of numeric user ids the authenticating user is blocking.
28
+ def blocking_ids
29
+ get("/blocks/blocking/ids.json")
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,84 @@
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
+ require 'twitter_oauth/trends'
13
+ require 'twitter_oauth/lists'
14
+ require 'twitter_oauth/saved_searches'
15
+ require 'twitter_oauth/spam'
16
+
17
+ module TwitterOAuth
18
+ class Client
19
+
20
+ def initialize(options = {})
21
+ @consumer_key = options[:consumer_key]
22
+ @consumer_secret = options[:consumer_secret]
23
+ @token = options[:token]
24
+ @secret = options[:secret]
25
+ end
26
+
27
+ def authorize(token, secret, options = {})
28
+ request_token = OAuth::RequestToken.new(
29
+ consumer, token, secret
30
+ )
31
+ @access_token = request_token.get_access_token(options)
32
+ @token = @access_token.token
33
+ @secret = @access_token.secret
34
+ @access_token
35
+ end
36
+
37
+ def show(username)
38
+ get("/users/show/#{username}.json")
39
+ end
40
+
41
+ # Returns the string "ok" in the requested format with a 200 OK HTTP status code.
42
+ def test
43
+ get("/help/test.json")
44
+ end
45
+
46
+ def request_token(options={})
47
+ consumer.get_request_token(options)
48
+ end
49
+
50
+ def authentication_request_token(options={})
51
+ consumer.options[:authorize_path] = '/oauth/authenticate'
52
+ request_token(options)
53
+ end
54
+
55
+ private
56
+ def consumer
57
+ @consumer ||= OAuth::Consumer.new(
58
+ @consumer_key,
59
+ @consumer_secret,
60
+ { :site=>"https://api.twitter.com" }
61
+ )
62
+ end
63
+
64
+ def access_token
65
+ @access_token ||= OAuth::AccessToken.new(consumer, @token, @secret)
66
+ end
67
+
68
+ def get(url)
69
+ oauth_response = access_token.get(url)
70
+ JSON.parse(oauth_response.body)
71
+ end
72
+
73
+ def post(url, body = '', headers = {})
74
+ oauth_response = access_token.post(url, body, headers)
75
+ JSON.parse(oauth_response.body)
76
+ end
77
+
78
+ def delete(url)
79
+ oauth_response = access_token.delete(url)
80
+ JSON.parse(oauth_response.body)
81
+ end
82
+ end
83
+ end
84
+
@@ -0,0 +1,29 @@
1
+ module TwitterOAuth
2
+ class Client
3
+
4
+ # Return the most recent direct messages sent to the authenticating user.
5
+ # By default, returns the last 20. See http://apiwiki.twitter.com/Twitter-REST-API-Method:-direct_messages
6
+ # for other options
7
+ def messages(options={})
8
+ args = options.map{|k,v| "#{k}=#{v}"}.join('&')
9
+ get("/direct_messages.json?#{args}")
10
+ end
11
+
12
+ # By default, returns a list of the 20 most recent direct messages sent by the authenticating user.
13
+ def sent_messages(options={})
14
+ args = options.map{|k,v| "#{k}=#{v}"}.join('&')
15
+ get("/direct_messages/sent.json?#{args}")
16
+ end
17
+
18
+ # Sends a new direct message to the specified user from the authenticating user.
19
+ def message(user, text)
20
+ post('/direct_messages/new.json', :user => user, :text => text)
21
+ end
22
+
23
+ # Destroys the direct message specified in the required ID parameter.
24
+ def message_destroy(id)
25
+ post("/direct_messages/destroy/#{id}.json")
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ module TwitterOAuth
2
+ class Client
3
+
4
+ # Returns the 20 most recent favorite statuses for the authenticating user or user specified by the ID parameter.
5
+ def favorites(page=1)
6
+ get("/favorites.json?page=#{page}")
7
+ end
8
+
9
+ # Favorites the status specified in the ID parameter as the authenticating user.
10
+ # Returns the favorite status when successful.
11
+ def favorite(id)
12
+ post("/favorites/create/#{id}.json")
13
+ end
14
+
15
+ # Un-favorites the status specified in the ID parameter as the authenticating user.
16
+ # Returns the un-favorited status when successful.
17
+ def unfavorite(id)
18
+ post("/favorites/destroy/#{id}.json")
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ module TwitterOAuth
2
+ class Client
3
+
4
+ # Returns an array of numeric IDs for every user the specified user is following.
5
+ def friends_ids(options={})
6
+ args = options.map{|k,v| "#{k}=#{v}"}.join('&')
7
+ get("/friends/ids.json?#{args}")
8
+ end
9
+
10
+ # Returns an array of numeric IDs for every user following the specified user.
11
+ def followers_ids(options={})
12
+ args = options.map{|k,v| "#{k}=#{v}"}.join('&')
13
+ get("/followers/ids.json?#{args}")
14
+ end
15
+
16
+ # Allows the authenticating user to follow the specified user. Returns the befriended user when successful.
17
+ def friend(id)
18
+ post("/friendships/create/#{id}.json")
19
+ end
20
+
21
+ # Allows the authenticating users to unfollow the specified user. Returns the unfollowed user when successful.
22
+ def unfriend(id)
23
+ post("/friendships/destroy/#{id}.json")
24
+ end
25
+
26
+ # Tests for the existence of friendship between two users. Will return true if user_a follows user_b, otherwise will return false.
27
+ # You are better off using get_friendship as it returns more extended information.
28
+ def friends?(a, b)
29
+ oauth_response = access_token.get("/friendships/exists.json?user_a=#{a}&user_b=#{b}")
30
+ oauth_response.body.strip == 'true'
31
+ end
32
+
33
+ # Returns detailed information about the relationship between two users.
34
+ def get_friendship(a, b)
35
+ get("/friendships/show.json?source_screen_name=#{a}&target_screen_name=#{b}")
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,100 @@
1
+ module TwitterOAuth
2
+ class Client
3
+
4
+ #
5
+ # List methods
6
+ #
7
+
8
+ # Creates a new list for the authenticated user. Accounts are limited to 20 lists.
9
+ def create_list(user, list, options={})
10
+ post("/#{user}/lists.json", options.merge(:name => list))
11
+ end
12
+
13
+ # Updates the specified list.
14
+ def update_list(user, list, options={})
15
+ post("/#{user}/lists/#{list}.json", options)
16
+ end
17
+
18
+ # List the lists of the specified user.
19
+ # Private lists will be included if the authenticated user is the same as the user whose lists are being returned.
20
+ def get_lists(user)
21
+ get("/#{user}/lists.json")
22
+ end
23
+
24
+ # Show the specified list. Private lists will only be shown if the authenticated user owns the specified list.
25
+ def get_list(user, list)
26
+ get("/#{user}/lists/#{list}.json")
27
+ end
28
+
29
+ # Deletes the specified list. Must be owned by the authenticated user.
30
+ def delete_list(user, list)
31
+ delete("/#{user}/lists/#{list}.json")
32
+ end
33
+
34
+ # Show tweet timeline for members of the specified list.
35
+ def list_statuses(user, list)
36
+ get("/#{user}/lists/#{list}/statuses.json")
37
+ end
38
+
39
+ # List the lists the specified user has been added to.
40
+ def list_memberships(user)
41
+ get("/#{user}/lists/memberships.json")
42
+ end
43
+
44
+ # List the lists the specified user follows.
45
+ def list_subscriptions(user)
46
+ get("/#{user}/lists/subscriptions.json")
47
+ end
48
+
49
+ #
50
+ # List Members Methods
51
+ #
52
+
53
+ # Returns the members of the specified list.
54
+ def list_members(user, list)
55
+ get("/#{user}/#{list}/members.json")
56
+ end
57
+
58
+ # Add a member to a list. The authenticated user must own the list to be able to add members to it.
59
+ # Lists are limited to having 500 members.
60
+ def add_member_to_list(user, list, member_id, options={})
61
+ post("/#{user}/#{list}/members.json", options.merge(:id => member_id))
62
+ end
63
+
64
+ # Removes the specified member from the list.
65
+ # The authenticated user must be the list's owner to remove members from the list.
66
+ def remove_member_from_list(user, list, member_id)
67
+ delete("/#{user}/#{list}/members.json?id=#{member_id}")
68
+ end
69
+
70
+ # Check if a user is a member of the specified list.
71
+ def get_member_of_list(user, list, member_id)
72
+ get("/#{user}/#{list}/members/#{member_id}.json")
73
+ end
74
+
75
+ #
76
+ # List Subscribers Methods
77
+ #
78
+
79
+ # Returns the subscribers of the specified list.
80
+ def list_subscribers(user, list)
81
+ get("/#{user}/#{list}/subscribers.json")
82
+ end
83
+
84
+ # Make the authenticated user follow the specified list.
85
+ def subscribe_to_list(user, list, options={})
86
+ post("/#{user}/#{list}/subscribers.json")
87
+ end
88
+
89
+ # Unsubscribes the authenticated user form the specified list.
90
+ def unsubscribe_from_list(user, list)
91
+ delete("/#{user}/#{list}/subscribers.json")
92
+ end
93
+
94
+ # Check if the specified user is a subscriber of the specified list.
95
+ def get_subscriber_of_list(user, list, subscriber_id)
96
+ get("/#{user}/#{list}/subscribers/#{subscriber_id}.json")
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,17 @@
1
+ module TwitterOAuth
2
+ class Client
3
+
4
+ # Enables device notifications for updates from the specified user.
5
+ # Returns the specified user when successful.
6
+ def follow(id)
7
+ post("/notifications/follow/#{id}.json")
8
+ end
9
+
10
+ # Disables notifications for updates from the specified user to the authenticating user.
11
+ # Returns the specified user when successful.
12
+ def leave(id)
13
+ post("/notifications/leave/#{id}.json")
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ module TwitterOAuth
2
+ class Client
3
+
4
+ # Returns the authenticated user's saved search queries.
5
+ def saved_searches
6
+ get("/saved_searches.json")
7
+ end
8
+
9
+ # Retrieve the data for a saved search owned by the authenticating user specified by the given id.
10
+ def get_saved_search(search_id)
11
+ get("/saved_searches/show/#{search_id}.json")
12
+ end
13
+
14
+ # Creates a saved search for the authenticated user.
15
+ def create_saved_search(query)
16
+ post("/saved_searches/create.json", :query => query)
17
+ end
18
+
19
+ def delete_saved_search(search_id)
20
+ post("/saved_searches/destroy/#{search_id}.json")
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,35 @@
1
+ require 'open-uri'
2
+
3
+ module TwitterOAuth
4
+ class Client
5
+
6
+ def search(q, options={})
7
+ options[:page] ||= 1
8
+ options[:rpp] ||= 20
9
+ options[:q] = URI.escape(q)
10
+ args = options.map{|k,v| "#{k}=#{v}"}.join('&')
11
+ search_get("/search.json?#{args}")
12
+ end
13
+
14
+ # Returns the current top 10 trending topics on Twitter.
15
+ def current_trends
16
+ search_get("/trends/current.json")
17
+ end
18
+
19
+ # Returns the top 20 trending topics for each hour in a given day.
20
+ def daily_trends
21
+ search_get("/trends/daily.json")
22
+ end
23
+
24
+ # Returns the top 30 trending topics for each day in a given week.
25
+ def weekly_trends
26
+ search_get("/trends/weekly.json")
27
+ end
28
+
29
+ private
30
+ def search_get(path)
31
+ response = open('http://search.twitter.com' + path, 'User-Agent' => 'github.com/moomerman/twitter_outh')
32
+ JSON.parse(response.read)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,10 @@
1
+ module TwitterOAuth
2
+ class Client
3
+
4
+ # The user specified in the id is blocked by the authenticated user and reported as a spammer.
5
+ def report_spam(user)
6
+ post("/report_spam.json", :id => user)
7
+ end
8
+
9
+ end
10
+ 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,25 @@
1
+ module TwitterOAuth
2
+ class Client
3
+
4
+ # Returns the top ten topics that are currently trending on Twitter.
5
+ def trends
6
+ get("/trends.json")
7
+ end
8
+
9
+ # Returns the locations that Twitter has trending topic information for.
10
+ # The response is an array of "locations" that encode the location's WOEID (a Yahoo! Where On Earth ID)
11
+ # and some other human-readable information such as a canonical name and country the location belongs in.
12
+ def trends_available
13
+ get("/trends/available.json")
14
+ end
15
+
16
+ # Returns the top 10 trending topics for a specific location Twitter has trending topic information for.
17
+ # The response is an array of "trend" objects that encode the name of the trending topic, the query
18
+ # parameter that can be used to search for the topic on Search, and the direct URL that can be issued against Search.
19
+ # This information is cached for five minutes, and therefore users are discouraged from querying these endpoints
20
+ # faster than once every five minutes. Global trends information is also available from this API by using a WOEID of 1.
21
+ def trends_for_location(woeid)
22
+ get("/trends/woeid.json")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,60 @@
1
+ module TwitterOAuth
2
+ class Client
3
+
4
+ # Returns the 100 last friends
5
+ # The page parameter is implemented for legacy reasons, but use of this is slow
6
+ # as passing page is no longer supported by the Twitter API as the use of cursors
7
+ # is now obligitory. It is recommended that you use all_friends instead
8
+ def friends(page=1)
9
+ return get("/statuses/friends.json?page=#{page}") if page == 1
10
+ users = []
11
+ cursor = "-1"
12
+ page.times do
13
+ return [] if cursor == 0
14
+ json = get("/statuses/friends.json?cursor=#{cursor}")
15
+ cursor = json["next_cursor"]
16
+ users = json["users"]
17
+ end
18
+ users
19
+ end
20
+
21
+ # Returns all pages of friends
22
+ def all_friends
23
+ users = []
24
+ cursor = "-1"
25
+ while cursor != 0 do
26
+ json = get("/statuses/friends.json?cursor=#{cursor}")
27
+ cursor = json["next_cursor"]
28
+ users += json["users"]
29
+ end
30
+ users
31
+ end
32
+
33
+ # Returns the 100 last followers
34
+ def followers(page=1)
35
+ return get("/statuses/followers.json?page=#{page}") if page == 1
36
+ users = []
37
+ cursor = "-1"
38
+ page.times do
39
+ return [] if cursor == 0
40
+ json = get("/statuses/followers.json?cursor=#{cursor}")
41
+ cursor = json["next_cursor"]
42
+ users = json["users"]
43
+ end
44
+ users
45
+ end
46
+
47
+ # Returns all pages of followers
48
+ def all_followers
49
+ users = []
50
+ cursor = "-1"
51
+ while cursor != 0 do
52
+ json = get("/statuses/followers.json?cursor=#{cursor}")
53
+ cursor = json["next_cursor"]
54
+ users += json["users"]
55
+ end
56
+ users
57
+ end
58
+
59
+ end
60
+ 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
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jarodluebbert-twitter_oauth
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 6
10
+ version: 0.3.6
11
+ platform: ruby
12
+ authors:
13
+ - Richard Taylor
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-05-06 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: oauth
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 31
30
+ segments:
31
+ - 0
32
+ - 3
33
+ - 6
34
+ version: 0.3.6
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: json
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 1
46
+ segments:
47
+ - 1
48
+ - 1
49
+ - 9
50
+ version: 1.1.9
51
+ - - <=
52
+ - !ruby/object:Gem::Version
53
+ hash: 23
54
+ segments:
55
+ - 1
56
+ - 2
57
+ - 4
58
+ version: 1.2.4
59
+ type: :runtime
60
+ version_requirements: *id002
61
+ - !ruby/object:Gem::Dependency
62
+ name: mime-types
63
+ prerelease: false
64
+ requirement: &id003 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 47
70
+ segments:
71
+ - 1
72
+ - 16
73
+ version: "1.16"
74
+ type: :runtime
75
+ version_requirements: *id003
76
+ - !ruby/object:Gem::Dependency
77
+ name: shoulda
78
+ prerelease: false
79
+ requirement: &id004 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ type: :development
89
+ version_requirements: *id004
90
+ - !ruby/object:Gem::Dependency
91
+ name: mocha
92
+ prerelease: false
93
+ requirement: &id005 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ type: :development
103
+ version_requirements: *id005
104
+ description: twitter_oauth is a Ruby library for talking to twitter using the new oauth method.
105
+ email: moomerman@gmail.com
106
+ executables: []
107
+
108
+ extensions: []
109
+
110
+ extra_rdoc_files: []
111
+
112
+ files:
113
+ - LICENSE
114
+ - README.textile
115
+ - lib/twitter_oauth.rb
116
+ - lib/twitter_oauth/account.rb
117
+ - lib/twitter_oauth/blocks.rb
118
+ - lib/twitter_oauth/client.rb
119
+ - lib/twitter_oauth/direct_messages.rb
120
+ - lib/twitter_oauth/favorites.rb
121
+ - lib/twitter_oauth/friendships.rb
122
+ - lib/twitter_oauth/lists.rb
123
+ - lib/twitter_oauth/notifications.rb
124
+ - lib/twitter_oauth/saved_searches.rb
125
+ - lib/twitter_oauth/search.rb
126
+ - lib/twitter_oauth/spam.rb
127
+ - lib/twitter_oauth/status.rb
128
+ - lib/twitter_oauth/timeline.rb
129
+ - lib/twitter_oauth/trends.rb
130
+ - lib/twitter_oauth/user.rb
131
+ - lib/twitter_oauth/utils.rb
132
+ has_rdoc: false
133
+ homepage: http://github.com/moomerman/twitter_oauth
134
+ licenses: []
135
+
136
+ post_install_message:
137
+ rdoc_options:
138
+ - --inline-source
139
+ - --charset=UTF-8
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ hash: 3
148
+ segments:
149
+ - 0
150
+ version: "0"
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ hash: 3
157
+ segments:
158
+ - 0
159
+ version: "0"
160
+ requirements: []
161
+
162
+ rubyforge_project: twitter_oauth
163
+ rubygems_version: 1.3.7
164
+ signing_key:
165
+ specification_version: 2
166
+ summary: twitter_oauth is a Ruby library for talking to twitter using the new oauth method.
167
+ test_files: []
168
+