twitter 4.8.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +36 -0
- data/CONTRIBUTING.md +13 -15
- data/LICENSE.md +1 -1
- data/README.md +401 -261
- data/Rakefile +6 -0
- data/lib/twitter/arguments.rb +14 -0
- data/lib/twitter/base.rb +109 -89
- data/lib/twitter/client.rb +38 -115
- data/lib/twitter/configuration.rb +5 -2
- data/lib/twitter/core_ext/kernel.rb +5 -1
- data/lib/twitter/creatable.rb +7 -4
- data/lib/twitter/cursor.rb +57 -45
- data/lib/twitter/direct_message.rb +2 -11
- data/lib/twitter/entity/uri.rb +14 -0
- data/lib/twitter/enumerable.rb +15 -0
- data/lib/twitter/error/already_favorited.rb +1 -1
- data/lib/twitter/error/already_posted.rb +10 -0
- data/lib/twitter/error/already_retweeted.rb +1 -1
- data/lib/twitter/error/bad_gateway.rb +2 -3
- data/lib/twitter/error/bad_request.rb +2 -2
- data/lib/twitter/error/forbidden.rb +2 -2
- data/lib/twitter/error/gateway_timeout.rb +2 -3
- data/lib/twitter/error/internal_server_error.rb +2 -3
- data/lib/twitter/error/not_acceptable.rb +2 -2
- data/lib/twitter/error/not_found.rb +2 -2
- data/lib/twitter/error/service_unavailable.rb +2 -3
- data/lib/twitter/error/too_many_requests.rb +2 -2
- data/lib/twitter/error/unauthorized.rb +2 -2
- data/lib/twitter/error/unprocessable_entity.rb +2 -2
- data/lib/twitter/error.rb +65 -14
- data/lib/twitter/factory.rb +13 -12
- data/lib/twitter/geo.rb +2 -7
- data/lib/twitter/geo_factory.rb +11 -7
- data/lib/twitter/geo_results.rb +40 -0
- data/lib/twitter/identity.rb +4 -34
- data/lib/twitter/list.rb +21 -4
- data/lib/twitter/media/photo.rb +6 -4
- data/lib/twitter/media_factory.rb +11 -7
- data/lib/twitter/null_object.rb +25 -0
- data/lib/twitter/oembed.rb +3 -2
- data/lib/twitter/place.rb +15 -15
- data/lib/twitter/profile_banner.rb +3 -2
- data/lib/twitter/rate_limit.rb +4 -17
- data/lib/twitter/relationship.rb +2 -19
- data/lib/twitter/rest/api/direct_messages.rb +138 -0
- data/lib/twitter/rest/api/favorites.rb +115 -0
- data/lib/twitter/rest/api/friends_and_followers.rb +287 -0
- data/lib/twitter/rest/api/help.rb +58 -0
- data/lib/twitter/rest/api/lists.rb +498 -0
- data/lib/twitter/rest/api/oauth.rb +62 -0
- data/lib/twitter/rest/api/places_and_geo.rb +86 -0
- data/lib/twitter/rest/api/saved_searches.rb +93 -0
- data/lib/twitter/rest/api/search.rb +37 -0
- data/lib/twitter/rest/api/spam_reporting.rb +29 -0
- data/lib/twitter/rest/api/suggested_users.rb +51 -0
- data/lib/twitter/rest/api/timelines.rb +202 -0
- data/lib/twitter/rest/api/trends.rb +58 -0
- data/lib/twitter/rest/api/tweets.rb +291 -0
- data/lib/twitter/rest/api/undocumented.rb +52 -0
- data/lib/twitter/rest/api/users.rb +383 -0
- data/lib/twitter/rest/api/utils.rb +246 -0
- data/lib/twitter/rest/client.rb +175 -0
- data/lib/twitter/rest/request/multipart_with_file.rb +36 -0
- data/lib/twitter/rest/response/parse_error_json.rb +15 -0
- data/lib/twitter/rest/response/parse_json.rb +31 -0
- data/lib/twitter/{response → rest/response}/raise_error.rb +8 -11
- data/lib/twitter/search_results.rb +37 -21
- data/lib/twitter/settings.rb +1 -6
- data/lib/twitter/size.rb +2 -15
- data/lib/twitter/streaming/client.rb +89 -0
- data/lib/twitter/streaming/connection.rb +22 -0
- data/lib/twitter/streaming/event.rb +35 -0
- data/lib/twitter/streaming/friend_list.rb +13 -0
- data/lib/twitter/streaming/message_parser.rb +18 -0
- data/lib/twitter/streaming/response.rb +34 -0
- data/lib/twitter/suggestion.rb +5 -8
- data/lib/twitter/token.rb +11 -1
- data/lib/twitter/trend.rb +4 -8
- data/lib/twitter/trend_results.rb +65 -0
- data/lib/twitter/tweet.rb +43 -92
- data/lib/twitter/user.rb +72 -47
- data/lib/twitter/version.rb +4 -4
- data/lib/twitter.rb +4 -39
- data/spec/fixtures/already_posted.json +1 -0
- data/spec/fixtures/ids_list.json +1 -1
- data/spec/fixtures/ids_list2.json +1 -1
- data/spec/fixtures/request_token.txt +6 -0
- data/spec/fixtures/search.json +1 -1
- data/spec/fixtures/search_malformed.json +1 -1
- data/spec/fixtures/track_streaming.json +3 -0
- data/spec/fixtures/track_streaming_user.json +5 -0
- data/spec/helper.rb +8 -13
- data/spec/twitter/base_spec.rb +13 -103
- data/spec/twitter/basic_user_spec.rb +3 -3
- data/spec/twitter/configuration_spec.rb +1 -1
- data/spec/twitter/cursor_spec.rb +17 -35
- data/spec/twitter/direct_message_spec.rb +44 -11
- data/spec/twitter/entity/uri_spec.rb +75 -0
- data/spec/twitter/error_spec.rb +59 -11
- data/spec/twitter/geo/point_spec.rb +6 -6
- data/spec/twitter/geo/polygon_spec.rb +5 -5
- data/spec/twitter/geo_factory_spec.rb +4 -4
- data/spec/twitter/geo_results_spec.rb +35 -0
- data/spec/twitter/geo_spec.rb +6 -6
- data/spec/twitter/identifiable_spec.rb +5 -26
- data/spec/twitter/list_spec.rb +54 -11
- data/spec/twitter/media/photo_spec.rb +122 -6
- data/spec/twitter/media_factory_spec.rb +3 -3
- data/spec/twitter/null_object_spec.rb +27 -0
- data/spec/twitter/oembed_spec.rb +69 -45
- data/spec/twitter/place_spec.rb +84 -28
- data/spec/twitter/profile_banner_spec.rb +1 -1
- data/spec/twitter/rate_limit_spec.rb +8 -25
- data/spec/twitter/relationship_spec.rb +26 -12
- data/spec/twitter/{api → rest/api}/direct_messages_spec.rb +28 -15
- data/spec/twitter/{api → rest/api}/favorites_spec.rb +80 -7
- data/spec/twitter/{api → rest/api}/friends_and_followers_spec.rb +121 -152
- data/spec/twitter/{api → rest/api}/geo_spec.rb +9 -23
- data/spec/twitter/{api → rest/api}/help_spec.rb +6 -6
- data/spec/twitter/{api → rest/api}/lists_spec.rb +116 -95
- data/spec/twitter/{api → rest/api}/oauth_spec.rb +21 -10
- data/spec/twitter/{api → rest/api}/saved_searches_spec.rb +13 -13
- data/spec/twitter/{api → rest/api}/search_spec.rb +8 -9
- data/spec/twitter/{api → rest/api}/spam_reporting_spec.rb +3 -3
- data/spec/twitter/{api → rest/api}/suggested_users_spec.rb +5 -5
- data/spec/twitter/{api → rest/api}/timelines_spec.rb +9 -9
- data/spec/twitter/{api → rest/api}/trends_spec.rb +6 -6
- data/spec/twitter/rest/api/tweets_spec.rb +503 -0
- data/spec/twitter/{api → rest/api}/undocumented_spec.rb +19 -45
- data/spec/twitter/{api → rest/api}/users_spec.rb +64 -39
- data/spec/twitter/rest/client_spec.rb +193 -0
- data/spec/twitter/saved_search_spec.rb +14 -3
- data/spec/twitter/search_results_spec.rb +32 -45
- data/spec/twitter/settings_spec.rb +17 -6
- data/spec/twitter/size_spec.rb +5 -15
- data/spec/twitter/source_user_spec.rb +3 -3
- data/spec/twitter/streaming/client_spec.rb +92 -0
- data/spec/twitter/streaming/event_spec.rb +45 -0
- data/spec/twitter/suggestion_spec.rb +5 -15
- data/spec/twitter/target_user_spec.rb +3 -3
- data/spec/twitter/token_spec.rb +16 -0
- data/spec/twitter/trend_results_spec.rb +89 -0
- data/spec/twitter/trend_spec.rb +26 -13
- data/spec/twitter/tweet_spec.rb +137 -124
- data/spec/twitter/user_spec.rb +139 -80
- data/spec/twitter_spec.rb +0 -119
- data/twitter.gemspec +12 -6
- data.tar.gz.sig +0 -0
- metadata +197 -138
- metadata.gz.sig +0 -0
- data/lib/twitter/action/favorite.rb +0 -19
- data/lib/twitter/action/follow.rb +0 -30
- data/lib/twitter/action/list_member_added.rb +0 -39
- data/lib/twitter/action/mention.rb +0 -46
- data/lib/twitter/action/reply.rb +0 -27
- data/lib/twitter/action/retweet.rb +0 -27
- data/lib/twitter/action/tweet.rb +0 -20
- data/lib/twitter/action_factory.rb +0 -22
- data/lib/twitter/api/arguments.rb +0 -13
- data/lib/twitter/api/direct_messages.rb +0 -148
- data/lib/twitter/api/favorites.rb +0 -126
- data/lib/twitter/api/friends_and_followers.rb +0 -334
- data/lib/twitter/api/help.rb +0 -64
- data/lib/twitter/api/lists.rb +0 -618
- data/lib/twitter/api/oauth.rb +0 -44
- data/lib/twitter/api/places_and_geo.rb +0 -121
- data/lib/twitter/api/saved_searches.rb +0 -99
- data/lib/twitter/api/search.rb +0 -37
- data/lib/twitter/api/spam_reporting.rb +0 -30
- data/lib/twitter/api/suggested_users.rb +0 -55
- data/lib/twitter/api/timelines.rb +0 -214
- data/lib/twitter/api/trends.rb +0 -63
- data/lib/twitter/api/tweets.rb +0 -304
- data/lib/twitter/api/undocumented.rb +0 -97
- data/lib/twitter/api/users.rb +0 -439
- data/lib/twitter/api/utils.rb +0 -187
- data/lib/twitter/configurable.rb +0 -96
- data/lib/twitter/default.rb +0 -102
- data/lib/twitter/entity/url.rb +0 -9
- data/lib/twitter/error/client_error.rb +0 -35
- data/lib/twitter/error/decode_error.rb +0 -9
- data/lib/twitter/error/identity_map_key_error.rb +0 -9
- data/lib/twitter/error/server_error.rb +0 -28
- data/lib/twitter/exceptable.rb +0 -36
- data/lib/twitter/identity_map.rb +0 -22
- data/lib/twitter/request/multipart_with_file.rb +0 -34
- data/lib/twitter/response/parse_json.rb +0 -25
- data/spec/fixtures/about_me.json +0 -1
- data/spec/fixtures/activity_summary.json +0 -1
- data/spec/fixtures/bad_gateway.json +0 -1
- data/spec/fixtures/bad_request.json +0 -1
- data/spec/fixtures/by_friends.json +0 -1
- data/spec/fixtures/end_session.json +0 -1
- data/spec/fixtures/forbidden.json +0 -1
- data/spec/fixtures/internal_server_error.json +0 -1
- data/spec/fixtures/not_acceptable.json +0 -1
- data/spec/fixtures/phoenix_search.phoenix +0 -1
- data/spec/fixtures/resolve.json +0 -1
- data/spec/fixtures/service_unavailable.json +0 -1
- data/spec/fixtures/totals.json +0 -1
- data/spec/fixtures/trends.json +0 -1
- data/spec/fixtures/unauthorized.json +0 -1
- data/spec/fixtures/video_facets.json +0 -1
- data/spec/twitter/action/favorite_spec.rb +0 -29
- data/spec/twitter/action/follow_spec.rb +0 -29
- data/spec/twitter/action/list_member_added_spec.rb +0 -41
- data/spec/twitter/action/mention_spec.rb +0 -52
- data/spec/twitter/action/reply_spec.rb +0 -41
- data/spec/twitter/action/retweet_spec.rb +0 -41
- data/spec/twitter/action_factory_spec.rb +0 -35
- data/spec/twitter/action_spec.rb +0 -16
- data/spec/twitter/api/tweets_spec.rb +0 -285
- data/spec/twitter/client_spec.rb +0 -223
- data/spec/twitter/error/client_error_spec.rb +0 -23
- data/spec/twitter/error/server_error_spec.rb +0 -20
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
require 'twitter/arguments'
|
|
2
|
+
require 'twitter/error/already_posted'
|
|
3
|
+
require 'twitter/error/already_retweeted'
|
|
4
|
+
require 'twitter/error/forbidden'
|
|
5
|
+
require 'twitter/oembed'
|
|
6
|
+
require 'twitter/rest/api/utils'
|
|
7
|
+
require 'twitter/tweet'
|
|
8
|
+
|
|
9
|
+
module Twitter
|
|
10
|
+
module REST
|
|
11
|
+
module API
|
|
12
|
+
module Tweets
|
|
13
|
+
include Twitter::REST::API::Utils
|
|
14
|
+
|
|
15
|
+
# Returns up to 100 of the first retweets of a given tweet
|
|
16
|
+
#
|
|
17
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/:id
|
|
18
|
+
# @rate_limited Yes
|
|
19
|
+
# @authentication Requires user context
|
|
20
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
21
|
+
# @return [Array<Twitter::Tweet>]
|
|
22
|
+
# @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
|
|
23
|
+
# @param options [Hash] A customizable set of options.
|
|
24
|
+
# @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
|
|
25
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
|
26
|
+
def retweets(tweet, options={})
|
|
27
|
+
id = extract_id(tweet)
|
|
28
|
+
objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/retweets/#{id}.json", options)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Show up to 100 users who retweeted the Tweet
|
|
32
|
+
#
|
|
33
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/:id
|
|
34
|
+
# @rate_limited Yes
|
|
35
|
+
# @authentication Requires user context
|
|
36
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
37
|
+
# @return [Array]
|
|
38
|
+
# @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
|
|
39
|
+
# @param options [Hash] A customizable set of options.
|
|
40
|
+
# @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
|
|
41
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
|
42
|
+
# @option options [Boolean] :ids_only ('false') Only return user ids instead of full user objects.
|
|
43
|
+
def retweeters_of(tweet, options={})
|
|
44
|
+
ids_only = !!options.delete(:ids_only)
|
|
45
|
+
retweeters = retweets(tweet, options).map(&:user)
|
|
46
|
+
ids_only ? retweeters.map(&:id) : retweeters
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Returns a Tweet
|
|
50
|
+
#
|
|
51
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/show/:id
|
|
52
|
+
# @rate_limited Yes
|
|
53
|
+
# @authentication Requires user context
|
|
54
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
55
|
+
# @raise [Twitter::Error::Forbidden] Error raised when supplied status is over 140 characters.
|
|
56
|
+
# @return [Twitter::Tweet] The requested Tweet.
|
|
57
|
+
# @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
|
|
58
|
+
# @param options [Hash] A customizable set of options.
|
|
59
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
|
60
|
+
def status(tweet, options={})
|
|
61
|
+
id = extract_id(tweet)
|
|
62
|
+
object_from_response(Twitter::Tweet, :get, "/1.1/statuses/show/#{id}.json", options)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Returns Tweets
|
|
66
|
+
#
|
|
67
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/show/:id
|
|
68
|
+
# @rate_limited Yes
|
|
69
|
+
# @authentication Requires user context
|
|
70
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
71
|
+
# @return [Array<Twitter::Tweet>] The requested Tweets.
|
|
72
|
+
# @overload statuses(*tweets)
|
|
73
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
|
74
|
+
# @overload statuses(*tweets, options)
|
|
75
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
|
76
|
+
# @param options [Hash] A customizable set of options.
|
|
77
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
|
78
|
+
def statuses(*args)
|
|
79
|
+
threaded_tweets_from_response(:get, "/1.1/statuses/show", args)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Destroys the specified Tweets
|
|
83
|
+
#
|
|
84
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/statuses/destroy/:id
|
|
85
|
+
# @note The authenticating user must be the author of the specified Tweets.
|
|
86
|
+
# @rate_limited No
|
|
87
|
+
# @authentication Requires user context
|
|
88
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
89
|
+
# @return [Array<Twitter::Tweet>] The deleted Tweets.
|
|
90
|
+
# @overload destroy_status(*tweets)
|
|
91
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
|
92
|
+
# @overload destroy_status(*tweets, options)
|
|
93
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
|
94
|
+
# @param options [Hash] A customizable set of options.
|
|
95
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
|
96
|
+
def destroy_status(*args)
|
|
97
|
+
threaded_tweets_from_response(:post, "/1.1/statuses/destroy", args)
|
|
98
|
+
end
|
|
99
|
+
alias destroy_tweet destroy_status
|
|
100
|
+
deprecate_alias :status_destroy, :destroy_status
|
|
101
|
+
deprecate_alias :tweet_destroy, :destroy_status
|
|
102
|
+
|
|
103
|
+
# Updates the authenticating user's status
|
|
104
|
+
#
|
|
105
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/statuses/update
|
|
106
|
+
# @note A status update with text identical to the authenticating user's current status will be ignored to prevent duplicates.
|
|
107
|
+
# @rate_limited No
|
|
108
|
+
# @authentication Requires user context
|
|
109
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
110
|
+
# @return [Twitter::Tweet] The created Tweet.
|
|
111
|
+
# @param status [String] The text of your status update, up to 140 characters.
|
|
112
|
+
# @param options [Hash] A customizable set of options.
|
|
113
|
+
# @option options [Integer] :in_reply_to_status_id The ID of an existing status that the update is in reply to.
|
|
114
|
+
# @option options [Float] :lat The latitude of the location this tweet refers to. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
|
|
115
|
+
# @option options [Float] :long The longitude of the location this tweet refers to. The valid ranges for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
|
|
116
|
+
# @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::REST::API::PlacesAndGeo#reverse_geocode}.
|
|
117
|
+
# @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from.
|
|
118
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
|
119
|
+
def update(status, options={})
|
|
120
|
+
object_from_response(Twitter::Tweet, :post, "/1.1/statuses/update.json", options.merge(:status => status))
|
|
121
|
+
rescue Twitter::Error::Forbidden => error
|
|
122
|
+
handle_forbidden_error(Twitter::Error::AlreadyPosted, error)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Retweets the specified Tweets as the authenticating user
|
|
126
|
+
#
|
|
127
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/:id
|
|
128
|
+
# @rate_limited Yes
|
|
129
|
+
# @authentication Requires user context
|
|
130
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
131
|
+
# @return [Array<Twitter::Tweet>] The original tweets with retweet details embedded.
|
|
132
|
+
# @overload retweet(*tweets)
|
|
133
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
|
134
|
+
# @overload retweet(*tweets, options)
|
|
135
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
|
136
|
+
# @param options [Hash] A customizable set of options.
|
|
137
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
|
138
|
+
def retweet(*args)
|
|
139
|
+
arguments = Twitter::Arguments.new(args)
|
|
140
|
+
arguments.flatten.threaded_map do |tweet|
|
|
141
|
+
id = extract_id(tweet)
|
|
142
|
+
begin
|
|
143
|
+
post_retweet(id, arguments.options)
|
|
144
|
+
rescue Twitter::Error::Forbidden => error
|
|
145
|
+
raise unless error.message == Twitter::Error::AlreadyRetweeted::MESSAGE
|
|
146
|
+
end
|
|
147
|
+
end.compact
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Retweets the specified Tweets as the authenticating user and raises an error if one has already been retweeted
|
|
151
|
+
#
|
|
152
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/:id
|
|
153
|
+
# @rate_limited Yes
|
|
154
|
+
# @authentication Requires user context
|
|
155
|
+
# @raise [Twitter::Error::AlreadyRetweeted] Error raised when tweet has already been retweeted.
|
|
156
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
157
|
+
# @return [Array<Twitter::Tweet>] The original tweets with retweet details embedded.
|
|
158
|
+
# @overload retweet!(*tweets)
|
|
159
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
|
160
|
+
# @overload retweet!(*tweets, options)
|
|
161
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
|
162
|
+
# @param options [Hash] A customizable set of options.
|
|
163
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
|
164
|
+
def retweet!(*args)
|
|
165
|
+
arguments = Twitter::Arguments.new(args)
|
|
166
|
+
arguments.flatten.threaded_map do |tweet|
|
|
167
|
+
id = extract_id(tweet)
|
|
168
|
+
begin
|
|
169
|
+
post_retweet(id, arguments.options)
|
|
170
|
+
rescue Twitter::Error::Forbidden => error
|
|
171
|
+
handle_forbidden_error(Twitter::Error::AlreadyRetweeted, error)
|
|
172
|
+
end
|
|
173
|
+
end.compact
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# Updates the authenticating user's status with media
|
|
177
|
+
#
|
|
178
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media
|
|
179
|
+
# @note A status update with text/media identical to the authenticating user's current status will NOT be ignored
|
|
180
|
+
# @rate_limited No
|
|
181
|
+
# @authentication Requires user context
|
|
182
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
183
|
+
# @return [Twitter::Tweet] The created Tweet.
|
|
184
|
+
# @param status [String] The text of your status update, up to 140 characters.
|
|
185
|
+
# @param media [File, Hash] A File object with your picture (PNG, JPEG or GIF)
|
|
186
|
+
# @param options [Hash] A customizable set of options.
|
|
187
|
+
# @option options [Integer] :in_reply_to_status_id The ID of an existing Tweet that the update is in reply to.
|
|
188
|
+
# @option options [Float] :lat The latitude of the location this tweet refers to. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
|
|
189
|
+
# @option options [Float] :long The longitude of the location this tweet refers to. The valid ranges for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
|
|
190
|
+
# @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::REST::API::PlacesAndGeo#reverse_geocode}.
|
|
191
|
+
# @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from.
|
|
192
|
+
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
|
193
|
+
def update_with_media(status, media, options={})
|
|
194
|
+
object_from_response(Twitter::Tweet, :post, "/1.1/statuses/update_with_media.json", options.merge('media[]' => media, 'status' => status))
|
|
195
|
+
rescue Twitter::Error::Forbidden => error
|
|
196
|
+
handle_forbidden_error(Twitter::Error::AlreadyPosted, error)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# Returns oEmbed for a Tweet
|
|
200
|
+
#
|
|
201
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/oembed
|
|
202
|
+
# @rate_limited Yes
|
|
203
|
+
# @authentication Requires user context
|
|
204
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
205
|
+
# @return [Twitter::OEmbed] OEmbed for the requested Tweet.
|
|
206
|
+
# @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
|
|
207
|
+
# @param options [Hash] A customizable set of options.
|
|
208
|
+
# @option options [Integer] :maxwidth The maximum width in pixels that the embed should be rendered at. This value is constrained to be between 250 and 550 pixels.
|
|
209
|
+
# @option options [Boolean, String, Integer] :hide_media Specifies whether the embedded Tweet should automatically expand images which were uploaded via {https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media POST statuses/update_with_media}. When set to either true, t or 1 images will not be expanded. Defaults to false.
|
|
210
|
+
# @option options [Boolean, String, Integer] :hide_thread Specifies whether the embedded Tweet should automatically show the original message in the case that the embedded Tweet is a reply. When set to either true, t or 1 the original Tweet will not be shown. Defaults to false.
|
|
211
|
+
# @option options [Boolean, String, Integer] :omit_script Specifies whether the embedded Tweet HTML should include a `<script>` element pointing to widgets.js. In cases where a page already includes widgets.js, setting this value to true will prevent a redundant script element from being included. When set to either true, t or 1 the `<script>` element will not be included in the embed HTML, meaning that pages must include a reference to widgets.js manually. Defaults to false.
|
|
212
|
+
# @option options [String] :align Specifies whether the embedded Tweet should be left aligned, right aligned, or centered in the page. Valid values are left, right, center, and none. Defaults to none, meaning no alignment styles are specified for the Tweet.
|
|
213
|
+
# @option options [String] :related A value for the TWT related parameter, as described in {https://dev.twitter.com/docs/intents Web Intents}. This value will be forwarded to all Web Intents calls.
|
|
214
|
+
# @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
|
|
215
|
+
def oembed(tweet, options={})
|
|
216
|
+
options[:id] = extract_id(tweet)
|
|
217
|
+
object_from_response(Twitter::OEmbed, :get, "/1.1/statuses/oembed.json", options)
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# Returns oEmbeds for Tweets
|
|
221
|
+
#
|
|
222
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/oembed
|
|
223
|
+
# @rate_limited Yes
|
|
224
|
+
# @authentication Requires user context
|
|
225
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
226
|
+
# @return [Array<Twitter::OEmbed>] OEmbeds for the requested Tweets.
|
|
227
|
+
# @overload oembed(*tweets)
|
|
228
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
|
229
|
+
# @overload oembed(*tweets, options)
|
|
230
|
+
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
|
|
231
|
+
# @param options [Hash] A customizable set of options.
|
|
232
|
+
# @option options [Integer] :maxwidth The maximum width in pixels that the embed should be rendered at. This value is constrained to be between 250 and 550 pixels.
|
|
233
|
+
# @option options [Boolean, String, Integer] :hide_media Specifies whether the embedded Tweet should automatically expand images which were uploaded via {https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media POST statuses/update_with_media}. When set to either true, t or 1 images will not be expanded. Defaults to false.
|
|
234
|
+
# @option options [Boolean, String, Integer] :hide_thread Specifies whether the embedded Tweet should automatically show the original message in the case that the embedded Tweet is a reply. When set to either true, t or 1 the original Tweet will not be shown. Defaults to false.
|
|
235
|
+
# @option options [Boolean, String, Integer] :omit_script Specifies whether the embedded Tweet HTML should include a `<script>` element pointing to widgets.js. In cases where a page already includes widgets.js, setting this value to true will prevent a redundant script element from being included. When set to either true, t or 1 the `<script>` element will not be included in the embed HTML, meaning that pages must include a reference to widgets.js manually. Defaults to false.
|
|
236
|
+
# @option options [String] :align Specifies whether the embedded Tweet should be left aligned, right aligned, or centered in the page. Valid values are left, right, center, and none. Defaults to none, meaning no alignment styles are specified for the Tweet.
|
|
237
|
+
# @option options [String] :related A value for the TWT related parameter, as described in {https://dev.twitter.com/docs/intents Web Intents}. This value will be forwarded to all Web Intents calls.
|
|
238
|
+
# @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
|
|
239
|
+
def oembeds(*args)
|
|
240
|
+
arguments = Twitter::Arguments.new(args)
|
|
241
|
+
arguments.flatten.threaded_map do |tweet|
|
|
242
|
+
id = extract_id(tweet)
|
|
243
|
+
oembed(id, arguments.options)
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
# Returns a collection of up to 100 user IDs belonging to users who have retweeted the tweet specified by the id parameter.
|
|
248
|
+
#
|
|
249
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweeters/ids
|
|
250
|
+
# @rate_limited Yes
|
|
251
|
+
# @authentication Required
|
|
252
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
253
|
+
# @return [Array<Integer>]
|
|
254
|
+
# @overload retweeters_ids(options)
|
|
255
|
+
# @param options [Hash] A customizable set of options.
|
|
256
|
+
# @overload retweeters_ids(id, options={})
|
|
257
|
+
# @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
|
|
258
|
+
# @param options [Hash] A customizable set of options.
|
|
259
|
+
def retweeters_ids(*args)
|
|
260
|
+
arguments = Twitter::Arguments.new(args)
|
|
261
|
+
arguments.options[:id] ||= extract_id(arguments.first)
|
|
262
|
+
cursor_from_response(:ids, nil, :get, "/1.1/statuses/retweeters/ids.json", arguments.options)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
private
|
|
266
|
+
|
|
267
|
+
# @param request_method [Symbol]
|
|
268
|
+
# @param path [String]
|
|
269
|
+
# @param args [Array]
|
|
270
|
+
# @return [Array<Twitter::Tweet>]
|
|
271
|
+
def threaded_tweets_from_response(request_method, path, args)
|
|
272
|
+
arguments = Twitter::Arguments.new(args)
|
|
273
|
+
arguments.flatten.threaded_map do |tweet|
|
|
274
|
+
id = extract_id(tweet)
|
|
275
|
+
object_from_response(Twitter::Tweet, request_method, path + "/#{id}.json", arguments.options)
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def post_retweet(tweet, options)
|
|
280
|
+
id = extract_id(tweet)
|
|
281
|
+
response = post("/1.1/statuses/retweet/#{id}.json", options)
|
|
282
|
+
retweeted_status = response.dup
|
|
283
|
+
retweeted_status[:body] = response[:body].delete(:retweeted_status)
|
|
284
|
+
retweeted_status[:body][:retweeted_status] = response[:body]
|
|
285
|
+
Twitter::Tweet.from_response(retweeted_status)
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require 'twitter/arguments'
|
|
2
|
+
require 'twitter/cursor'
|
|
3
|
+
require 'twitter/rest/api/utils'
|
|
4
|
+
require 'twitter/tweet'
|
|
5
|
+
require 'twitter/user'
|
|
6
|
+
|
|
7
|
+
module Twitter
|
|
8
|
+
module REST
|
|
9
|
+
module API
|
|
10
|
+
module Undocumented
|
|
11
|
+
include Twitter::REST::API::Utils
|
|
12
|
+
|
|
13
|
+
# @note Undocumented
|
|
14
|
+
# @rate_limited Yes
|
|
15
|
+
# @authentication Requires user context
|
|
16
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
17
|
+
#
|
|
18
|
+
# @overload following_followers_of(options={})
|
|
19
|
+
# Returns users following followers of the specified user
|
|
20
|
+
#
|
|
21
|
+
# @param options [Hash] A customizable set of options.
|
|
22
|
+
# @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
|
|
23
|
+
# @return [Twitter::Cursor]
|
|
24
|
+
#
|
|
25
|
+
# @overload following_followers_of(user, options={})
|
|
26
|
+
# Returns users following followers of the authenticated user
|
|
27
|
+
#
|
|
28
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
|
29
|
+
# @param options [Hash] A customizable set of options.
|
|
30
|
+
# @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
|
|
31
|
+
# @return [Twitter::Cursor]
|
|
32
|
+
def following_followers_of(*args)
|
|
33
|
+
cursor_from_response_with_user(:users, Twitter::User, :get, "/users/following_followers_of.json", args)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Returns Tweets count for a URI
|
|
37
|
+
#
|
|
38
|
+
# @note Undocumented
|
|
39
|
+
# @rate_limited No
|
|
40
|
+
# @authentication Not required
|
|
41
|
+
# @return [Integer]
|
|
42
|
+
# @param uri [String, URI] A URI.
|
|
43
|
+
# @param options [Hash] A customizable set of options.
|
|
44
|
+
def tweet_count(uri, options={})
|
|
45
|
+
connection = Faraday.new("https://cdn.api.twitter.com", connection_options.merge(:builder => middleware))
|
|
46
|
+
connection.get("/1/urls/count.json", options.merge(:url => uri.to_s)).body[:count]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|