twitter_oauth 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'oauth'
3
2
  require 'json'
4
3
  require 'mime/types'
@@ -6,4 +5,4 @@ require 'mime/types'
6
5
  require 'twitter_oauth/client'
7
6
 
8
7
  module TwitterOAuth
9
- end
8
+ end
@@ -10,36 +10,33 @@ module TwitterOAuth
10
10
 
11
11
  # Returns client info
12
12
  def info
13
- oauth_response = access_token.get('/account/verify_credentials.json')
14
- JSON.parse(oauth_response.body)
13
+ get('/account/verify_credentials.json')
15
14
  end
16
15
 
17
16
  # Returns the remaining number of API requests available to the requesting user before the API limit is reached for the current hour.
18
17
  def rate_limit_status
19
- oauth_response = access_token.get('/account/rate_limit_status.json')
20
- JSON.parse(oauth_response.body)
18
+ get('/account/rate_limit_status.json')
21
19
  end
22
20
 
23
21
  # Updates profile background image. Takes a File object and optional tile argument.
24
22
  # Returns extended user info object.
25
23
  def update_profile_background_image(image, tile = false)
26
24
  body, headers = http_multipart_data({:image => image, :tile => tile})
27
- oauth_response = access_token.post('/account/update_profile_background_image.json', body, headers)
25
+ post('/account/update_profile_background_image.json', body, headers)
28
26
  end
29
27
 
30
28
  # Updates profile avatar image. Takes a File object which should be an image.
31
29
  # Returns extended user info object.
32
30
  def update_profile_image(image)
33
31
  body, headers = http_multipart_data({:image => image})
34
- oauth_response = access_token.post('/account/update_profile_image.json', body, headers)
32
+ post('/account/update_profile_image.json', body, headers)
35
33
  end
36
34
 
37
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
38
36
  # returns extended user info object.
39
37
  def update_profile_colors(colors)
40
- oauth_response = access_token.post('/account/update_profile_colors.json', colors)
41
- JSON.parse(oauth_response.body)
38
+ post('/account/update_profile_colors.json', colors)
42
39
  end
43
40
 
44
41
  end
45
- end
42
+ end
@@ -3,15 +3,13 @@ module TwitterOAuth
3
3
 
4
4
  # unblock this user.
5
5
  def block(id)
6
- oauth_response = access_token.post("/blocks/create/#{id}.json")
7
- JSON.parse(oauth_response.body)
6
+ post("/blocks/create/#{id}.json")
8
7
  end
9
8
 
10
9
  # block this user.
11
10
  def unblock(id)
12
- oauth_response = access_token.post("/blocks/destroy/#{id}.json")
13
- JSON.parse(oauth_response.body)
11
+ post("/blocks/destroy/#{id}.json")
14
12
  end
15
13
 
16
14
  end
17
- end
15
+ end
@@ -10,6 +10,7 @@ require 'twitter_oauth/user'
10
10
  require 'twitter_oauth/favorites'
11
11
  require 'twitter_oauth/utils'
12
12
  require 'twitter_oauth/trends'
13
+ require 'twitter_oauth/lists'
13
14
 
14
15
  module TwitterOAuth
15
16
  class Client
@@ -30,11 +31,25 @@ module TwitterOAuth
30
31
  @secret = @access_token.secret
31
32
  @access_token
32
33
  end
34
+
35
+ def get(url)
36
+ oauth_response = access_token.get(url)
37
+ JSON.parse(oauth_response.body)
38
+ end
39
+
40
+ def post(url, body = '', headers = {})
41
+ oauth_response = access_token.post(url, body, headers)
42
+ JSON.parse(oauth_response.body)
43
+ end
33
44
 
34
- def show(username)
35
- oauth_response = access_token.get("/users/show/#{username}.json")
45
+ def delete(url)
46
+ oauth_response = access_token.delete(url)
36
47
  JSON.parse(oauth_response.body)
37
48
  end
49
+
50
+ def show(username)
51
+ get("/users/show/#{username}.json")
52
+ end
38
53
 
39
54
  def request_token(options={})
40
55
  consumer.get_request_token(options)
@@ -3,27 +3,23 @@ module TwitterOAuth
3
3
 
4
4
  # Returns a list of the 20 most recent direct messages sent to the authenticating user.
5
5
  def messages(page=1)
6
- oauth_response = access_token.get("/direct_messages.json?page=#{page}")
7
- JSON.parse(oauth_response.body)
6
+ get("/direct_messages.json?page=#{page}")
8
7
  end
9
8
 
10
9
  # Returns a list of the 20 most recent direct messages sent by the authenticating user.
11
10
  def sent_messages
12
- oauth_response = access_token.get('/direct_messages/sent.json')
13
- JSON.parse(oauth_response.body)
11
+ get('/direct_messages/sent.json')
14
12
  end
15
13
 
16
14
  # Sends a new direct message to the specified user from the authenticating user.
17
15
  def message(user, text)
18
- oauth_response = access_token.post('/direct_messages/new.json', :user => user, :text => text)
19
- JSON.parse(oauth_response.body)
16
+ post('/direct_messages/new.json', :user => user, :text => text)
20
17
  end
