twitter 5.6.0 → 5.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.yardopts +1 -0
  3. data/CHANGELOG.md +8 -0
  4. data/README.md +3 -3
  5. data/Rakefile +1 -1
  6. data/lib/twitter/base.rb +0 -8
  7. data/lib/twitter/client.rb +2 -1
  8. data/lib/twitter/cursor.rb +2 -15
  9. data/lib/twitter/error.rb +90 -18
  10. data/lib/twitter/geo_results.rb +0 -10
  11. data/lib/twitter/request.rb +4 -4
  12. data/lib/twitter/rest/api.rb +43 -0
  13. data/lib/twitter/rest/client.rb +10 -44
  14. data/lib/twitter/rest/direct_messages.rb +138 -0
  15. data/lib/twitter/rest/favorites.rb +108 -0
  16. data/lib/twitter/rest/friends_and_followers.rb +281 -0
  17. data/lib/twitter/rest/help.rb +56 -0
  18. data/lib/twitter/rest/lists.rb +497 -0
  19. data/lib/twitter/rest/oauth.rb +65 -0
  20. data/lib/twitter/rest/places_and_geo.rb +84 -0
  21. data/lib/twitter/rest/request/multipart_with_file.rb +5 -5
  22. data/lib/twitter/rest/response/parse_json.rb +2 -4
  23. data/lib/twitter/rest/response/raise_error.rb +24 -15
  24. data/lib/twitter/rest/saved_searches.rb +93 -0
  25. data/lib/twitter/rest/search.rb +37 -0
  26. data/lib/twitter/rest/spam_reporting.rb +27 -0
  27. data/lib/twitter/rest/suggested_users.rb +49 -0
  28. data/lib/twitter/rest/timelines.rb +200 -0
  29. data/lib/twitter/rest/trends.rb +57 -0
  30. data/lib/twitter/rest/tweets.rb +309 -0
  31. data/lib/twitter/rest/undocumented.rb +49 -0
  32. data/lib/twitter/rest/users.rb +383 -0
  33. data/lib/twitter/rest/utils.rb +205 -0
  34. data/lib/twitter/search_results.rb +2 -13
  35. data/lib/twitter/trend_results.rb +0 -10
  36. data/lib/twitter/version.rb +1 -1
  37. data/spec/helper.rb +1 -1
  38. data/spec/twitter/error_spec.rb +26 -42
  39. data/spec/twitter/rest/{api/direct_messages_spec.rb → direct_messages_spec.rb} +1 -1
  40. data/spec/twitter/rest/{api/favorites_spec.rb → favorites_spec.rb} +1 -1
  41. data/spec/twitter/rest/{api/friends_and_followers_spec.rb → friends_and_followers_spec.rb} +1 -1
  42. data/spec/twitter/rest/{api/geo_spec.rb → geo_spec.rb} +1 -1
  43. data/spec/twitter/rest/{api/help_spec.rb → help_spec.rb} +1 -1
  44. data/spec/twitter/rest/{api/lists_spec.rb → lists_spec.rb} +1 -1
  45. data/spec/twitter/rest/{api/oauth_spec.rb → oauth_spec.rb} +4 -8
  46. data/spec/twitter/rest/{api/saved_searches_spec.rb → saved_searches_spec.rb} +1 -1
  47. data/spec/twitter/rest/{api/search_spec.rb → search_spec.rb} +1 -1
  48. data/spec/twitter/rest/{api/spam_reporting_spec.rb → spam_reporting_spec.rb} +1 -1
  49. data/spec/twitter/rest/{api/suggested_users_spec.rb → suggested_users_spec.rb} +1 -1
  50. data/spec/twitter/rest/{api/timelines_spec.rb → timelines_spec.rb} +1 -1
  51. data/spec/twitter/rest/{api/trends_spec.rb → trends_spec.rb} +1 -1
  52. data/spec/twitter/rest/{api/tweets_spec.rb → tweets_spec.rb} +74 -5
  53. data/spec/twitter/rest/{api/undocumented_spec.rb → undocumented_spec.rb} +1 -1
  54. data/spec/twitter/rest/{api/users_spec.rb → users_spec.rb} +5 -5
  55. data/spec/twitter/tweet_spec.rb +1 -1
  56. data/twitter.gemspec +0 -1
  57. metadata +247 -237
  58. metadata.gz.sig +0 -0
  59. checksums.yaml +0 -7
  60. checksums.yaml.gz.sig +0 -0
  61. data/lib/twitter/error/already_favorited.rb +0 -10
  62. data/lib/twitter/error/already_posted.rb +0 -10
  63. data/lib/twitter/error/already_retweeted.rb +0 -10
  64. data/lib/twitter/error/bad_gateway.rb +0 -10
  65. data/lib/twitter/error/bad_request.rb +0 -10
  66. data/lib/twitter/error/configuration_error.rb +0 -8
  67. data/lib/twitter/error/forbidden.rb +0 -10
  68. data/lib/twitter/error/gateway_timeout.rb +0 -10
  69. data/lib/twitter/error/internal_server_error.rb +0 -10
  70. data/lib/twitter/error/not_acceptable.rb +0 -10
  71. data/lib/twitter/error/not_found.rb +0 -10
  72. data/lib/twitter/error/request_timeout.rb +0 -10
  73. data/lib/twitter/error/service_unavailable.rb +0 -10
  74. data/lib/twitter/error/too_many_requests.rb +0 -12
  75. data/lib/twitter/error/unauthorized.rb +0 -10
  76. data/lib/twitter/error/unprocessable_entity.rb +0 -10
  77. data/lib/twitter/rest/api/direct_messages.rb +0 -140
  78. data/lib/twitter/rest/api/favorites.rb +0 -115
  79. data/lib/twitter/rest/api/friends_and_followers.rb +0 -284
  80. data/lib/twitter/rest/api/help.rb +0 -58
  81. data/lib/twitter/rest/api/lists.rb +0 -500
  82. data/lib/twitter/rest/api/oauth.rb +0 -67
  83. data/lib/twitter/rest/api/places_and_geo.rb +0 -86
  84. data/lib/twitter/rest/api/saved_searches.rb +0 -95
  85. data/lib/twitter/rest/api/search.rb +0 -39
  86. data/lib/twitter/rest/api/spam_reporting.rb +0 -29
  87. data/lib/twitter/rest/api/suggested_users.rb +0 -51
  88. data/lib/twitter/rest/api/timelines.rb +0 -202
  89. data/lib/twitter/rest/api/trends.rb +0 -58
  90. data/lib/twitter/rest/api/tweets.rb +0 -297
  91. data/lib/twitter/rest/api/undocumented.rb +0 -51
  92. data/lib/twitter/rest/api/users.rb +0 -383
  93. data/lib/twitter/rest/api/utils.rb +0 -212
