ifttt-twitter 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/.yardopts +8 -0
- data/Gemfile +7 -0
- data/HISTORY.md +520 -0
- data/LICENSE.md +20 -0
- data/README.md +251 -0
- data/Rakefile +13 -0
- data/lib/twitter.rb +24 -0
- data/lib/twitter/action.rb +9 -0
- data/lib/twitter/action_factory.rb +28 -0
- data/lib/twitter/authenticatable.rb +24 -0
- data/lib/twitter/base.rb +40 -0
- data/lib/twitter/client.rb +126 -0
- data/lib/twitter/client/accounts.rb +180 -0
- data/lib/twitter/client/activity.rb +48 -0
- data/lib/twitter/client/block.rb +104 -0
- data/lib/twitter/client/direct_messages.rb +110 -0
- data/lib/twitter/client/favorites.rb +82 -0
- data/lib/twitter/client/friends_and_followers.rb +293 -0
- data/lib/twitter/client/help.rb +38 -0
- data/lib/twitter/client/legal.rb +32 -0
- data/lib/twitter/client/lists.rb +643 -0
- data/lib/twitter/client/local_trends.rb +46 -0
- data/lib/twitter/client/notification.rb +49 -0
- data/lib/twitter/client/places_and_geo.rb +113 -0
- data/lib/twitter/client/saved_searches.rb +73 -0
- data/lib/twitter/client/search.rb +94 -0
- data/lib/twitter/client/spam_reporting.rb +30 -0
- data/lib/twitter/client/suggested_users.rb +60 -0
- data/lib/twitter/client/timelines.rb +265 -0
- data/lib/twitter/client/trends.rb +55 -0
- data/lib/twitter/client/tweets.rb +191 -0
- data/lib/twitter/client/urls.rb +26 -0
- data/lib/twitter/client/users.rb +203 -0
- data/lib/twitter/config.rb +106 -0
- data/lib/twitter/configuration.rb +20 -0
- data/lib/twitter/connection.rb +43 -0
- data/lib/twitter/core_ext/hash.rb +81 -0
- data/lib/twitter/creatable.rb +14 -0
- data/lib/twitter/cursor.rb +44 -0
- data/lib/twitter/direct_message.rb +27 -0
- data/lib/twitter/error.rb +37 -0
- data/lib/twitter/error/bad_gateway.rb +7 -0
- data/lib/twitter/error/bad_request.rb +7 -0
- data/lib/twitter/error/client_error.rb +7 -0
- data/lib/twitter/error/enhance_your_calm.rb +13 -0
- data/lib/twitter/error/forbidden.rb +7 -0
- data/lib/twitter/error/internal_server_error.rb +7 -0
- data/lib/twitter/error/not_acceptable.rb +7 -0
- data/lib/twitter/error/not_found.rb +7 -0
- data/lib/twitter/error/server_error.rb +7 -0
- data/lib/twitter/error/service_unavailable.rb +7 -0
- data/lib/twitter/error/unauthorized.rb +7 -0
- data/lib/twitter/favorite.rb +28 -0
- data/lib/twitter/follow.rb +27 -0
- data/lib/twitter/geo_factory.rb +22 -0
- data/lib/twitter/language.rb +7 -0
- data/lib/twitter/list.rb +22 -0
- data/lib/twitter/list_member_added.rb +36 -0
- data/lib/twitter/media_factory.rb +21 -0
- data/lib/twitter/mention.rb +43 -0
- data/lib/twitter/metadata.rb +7 -0
- data/lib/twitter/oembed.rb +8 -0
- data/lib/twitter/photo.rb +24 -0
- data/lib/twitter/place.rb +36 -0
- data/lib/twitter/point.rb +27 -0
- data/lib/twitter/polygon.rb +14 -0
- data/lib/twitter/rate_limit_status.rb +15 -0
- data/lib/twitter/relationship.rb +18 -0
- data/lib/twitter/reply.rb +36 -0
- data/lib/twitter/request.rb +38 -0
- data/lib/twitter/request/gateway.rb +20 -0
- data/lib/twitter/request/multipart_with_file.rb +37 -0
- data/lib/twitter/request/oauth.rb +26 -0
- data/lib/twitter/request/phoenix.rb +22 -0
- data/lib/twitter/response/parse_json.rb +28 -0
- data/lib/twitter/response/raise_client_error.rb +49 -0
- data/lib/twitter/response/raise_server_error.rb +23 -0
- data/lib/twitter/retweet.rb +36 -0
- data/lib/twitter/saved_search.rb +16 -0
- data/lib/twitter/settings.rb +17 -0
- data/lib/twitter/size.rb +16 -0
- data/lib/twitter/status.rb +80 -0
- data/lib/twitter/suggestion.rb +22 -0
- data/lib/twitter/trend.rb +14 -0
- data/lib/twitter/user.rb +65 -0
- data/lib/twitter/version.rb +30 -0
- data/spec/faraday/request_spec.rb +25 -0
- data/spec/faraday/response_spec.rb +68 -0
- data/spec/fixtures/about_me.json +1 -0
- data/spec/fixtures/all.json +1 -0
- data/spec/fixtures/bad_gateway.json +1 -0
- data/spec/fixtures/bad_request.json +1 -0
- data/spec/fixtures/by_friends.json +1 -0
- data/spec/fixtures/category.json +1 -0
- data/spec/fixtures/configuration.json +1 -0
- data/spec/fixtures/contributees.json +1 -0
- data/spec/fixtures/contributors.json +1 -0
- data/spec/fixtures/direct_message.json +1 -0
- data/spec/fixtures/direct_messages.json +1 -0
- data/spec/fixtures/end_session.json +1 -0
- data/spec/fixtures/enhance_your_calm.text +11 -0
- data/spec/fixtures/false.json +1 -0
- data/spec/fixtures/favorites.json +1 -0
- data/spec/fixtures/forbidden.json +1 -0
- data/spec/fixtures/friendships.json +1 -0
- data/spec/fixtures/id_list.json +1 -0
- data/spec/fixtures/ids.json +1 -0
- data/spec/fixtures/image_facets.json +1 -0
- data/spec/fixtures/internal_server_error.json +1 -0
- data/spec/fixtures/languages.json +1 -0
- data/spec/fixtures/list.json +1 -0
- data/spec/fixtures/lists.json +1 -0
- data/spec/fixtures/locations.json +1 -0
- data/spec/fixtures/matching_trends.json +1 -0
- data/spec/fixtures/me.jpeg +0 -0
- data/spec/fixtures/media_timeline.json +1 -0
- data/spec/fixtures/members.json +1 -0
- data/spec/fixtures/n605431196_2079896_558_normal.jpg +0 -0
- data/spec/fixtures/no_user_matches.json +1 -0
- data/spec/fixtures/not_acceptable.json +1 -0
- data/spec/fixtures/not_found.json +1 -0
- data/spec/fixtures/oembed.json +1 -0
- data/spec/fixtures/pengwynn.json +1 -0
- data/spec/fixtures/phoenix_search.phoenix +1 -0
- data/spec/fixtures/place.json +1 -0
- data/spec/fixtures/places.json +1 -0
- data/spec/fixtures/privacy.json +1 -0
- data/spec/fixtures/profile_image.text +24 -0
- data/spec/fixtures/rate_limit_status.json +1 -0
- data/spec/fixtures/recommendations.json +1 -0
- data/spec/fixtures/relationship.json +1 -0
- data/spec/fixtures/resolve.json +1 -0
- data/spec/fixtures/retweet.json +1 -0
- data/spec/fixtures/retweeters_of.json +1 -0
- data/spec/fixtures/retweets.json +1 -0
- data/spec/fixtures/saved_search.json +1 -0
- data/spec/fixtures/saved_searches.json +1 -0
- data/spec/fixtures/search.json +1 -0
- data/spec/fixtures/service_unavailable.json +1 -0
- data/spec/fixtures/settings.json +1 -0
- data/spec/fixtures/sferik.json +1 -0
- data/spec/fixtures/status.json +1 -0
- data/spec/fixtures/status_with_media.json +104 -0
- data/spec/fixtures/statuses.json +1 -0
- data/spec/fixtures/suggestions.json +1 -0
- data/spec/fixtures/tos.json +1 -0
- data/spec/fixtures/totals.json +1 -0
- data/spec/fixtures/trends.json +1 -0
- data/spec/fixtures/trends_current.json +1 -0
- data/spec/fixtures/trends_daily.json +1 -0
- data/spec/fixtures/trends_weekly.json +1 -0
- data/spec/fixtures/true.json +1 -0
- data/spec/fixtures/unauthorized.json +1 -0
- data/spec/fixtures/user_search.json +1 -0
- data/spec/fixtures/user_timeline.json +1 -0
- data/spec/fixtures/users.json +1 -0
- data/spec/fixtures/users_list.json +1 -0
- data/spec/fixtures/video_facets.json +1 -0
- data/spec/fixtures/we_concept_bg2.png +0 -0
- data/spec/helper.rb +49 -0
- data/spec/twitter/action_factory_spec.rb +37 -0
- data/spec/twitter/action_spec.rb +16 -0
- data/spec/twitter/base_spec.rb +29 -0
- data/spec/twitter/client/accounts_spec.rb +181 -0
- data/spec/twitter/client/activity_spec.rb +43 -0
- data/spec/twitter/client/block_spec.rb +106 -0
- data/spec/twitter/client/direct_messages_spec.rb +98 -0
- data/spec/twitter/client/favorites_spec.rb +80 -0
- data/spec/twitter/client/friends_and_followers_spec.rb +478 -0
- data/spec/twitter/client/help_spec.rb +44 -0
- data/spec/twitter/client/legal_spec.rb +41 -0
- data/spec/twitter/client/lists_spec.rb +1104 -0
- data/spec/twitter/client/local_trends_spec.rb +58 -0
- data/spec/twitter/client/notification_spec.rb +47 -0
- data/spec/twitter/client/places_and_geo_spec.rb +100 -0
- data/spec/twitter/client/saved_searches_spec.rb +80 -0
- data/spec/twitter/client/search_spec.rb +92 -0
- data/spec/twitter/client/spam_reporting_spec.rb +28 -0
- data/spec/twitter/client/suggested_users_spec.rb +65 -0
- data/spec/twitter/client/timelines_spec.rb +231 -0
- data/spec/twitter/client/trends_spec.rb +51 -0
- data/spec/twitter/client/tweets_spec.rb +189 -0
- data/spec/twitter/client/urls_spec.rb +31 -0
- data/spec/twitter/client/users_spec.rb +323 -0
- data/spec/twitter/client_spec.rb +94 -0
- data/spec/twitter/configuration_spec.rb +17 -0
- data/spec/twitter/cursor_spec.rb +43 -0
- data/spec/twitter/direct_message_spec.rb +56 -0
- data/spec/twitter/favorite_spec.rb +29 -0
- data/spec/twitter/follow_spec.rb +29 -0
- data/spec/twitter/geo_factory_spec.rb +21 -0
- data/spec/twitter/list_spec.rb +34 -0
- data/spec/twitter/media_factory_spec.rb +17 -0
- data/spec/twitter/mention_spec.rb +52 -0
- data/spec/twitter/oembed_spec.rb +145 -0
- data/spec/twitter/photo_spec.rb +35 -0
- data/spec/twitter/place_spec.rb +75 -0
- data/spec/twitter/point_spec.rb +32 -0
- data/spec/twitter/polygon_spec.rb +18 -0
- data/spec/twitter/rate_limit_status_spec.rb +16 -0
- data/spec/twitter/relationship_spec.rb +27 -0
- data/spec/twitter/reply_spec.rb +41 -0
- data/spec/twitter/retweet_spec.rb +41 -0
- data/spec/twitter/saved_search_spec.rb +34 -0
- data/spec/twitter/settings_spec.rb +16 -0
- data/spec/twitter/size_spec.rb +18 -0
- data/spec/twitter/status_spec.rb +148 -0
- data/spec/twitter/suggestion_spec.rb +20 -0
- data/spec/twitter/trend_spec.rb +20 -0
- data/spec/twitter/user_spec.rb +50 -0
- data/spec/twitter_spec.rb +91 -0
- data/twitter.gemspec +42 -0
- metadata +564 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
module Twitter
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Defines methods related to URLs
|
5
|
+
module Urls
|
6
|
+
# Returns the canonical version of a URL shortened by Twitter
|
7
|
+
#
|
8
|
+
# @note Undocumented
|
9
|
+
# @rate_limited Yes
|
10
|
+
# @requires_authentication Yes
|
11
|
+
# @overload resolve(urls, options={})
|
12
|
+
# @param urls [String] A list of shortened URLs.
|
13
|
+
# @param options [Hash] A customizable set of options.
|
14
|
+
# @return [Hash] A hash of URLs with the shortened URLs as the key
|
15
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
16
|
+
# @example Return the canonical version of a URL shortened by Twitter
|
17
|
+
# Twitter.resolve('http://t.co/uw5bn1w', 'http://t.co/dXvMz9i')
|
18
|
+
# Twitter.resolve(['http://t.co/uw5bn1w', 'http://t.co/dXvMz9i']) # Same as above
|
19
|
+
def resolve(*args)
|
20
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
21
|
+
get("/1/urls/resolve.json", options.merge("urls[]" => args), :phoenix => true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'twitter/core_ext/hash'
|
2
|
+
require 'twitter/error/not_found'
|
3
|
+
require 'twitter/user'
|
4
|
+
|
5
|
+
module Twitter
|
6
|
+
class Client
|
7
|
+
# Defines methods related to users
|
8
|
+
module Users
|
9
|
+
|
10
|
+
# Returns extended information for up to 100 users
|
11
|
+
#
|
12
|
+
# @see https://dev.twitter.com/docs/api/1/get/users/lookup
|
13
|
+
# @rate_limited Yes
|
14
|
+
# @requires_authentication Yes
|
15
|
+
# @overload users(*users, options={})
|
16
|
+
# @param users [Array<Integer, String>, Set<Integer, String>] Twitter user IDs or screen names.
|
17
|
+
# @param options [Hash] A customizable set of options.
|
18
|
+
# @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
|
19
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
20
|
+
# @return [Array<Twitter::User>] The requested users.
|
21
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
22
|
+
# @example Return extended information for @sferik and @pengwynn
|
23
|
+
# Twitter.users("sferik", "pengwynn")
|
24
|
+
# Twitter.users("sferik", 14100886) # Same as above
|
25
|
+
# Twitter.users(7505382, 14100886) # Same as above
|
26
|
+
def users(*args)
|
27
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
28
|
+
users = args
|
29
|
+
options.merge_users!(Array(users))
|
30
|
+
get("/1/users/lookup.json", options).map do |user|
|
31
|
+
Twitter::User.new(user)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Access the profile image in various sizes for the user with the indicated screen name
|
36
|
+
#
|
37
|
+
# @see https://dev.twitter.com/docs/api/1/get/users/profile_image/:screen_name
|
38
|
+
# @rate_limited No
|
39
|
+
# @requires_authentication No
|
40
|
+
# @overload profile_image(screen_name, options={})
|
41
|
+
# @param screen_name [String] The screen name of the user for whom to return results for.
|
42
|
+
# @param options [Hash] A customizable set of options.
|
43
|
+
# @option options [String] :size ('normal') Specifies the size of image to fetch. Valid options include: 'bigger' (73px by 73px), 'normal' (48px by 48px), and 'mini' (24px by 24px).
|
44
|
+
# @example Return the URL for the 24px by 24px version of @sferik's profile image
|
45
|
+
# Twitter.profile_image("sferik", :size => 'mini')
|
46
|
+
# @return [String] The URL for the requested user's profile image.
|
47
|
+
def profile_image(*args)
|
48
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
49
|
+
screen_name = args.pop || self.current_user.screen_name
|
50
|
+
get("/1/users/profile_image/#{screen_name}", options, :raw => true).headers['location']
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns users that match the given query
|
54
|
+
#
|
55
|
+
# @see https://dev.twitter.com/docs/api/1/get/users/search
|
56
|
+
# @rate_limited Yes
|
57
|
+
# @requires_authentication Yes
|
58
|
+
# @param query [String] The search query to run against people search.
|
59
|
+
# @param options [Hash] A customizable set of options.
|
60
|
+
# @option options [Integer] :per_page The number of people to retrieve. Maxiumum of 20 allowed per page.
|
61
|
+
# @option options [Integer] :page Specifies the page of results to retrieve.
|
62
|
+
# @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
|
63
|
+
# @return [Array<Twitter::User>]
|
64
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
65
|
+
# @example Return users that match "Erik Michaels-Ober"
|
66
|
+
# Twitter.user_search("Erik Michaels-Ober")
|
67
|
+
def user_search(query, options={})
|
68
|
+
get("/1/users/search.json", options.merge(:q => query)).map do |user|
|
69
|
+
Twitter::User.new(user)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns extended information of a given user
|
74
|
+
#
|
75
|
+
# @see https://dev.twitter.com/docs/api/1/get/users/show
|
76
|
+
# @rate_limited Yes
|
77
|
+
# @requires_authentication No
|
78
|
+
# @overload user(user, options={})
|
79
|
+
# @param user [Integer, String] A Twitter user ID or screen name.
|
80
|
+
# @param options [Hash] A customizable set of options.
|
81
|
+
# @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
|
82
|
+
# @return [Twitter::User] The requested user.
|
83
|
+
# @example Return extended information for @sferik
|
84
|
+
# Twitter.user("sferik")
|
85
|
+
# Twitter.user(7505382) # Same as above
|
86
|
+
def user(*args)
|
87
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
88
|
+
if user = args.pop
|
89
|
+
options.merge_user!(user)
|
90
|
+
user = get("/1/users/show.json", options)
|
91
|
+
else
|
92
|
+
user = get("/1/account/verify_credentials.json", options)
|
93
|
+
end
|
94
|
+
Twitter::User.new(user)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Returns true if the specified user exists
|
98
|
+
#
|
99
|
+
# @param user [Integer, String] A Twitter user ID or screen name.
|
100
|
+
# @return [Boolean] true if the user exists, otherwise false.
|
101
|
+
# @example Return true if @sferik exists
|
102
|
+
# Twitter.user?("sferik")
|
103
|
+
# Twitter.user?(7505382) # Same as above
|
104
|
+
# @requires_authentication No
|
105
|
+
# @rate_limited Yes
|
106
|
+
def user?(user, options={})
|
107
|
+
options.merge_user!(user)
|
108
|
+
get("/1/users/show.json", options, :raw => true)
|
109
|
+
true
|
110
|
+
rescue Twitter::Error::NotFound
|
111
|
+
false
|
112
|
+
end
|
113
|
+
|
114
|
+
# Returns an array of users that the specified user can contribute to
|
115
|
+
#
|
116
|
+
# @see http://dev.twitter.com/docs/api/1/get/users/contributees
|
117
|
+
# @rate_limited Yes
|
118
|
+
# @requires_authentication No unless requesting it from a protected user
|
119
|
+
#
|
120
|
+
# If getting this data of a protected user, you must authenticate (and be allowed to see that user).
|
121
|
+
# @overload contributees(options={})
|
122
|
+
# @param options [Hash] A customizable set of options.
|
123
|
+
# @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
|
124
|
+
# @option options [Boolean, String, Integer] :skip_status Do not include contributee's statuses when set to true, 't' or 1.
|
125
|
+
# @return [Array<Twitter::User>]
|
126
|
+
# @example Return the authenticated user's contributees
|
127
|
+
# Twitter.contributees
|
128
|
+
## @overload contributees(user, options={})
|
129
|
+
# @param user [Integer, String] A Twitter user ID or screen name.
|
130
|
+
# @param options [Hash] A customizable set of options.
|
131
|
+
# @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
|
132
|
+
# @option options [Boolean, String, Integer] :skip_status Do not include contributee's statuses when set to true, 't' or 1.
|
133
|
+
# @return [Array<Twitter::User>]
|
134
|
+
# @example Return users @sferik can contribute to
|
135
|
+
# Twitter.contributees("sferik")
|
136
|
+
# Twitter.contributees(7505382) # Same as above
|
137
|
+
def contributees(*args)
|
138
|
+
options = {}
|
139
|
+
options.merge!(args.last.is_a?(Hash) ? args.pop : {})
|
140
|
+
user = args.pop || self.current_user.screen_name
|
141
|
+
options.merge_user!(user)
|
142
|
+
get("/1/users/contributees.json", options).map do |user|
|
143
|
+
Twitter::User.new(user)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# Returns an array of users who can contribute to the specified account
|
148
|
+
#
|
149
|
+
# @see http://dev.twitter.com/docs/api/1/get/users/contributors
|
150
|
+
# @rate_limited Yes
|
151
|
+
# @requires_authentication No unless requesting it from a protected user
|
152
|
+
#
|
153
|
+
# If getting this data of a protected user, you must authenticate (and be allowed to see that user).
|
154
|
+
# @overload contributors(options={})
|
155
|
+
# @param options [Hash] A customizable set of options.
|
156
|
+
# @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
|
157
|
+
# @option options [Boolean, String, Integer] :skip_status Do not include contributee's statuses when set to true, 't' or 1.
|
158
|
+
# @return [Array<Twitter::User>]
|
159
|
+
# @example Return the authenticated user's contributors
|
160
|
+
# Twitter.contributors
|
161
|
+
## @overload contributors(user, options={})
|
162
|
+
# @param user [Integer, String] A Twitter user ID or screen name.
|
163
|
+
# @param options [Hash] A customizable set of options.
|
164
|
+
# @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
|
165
|
+
# @option options [Boolean, String, Integer] :skip_status Do not include contributee's statuses when set to true, 't' or 1.
|
166
|
+
# @return [Array<Twitter::User>]
|
167
|
+
# @example Return users who can contribute to @sferik's account
|
168
|
+
# Twitter.contributors("sferik")
|
169
|
+
# Twitter.contributors(7505382) # Same as above
|
170
|
+
def contributors(*args)
|
171
|
+
options = {}
|
172
|
+
options.merge!(args.last.is_a?(Hash) ? args.pop : {})
|
173
|
+
user = args.pop || self.current_user.screen_name
|
174
|
+
options.merge_user!(user)
|
175
|
+
get("/1/users/contributors.json", options).map do |user|
|
176
|
+
Twitter::User.new(user)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# Returns recommended users for the authenticated user
|
181
|
+
#
|
182
|
+
# @note {https://dev.twitter.com/discussions/1120 Undocumented}
|
183
|
+
# @rate_limited Yes
|
184
|
+
# @requires_authentication Yes
|
185
|
+
# @param options [Hash] A customizable set of options.
|
186
|
+
# @option options [Integer] :limit (20) Specifies the number of records to retrieve.
|
187
|
+
# @option options [String] :excluded Comma-separated list of user IDs to exclude.
|
188
|
+
# @option options [String] :screen_name Find users similar to this screen_name
|
189
|
+
# @option options [Integer] :user_id Find users similar to this user ID.
|
190
|
+
# @return [Array<Twitter::User>]
|
191
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
192
|
+
# @example Return recommended users for the authenticated user
|
193
|
+
# Twitter.recommendations
|
194
|
+
def recommendations(options={})
|
195
|
+
options[:excluded] = options[:excluded].join(',') if options[:excluded].is_a?(Array)
|
196
|
+
get("/1/users/recommendations.json", options).map do |recommendation|
|
197
|
+
Twitter::User.new(recommendation['user'])
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'twitter/version'
|
2
|
+
|
3
|
+
module Twitter
|
4
|
+
# Defines constants and methods related to configuration
|
5
|
+
module Config
|
6
|
+
|
7
|
+
# The HTTP connection adapter that will be used to connect if none is set
|
8
|
+
DEFAULT_ADAPTER = :net_http
|
9
|
+
|
10
|
+
# The Faraday connection options if none is set
|
11
|
+
DEFAULT_CONNECTION_OPTIONS = {}
|
12
|
+
|
13
|
+
# The consumer key if none is set
|
14
|
+
DEFAULT_CONSUMER_KEY = nil
|
15
|
+
|
16
|
+
# The consumer secret if none is set
|
17
|
+
DEFAULT_CONSUMER_SECRET = nil
|
18
|
+
|
19
|
+
# The endpoint that will be used to connect if none is set
|
20
|
+
#
|
21
|
+
# @note This is configurable in case you want to use HTTP instead of HTTPS, specify a different API version, or use a Twitter-compatible endpoint.
|
22
|
+
# @see http://status.net/wiki/Twitter-compatible_API
|
23
|
+
# @see http://en.blog.wordpress.com/2009/12/12/twitter-api/
|
24
|
+
# @see http://staff.tumblr.com/post/287703110/api
|
25
|
+
# @see http://developer.typepad.com/typepad-twitter-api/twitter-api.html
|
26
|
+
DEFAULT_ENDPOINT = 'https://api.twitter.com'
|
27
|
+
|
28
|
+
# The gateway server if none is set
|
29
|
+
DEFAULT_GATEWAY = nil
|
30
|
+
|
31
|
+
# This endpoint will be used by default when updating statuses with media
|
32
|
+
DEFAULT_MEDIA_ENDPOINT = 'https://upload.twitter.com'
|
33
|
+
|
34
|
+
# The oauth token if none is set
|
35
|
+
DEFAULT_OAUTH_TOKEN = nil
|
36
|
+
|
37
|
+
# The oauth token secret if none is set
|
38
|
+
DEFAULT_OAUTH_TOKEN_SECRET = nil
|
39
|
+
|
40
|
+
# The proxy server if none is set
|
41
|
+
DEFAULT_PROXY = nil
|
42
|
+
|
43
|
+
# The search endpoint that will be used to connect if none is set
|
44
|
+
#
|
45
|
+
# @note This is configurable in case you want to use HTTP instead of HTTPS or use a Twitter-compatible endpoint.
|
46
|
+
# @see http://status.net/wiki/Twitter-compatible_API
|
47
|
+
DEFAULT_SEARCH_ENDPOINT = 'https://search.twitter.com'
|
48
|
+
|
49
|
+
# The value sent in the 'User-Agent' header if none is set
|
50
|
+
DEFAULT_USER_AGENT = "Twitter Ruby Gem #{Twitter::Version}"
|
51
|
+
|
52
|
+
# An array of valid keys in the options hash when configuring a {Twitter::Client}
|
53
|
+
VALID_OPTIONS_KEYS = [
|
54
|
+
:adapter,
|
55
|
+
:connection_options,
|
56
|
+
:consumer_key,
|
57
|
+
:consumer_secret,
|
58
|
+
:endpoint,
|
59
|
+
:gateway,
|
60
|
+
:oauth_token,
|
61
|
+
:oauth_token_secret,
|
62
|
+
:proxy,
|
63
|
+
:search_endpoint,
|
64
|
+
:user_agent,
|
65
|
+
:media_endpoint
|
66
|
+
]
|
67
|
+
|
68
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
69
|
+
|
70
|
+
# When this module is extended, set all configuration options to their default values
|
71
|
+
def self.extended(base)
|
72
|
+
base.reset
|
73
|
+
end
|
74
|
+
|
75
|
+
# Convenience method to allow configuration options to be set in a block
|
76
|
+
def configure
|
77
|
+
yield self
|
78
|
+
self
|
79
|
+
end
|
80
|
+
|
81
|
+
# Create a hash of options and their values
|
82
|
+
def options
|
83
|
+
options = {}
|
84
|
+
VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
|
85
|
+
options
|
86
|
+
end
|
87
|
+
|
88
|
+
# Reset all configuration options to defaults
|
89
|
+
def reset
|
90
|
+
self.adapter = DEFAULT_ADAPTER
|
91
|
+
self.connection_options = DEFAULT_CONNECTION_OPTIONS
|
92
|
+
self.consumer_key = DEFAULT_CONSUMER_KEY
|
93
|
+
self.consumer_secret = DEFAULT_CONSUMER_SECRET
|
94
|
+
self.endpoint = DEFAULT_ENDPOINT
|
95
|
+
self.gateway = DEFAULT_GATEWAY
|
96
|
+
self.media_endpoint = DEFAULT_MEDIA_ENDPOINT
|
97
|
+
self.oauth_token = DEFAULT_OAUTH_TOKEN
|
98
|
+
self.oauth_token_secret = DEFAULT_OAUTH_TOKEN_SECRET
|
99
|
+
self.proxy = DEFAULT_PROXY
|
100
|
+
self.search_endpoint = DEFAULT_SEARCH_ENDPOINT
|
101
|
+
self.user_agent = DEFAULT_USER_AGENT
|
102
|
+
self
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'active_support/core_ext/enumerable'
|
2
|
+
require 'twitter/base'
|
3
|
+
require 'twitter/size'
|
4
|
+
|
5
|
+
module Twitter
|
6
|
+
class Configuration < Twitter::Base
|
7
|
+
lazy_attr_reader :characters_reserved_per_media, :max_media_per_upload,
|
8
|
+
:non_username_paths, :photo_size_limit, :short_url_length, :short_url_length_https
|
9
|
+
|
10
|
+
# Returns an array of photo sizes
|
11
|
+
#
|
12
|
+
# @return [Array<Twitter::Size>]
|
13
|
+
def photo_sizes
|
14
|
+
@photo_sizes ||= Array(@attrs['photo_sizes']).each_with_object({}) do |(key, value), object|
|
15
|
+
object[key] = Twitter::Size.new(value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'twitter/core_ext/hash'
|
3
|
+
require 'twitter/request/gateway'
|
4
|
+
require 'twitter/request/multipart_with_file'
|
5
|
+
require 'twitter/request/phoenix'
|
6
|
+
require 'twitter/request/oauth'
|
7
|
+
require 'twitter/response/parse_json'
|
8
|
+
require 'twitter/response/raise_client_error'
|
9
|
+
require 'twitter/response/raise_server_error'
|
10
|
+
|
11
|
+
module Twitter
|
12
|
+
module Connection
|
13
|
+
private
|
14
|
+
|
15
|
+
# Returns a Faraday::Connection object
|
16
|
+
#
|
17
|
+
# @param options [Hash] A hash of options
|
18
|
+
# @return [Faraday::Connection]
|
19
|
+
def connection(options={})
|
20
|
+
default_options = {
|
21
|
+
:headers => {
|
22
|
+
:accept => 'application/json',
|
23
|
+
:user_agent => user_agent,
|
24
|
+
},
|
25
|
+
:proxy => proxy,
|
26
|
+
:ssl => {:verify => false},
|
27
|
+
:url => options.fetch(:endpoint, endpoint),
|
28
|
+
}
|
29
|
+
@connection ||=Faraday.new(default_options.deep_merge(connection_options)) do |builder|
|
30
|
+
builder.use Twitter::Request::Phoenix
|
31
|
+
builder.use Twitter::Request::MultipartWithFile
|
32
|
+
builder.use Twitter::Request::TwitterOAuth, credentials if credentials?
|
33
|
+
builder.use Faraday::Request::Multipart
|
34
|
+
builder.use Faraday::Request::UrlEncoded
|
35
|
+
builder.use Twitter::Request::Gateway, gateway if gateway
|
36
|
+
builder.use Twitter::Response::RaiseClientError
|
37
|
+
builder.use Twitter::Response::ParseJson
|
38
|
+
builder.use Twitter::Response::RaiseServerError
|
39
|
+
builder.adapter(adapter)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
class Hash
|
2
|
+
|
3
|
+
# Merges self with another hash, recursively
|
4
|
+
#
|
5
|
+
# @param hash [Hash] The hash to merge
|
6
|
+
# @return [Hash]
|
7
|
+
def deep_merge(hash)
|
8
|
+
target = self.dup
|
9
|
+
hash.keys.each do |key|
|
10
|
+
if hash[key].is_a?(Hash) && self[key].is_a?(Hash)
|
11
|
+
target[key] = target[key].deep_merge(hash[key])
|
12
|
+
next
|
13
|
+
end
|
14
|
+
target[key] = hash[key]
|
15
|
+
end
|
16
|
+
target
|
17
|
+
end
|
18
|
+
|
19
|
+
# Take a single user ID or screen name and merge it into self with the correct key
|
20
|
+
#
|
21
|
+
# @param user_id_or_screen_name [Integer, String] A Twitter user ID or screen_name.
|
22
|
+
# @return [Hash]
|
23
|
+
def merge_user!(user_id_or_screen_name)
|
24
|
+
case user_id_or_screen_name
|
25
|
+
when Integer
|
26
|
+
self[:user_id] = user_id_or_screen_name
|
27
|
+
when String
|
28
|
+
self[:screen_name] = user_id_or_screen_name
|
29
|
+
end
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
# Take a multiple user IDs and screen names and merge them into self with the correct keys
|
34
|
+
#
|
35
|
+
# @param users_id_or_screen_names [Array] An array of Twitter user IDs or screen_names.
|
36
|
+
# @return [Hash]
|
37
|
+
def merge_users!(user_ids_or_screen_names)
|
38
|
+
user_ids, screen_names = [], []
|
39
|
+
user_ids_or_screen_names.flatten.each do |user_id_or_screen_name|
|
40
|
+
case user_id_or_screen_name
|
41
|
+
when Integer
|
42
|
+
user_ids << user_id_or_screen_name
|
43
|
+
when String
|
44
|
+
screen_names << user_id_or_screen_name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
self[:user_id] = user_ids.join(',') unless user_ids.empty?
|
48
|
+
self[:screen_name] = screen_names.join(',') unless screen_names.empty?
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
# Take a single owner ID or owner screen name and merge it into self with the correct key
|
53
|
+
# (for Twitter API endpoints that want :owner_id and :owner_screen_name)
|
54
|
+
#
|
55
|
+
# @param owner_id_or_owner_screen_name [Integer, String] A Twitter user ID or screen_name.
|
56
|
+
# @return [Hash]
|
57
|
+
def merge_owner!(owner_id_or_owner_screen_name)
|
58
|
+
case owner_id_or_owner_screen_name
|
59
|
+
when Integer
|
60
|
+
self[:owner_id] = owner_id_or_owner_screen_name
|
61
|
+
when String
|
62
|
+
self[:owner_screen_name] = owner_id_or_owner_screen_name
|
63
|
+
end
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
# Take a single list ID or slug and merge it into self with the correct key
|
68
|
+
#
|
69
|
+
# @param list_id_or_slug [Integer, String] A Twitter list ID or slug.
|
70
|
+
# @return [Hash]
|
71
|
+
def merge_list!(list_id_or_screen_name)
|
72
|
+
case list_id_or_screen_name
|
73
|
+
when Integer
|
74
|
+
self[:list_id] = list_id_or_screen_name
|
75
|
+
when String
|
76
|
+
self[:slug] = list_id_or_screen_name
|
77
|
+
end
|
78
|
+
self
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|