21
18
 
22
19
  # Destroys the direct message specified in the required ID parameter.
23
20
  def message_destroy(id)
24
- oauth_response = access_token.post("/direct_messages/destroy/#{id}.json")
25
- JSON.parse(oauth_response.body)
21
+ post("/direct_messages/destroy/#{id}.json")
26
22
  end
27
23
 
28
24
  end
29
- end
25
+ end
@@ -2,19 +2,16 @@ module TwitterOAuth
2
2
  class Client
3
3
 
4
4
  def favorites(page=1)
5
- oauth_response = access_token.get("/favorites.json?page=#{page}")
6
- JSON.parse(oauth_response.body)
5
+ get("/favorites.json?page=#{page}")
7
6
  end
8
7
 
9
8
  def favorite
10
- oauth_response = access_token.post("/favorites/create/#{id}.json")
11
- JSON.parse(oauth_response.body)
9
+ post("/favorites/create/#{id}.json")
12
10
  end
13
11
 
14
12
  def unfavorite
15
- oauth_response = access_token.post("/favorites/destroy/#{id}.json")
16
- JSON.parse(oauth_response.body)
13
+ post("/favorites/destroy/#{id}.json")
17
14
  end
18
15
 
19
16
  end
20
- end
17
+ end
@@ -3,26 +3,22 @@ module TwitterOAuth
3
3
 
4
4
  def friends_ids(options={})
5
5
  args = options.map{|k,v| "#{k}=#{v}"}.join('&')
6
- oauth_response = access_token.get("/friends/ids.json?#{args}")
7
- JSON.parse(oauth_response.body)
6
+ get("/friends/ids.json?#{args}")
8
7
  end
9
8
 
10
9
  def followers_ids(options={})
11
10
  args = options.map{|k,v| "#{k}=#{v}"}.join('&')
12
- oauth_response = access_token.get("/followers/ids.json?#{args}")
13
- JSON.parse(oauth_response.body)
11
+ get("/followers/ids.json?#{args}")
14
12
  end
15
13
 
16
14
  # friend this user.
17
15
  def friend(id)
18
- oauth_response = access_token.post("/friendships/create/#{id}.json")
19
- JSON.parse(oauth_response.body)
16
+ post("/friendships/create/#{id}.json")
20
17
  end
21
18
 
22
19
  # unfriend.
23
20
  def unfriend(id)
24
- oauth_response = access_token.post("/friendships/destroy/#{id}.json")
25
- JSON.parse(oauth_response.body)
21
+ post("/friendships/destroy/#{id}.json")
26
22
  end
27
23
 
28
24
  # exists?.
@@ -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
@@ -3,15 +3,13 @@ module TwitterOAuth
3
3
 
4
4
  # follow this user.
5
5
  def follow(id)
6
- oauth_response = access_token.post("/notifications/follow/#{id}.json")
7
- JSON.parse(oauth_response.body)
6
+ post("/notifications/follow/#{id}.json")
8
7
  end
9
8
 
10
9
  # unfollow.
11
10
  def leave(id)
12
- oauth_response = access_token.post("/notifications/leave/#{id}.json")
13
- JSON.parse(oauth_response.body)
11
+ post("/notifications/leave/#{id}.json")
14
12
  end
15
13
 
16
14
  end
17
- end
15
+ end
@@ -3,27 +3,23 @@ module TwitterOAuth
3
3
 
4
4
  # Returns a single status, specified by the id parameter below.
5
5
  def status(id)
6
- oauth_response = access_token.get("/statuses/show/#{id}.json")
7
- JSON.parse(oauth_response.body)
6
+ get("/statuses/show/#{id}.json")
8
7
  end
9
8
 
10
9
  # Updates the authenticating user's status.
11
10
  def update(message, options={})
12
- oauth_response = access_token.post('/statuses/update.json', options.merge(:status => message))
13
- JSON.parse(oauth_response.body)
11
+ post('/statuses/update.json', options.merge(:status => message))
14
12
  end
15
13
 
16
14
  # Destroys the status specified by the required ID parameter
17
15
  def status_destroy(id)
18
- oauth_response = access_token.post("/statuses/destroy/#{id}.json")
19
- JSON.parse(oauth_response.body)
16
+ post("/statuses/destroy/#{id}.json")
20
17
  end
21
18
 
22
19
  # Retweets the tweet specified by the id parameter. Returns the original tweet with retweet details embedded.
23
20
  def retweet(id)
24
- oauth_response = access_token.post("/statuses/retweet/#{id}.json")
25
- JSON.parse(oauth_response.body)
21
+ post("/statuses/retweet/#{id}.json")
26
22
  end
27
23
 
28
24
  end
29
- end
25
+ end
@@ -4,61 +4,53 @@ module TwitterOAuth
4
4
  # Returns the 20 most recent statuses from non-protected users who have set a custom user icon.
5
5
  def public_timeline(options={})
6
6
  args = options.map{|k,v| "#{k}=#{v}"}.join('&')
