twitter_oauth 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/twitter_oauth/blocks.rb +20 -2
- data/lib/twitter_oauth/client.rb +22 -15
- data/lib/twitter_oauth/favorites.rb +5 -0
- data/lib/twitter_oauth/friendships.rb +12 -4
- data/lib/twitter_oauth/notifications.rb +4 -2
- data/lib/twitter_oauth/saved_searches.rb +24 -0
- data/lib/twitter_oauth/search.rb +8 -6
- data/lib/twitter_oauth/spam.rb +10 -0
- data/lib/twitter_oauth/trends.rb +15 -0
- metadata +4 -2
data/lib/twitter_oauth/blocks.rb
CHANGED
@@ -1,15 +1,33 @@
|
|
1
1
|
module TwitterOAuth
|
2
2
|
class Client
|
3
3
|
|
4
|
-
#
|
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.
|
5
7
|
def block(id)
|
6
8
|
post("/blocks/create/#{id}.json")
|
7
9
|
end
|
8
10
|
|
9
|
-
#
|
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.
|
10
13
|
def unblock(id)
|
11
14
|
post("/blocks/destroy/#{id}.json")
|
12
15
|
end
|
13
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
|
+
|
14
32
|
end
|
15
33
|
end
|
data/lib/twitter_oauth/client.rb
CHANGED
@@ -11,6 +11,8 @@ require 'twitter_oauth/favorites'
|
|
11
11
|
require 'twitter_oauth/utils'
|
12
12
|
require 'twitter_oauth/trends'
|
13
13
|
require 'twitter_oauth/lists'
|
14
|
+
require 'twitter_oauth/saved_searches'
|
15
|
+
require 'twitter_oauth/spam'
|
14
16
|
|
15
17
|
module TwitterOAuth
|
16
18
|
class Client
|
@@ -31,26 +33,16 @@ module TwitterOAuth
|
|
31
33
|
@secret = @access_token.secret
|
32
34
|
@access_token
|
33
35
|
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
|
44
|
-
|
45
|
-
def delete(url)
|
46
|
-
oauth_response = access_token.delete(url)
|
47
|
-
JSON.parse(oauth_response.body)
|
48
|
-
end
|
49
36
|
|
50
37
|
def show(username)
|
51
38
|
get("/users/show/#{username}.json")
|
52
39
|
end
|
53
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
|
+
|
54
46
|
def request_token(options={})
|
55
47
|
consumer.get_request_token(options)
|
56
48
|
end
|
@@ -72,6 +64,21 @@ module TwitterOAuth
|
|
72
64
|
def access_token
|
73
65
|
@access_token ||= OAuth::AccessToken.new(consumer, @token, @secret)
|
74
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
|
75
82
|
end
|
76
83
|
end
|
77
84
|
|
@@ -1,14 +1,19 @@
|
|
1
1
|
module TwitterOAuth
|
2
2
|
class Client
|
3
3
|
|
4
|
+
# Returns the 20 most recent favorite statuses for the authenticating user or user specified by the ID parameter.
|
4
5
|
def favorites(page=1)
|
5
6
|
get("/favorites.json?page=#{page}")
|
6
7
|
end
|
7
8
|
|
9
|
+
# Favorites the status specified in the ID parameter as the authenticating user.
|
10
|
+
# Returns the favorite status when successful.
|
8
11
|
def favorite
|
9
12
|
post("/favorites/create/#{id}.json")
|
10
13
|
end
|
11
14
|
|
15
|
+
# Un-favorites the status specified in the ID parameter as the authenticating user.
|
16
|
+
# Returns the un-favorited status when successful.
|
12
17
|
def unfavorite
|
13
18
|
post("/favorites/destroy/#{id}.json")
|
14
19
|
end
|
@@ -1,31 +1,39 @@
|
|
1
1
|
module TwitterOAuth
|
2
2
|
class Client
|
3
3
|
|
4
|
+
# Returns an array of numeric IDs for every user the specified user is following.
|
4
5
|
def friends_ids(options={})
|
5
6
|
args = options.map{|k,v| "#{k}=#{v}"}.join('&')
|
6
7
|
get("/friends/ids.json?#{args}")
|
7
8
|
end
|
8
9
|
|
10
|
+
# Returns an array of numeric IDs for every user following the specified user.
|
9
11
|
def followers_ids(options={})
|
10
12
|
args = options.map{|k,v| "#{k}=#{v}"}.join('&')
|
11
13
|
get("/followers/ids.json?#{args}")
|
12
14
|
end
|
13
15
|
|
14
|
-
#
|
16
|
+
# Allows the authenticating user to follow the specified user. Returns the befriended user when successful.
|
15
17
|
def friend(id)
|
16
18
|
post("/friendships/create/#{id}.json")
|
17
19
|
end
|
18
20
|
|
19
|
-
#
|
21
|
+
# Allows the authenticating users to unfollow the specified user. Returns the unfollowed user when successful.
|
20
22
|
def unfriend(id)
|
21
23
|
post("/friendships/destroy/#{id}.json")
|
22
24
|
end
|
23
25
|
|
24
|
-
#
|
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)
|
26
29
|
oauth_response = access_token.get("/friendships/exists.json?user_a=#{a}&user_b=#{b}")
|
27
30
|
oauth_response.body.strip == 'true'
|
28
31
|
end
|
29
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
|
+
|
30
38
|
end
|
31
39
|
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
module TwitterOAuth
|
2
2
|
class Client
|
3
3
|
|
4
|
-
#
|
4
|
+
# Enables device notifications for updates from the specified user.
|
5
|
+
# Returns the specified user when successful.
|
5
6
|
def follow(id)
|
6
7
|
post("/notifications/follow/#{id}.json")
|
7
8
|
end
|
8
9
|
|
9
|
-
#
|
10
|
+
# Disables notifications for updates from the specified user to the authenticating user.
|
11
|
+
# Returns the specified user when successful.
|
10
12
|
def leave(id)
|
11
13
|
post("/notifications/leave/#{id}.json")
|
12
14
|
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
|
data/lib/twitter_oauth/search.rb
CHANGED
@@ -6,27 +6,29 @@ module TwitterOAuth
|
|
6
6
|
def search(q, options={})
|
7
7
|
options[:page] ||= 1
|
8
8
|
options[:per_page] ||= 20
|
9
|
-
|
9
|
+
options[:q] = URI.escape(q)
|
10
|
+
args = options.map{|k,v| "#{k}=#{v}"}.join('&')
|
11
|
+
search_get("/search.json?#{args}")
|
10
12
|
end
|
11
13
|
|
12
14
|
# Returns the current top 10 trending topics on Twitter.
|
13
15
|
def current_trends
|
14
|
-
search_get("
|
16
|
+
search_get("/trends/current.json")
|
15
17
|
end
|
16
18
|
|
17
19
|
# Returns the top 20 trending topics for each hour in a given day.
|
18
20
|
def daily_trends
|
19
|
-
search_get("
|
21
|
+
search_get("/trends/daily.json")
|
20
22
|
end
|
21
23
|
|
22
24
|
# Returns the top 30 trending topics for each day in a given week.
|
23
25
|
def weekly_trends
|
24
|
-
search_get("
|
26
|
+
search_get("/trends/weekly.json")
|
25
27
|
end
|
26
28
|
|
27
29
|
private
|
28
|
-
def search_get(
|
29
|
-
response = open(
|
30
|
+
def search_get(path)
|
31
|
+
response = open('http://search.twitter.com' + path, 'User-Agent' => 'github.com/moomerman/twitter_outh')
|
30
32
|
JSON.parse(response.read)
|
31
33
|
end
|
32
34
|
end
|
data/lib/twitter_oauth/trends.rb
CHANGED
@@ -6,5 +6,20 @@ module TwitterOAuth
|
|
6
6
|
get("/trends.json")
|
7
7
|
end
|
8
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
|
9
24
|
end
|
10
25
|
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Taylor
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-30 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -61,7 +61,9 @@ files:
|
|
61
61
|
- lib/twitter_oauth/friendships.rb
|
62
62
|
- lib/twitter_oauth/lists.rb
|
63
63
|
- lib/twitter_oauth/notifications.rb
|
64
|
+
- lib/twitter_oauth/saved_searches.rb
|
64
65
|
- lib/twitter_oauth/search.rb
|
66
|
+
- lib/twitter_oauth/spam.rb
|
65
67
|
- lib/twitter_oauth/status.rb
|
66
68
|
- lib/twitter_oauth/timeline.rb
|
67
69
|
- lib/twitter_oauth/trends.rb
|