@@ -1,67 +0,0 @@
1
- require 'twitter/request'
2
- require 'twitter/rest/api/utils'
3
- require 'twitter/rest/response/parse_error_json'
4
- require 'twitter/token'
5
-
6
- module Twitter
7
- module REST
8
- module API
9
- module OAuth
10
- include Twitter::REST::API::Utils
11
-
12
- # Allows a registered application to obtain an OAuth 2 Bearer Token, which can be used to make API requests
13
- # on an application's own behalf, without a user context.
14
- #
15
- # Only one bearer token may exist outstanding for an application, and repeated requests to this method
16
- # will yield the same already-existent token until it has been invalidated.
17
- #
18
- # @see https://dev.twitter.com/docs/api/1.1/post/oauth2/token
19
- # @rate_limited No
20
- # @authentication Required
21
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
22
- # @return [Twitter::Token] The Bearer Token. token_type should be 'bearer'.
23
- # @param options [Hash] A customizable set of options.
24
- # @example Generate a Bearer Token
25
- # client = Twitter::REST::Client.new(:consumer_key => "abc", :consumer_secret => 'def')
26
- # bearer_token = client.token
27
- def token(options = {})
28
- options[:bearer_token_request] = true
29
- options[:grant_type] ||= 'client_credentials'
30
- perform_with_object(:post, '/oauth2/token', options, Twitter::Token)
31
- end
32
- alias_method :bearer_token, :token
33
-
34
- # Allows a registered application to revoke an issued OAuth 2 Bearer Token by presenting its client credentials.
35
- #
36
- # @see https://dev.twitter.com/docs/api/1.1/post/oauth2/invalidate_token
37
- # @rate_limited No
38
- # @authentication Required
39
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
40
- # @param access_token [String, Twitter::Token] The bearer token to revoke.
41
- # @param options [Hash] A customizable set of options.
42
- # @return [Twitter::Token] The invalidated token. token_type should be nil.
43
- def invalidate_token(access_token, options = {})
44
- access_token = access_token.access_token if access_token.is_a?(Twitter::Token)
45
- options[:access_token] = access_token
46
- perform_with_object(:post, '/oauth2/invalidate_token', options, Twitter::Token)
47
- end
48
-
49
- # Allows a registered application to revoke an issued OAuth 2 Bearer Token by presenting its client credentials.
50
- #
51
- # @see https://dev.twitter.com/docs/api/1.1/post/oauth2/invalidate_token
52
- # @rate_limited No
53
- # @authentication Required
54
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
55
- # @return [String] The token string.
56
- def reverse_token
57
- conn = connection.dup
58
- conn.builder.swap(4, Twitter::REST::Response::ParseErrorJson)
59
- response = conn.post('/oauth/request_token?x_auth_mode=reverse_auth') do |request|
60
- request.headers[:authorization] = oauth_auth_header(:post, 'https://api.twitter.com/oauth/request_token', :x_auth_mode => 'reverse_auth').to_s
61
- end
62
- response.body
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,86 +0,0 @@
1
- require 'twitter/geo_results'
2
- require 'twitter/place'
3
- require 'twitter/request'
4
- require 'twitter/rest/api/utils'
5
-
6
- module Twitter
7
- module REST
8
- module API
9
- module PlacesAndGeo
10
- include Twitter::REST::API::Utils
11
-
12
- # Returns all the information about a known place
13
- #
14
- # @see https://dev.twitter.com/docs/api/1.1/get/geo/id/:place_id
15
- # @rate_limited Yes
16
- # @authentication Requires user context
17
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
18
- # @param place_id [String] A place in the world. These IDs can be retrieved from {Twitter::REST::API::PlacesAndGeo#reverse_geocode}.
19
- # @param options [Hash] A customizable set of options.
20
- # @return [Twitter::Place] The requested place.
21
- def place(place_id, options = {})
22
- perform_with_object(:get, "/1.1/geo/id/#{place_id}.json", options, Twitter::Place)
23
- end
24
-
25
- # Searches for up to 20 places that can be used as a place_id
26
- #
27
- # @see https://dev.twitter.com/docs/api/1.1/get/geo/reverse_geocode
28
- # @note This request is an informative call and will deliver generalized results about geography.
29
- # @rate_limited Yes
30
- # @authentication Requires user context
31
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
32
- # @param options [Hash] A customizable set of options.
33
- # @option options [Float] :lat The latitude to search around. 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.
34
- # @option options [Float] :long The longitude to search around. The valid range 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.
35
- # @option options [String] :accuracy ('0m') A hint on the "region" in which to search. If a number, then this is a radius in meters, but it can also take a string that is suffixed with ft to specify feet. If coming from a device, in practice, this value is whatever accuracy the device has measuring its location (whether it be coming from a GPS, WiFi triangulation, etc.).
36
- # @option options [String] :granularity ('neighborhood') This is the minimal granularity of place types to return and must be one of: 'poi', 'neighborhood', 'city', 'admin' or 'country'.
37
- # @option options [Integer] :max_results A hint as to the number of results to return. This does not guarantee that the number of results returned will equal max_results, but instead informs how many "nearby" results to return. Ideally, only pass in the number of places you intend to display to the user here.
38
- # @return [Array<Twitter::Place>]
39
- def reverse_geocode(options = {})
40
- perform_with_object(:get, '/1.1/geo/reverse_geocode.json', options, Twitter::GeoResults)
41
- end
42
-
43
- # Search for places that can be attached to a {Twitter::REST::API::Tweets#update}
44
- #
45
- # @see https://dev.twitter.com/docs/api/1.1/get/geo/search
46
- # @rate_limited Yes
47
- # @authentication Requires user context
48
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
49
- # @param options [Hash] A customizable set of options.
50
- # @option options [Float] :lat The latitude to search around. 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.
51
- # @option options [Float] :long The longitude to search around. The valid range 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.
52
- # @option options [String] :query Free-form text to match against while executing a geo-based query, best suited for finding nearby locations by name.
53
- # @option options [String] :ip An IP address. Used when attempting to fix geolocation based off of the user's IP address.
54
- # @option options [String] :granularity ('neighborhood') This is the minimal granularity of place types to return and must be one of: 'poi', 'neighborhood', 'city', 'admin' or 'country'.
55
- # @option options [String] :accuracy ('0m') A hint on the "region" in which to search. If a number, then this is a radius in meters, but it can also take a string that is suffixed with ft to specify feet. If coming from a device, in practice, this value is whatever accuracy the device has measuring its location (whether it be coming from a GPS, WiFi triangulation, etc.).
56
- # @option options [Integer] :max_results A hint as to the number of results to return. This does not guarantee that the number of results returned will equal max_results, but instead informs how many "nearby" results to return. Ideally, only pass in the number of places you intend to display to the user here.
57
- # @option options [String] :contained_within This is the place_id which you would like to restrict the search results to. Setting this value means only places within the given place_id will be found.
58
- # @option options [String] :"attribute:street_address" This option searches for places which have this given street address. There are other well-known and application-specific attributes available. Custom attributes are also permitted.
59
- # @return [Array<Twitter::Place>]
60
- def geo_search(options = {})
61
- perform_with_object(:get, '/1.1/geo/search.json', options, Twitter::GeoResults)
62
- end
63
- alias_method :places_nearby, :geo_search
64
-
65
- # Locates places near the given coordinates which are similar in name
66
- #
67
- # @see https://dev.twitter.com/docs/api/1.1/get/geo/similar_places
68
- # @note Conceptually, you would use this method to get a list of known places to choose from first. Then, if the desired place doesn't exist, make a request to {Twitter::REST::API::PlacesAndGeo#place} to create a new one. The token contained in the response is the token necessary to create a new place.
69
- # @rate_limited Yes
70
- # @authentication Requires user context
71
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
72
- # @param options [Hash] A customizable set of options.
73
- # @option options [Float] :lat The latitude to search around. 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.
74
- # @option options [Float] :long The longitude to search around. The valid range 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.
75
- # @option options [String] :name The name a place is known as.
76
- # @option options [String] :contained_within This is the place_id which you would like to restrict the search results to. Setting this value means only places within the given place_id will be found.
77
- # @option options [String] :"attribute:street_address" This option searches for places which have this given street address. There are other well-known and application-specific attributes available. Custom attributes are also permitted.
78
- # @return [Array<Twitter::Place>]
79
- def similar_places(options = {})
80
- perform_with_object(:get, '/1.1/geo/similar_places.json', options, Twitter::GeoResults)
81
- end
82
- alias_method :places_similar, :similar_places
83
- end
84
- end
85
- end
86
- end
@@ -1,95 +0,0 @@
1
- require 'twitter/arguments'
2
- require 'twitter/request'
3
- require 'twitter/rest/api/utils'
4
- require 'twitter/saved_search'
5
- require 'twitter/utils'
6
-
7
- module Twitter
8
- module REST
9
- module API
10
- module SavedSearches
11
- include Twitter::REST::API::Utils
12
- include Twitter::Utils
13
-
14
- # @rate_limited Yes
15
- # @authentication Requires user context
16
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
17
- # @return [Array<Twitter::SavedSearch>] The saved searches.
18
- # @overload saved_search(options = {})
19
- # Returns the authenticated user's saved search queries
20
- #
21
- # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/list
22
- # @param options [Hash] A customizable set of options.
23
- # @overload saved_search(*ids)
24
- # Retrieve the data for saved searches owned by the authenticating user
25
- #
26
- # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id
27
- # @param ids [Enumerable<Integer>] A collection of saved search IDs.
28
- # @overload saved_search(*ids, options)
29
- # Retrieve the data for saved searches owned by the authenticating user
30
- #
31
- # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id
32
- # @param ids [Enumerable<Integer>] A collection of saved search IDs.
33
- # @param options [Hash] A customizable set of options.
34
- def saved_searches(*args)
35
- arguments = Twitter::Arguments.new(args)
36
- if arguments.empty?
37
- perform_with_objects(:get, '/1.1/saved_searches/list.json', arguments.options, Twitter::SavedSearch)
38
- else
39
- parallel_map(arguments) do |id|
40
- saved_search(id, arguments.options)
41
- end
42
- end
43
- end
44
-
45
- # Retrieve the data for saved searches owned by the authenticating user
46
- #
47
- # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id
48
- # @rate_limited Yes
49
- # @authentication Requires user context
50
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
51
- # @return [Twitter::SavedSearch] The saved searches.
52
- # @param id [Integer] The ID of the saved search.
53
- # @param options [Hash] A customizable set of options.
54
- def saved_search(id, options = {})
55
- perform_with_object(:get, "/1.1/saved_searches/show/#{id}.json", options, Twitter::SavedSearch)
56
- end
57
-
58
- # Creates a saved search for the authenticated user
59
- #
60
- # @see https://dev.twitter.com/docs/api/1.1/post/saved_searches/create
61
- # @rate_limited No
62
- # @authentication Requires user context
63
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
64
- # @return [Twitter::SavedSearch] The created saved search.
65
- # @param query [String] The query of the search the user would like to save.
66
- # @param options [Hash] A customizable set of options.
67
- def create_saved_search(query, options = {})
68
- perform_with_object(:post, '/1.1/saved_searches/create.json', options.merge(:query => query), Twitter::SavedSearch)
69
- end
70
- deprecate_alias :saved_search_create, :create_saved_search
71
-
72
- # Destroys saved searches for the authenticated user
73
- #
74
- # @see https://dev.twitter.com/docs/api/1.1/post/saved_searches/destroy/:id
75
- # @note The search specified by ID must be owned by the authenticating user.
76
- # @rate_limited No
77
- # @authentication Requires user context
78
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
79
- # @return [Array<Twitter::SavedSearch>] The deleted saved searches.
80
- # @overload destroy_saved_search(*ids)
81
- # @param ids [Enumerable<Integer>] A collection of saved search IDs.
82
- # @overload destroy_saved_search(*ids, options)
83
- # @param ids [Enumerable<Integer>] A collection of saved search IDs.
84
- # @param options [Hash] A customizable set of options.
85
- def destroy_saved_search(*args)
86
- arguments = Twitter::Arguments.new(args)
87
- parallel_map(arguments) do |id|
88
- perform_with_object(:post, "/1.1/saved_searches/destroy/#{id}.json", arguments.options, Twitter::SavedSearch)
89
- end
90
- end
91
- deprecate_alias :saved_search_destroy, :destroy_saved_search
92
- end
93
- end
94
- end
95
- end
@@ -1,39 +0,0 @@
1
- require 'twitter/request'
2
- require 'twitter/search_results'
3
-
4
- module Twitter
5
- module REST
6
- module API
7
- module Search
8
- MAX_TWEETS_PER_REQUEST = 100
9
-
10
- # Returns tweets that match a specified query.
11
- #
12
- # @see https://dev.twitter.com/docs/api/1.1/get/search/tweets
13
- # @see https://dev.twitter.com/docs/using-search
14
- # @note Please note that Twitter's search service and, by extension, the Search API is not meant to be an exhaustive source of Tweets. Not all Tweets will be indexed or made available via the search interface.
15
- # @rate_limited Yes
16
- # @authentication Requires user context
17
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
18
- # @param q [String] A search term.
19
- # @param options [Hash] A customizable set of options.
20
- # @option options [String] :geocode Returns tweets by users located within a given radius of the given latitude/longitude. The location is preferentially taking from the Geotagging API, but will fall back to their Twitter profile. The parameter value is specified by "latitude,longitude,radius", where radius units must be specified as either "mi" (miles) or "km" (kilometers). Note that you cannot use the near operator via the API to geocode arbitrary locations; however you can use this geocode parameter to search near geocodes directly.
21
- # @option options [String] :lang Restricts tweets to the given language, given by an ISO 639-1 code.
22
- # @option options [String] :locale Specify the language of the query you are sending (only ja is currently effective). This is intended for language-specific clients and the default should work in the majority of cases.
23
- # @option options [String] :result_type Specifies what type of search results you would prefer to receive. Options are "mixed", "recent", and "popular". The current default is "mixed."
24
- # @option options [Integer] :count The number of tweets to return per page, up to a maximum of 100.
25
- # @option options [String] :until Optional. Returns tweets generated before the given date. Date should be formatted as YYYY-MM-DD.
26
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. There are limits to the number of Tweets which can be accessed through the API. If the limit of Tweets has occured since the since_id, the since_id will be forced to the oldest ID available.
27
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
28
- # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
29
- # @return [Twitter::SearchResults] Return tweets that match a specified query with search metadata
30
- def search(q, options = {})
31
- options[:count] ||= MAX_TWEETS_PER_REQUEST
32
- request = Twitter::Request.new(self, :get, '/1.1/search/tweets.json', options.merge(:q => q))
33
- response = get(request.path, request.options)
34
- Twitter::SearchResults.from_response(response, request)
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,29 +0,0 @@
1
- require 'twitter/request'
2
- require 'twitter/rest/api/utils'
3
- require 'twitter/user'
4
-
5
- module Twitter
6
- module REST
7
- module API
8
- module SpamReporting
9
- include Twitter::REST::API::Utils
10
-
11
- # The users specified are blocked by the authenticated user and reported as spammers
12
- #
13
- # @see https://dev.twitter.com/docs/api/1.1/post/users/report_spam
14
- # @rate_limited Yes
15
- # @authentication Requires user context
16
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
17
- # @return [Array<Twitter::User>] The reported users.
18
- # @overload report_spam(*users)
19
- # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
20
- # @overload report_spam(*users, options)
21
- # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
22
- # @param options [Hash] A customizable set of options.
23
- def report_spam(*args)
24
- parallel_user_objects_from_response(:post, '/1.1/users/report_spam.json', args)
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,51 +0,0 @@
1
- require 'twitter/arguments'
2
- require 'twitter/request'
3
- require 'twitter/rest/api/utils'
4
- require 'twitter/suggestion'
5
- require 'twitter/user'
6
-
7
- module Twitter
8
- module REST
9
- module API
10
- module SuggestedUsers
11
- include Twitter::REST::API::Utils
12
-
13
- # @return [Array<Twitter::Suggestion>]
14
- # @rate_limited Yes
15
- # @authentication Requires user context
16
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
17
- # @overload suggestions(options = {})
18
- # Returns the list of suggested user categories
19
- #
20
- # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions
21
- # @param options [Hash] A customizable set of options.
22
- # @overload suggestions(slug, options = {})
23
- # Returns the users in a given category
24
- #
25
- # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions/:slug
26
- # @param slug [String] The short name of list or a category.
27
- # @param options [Hash] A customizable set of options.
28
- def suggestions(*args)
29
- arguments = Twitter::Arguments.new(args)
30
- if arguments.last
31
- perform_with_object(:get, "/1.1/users/suggestions/#{arguments.pop}.json", arguments.options, Twitter::Suggestion)
32
- else
33
- perform_with_objects(:get, '/1.1/users/suggestions.json', arguments.options, Twitter::Suggestion)
34
- end
35
- end
36
-
37
- # Access the users in a given category of the Twitter suggested user list and return their most recent Tweet if they are not a protected user
38
- #
39
- # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions/:slug/members
40
- # @rate_limited Yes
41
- # @authentication Requires user context
42
- # @param slug [String] The short name of list or a category.
43
- # @param options [Hash] A customizable set of options.
44
- # @return [Array<Twitter::User>]
45
- def suggest_users(slug, options = {})
46
- perform_with_objects(:get, "/1.1/users/suggestions/#{slug}/members.json", options, Twitter::User)
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,202 +0,0 @@
1
- require 'twitter/request'
2
- require 'twitter/rest/api/utils'
3
- require 'twitter/tweet'
4
- require 'twitter/user'
5
-
6
- module Twitter
7
- module REST
8
- module API
9
- module Timelines
10
- include Twitter::REST::API::Utils
11
- DEFAULT_TWEETS_PER_REQUEST = 20
12
- MAX_TWEETS_PER_REQUEST = 200
13
-
14
- # Returns the 20 most recent mentions (statuses containing @username) for the authenticating user
15
- #
16
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/mentions_timeline
17
- # @note This method can only return up to 800 Tweets.
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 options [Hash] A customizable set of options.
23
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
24
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
25
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
26
- # @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.
27
- def mentions_timeline(options = {})
28
- perform_with_objects(:get, '/1.1/statuses/mentions_timeline.json', options, Twitter::Tweet)
29
- end
30
- alias_method :mentions, :mentions_timeline
31
-
32
- # Returns the 20 most recent Tweets posted by the specified user
33
- #
34
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
35
- # @note This method can only return up to 3,200 Tweets.
36
- # @rate_limited Yes
37
- # @authentication Requires user context
38
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
39
- # @return [Array<Twitter::Tweet>]
40
- # @overload user_timeline(user, options = {})
41
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
42
- # @param options [Hash] A customizable set of options.
43
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
44
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
45
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
46
- # @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.
47
- # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets - this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
48
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
49
- # @option options [Boolean, String, Integer] :include_rts Specifies that the timeline should include native retweets in addition to regular tweets. Note: If you're using the trim_user parameter in conjunction with include_rts, the retweets will no longer contain a full user object.
50
- def user_timeline(*args)
51
- objects_from_response_with_user(Twitter::Tweet, :get, '/1.1/statuses/user_timeline.json', args)
52
- end
53
-
54
- # Returns the 20 most recent retweets posted by the specified user
55
- #
56
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
57
- # @note This method can only return up to 3,200 Tweets.
58
- # @rate_limited Yes
59
- # @authentication Requires user context
60
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
61
- # @return [Array<Twitter::Tweet>]
62
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
63
- # @param options [Hash] A customizable set of options.
64
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
65
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
66
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
67
- # @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.
68
- # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets - this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
69
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
70
- def retweeted_by_user(user, options = {})
71
- retweets_from_timeline(options) do |opts|
72
- user_timeline(user, opts)
73
- end
74
- end
75
- alias_method :retweeted_by, :retweeted_by_user
76
-
77
- # Returns the 20 most recent retweets posted by the authenticating user
78
- #
79
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
80
- # @note This method can only return up to 3,200 Tweets.
81
- # @rate_limited Yes
82
- # @authentication Requires user context
83
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
84
- # @return [Array<Twitter::Tweet>]
85
- # @param options [Hash] A customizable set of options.
86
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
87
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
88
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
89
- # @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.
90
- # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets - this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
91
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
92
- def retweeted_by_me(options = {})
93
- retweets_from_timeline(options) do |opts|
94
- user_timeline(opts)
95
- end
96
- end
97
-
98
- # Returns the 20 most recent Tweets, including retweets if they exist, posted by the authenticating user and the users they follow
99
- #
100
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
101
- # @note This method can only return up to 800 Tweets, including retweets.
102
- # @rate_limited Yes
103
- # @authentication Requires user context
104
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
105
- # @return [Array<Twitter::Tweet>]
106
- # @param options [Hash] A customizable set of options.
107
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
108
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
109
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
110
- # @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.
111
- # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets - this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
112
- # @option options [Boolean, String, Integer] :include_rts Specifies that the timeline should include native retweets in addition to regular tweets. Note: If you're using the trim_user parameter in conjunction with include_rts, the retweets will no longer contain a full user object.
113
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
114
- # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
115
- def home_timeline(options = {})
116
- perform_with_objects(:get, '/1.1/statuses/home_timeline.json', options, Twitter::Tweet)
117
- end
118
-
119
- # Returns the 20 most recent retweets posted by users the authenticating user follow.
120
- #
121
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
122
- # @note This method can only return up to 800 Tweets, including retweets.
123
- # @rate_limited Yes
124
- # @authentication Requires user context
125
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
126
- # @return [Array<Twitter::Tweet>]
127
- # @param options [Hash] A customizable set of options.
128
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
129
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
130
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
131
- # @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.
132
- # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets - this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
133
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
134
- # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
135
- def retweeted_to_me(options = {})
136
- retweets_from_timeline(options) do |opts|
137
- home_timeline(opts)
138
- end
139
- end
140
-
141
- # Returns the 20 most recent tweets of the authenticated user that have been retweeted by others
142
- #
143
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets_of_me
144
- # @rate_limited Yes
145
- # @authentication Requires user context
146
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
147
- # @return [Array<Twitter::Tweet>]
148
- # @param options [Hash] A customizable set of options.
149
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
150
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
151
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
152
- # @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.
153
- # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
154
- # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false.
155
- def retweets_of_me(options = {})
156
- perform_with_objects(:get, '/1.1/statuses/retweets_of_me.json', options, Twitter::Tweet)
157
- end
158
-
159
- private
160
-
161
- def retweets_from_timeline(options)
162
- options[:include_rts] = true
163
- count = options[:count] || DEFAULT_TWEETS_PER_REQUEST
164
- collect_with_count(count) do |count_options|
165
- select_retweets(yield(options.merge(count_options)))
166
- end
167
- end
168
-
169
- # @param tweets [Array]
170
- # @return [Array<Twitter::Tweet>]
171
- def select_retweets(tweets)
172
- tweets.select(&:retweet?)
173
- end
174
-
175
- # @param count [Integer]
176
- # @return [Array<Twitter::Tweet>]
177
- def collect_with_count(count)
178
- options = {}
179
- options[:count] = MAX_TWEETS_PER_REQUEST
180
- collect_with_max_id do |max_id|
181
- options[:max_id] = max_id unless max_id.nil?
182
- if count > 0
183
- tweets = yield(options)
184
- count -= tweets.length
185
- tweets
186
- end
187
- end.flatten.compact[0...count]
188
- end
189
-
190
- # @param collection [Array]
191
- # @param max_id [Integer, NilClass]
192
- # @return [Array<Twitter::Tweet>]
193
- def collect_with_max_id(collection = [], max_id = nil, &block)
194
- tweets = yield(max_id)
195
- return collection if tweets.nil?
196
- collection += tweets
197
- tweets.empty? ? collection.flatten : collect_with_max_id(collection, tweets.last.id - 1, &block)
198
- end
199
- end
200
- end
201
- end
202
- end