7
- oauth_response = access_token.get("/statuses/public_timeline.json?#{args}")
8
- JSON.parse(oauth_response.body)
7
+ get("/statuses/public_timeline.json?#{args}")
9
8
  end
10
9
 
11
10
  # Returns the 20 most recent statuses, including retweets, posted by the authenticating user and that user's friends.
12
11
  # This is the equivalent of /timeline/home on the Web.
13
12
  def home_timeline(options={})
14
13
  args = options.map{|k,v| "#{k}=#{v}"}.join('&')
15
- oauth_response = access_token.get("/statuses/home_timeline.json?#{args}")
16
- JSON.parse(oauth_response.body)
14
+ get("/statuses/home_timeline.json?#{args}")
17
15
  end
18
16
 
19
17
  # Returns the 20 most recent statuses posted by the authenticating user and that user's friends.
20
18
  def friends_timeline(options={})
21
19
  args = options.map{|k,v| "#{k}=#{v}"}.join('&')
22
- oauth_response = access_token.get("/statuses/friends_timeline.json?#{args}")
23
- JSON.parse(oauth_response.body)
20
+ get("/statuses/friends_timeline.json?#{args}")
24
21
  end
25
22
 
26
23
  # Returns the 20 most recent statuses posted from the authenticating user.
27
24
  def user_timeline(options={})
28
25
  args = options.map{|k,v| "#{k}=#{v}"}.join('&')
29
- oauth_response = access_token.get("/statuses/user_timeline.json?#{args}")
30
- JSON.parse(oauth_response.body)
26
+ get("/statuses/user_timeline.json?#{args}")
31
27
  end
32
28
  alias :user :user_timeline
33
29
 
34
30
  # Returns the 20 most recent @replies (status updates prefixed with @username) for the authenticating user.
35
31
  def mentions(options={})
36
32
  args = options.map{|k,v| "#{k}=#{v}"}.join('&')
37
- oauth_response = access_token.get("/statuses/mentions.json?#{args}")
38
- JSON.parse(oauth_response.body)
33
+ get("/statuses/mentions.json?#{args}")
39
34
  end
40
35
  alias :replies :mentions
41
36
 
42
37
  # Returns the 20 most recent retweets posted by the authenticating user
43
38
  def retweeted_by_me(options={})
44
39
  args = options.map{|k,v| "#{k}=#{v}"}.join('&')
45
- oauth_response = access_token.get("/statuses/retweeted_by_me.json?#{args}")
46
- JSON.parse(oauth_response.body)
40
+ get("/statuses/retweeted_by_me.json?#{args}")
47
41
  end
48
42
 
49
43
  # Returns the 20 most recent retweets posted by the authenticating user's friends.
50
44
  def retweeted_to_me(options={})
51
45
  args = options.map{|k,v| "#{k}=#{v}"}.join('&')
52
- oauth_response = access_token.get("/statuses/retweeted_to_me.json?#{args}")
53
- JSON.parse(oauth_response.body)
46
+ get("/statuses/retweeted_to_me.json?#{args}")
54
47
  end
55
48
 
56
49
  # Returns the 20 most recent tweets of the authenticated user that have been retweeted by others.
57
50
  def retweets_of_me(options={})
58
51
  args = options.map{|k,v| "#{k}=#{v}"}.join('&')
59
- oauth_response = access_token.get("/statuses/retweets_of_me.json?#{args}")
60
- JSON.parse(oauth_response.body)
52
+ get("/statuses/retweets_of_me.json?#{args}")
61
53
  end
62
54
 
63
55
  end
64
- end
56
+ end
@@ -3,8 +3,7 @@ module TwitterOAuth
3
3
 
4
4
  # Returns the top ten topics that are currently trending on Twitter.
5
5
  def trends
6
- oauth_response = access_token.get("/trends.json")
7
- JSON.parse(oauth_response.body)
6
+ get("/trends.json")
8
7
  end
9
8
 
10
9
  end
@@ -3,15 +3,13 @@ module TwitterOAuth
3
3
 
4
4
  # Returns the 100 last friends
5
5
  def friends(page=1)
6
- oauth_response = access_token.get("/statuses/friends.json?page=#{page}")
7
- JSON.parse(oauth_response.body)
6
+ get("/statuses/friends.json?page=#{page}")
8
7
  end
9
8
 
10
9
  # Returns the 100 last followers
11
10
  def followers(page=1)
12
- oauth_response = access_token.get("/statuses/followers.json?page=#{page}")
13
- JSON.parse(oauth_response.body)
11
+ get("/statuses/followers.json?page=#{page}")
14
12
  end
15
13
 
16
14
  end
17
- end
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter_oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Taylor
@@ -59,6 +59,7 @@ files:
59
59
  - lib/twitter_oauth/direct_messages.rb
60
60
  - lib/twitter_oauth/favorites.rb
61
61
  - lib/twitter_oauth/friendships.rb
62
+ - lib/twitter_oauth/lists.rb
62
63
  - lib/twitter_oauth/notifications.rb
63
64
  - lib/twitter_oauth/search.rb
64
65
  - lib/twitter_oauth/status.rb