From f9c4e8214bfe0e4cbd13681a6454956f2c6ac21b Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Wed, 29 Jan 2014 15:56:20 +0100 Subject: [PATCH] Remove Twitter::REST::API namespace --- lib/twitter/rest/api/direct_messages.rb | 140 ----- lib/twitter/rest/api/favorites.rb | 115 ---- lib/twitter/rest/api/friends_and_followers.rb | 284 ---------- lib/twitter/rest/api/help.rb | 58 -- lib/twitter/rest/api/lists.rb | 500 ------------------ lib/twitter/rest/api/places_and_geo.rb | 86 --- lib/twitter/rest/api/saved_searches.rb | 95 ---- lib/twitter/rest/api/search.rb | 39 -- lib/twitter/rest/api/spam_reporting.rb | 29 - lib/twitter/rest/api/suggested_users.rb | 51 -- lib/twitter/rest/api/timelines.rb | 202 ------- lib/twitter/rest/api/trends.rb | 58 -- lib/twitter/rest/api/tweets.rb | 297 ----------- lib/twitter/rest/api/undocumented.rb | 51 -- lib/twitter/rest/api/users.rb | 383 -------------- lib/twitter/rest/api/utils.rb | 212 -------- lib/twitter/rest/client.rb | 64 +-- lib/twitter/rest/direct_messages.rb | 138 +++++ lib/twitter/rest/favorites.rb | 113 ++++ lib/twitter/rest/friends_and_followers.rb | 282 ++++++++++ lib/twitter/rest/help.rb | 56 ++ lib/twitter/rest/lists.rb | 498 +++++++++++++++++ lib/twitter/rest/oauth.rb | 65 +++ lib/twitter/rest/places_and_geo.rb | 84 +++ lib/twitter/rest/saved_searches.rb | 93 ++++ lib/twitter/rest/search.rb | 37 ++ lib/twitter/rest/spam_reporting.rb | 27 + lib/twitter/rest/suggested_users.rb | 49 ++ lib/twitter/rest/timelines.rb | 200 +++++++ lib/twitter/rest/trends.rb | 56 ++ lib/twitter/rest/tweets.rb | 295 +++++++++++ lib/twitter/rest/undocumented.rb | 49 ++ lib/twitter/rest/users.rb | 381 +++++++++++++ lib/twitter/rest/utils.rb | 210 ++++++++ .../rest/{api => }/direct_messages_spec.rb | 2 +- spec/twitter/rest/{api => }/favorites_spec.rb | 2 +- .../{api => }/friends_and_followers_spec.rb | 2 +- spec/twitter/rest/{api => }/geo_spec.rb | 2 +- spec/twitter/rest/{api => }/help_spec.rb | 2 +- spec/twitter/rest/{api => }/lists_spec.rb | 2 +- spec/twitter/rest/{api => }/oauth_spec.rb | 2 +- .../rest/{api => }/saved_searches_spec.rb | 2 +- spec/twitter/rest/{api => }/search_spec.rb | 2 +- .../rest/{api => }/spam_reporting_spec.rb | 2 +- .../rest/{api => }/suggested_users_spec.rb | 2 +- spec/twitter/rest/{api => }/timelines_spec.rb | 2 +- spec/twitter/rest/{api => }/trends_spec.rb | 2 +- spec/twitter/rest/{api => }/tweets_spec.rb | 2 +- .../rest/{api => }/undocumented_spec.rb | 2 +- spec/twitter/rest/{api => }/users_spec.rb | 2 +- 50 files changed, 2681 insertions(+), 2648 deletions(-) delete mode 100644 lib/twitter/rest/api/direct_messages.rb delete mode 100644 lib/twitter/rest/api/favorites.rb delete mode 100644 lib/twitter/rest/api/friends_and_followers.rb delete mode 100644 lib/twitter/rest/api/help.rb delete mode 100644 lib/twitter/rest/api/lists.rb delete mode 100644 lib/twitter/rest/api/places_and_geo.rb delete mode 100644 lib/twitter/rest/api/saved_searches.rb delete mode 100644 lib/twitter/rest/api/search.rb delete mode 100644 lib/twitter/rest/api/spam_reporting.rb delete mode 100644 lib/twitter/rest/api/suggested_users.rb delete mode 100644 lib/twitter/rest/api/timelines.rb delete mode 100644 lib/twitter/rest/api/trends.rb delete mode 100644 lib/twitter/rest/api/tweets.rb delete mode 100644 lib/twitter/rest/api/undocumented.rb delete mode 100644 lib/twitter/rest/api/users.rb delete mode 100644 lib/twitter/rest/api/utils.rb create mode 100644 lib/twitter/rest/direct_messages.rb create mode 100644 lib/twitter/rest/favorites.rb create mode 100644 lib/twitter/rest/friends_and_followers.rb create mode 100644 lib/twitter/rest/help.rb create mode 100644 lib/twitter/rest/lists.rb create mode 100644 lib/twitter/rest/oauth.rb create mode 100644 lib/twitter/rest/places_and_geo.rb create mode 100644 lib/twitter/rest/saved_searches.rb create mode 100644 lib/twitter/rest/search.rb create mode 100644 lib/twitter/rest/spam_reporting.rb create mode 100644 lib/twitter/rest/suggested_users.rb create mode 100644 lib/twitter/rest/timelines.rb create mode 100644 lib/twitter/rest/trends.rb create mode 100644 lib/twitter/rest/tweets.rb create mode 100644 lib/twitter/rest/undocumented.rb create mode 100644 lib/twitter/rest/users.rb create mode 100644 lib/twitter/rest/utils.rb rename spec/twitter/rest/{api => }/direct_messages_spec.rb (99%) rename spec/twitter/rest/{api => }/favorites_spec.rb (99%) rename spec/twitter/rest/{api => }/friends_and_followers_spec.rb (99%) rename spec/twitter/rest/{api => }/geo_spec.rb (98%) rename spec/twitter/rest/{api => }/help_spec.rb (98%) rename spec/twitter/rest/{api => }/lists_spec.rb (99%) rename spec/twitter/rest/{api => }/oauth_spec.rb (98%) rename spec/twitter/rest/{api => }/saved_searches_spec.rb (98%) rename spec/twitter/rest/{api => }/search_spec.rb (98%) rename spec/twitter/rest/{api => }/spam_reporting_spec.rb (94%) rename spec/twitter/rest/{api => }/suggested_users_spec.rb (98%) rename spec/twitter/rest/{api => }/timelines_spec.rb (99%) rename spec/twitter/rest/{api => }/trends_spec.rb (98%) rename spec/twitter/rest/{api => }/tweets_spec.rb (99%) rename spec/twitter/rest/{api => }/undocumented_spec.rb (99%) rename spec/twitter/rest/{api => }/users_spec.rb (99%) diff --git a/lib/twitter/rest/api/direct_messages.rb b/lib/twitter/rest/api/direct_messages.rb deleted file mode 100644 index 16e11caf1..000000000 --- a/lib/twitter/rest/api/direct_messages.rb +++ /dev/null @@ -1,140 +0,0 @@ -require 'twitter/arguments' -require 'twitter/direct_message' -require 'twitter/request' -require 'twitter/rest/api/utils' -require 'twitter/user' -require 'twitter/utils' - -module Twitter - module REST - module API - module DirectMessages - include Twitter::REST::API::Utils - include Twitter::Utils - - # Returns the 20 most recent direct messages sent to the authenticating user - # - # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages - # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information. - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] Direct messages sent to the authenticating user. - # @param options [Hash] A customizable set of options. - # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. - # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID. - # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200. - # @option options [Integer] :page Specifies the page of results to retrieve. - def direct_messages_received(options = {}) - perform_with_objects(:get, '/1.1/direct_messages.json', options, Twitter::DirectMessage) - end - - # Returns the 20 most recent direct messages sent by the authenticating user - # - # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/sent - # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information. - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] Direct messages sent by the authenticating user. - # @param options [Hash] A customizable set of options. - # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. - # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID. - # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200. - # @option options [Integer] :page Specifies the page of results to retrieve. - def direct_messages_sent(options = {}) - perform_with_objects(:get, '/1.1/direct_messages/sent.json', options, Twitter::DirectMessage) - end - - # Returns a direct message - # - # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show - # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information. - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::DirectMessage] The requested messages. - # @param id [Integer] A direct message ID. - # @param options [Hash] A customizable set of options. - def direct_message(id, options = {}) - options[:id] = id - perform_with_object(:get, '/1.1/direct_messages/show.json', options, Twitter::DirectMessage) - end - - # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information. - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] The requested messages. - # @overload direct_messages(options = {}) - # Returns the 20 most recent direct messages sent to the authenticating user - # - # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages - # @param options [Hash] A customizable set of options. - # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. - # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID. - # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200. - # @option options [Integer] :page Specifies the page of results to retrieve. - # @overload direct_messages(*ids) - # Returns direct messages - # - # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show - # @param ids [Enumerable] A collection of direct message IDs. - # @overload direct_messages(*ids, options) - # Returns direct messages - # - # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show - # @param ids [Enumerable] A collection of direct message IDs. - # @param options [Hash] A customizable set of options. - def direct_messages(*args) - arguments = Twitter::Arguments.new(args) - if arguments.empty? - direct_messages_received(arguments.options) - else - parallel_map(arguments) do |id| - direct_message(id, arguments.options) - end - end - end - - # Destroys direct messages - # - # @see https://dev.twitter.com/docs/api/1.1/post/direct_messages/destroy - # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information. - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] Deleted direct message. - # @overload destroy_direct_message(*ids) - # @param ids [Enumerable] A collection of direct message IDs. - # @overload destroy_direct_message(*ids, options) - # @param ids [Enumerable] A collection of direct message IDs. - # @param options [Hash] A customizable set of options. - def destroy_direct_message(*args) - parallel_objects_from_response(Twitter::DirectMessage, :post, '/1.1/direct_messages/destroy.json', args) - end - deprecate_alias :direct_message_destroy, :destroy_direct_message - - # Sends a new direct message to the specified user from the authenticating user - # - # @see https://dev.twitter.com/docs/api/1.1/post/direct_messages/new - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::DirectMessage] The sent message. - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param text [String] The text of your direct message, up to 140 characters. - # @param options [Hash] A customizable set of options. - def create_direct_message(user, text, options = {}) - merge_user!(options, user) - options[:text] = text - perform_with_object(:post, '/1.1/direct_messages/new.json', options, Twitter::DirectMessage) - end - alias_method :d, :create_direct_message - alias_method :m, :create_direct_message - alias_method :dm, :create_direct_message - deprecate_alias :direct_message_create, :create_direct_message - end - end - end -end diff --git a/lib/twitter/rest/api/favorites.rb b/lib/twitter/rest/api/favorites.rb deleted file mode 100644 index bb8ac6859..000000000 --- a/lib/twitter/rest/api/favorites.rb +++ /dev/null @@ -1,115 +0,0 @@ -require 'twitter/arguments' -require 'twitter/error/already_favorited' -require 'twitter/error/forbidden' -require 'twitter/request' -require 'twitter/rest/api/utils' -require 'twitter/tweet' -require 'twitter/user' -require 'twitter/utils' - -module Twitter - module REST - module API - module Favorites - include Twitter::REST::API::Utils - include Twitter::Utils - - # @see https://dev.twitter.com/docs/api/1.1/get/favorites/list - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] favorite Tweets. - # @overload favorites(options = {}) - # Returns the 20 most recent favorite Tweets for the authenticating user - # - # @param options [Hash] A customizable set of options. - # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100. - # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. - # @overload favorites(user, options = {}) - # Returns the 20 most recent favorite Tweets for the specified user - # - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param options [Hash] A customizable set of options. - # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100. - # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. - def favorites(*args) - arguments = Twitter::Arguments.new(args) - merge_user!(arguments.options, arguments.pop) if arguments.last - perform_with_objects(:get, '/1.1/favorites/list.json', arguments.options, Twitter::Tweet) - end - - # Un-favorites the specified Tweets as the authenticating user - # - # @see https://dev.twitter.com/docs/api/1.1/post/favorites/destroy - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] The un-favorited Tweets. - # @overload unfavorite(*tweets) - # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @overload unfavorite(*tweets, options) - # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @param options [Hash] A customizable set of options. - def unfavorite(*args) - parallel_objects_from_response(Twitter::Tweet, :post, '/1.1/favorites/destroy.json', args) - end - alias_method :destroy_favorite, :unfavorite - deprecate_alias :favorite_destroy, :unfavorite - - # Favorites the specified Tweets as the authenticating user - # - # @see https://dev.twitter.com/docs/api/1.1/post/favorites/create - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] The favorited Tweets. - # @overload favorite(*tweets) - # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @overload favorite(*tweets, options) - # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @param options [Hash] A customizable set of options. - def favorite(*args) - arguments = Twitter::Arguments.new(args) - parallel_map(arguments) do |tweet| - begin - perform_with_object(:post, '/1.1/favorites/create.json', arguments.options.merge(:id => extract_id(tweet)), Twitter::Tweet) - rescue Twitter::Error::Forbidden => error - raise unless error.message == Twitter::Error::AlreadyFavorited::MESSAGE - end - end.compact - end - alias_method :fav, :favorite - alias_method :fave, :favorite - deprecate_alias :favorite_create, :favorite - - # Favorites the specified Tweets as the authenticating user and raises an error if one has already been favorited - # - # @see https://dev.twitter.com/docs/api/1.1/post/favorites/create - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::AlreadyFavorited] Error raised when tweet has already been favorited. - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] The favorited Tweets. - # @overload favorite(*tweets) - # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @overload favorite(*tweets, options) - # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @param options [Hash] A customizable set of options. - def favorite!(*args) - arguments = Twitter::Arguments.new(args) - parallel_map(arguments) do |tweet| - begin - perform_with_object(:post, '/1.1/favorites/create.json', arguments.options.merge(:id => extract_id(tweet)), Twitter::Tweet) - rescue Twitter::Error::Forbidden => error - handle_forbidden_error(Twitter::Error::AlreadyFavorited, error) - end - end - end - alias_method :create_favorite!, :favorite! - alias_method :fav!, :favorite! - alias_method :fave!, :favorite! - deprecate_alias :favorite_create!, :favorite! - end - end - end -end diff --git a/lib/twitter/rest/api/friends_and_followers.rb b/lib/twitter/rest/api/friends_and_followers.rb deleted file mode 100644 index 2810c879e..000000000 --- a/lib/twitter/rest/api/friends_and_followers.rb +++ /dev/null @@ -1,284 +0,0 @@ -require 'twitter/arguments' -require 'twitter/cursor' -require 'twitter/error/forbidden' -require 'twitter/relationship' -require 'twitter/request' -require 'twitter/rest/api/utils' -require 'twitter/user' -require 'twitter/utils' - -module Twitter - module REST - module API - module FriendsAndFollowers - include Twitter::REST::API::Utils - include Twitter::Utils - - # @see https://dev.twitter.com/docs/api/1.1/get/friends/ids - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::Cursor] - # @overload friend_ids(options = {}) - # Returns an array of numeric IDs for every user the authenticated user is following - # - # @param options [Hash] A customizable set of options. - # @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list. - # @overload friend_ids(user, options = {}) - # Returns an array of numeric IDs for every user the specified user is following - # - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param options [Hash] A customizable set of options. - # @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. - def friend_ids(*args) - cursor_from_response_with_user(:ids, nil, :get, '/1.1/friends/ids.json', args) - end - - # @see https://dev.twitter.com/docs/api/1.1/get/followers/ids - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::Cursor] - # @overload follower_ids(options = {}) - # Returns an array of numeric IDs for every user following the authenticated user - # - # @param options [Hash] A customizable set of options. - # @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. - # @overload follower_ids(user, options = {}) - # Returns an array of numeric IDs for every user following the specified user - # - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param options [Hash] A customizable set of options. - # @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list. - def follower_ids(*args) - cursor_from_response_with_user(:ids, nil, :get, '/1.1/followers/ids.json', args) - end - - # Returns the relationship of the authenticating user to the comma separated list of up to 100 screen_names or user_ids provided. Values for connections can be: following, following_requested, followed_by, none. - # - # @see https://dev.twitter.com/docs/api/1.1/get/friendships/lookup - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] The requested users. - # @overload friendships(*users) - # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @overload friendships(*users, options) - # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @param options [Hash] A customizable set of options. - def friendships(*args) - arguments = Twitter::Arguments.new(args) - merge_users!(arguments.options, arguments) - perform_with_objects(:get, '/1.1/friendships/lookup.json', arguments.options, Twitter::User) - end - - # Returns an array of numeric IDs for every user who has a pending request to follow the authenticating user - # - # @see https://dev.twitter.com/docs/api/1.1/get/friendships/incoming - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::Cursor] - # @param options [Hash] A customizable set of options. - # @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. - def friendships_incoming(options = {}) - perform_with_cursor(:get, '/1.1/friendships/incoming.json', options, :ids) - end - - # Returns an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request - # - # @see https://dev.twitter.com/docs/api/1.1/get/friendships/outgoing - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::Cursor] - # @param options [Hash] A customizable set of options. - # @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. - def friendships_outgoing(options = {}) - perform_with_cursor(:get, '/1.1/friendships/outgoing.json', options, :ids) - end - - # Allows the authenticating user to follow the specified users, unless they are already followed - # - # @see https://dev.twitter.com/docs/api/1.1/post/friendships/create - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] The followed users. - # @overload follow(*users) - # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @overload follow(*users, options) - # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @param options [Hash] A customizable set of options. - # @option options [Boolean] :follow (false) Enable notifications for the target user. - def follow(*args) - arguments = Twitter::Arguments.new(args) - existing_friends = Thread.new do - friend_ids.to_a - end - new_friends = Thread.new do - users(args).collect(&:id) - end - follow!(new_friends.value - existing_friends.value, arguments.options) - end - alias_method :create_friendship, :follow - deprecate_alias :friendship_create, :follow - - # Allows the authenticating user to follow the specified users - # - # @see https://dev.twitter.com/docs/api/1.1/post/friendships/create - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] The followed users. - # @overload follow!(*users) - # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @overload follow!(*users, options) - # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @param options [Hash] A customizable set of options. - # @option options [Boolean] :follow (false) Enable notifications for the target user. - def follow!(*args) - arguments = Twitter::Arguments.new(args) - parallel_map(arguments) do |user| - perform_with_object(:post, '/1.1/friendships/create.json', merge_user(arguments.options, user), Twitter::User) - end.compact - end - alias_method :create_friendship!, :follow! - deprecate_alias :friendship_create!, :follow! - - # Allows the authenticating user to unfollow the specified users - # - # @see https://dev.twitter.com/docs/api/1.1/post/friendships/destroy - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] The unfollowed users. - # @overload unfollow(*users) - # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @overload unfollow(*users, options) - # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @param options [Hash] A customizable set of options. - def unfollow(*args) - parallel_user_objects_from_response(:post, '/1.1/friendships/destroy.json', args) - end - alias_method :destroy_friendship, :unfollow - deprecate_alias :friendship_destroy, :unfollow - - # Allows one to enable or disable retweets and device notifications from the specified user. - # - # @see https://dev.twitter.com/docs/api/1.1/post/friendships/update - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::Relationship] - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param options [Hash] A customizable set of options. - # @option options [Boolean] :device Enable/disable device notifications from the target user. - # @option options [Boolean] :retweets Enable/disable retweets from the target user. - def friendship_update(user, options = {}) - merge_user!(options, user) - perform_with_object(:post, '/1.1/friendships/update.json', options, Twitter::Relationship) - end - - # Returns detailed information about the relationship between two users - # - # @see https://dev.twitter.com/docs/api/1.1/get/friendships/show - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::Relationship] - # @param source [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the source user. - # @param target [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the target user. - # @param options [Hash] A customizable set of options. - def friendship(source, target, options = {}) - merge_user!(options, source, 'source') - options[:source_id] = options.delete(:source_user_id) unless options[:source_user_id].nil? - merge_user!(options, target, 'target') - options[:target_id] = options.delete(:target_user_id) unless options[:target_user_id].nil? - perform_with_object(:get, '/1.1/friendships/show.json', options, Twitter::Relationship) - end - alias_method :friendship_show, :friendship - alias_method :relationship, :friendship - - # Test for the existence of friendship between two users - # - # @see https://dev.twitter.com/docs/api/1.1/get/friendships/show - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Boolean] true if user_a follows user_b, otherwise false. - # @param source [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the source user. - # @param target [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the target user. - # @param options [Hash] A customizable set of options. - def friendship?(source, target, options = {}) - friendship(source, target, options).source.following? - end - - # Returns a cursored collection of user objects for users following the specified user. - # - # @see https://dev.twitter.com/docs/api/1.1/get/followers/list - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::Cursor] - # @overload followers(options = {}) - # Returns a cursored collection of user objects for users following the authenticated user. - # - # @param options [Hash] A customizable set of options. - # @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list. - # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1. - # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false. - # @overload followers(user, options = {}) - # Returns a cursored collection of user objects for users following the specified user. - # - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param options [Hash] A customizable set of options. - # @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. - # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1. - # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false. - def followers(*args) - cursor_from_response_with_user(:users, Twitter::User, :get, '/1.1/followers/list.json', args) - end - - # Returns a cursored collection of user objects for every user the specified user is following (otherwise known as their "friends"). - # - # @see https://dev.twitter.com/docs/api/1.1/get/friendships/show - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::Cursor] - # @overload friends(options = {}) - # Returns a cursored collection of user objects for every user the authenticated user is following (otherwise known as their "friends"). - # - # @param options [Hash] A customizable set of options. - # @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list. - # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1. - # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false. - # @overload friends(user, options = {}) - # Returns a cursored collection of user objects for every user the specified user is following (otherwise known as their "friends"). - # - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param options [Hash] A customizable set of options. - # @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. - # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1. - # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false. - def friends(*args) - cursor_from_response_with_user(:users, Twitter::User, :get, '/1.1/friends/list.json', args) - end - alias_method :following, :friends - - # Returns a collection of user IDs that the currently authenticated user does not want to receive retweets from. - # @see https://dev.twitter.com/docs/api/1.1/get/friendships/no_retweets/ids - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] - # @param options [Hash] A customizable set of options. - def no_retweet_ids(options = {}) - get('/1.1/friendships/no_retweets/ids.json', options)[:body].collect(&:to_i) - end - alias_method :no_retweets_ids, :no_retweet_ids - end - end - end -end diff --git a/lib/twitter/rest/api/help.rb b/lib/twitter/rest/api/help.rb deleted file mode 100644 index 8d33c5e72..000000000 --- a/lib/twitter/rest/api/help.rb +++ /dev/null @@ -1,58 +0,0 @@ -require 'twitter/configuration' -require 'twitter/language' -require 'twitter/request' -require 'twitter/rest/api/utils' - -module Twitter - module REST - module API - module Help - include Twitter::REST::API::Utils - - # Returns the current configuration used by Twitter - # - # @see https://dev.twitter.com/docs/api/1.1/get/help/configuration - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::Configuration] Twitter's configuration. - def configuration(options = {}) - perform_with_object(:get, '/1.1/help/configuration.json', options, Twitter::Configuration) - end - - # Returns the list of languages supported by Twitter - # - # @see https://dev.twitter.com/docs/api/1.1/get/help/languages - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] - def languages(options = {}) - perform_with_objects(:get, '/1.1/help/languages.json', options, Twitter::Language) - end - - # Returns {https://twitter.com/privacy Twitter's Privacy Policy} - # - # @see https://dev.twitter.com/docs/api/1.1/get/help/privacy - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [String] - def privacy(options = {}) - get('/1.1/help/privacy.json', options)[:body][:privacy] - end - - # Returns {https://twitter.com/tos Twitter's Terms of Service} - # - # @see https://dev.twitter.com/docs/api/1.1/get/help/tos - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [String] - def tos(options = {}) - get('/1.1/help/tos.json', options)[:body][:tos] - end - end - end - end -end diff --git a/lib/twitter/rest/api/lists.rb b/lib/twitter/rest/api/lists.rb deleted file mode 100644 index 88103cee9..000000000 --- a/lib/twitter/rest/api/lists.rb +++ /dev/null @@ -1,500 +0,0 @@ -require 'twitter/arguments' -require 'twitter/cursor' -require 'twitter/error/forbidden' -require 'twitter/error/not_found' -require 'twitter/list' -require 'twitter/request' -require 'twitter/rest/api/utils' -require 'twitter/tweet' -require 'twitter/user' -require 'twitter/utils' - -module Twitter - module REST - module API - module Lists - include Twitter::REST::API::Utils - include Twitter::Utils - MAX_USERS_PER_REQUEST = 100 - URI_SUBSTRING = '://' - - # Returns all lists the authenticating or specified user subscribes to, including their own - # - # @see https://dev.twitter.com/docs/api/1.1/get/lists/list - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] - # @overload lists(options = {}) - # @param options [Hash] A customizable set of options. - # @option options [Boolean] :reverse Set this to true if you would like owned lists to be returned first. - # @overload lists(user, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param options [Hash] A customizable set of options. - # @option options [Boolean] :reverse Set this to true if you would like owned lists to be returned first. - def lists(*args) - objects_from_response_with_user(Twitter::List, :get, '/1.1/lists/list.json', args) - end - alias_method :lists_subscribed_to, :lists - - # Show tweet timeline for members of the specified list - # - # @see https://dev.twitter.com/docs/api/1.1/get/lists/statuses - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] - # @overload list_timeline(list, options = {}) - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. - # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID. - # @option options [Integer] :count The number of results to retrieve. - # @overload list_timeline(user, list, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. - # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID. - # @option options [Integer] :count The number of results to retrieve. - def list_timeline(*args) - arguments = Twitter::Arguments.new(args) - merge_list!(arguments.options, arguments.pop) - merge_owner!(arguments.options, arguments.pop) - perform_with_objects(:get, '/1.1/lists/statuses.json', arguments.options, Twitter::Tweet) - end - - # Removes the specified member from the list - # - # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::List] The list. - # @overload remove_list_member(list, user_to_remove, options = {}) - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param user_to_remove [Integer, String] The user id or screen name of the list member to remove. - # @param options [Hash] A customizable set of options. - # @overload remove_list_member(user, list, user_to_remove, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param user_to_remove [Integer, String] The user id or screen name of the list member to remove. - # @param options [Hash] A customizable set of options. - def remove_list_member(*args) - list_from_response_with_user(:post, '/1.1/lists/members/destroy.json', args) - end - deprecate_alias :list_remove_member, :remove_list_member - - # List the lists the specified user has been added to - # - # @see https://dev.twitter.com/docs/api/1.1/get/lists/memberships - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::Cursor] - # @overload memberships(options = {}) - # @param options [Hash] A customizable set of options. - # @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. - # @option options [Boolean, String, Integer] :filter_to_owned_lists When set to true, t or 1, will return just lists the authenticating user owns, and the user represented by user_id or screen_name is a member of. - # @overload memberships(user, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param options [Hash] A customizable set of options. - # @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. - # @option options [Boolean, String, Integer] :filter_to_owned_lists When set to true, t or 1, will return just lists the authenticating user owns, and the user represented by user_id or screen_name is a member of. - def memberships(*args) - cursor_from_response_with_user(:lists, Twitter::List, :get, '/1.1/lists/memberships.json', args) - end - - # Returns the subscribers of the specified list - # - # @see https://dev.twitter.com/docs/api/1.1/get/lists/subscribers - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::Cursor] The subscribers of the specified list. - # @overload list_subscribers(list, options = {}) - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - # @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. - # @overload list_subscribers(user, list, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - # @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. - def list_subscribers(*args) - cursor_from_response_with_list(:get, '/1.1/lists/subscribers.json', args) - end - - # Make the authenticated user follow the specified list - # - # @see https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/create - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::List] The specified list. - # @overload list_subscribe(list, options = {}) - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - # @overload list_subscribe(user, list, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - def list_subscribe(*args) - list_from_response(:post, '/1.1/lists/subscribers/create.json', args) - end - - # Check if a user is a subscriber of the specified list - # - # @see https://dev.twitter.com/docs/api/1.1/get/lists/subscribers/show - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Boolean] true if user is a subscriber of the specified list, otherwise false. - # @overload list_subscriber?(list, user_to_check, options = {}) - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param user_to_check [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param options [Hash] A customizable set of options. - # @overload list_subscriber?(user, list, user_to_check, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param user_to_check [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param options [Hash] A customizable set of options. - # @return [Boolean] true if user is a subscriber of the specified list, otherwise false. - def list_subscriber?(*args) - list_user?(:get, '/1.1/lists/subscribers/show.json', args) - end - - # Unsubscribes the authenticated user form the specified list - # - # @see https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/destroy - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::List] The specified list. - # @overload list_unsubscribe(list, options = {}) - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - # @overload list_unsubscribe(user, list, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - def list_unsubscribe(*args) - list_from_response(:post, '/1.1/lists/subscribers/destroy.json', args) - end - - # Adds specified members to a list - # - # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/create_all - # @note Lists are limited to having 500 members, and you are limited to adding up to 100 members to a list at a time with this method. - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::List] The list. - # @overload add_list_members(list, users, options = {}) - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @param options [Hash] A customizable set of options. - # @overload add_list_members(user, list, users, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @param options [Hash] A customizable set of options. - def add_list_members(*args) - list_from_response_with_users(:post, '/1.1/lists/members/create_all.json', args) - end - deprecate_alias :list_add_members, :add_list_members - - # Check if a user is a member of the specified list - # - # @see https://dev.twitter.com/docs/api/1.1/get/lists/members/show - # @authentication Requires user context - # @rate_limited Yes - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Boolean] true if user is a member of the specified list, otherwise false. - # @overload list_member?(list, user_to_check, options = {}) - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param user_to_check [Integer, String] The user ID or screen name of the list member. - # @param options [Hash] A customizable set of options. - # @overload list_member?(user, list, user_to_check, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param user_to_check [Integer, String] The user ID or screen name of the list member. - # @param options [Hash] A customizable set of options. - def list_member?(*args) - list_user?(:get, '/1.1/lists/members/show.json', args) - end - - # Returns the members of the specified list - # - # @see https://dev.twitter.com/docs/api/1.1/get/lists/members - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::Cursor] - # @overload list_members(list, options = {}) - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - # @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. - # @overload list_members(user, list, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - # @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. - def list_members(*args) - cursor_from_response_with_list(:get, '/1.1/lists/members.json', args) - end - - # Add a member to a list - # - # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/create - # @note Lists are limited to having 500 members. - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::List] The list. - # @overload add_list_member(list, user_to_add, options = {}) - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param user_to_add [Integer, String] The user id or screen name to add to the list. - # @param options [Hash] A customizable set of options. - # @overload add_list_member(user, list, user_to_add, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param user_to_add [Integer, String] The user id or screen name to add to the list. - # @param options [Hash] A customizable set of options. - def add_list_member(*args) - list_from_response_with_user(:post, '/1.1/lists/members/create.json', args) - end - deprecate_alias :list_add_member, :add_list_member - - # Deletes the specified list - # - # @see https://dev.twitter.com/docs/api/1.1/post/lists/destroy - # @note Must be owned by the authenticated user. - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::List] The deleted list. - # @overload destroy_list(list, options = {}) - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - # @overload destroy_list(user, list, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - def destroy_list(*args) - list_from_response(:post, '/1.1/lists/destroy.json', args) - end - deprecate_alias :list_destroy, :destroy_list - - # Updates the specified list - # - # @see https://dev.twitter.com/docs/api/1.1/post/lists/update - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::List] The created list. - # @overload list_update(list, options = {}) - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'. - # @option options [String] :description The description to give the list. - # @overload list_update(user, list, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'. - # @option options [String] :description The description to give the list. - def list_update(*args) - list_from_response(:post, '/1.1/lists/update.json', args) - end - - # Creates a new list for the authenticated user - # - # @see https://dev.twitter.com/docs/api/1.1/post/lists/create - # @note Accounts are limited to 20 lists. - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::List] The created list. - # @param name [String] The name for the list. - # @param options [Hash] A customizable set of options. - # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'. - # @option options [String] :description The description to give the list. - def create_list(name, options = {}) - perform_with_object(:post, '/1.1/lists/create.json', options.merge(:name => name), Twitter::List) - end - deprecate_alias :list_create, :create_list - - # Show the specified list - # - # @see https://dev.twitter.com/docs/api/1.1/get/lists/show - # @note Private lists will only be shown if the authenticated user owns the specified list. - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::List] The specified list. - # @overload list(list, options = {}) - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - # @overload list(user, list, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param options [Hash] A customizable set of options. - def list(*args) - list_from_response(:get, '/1.1/lists/show.json', args) - end - - # List the lists the specified user follows - # - # @see https://dev.twitter.com/docs/api/1.1/get/lists/subscriptions - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::Cursor] - # @overload subscriptions(options = {}) - # @param options [Hash] A customizable set of options. - # @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. - # @overload subscriptions(user, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param options [Hash] A customizable set of options. - # @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. - def subscriptions(*args) - cursor_from_response_with_user(:lists, Twitter::List, :get, '/1.1/lists/subscriptions.json', args) - end - - # Removes specified members from the list - # - # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy_all - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::List] The list. - # @overload remove_list_members(list, users, options = {}) - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @param options [Hash] A customizable set of options. - # @overload remove_list_members(user, list, users, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. - # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @param options [Hash] A customizable set of options. - def remove_list_members(*args) - list_from_response_with_users(:post, '/1.1/lists/members/destroy_all.json', args) - end - deprecate_alias :list_remove_members, :remove_list_members - - # Returns the lists owned by the specified Twitter user - # - # @see https://dev.twitter.com/docs/api/1.1/get/lists/ownerships - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] - # @overload owned_lists(options = {}) - # @param options [Hash] A customizable set of options. - # @option options [Integer] :count The amount of results to return per page. Defaults to 20. No more than 1000 results will ever be returned in a single page. - # @overload owned_lists(user, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param options [Hash] A customizable set of options. - # @option options [Integer] :count The amount of results to return per page. Defaults to 20. No more than 1000 results will ever be returned in a single page. - def owned_lists(*args) - cursor_from_response_with_user(:lists, Twitter::List, :get, '/1.1/lists/ownerships.json', args) - end - deprecate_alias :lists_ownerships, :owned_lists - deprecate_alias :lists_owned, :owned_lists - - private - - # @param request_method [Symbol] - # @param path [String] - # @param args [Array] - # @return [Array] - def list_from_response(request_method, path, args) - arguments = Twitter::Arguments.new(args) - merge_list!(arguments.options, arguments.pop) - merge_owner!(arguments.options, arguments.pop) - perform_with_object(request_method, path, arguments.options, Twitter::List) - end - - def cursor_from_response_with_list(request_method, path, args) - arguments = Twitter::Arguments.new(args) - merge_list!(arguments.options, arguments.pop) - merge_owner!(arguments.options, arguments.pop) - perform_with_cursor(request_method, path, arguments.options, :users, Twitter::User) - end - - def list_user?(request_method, path, args) - arguments = Twitter::Arguments.new(args) - merge_user!(arguments.options, arguments.pop) - merge_list!(arguments.options, arguments.pop) - merge_owner!(arguments.options, arguments.pop) - send(request_method.to_sym, path, arguments.options) - true - rescue Twitter::Error::NotFound, Twitter::Error::Forbidden - false - end - - def list_from_response_with_user(request_method, path, args) - arguments = Twitter::Arguments.new(args) - merge_user!(arguments.options, arguments.pop) - merge_list!(arguments.options, arguments.pop) - merge_owner!(arguments.options, arguments.pop) - perform_with_object(request_method, path, arguments.options, Twitter::List) - end - - def list_from_response_with_users(request_method, path, args) - arguments = args.dup - options = arguments.last.is_a?(::Hash) ? arguments.pop : {} - members = arguments.pop - merge_list!(options, arguments.pop) - merge_owner!(options, arguments.pop) - parallel_map(members.flatten.each_slice(MAX_USERS_PER_REQUEST)) do |users| - perform_with_object(request_method, path, merge_users(options, users), Twitter::List) - end.last - end - - # Take a list and merge it into the hash with the correct key - # - # @param hash [Hash] - # @param list [Integer, String, URI, Twitter::List] A Twitter list ID, slug, URI, or object. - # @return [Hash] - def merge_list!(hash, list) # rubocop:disable MethodLength - case list - when Integer - hash[:list_id] = list - when String - if list[URI_SUBSTRING] - list = list.split('/') - hash[:slug] = list.pop - hash[:owner_screen_name] = list.pop - else - hash[:slug] = list - end - when URI - list = list.path.split('/') - hash[:slug] = list.pop - hash[:owner_screen_name] = list.pop - when Twitter::List - hash[:list_id] = list.id - merge_owner!(hash, list.user) - end - hash - end - - # Take an owner and merge it into the hash with the correct key - # - # @param hash [Hash] - # @param user[Integer, String, Twitter::User] A Twitter user ID, screen_name, or object. - # @return [Hash] - def merge_owner!(hash, user) - unless hash[:owner_id] || hash[:owner_screen_name] - user ||= screen_name - merge_user!(hash, user, 'owner') - hash[:owner_id] = hash.delete(:owner_user_id) unless hash[:owner_user_id].nil? - end - hash - end - end - end - end -end diff --git a/lib/twitter/rest/api/places_and_geo.rb b/lib/twitter/rest/api/places_and_geo.rb deleted file mode 100644 index 56fc981bb..000000000 --- a/lib/twitter/rest/api/places_and_geo.rb +++ /dev/null @@ -1,86 +0,0 @@ -require 'twitter/geo_results' -require 'twitter/place' -require 'twitter/request' -require 'twitter/rest/api/utils' - -module Twitter - module REST - module API - module PlacesAndGeo - include Twitter::REST::API::Utils - - # Returns all the information about a known place - # - # @see https://dev.twitter.com/docs/api/1.1/get/geo/id/:place_id - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @param place_id [String] A place in the world. These IDs can be retrieved from {Twitter::REST::API::PlacesAndGeo#reverse_geocode}. - # @param options [Hash] A customizable set of options. - # @return [Twitter::Place] The requested place. - def place(place_id, options = {}) - perform_with_object(:get, "/1.1/geo/id/#{place_id}.json", options, Twitter::Place) - end - - # Searches for up to 20 places that can be used as a place_id - # - # @see https://dev.twitter.com/docs/api/1.1/get/geo/reverse_geocode - # @note This request is an informative call and will deliver generalized results about geography. - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @param options [Hash] A customizable set of options. - # @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. - # @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. - # @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.). - # @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'. - # @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. - # @return [Array] - def reverse_geocode(options = {}) - perform_with_object(:get, '/1.1/geo/reverse_geocode.json', options, Twitter::GeoResults) - end - - # Search for places that can be attached to a {Twitter::REST::API::Tweets#update} - # - # @see https://dev.twitter.com/docs/api/1.1/get/geo/search - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @param options [Hash] A customizable set of options. - # @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. - # @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. - # @option options [String] :query Free-form text to match against while executing a geo-based query, best suited for finding nearby locations by name. - # @option options [String] :ip An IP address. Used when attempting to fix geolocation based off of the user's IP address. - # @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'. - # @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.). - # @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. - # @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. - # @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. - # @return [Array] - def geo_search(options = {}) - perform_with_object(:get, '/1.1/geo/search.json', options, Twitter::GeoResults) - end - alias_method :places_nearby, :geo_search - - # Locates places near the given coordinates which are similar in name - # - # @see https://dev.twitter.com/docs/api/1.1/get/geo/similar_places - # @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. - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @param options [Hash] A customizable set of options. - # @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. - # @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. - # @option options [String] :name The name a place is known as. - # @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. - # @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. - # @return [Array] - def similar_places(options = {}) - perform_with_object(:get, '/1.1/geo/similar_places.json', options, Twitter::GeoResults) - end - alias_method :places_similar, :similar_places - end - end - end -end diff --git a/lib/twitter/rest/api/saved_searches.rb b/lib/twitter/rest/api/saved_searches.rb deleted file mode 100644 index 0056b7d6e..000000000 --- a/lib/twitter/rest/api/saved_searches.rb +++ /dev/null @@ -1,95 +0,0 @@ -require 'twitter/arguments' -require 'twitter/request' -require 'twitter/rest/api/utils' -require 'twitter/saved_search' -require 'twitter/utils' - -module Twitter - module REST - module API - module SavedSearches - include Twitter::REST::API::Utils - include Twitter::Utils - - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] The saved searches. - # @overload saved_search(options = {}) - # Returns the authenticated user's saved search queries - # - # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/list - # @param options [Hash] A customizable set of options. - # @overload saved_search(*ids) - # Retrieve the data for saved searches owned by the authenticating user - # - # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id - # @param ids [Enumerable] A collection of saved search IDs. - # @overload saved_search(*ids, options) - # Retrieve the data for saved searches owned by the authenticating user - # - # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id - # @param ids [Enumerable] A collection of saved search IDs. - # @param options [Hash] A customizable set of options. - def saved_searches(*args) - arguments = Twitter::Arguments.new(args) - if arguments.empty? - perform_with_objects(:get, '/1.1/saved_searches/list.json', arguments.options, Twitter::SavedSearch) - else - parallel_map(arguments) do |id| - saved_search(id, arguments.options) - end - end - end - - # Retrieve the data for saved searches owned by the authenticating user - # - # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::SavedSearch] The saved searches. - # @param id [Integer] The ID of the saved search. - # @param options [Hash] A customizable set of options. - def saved_search(id, options = {}) - perform_with_object(:get, "/1.1/saved_searches/show/#{id}.json", options, Twitter::SavedSearch) - end - - # Creates a saved search for the authenticated user - # - # @see https://dev.twitter.com/docs/api/1.1/post/saved_searches/create - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::SavedSearch] The created saved search. - # @param query [String] The query of the search the user would like to save. - # @param options [Hash] A customizable set of options. - def create_saved_search(query, options = {}) - perform_with_object(:post, '/1.1/saved_searches/create.json', options.merge(:query => query), Twitter::SavedSearch) - end - deprecate_alias :saved_search_create, :create_saved_search - - # Destroys saved searches for the authenticated user - # - # @see https://dev.twitter.com/docs/api/1.1/post/saved_searches/destroy/:id - # @note The search specified by ID must be owned by the authenticating user. - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] The deleted saved searches. - # @overload destroy_saved_search(*ids) - # @param ids [Enumerable] A collection of saved search IDs. - # @overload destroy_saved_search(*ids, options) - # @param ids [Enumerable] A collection of saved search IDs. - # @param options [Hash] A customizable set of options. - def destroy_saved_search(*args) - arguments = Twitter::Arguments.new(args) - parallel_map(arguments) do |id| - perform_with_object(:post, "/1.1/saved_searches/destroy/#{id}.json", arguments.options, Twitter::SavedSearch) - end - end - deprecate_alias :saved_search_destroy, :destroy_saved_search - end - end - end -end diff --git a/lib/twitter/rest/api/search.rb b/lib/twitter/rest/api/search.rb deleted file mode 100644 index bc75acb19..000000000 --- a/lib/twitter/rest/api/search.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'twitter/request' -require 'twitter/search_results' - -module Twitter - module REST - module API - module Search - MAX_TWEETS_PER_REQUEST = 100 - - # Returns tweets that match a specified query. - # - # @see https://dev.twitter.com/docs/api/1.1/get/search/tweets - # @see https://dev.twitter.com/docs/using-search - # @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. - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @param q [String] A search term. - # @param options [Hash] A customizable set of options. - # @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. - # @option options [String] :lang Restricts tweets to the given language, given by an ISO 639-1 code. - # @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. - # @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." - # @option options [Integer] :count The number of tweets to return per page, up to a maximum of 100. - # @option options [String] :until Optional. Returns tweets generated before the given date. Date should be formatted as YYYY-MM-DD. - # @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. - # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID. - # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false. - # @return [Twitter::SearchResults] Return tweets that match a specified query with search metadata - def search(q, options = {}) - options[:count] ||= MAX_TWEETS_PER_REQUEST - request = Twitter::Request.new(self, :get, '/1.1/search/tweets.json', options.merge(:q => q)) - response = get(request.path, request.options) - Twitter::SearchResults.from_response(response, request) - end - end - end - end -end diff --git a/lib/twitter/rest/api/spam_reporting.rb b/lib/twitter/rest/api/spam_reporting.rb deleted file mode 100644 index 817f18631..000000000 --- a/lib/twitter/rest/api/spam_reporting.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'twitter/request' -require 'twitter/rest/api/utils' -require 'twitter/user' - -module Twitter - module REST - module API - module SpamReporting - include Twitter::REST::API::Utils - - # The users specified are blocked by the authenticated user and reported as spammers - # - # @see https://dev.twitter.com/docs/api/1.1/post/users/report_spam - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] The reported users. - # @overload report_spam(*users) - # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @overload report_spam(*users, options) - # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @param options [Hash] A customizable set of options. - def report_spam(*args) - parallel_user_objects_from_response(:post, '/1.1/users/report_spam.json', args) - end - end - end - end -end diff --git a/lib/twitter/rest/api/suggested_users.rb b/lib/twitter/rest/api/suggested_users.rb deleted file mode 100644 index ca9663978..000000000 --- a/lib/twitter/rest/api/suggested_users.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'twitter/arguments' -require 'twitter/request' -require 'twitter/rest/api/utils' -require 'twitter/suggestion' -require 'twitter/user' - -module Twitter - module REST - module API - module SuggestedUsers - include Twitter::REST::API::Utils - - # @return [Array] - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @overload suggestions(options = {}) - # Returns the list of suggested user categories - # - # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions - # @param options [Hash] A customizable set of options. - # @overload suggestions(slug, options = {}) - # Returns the users in a given category - # - # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions/:slug - # @param slug [String] The short name of list or a category. - # @param options [Hash] A customizable set of options. - def suggestions(*args) - arguments = Twitter::Arguments.new(args) - if arguments.last - perform_with_object(:get, "/1.1/users/suggestions/#{arguments.pop}.json", arguments.options, Twitter::Suggestion) - else - perform_with_objects(:get, '/1.1/users/suggestions.json', arguments.options, Twitter::Suggestion) - end - end - - # 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 - # - # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions/:slug/members - # @rate_limited Yes - # @authentication Requires user context - # @param slug [String] The short name of list or a category. - # @param options [Hash] A customizable set of options. - # @return [Array] - def suggest_users(slug, options = {}) - perform_with_objects(:get, "/1.1/users/suggestions/#{slug}/members.json", options, Twitter::User) - end - end - end - end -end diff --git a/lib/twitter/rest/api/timelines.rb b/lib/twitter/rest/api/timelines.rb deleted file mode 100644 index 410326eb6..000000000 --- a/lib/twitter/rest/api/timelines.rb +++ /dev/null @@ -1,202 +0,0 @@ -require 'twitter/request' -require 'twitter/rest/api/utils' -require 'twitter/tweet' -require 'twitter/user' - -module Twitter - module REST - module API - module Timelines - include Twitter::REST::API::Utils - DEFAULT_TWEETS_PER_REQUEST = 20 - MAX_TWEETS_PER_REQUEST = 200 - - # Returns the 20 most recent mentions (statuses containing @username) for the authenticating user - # - # @see https://dev.twitter.com/docs/api/1.1/get/statuses/mentions_timeline - # @note This method can only return up to 800 Tweets. - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] - # @param options [Hash] A customizable set of options. - # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. - # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID. - # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200. - # @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. - def mentions_timeline(options = {}) - perform_with_objects(:get, '/1.1/statuses/mentions_timeline.json', options, Twitter::Tweet) - end - alias_method :mentions, :mentions_timeline - - # Returns the 20 most recent Tweets posted by the specified user - # - # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline - # @note This method can only return up to 3,200 Tweets. - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] - # @overload user_timeline(user, options = {}) - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param options [Hash] A customizable set of options. - # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. - # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID. - # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200. - # @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. - # @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. - # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor. - # @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. - def user_timeline(*args) - objects_from_response_with_user(Twitter::Tweet, :get, '/1.1/statuses/user_timeline.json', args) - end - - # Returns the 20 most recent retweets posted by the specified user - # - # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline - # @note This method can only return up to 3,200 Tweets. - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] - # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @param options [Hash] A customizable set of options. - # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. - # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID. - # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200. - # @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. - # @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. - # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor. - def retweeted_by_user(user, options = {}) - retweets_from_timeline(options) do |opts| - user_timeline(user, opts) - end - end - alias_method :retweeted_by, :retweeted_by_user - - # Returns the 20 most recent retweets posted by the authenticating user - # - # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline - # @note This method can only return up to 3,200 Tweets. - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] - # @param options [Hash] A customizable set of options. - # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. - # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID. - # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200. - # @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. - # @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. - # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor. - def retweeted_by_me(options = {}) - retweets_from_timeline(options) do |opts| - user_timeline(opts) - end - end - - # Returns the 20 most recent Tweets, including retweets if they exist, posted by the authenticating user and the users they follow - # - # @see https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline - # @note This method can only return up to 800 Tweets, including retweets. - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] - # @param options [Hash] A customizable set of options. - # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. - # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID. - # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200. - # @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. - # @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. - # @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. - # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor. - # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false. - def home_timeline(options = {}) - perform_with_objects(:get, '/1.1/statuses/home_timeline.json', options, Twitter::Tweet) - end - - # Returns the 20 most recent retweets posted by users the authenticating user follow. - # - # @see https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline - # @note This method can only return up to 800 Tweets, including retweets. - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] - # @param options [Hash] A customizable set of options. - # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. - # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID. - # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200. - # @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. - # @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. - # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor. - # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false. - def retweeted_to_me(options = {}) - retweets_from_timeline(options) do |opts| - home_timeline(opts) - end - end - - # Returns the 20 most recent tweets of the authenticated user that have been retweeted by others - # - # @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets_of_me - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] - # @param options [Hash] A customizable set of options. - # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200. - # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. - # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID. - # @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. - # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false. - # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false. - def retweets_of_me(options = {}) - perform_with_objects(:get, '/1.1/statuses/retweets_of_me.json', options, Twitter::Tweet) - end - - private - - def retweets_from_timeline(options) - options[:include_rts] = true - count = options[:count] || DEFAULT_TWEETS_PER_REQUEST - collect_with_count(count) do |count_options| - select_retweets(yield(options.merge(count_options))) - end - end - - # @param tweets [Array] - # @return [Array] - def select_retweets(tweets) - tweets.select(&:retweet?) - end - - # @param count [Integer] - # @return [Array] - def collect_with_count(count) - options = {} - options[:count] = MAX_TWEETS_PER_REQUEST - collect_with_max_id do |max_id| - options[:max_id] = max_id unless max_id.nil? - if count > 0 - tweets = yield(options) - count -= tweets.length - tweets - end - end.flatten.compact[0...count] - end - - # @param collection [Array] - # @param max_id [Integer, NilClass] - # @return [Array] - def collect_with_max_id(collection = [], max_id = nil, &block) - tweets = yield(max_id) - return collection if tweets.nil? - collection += tweets - tweets.empty? ? collection.flatten : collect_with_max_id(collection, tweets.last.id - 1, &block) - end - end - end - end -end diff --git a/lib/twitter/rest/api/trends.rb b/lib/twitter/rest/api/trends.rb deleted file mode 100644 index ad08928c3..000000000 --- a/lib/twitter/rest/api/trends.rb +++ /dev/null @@ -1,58 +0,0 @@ -require 'twitter/place' -require 'twitter/request' -require 'twitter/rest/api/utils' -require 'twitter/trend_results' - -module Twitter - module REST - module API - module Trends - include Twitter::REST::API::Utils - - # Returns the top 10 trending topics for a specific WOEID - # - # @see https://dev.twitter.com/docs/api/1.1/get/trends/place - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @param id [Integer] The {https://developer.yahoo.com/geo/geoplanet Yahoo! Where On Earth ID} of the location to return trending information for. WOEIDs can be retrieved by calling {Twitter::REST::API::Trends#trends_available}. Global information is available by using 1 as the WOEID. - # @param options [Hash] A customizable set of options. - # @option options [String] :exclude Setting this equal to 'hashtags' will remove all hashtags from the trends list. - # @return [Array] - def trends(id = 1, options = {}) - options[:id] = id - perform_with_object(:get, '/1.1/trends/place.json', options, Twitter::TrendResults) - end - alias_method :local_trends, :trends - alias_method :trends_place, :trends - - # Returns the locations that Twitter has trending topic information for - # - # @see https://dev.twitter.com/docs/api/1.1/get/trends/available - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @param options [Hash] A customizable set of options. - # @return [Array] - def trends_available(options = {}) - perform_with_objects(:get, '/1.1/trends/available.json', options, Twitter::Place) - end - alias_method :trend_locations, :trends_available - - # Returns the locations that Twitter has trending topic information for, closest to a specified location. - # - # @see https://dev.twitter.com/docs/api/1.1/get/trends/closest - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @param options [Hash] A customizable set of options. - # @option options [Float] :lat If provided with a :long option the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for latitude are -90.0 to +90.0 (North is positive) inclusive. - # @option options [Float] :long If provided with a :lat option the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for longitude are -180.0 to +180.0 (East is positive) inclusive. - # @return [Array] - def trends_closest(options = {}) - perform_with_objects(:get, '/1.1/trends/closest.json', options, Twitter::Place) - end - end - end - end -end diff --git a/lib/twitter/rest/api/tweets.rb b/lib/twitter/rest/api/tweets.rb deleted file mode 100644 index e5fabe6f3..000000000 --- a/lib/twitter/rest/api/tweets.rb +++ /dev/null @@ -1,297 +0,0 @@ -require 'twitter/arguments' -require 'twitter/error/already_posted' -require 'twitter/error/already_retweeted' -require 'twitter/error/forbidden' -require 'twitter/oembed' -require 'twitter/request' -require 'twitter/rest/api/utils' -require 'twitter/tweet' -require 'twitter/utils' - -module Twitter - module REST - module API - module Tweets - include Twitter::REST::API::Utils - include Twitter::Utils - - # Returns up to 100 of the first retweets of a given tweet - # - # @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/:id - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] - # @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object. - # @param options [Hash] A customizable set of options. - # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100. - # @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. - def retweets(tweet, options = {}) - perform_with_objects(:get, "/1.1/statuses/retweets/#{extract_id(tweet)}.json", options, Twitter::Tweet) - end - - # Show up to 100 users who retweeted the Tweet - # - # @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/:id - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] - # @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object. - # @param options [Hash] A customizable set of options. - # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100. - # @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. - # @option options [Boolean] :ids_only ('false') Only return user ids instead of full user objects. - def retweeters_of(tweet, options = {}) - ids_only = !!options.delete(:ids_only) - retweeters = retweets(tweet, options).collect(&:user) - ids_only ? retweeters.collect(&:id) : retweeters - end - - # Returns a Tweet - # - # @see https://dev.twitter.com/docs/api/1.1/get/statuses/show/:id - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @raise [Twitter::Error::Forbidden] Error raised when supplied status is over 140 characters. - # @return [Twitter::Tweet] The requested Tweet. - # @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object. - # @param options [Hash] A customizable set of options. - # @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. - def status(tweet, options = {}) - perform_with_object(:get, "/1.1/statuses/show/#{extract_id(tweet)}.json", options, Twitter::Tweet) - end - - # Returns Tweets - # - # @see https://dev.twitter.com/docs/api/1.1/get/statuses/show/:id - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] The requested Tweets. - # @overload statuses(*tweets) - # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @overload statuses(*tweets, options) - # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @param options [Hash] A customizable set of options. - # @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. - def statuses(*args) - parallel_tweets_from_response(:get, '/1.1/statuses/show', args) - end - - # Destroys the specified Tweets - # - # @see https://dev.twitter.com/docs/api/1.1/post/statuses/destroy/:id - # @note The authenticating user must be the author of the specified Tweets. - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] The deleted Tweets. - # @overload destroy_status(*tweets) - # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @overload destroy_status(*tweets, options) - # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @param options [Hash] A customizable set of options. - # @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. - def destroy_status(*args) - parallel_tweets_from_response(:post, '/1.1/statuses/destroy', args) - end - alias_method :destroy_tweet, :destroy_status - deprecate_alias :status_destroy, :destroy_status - deprecate_alias :tweet_destroy, :destroy_status - - # Updates the authenticating user's status - # - # @see https://dev.twitter.com/docs/api/1.1/post/statuses/update - # @note A status update with text identical to the authenticating user's current status will be ignored to prevent duplicates. - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::Tweet] The created Tweet. - # @param status [String] The text of your status update, up to 140 characters. - # @param options [Hash] A customizable set of options. - # @option options [Twitter::Tweet] :in_reply_to_status An existing status that the update is in reply to. - # @option options [Integer] :in_reply_to_status_id The ID of an existing status that the update is in reply to. - # @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. - # @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. - # @option options [Twitter::Place] :place A place in the world. These can be retrieved from {Twitter::REST::API::PlacesAndGeo#reverse_geocode}. - # @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::REST::API::PlacesAndGeo#reverse_geocode}. - # @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from. - # @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. - def update(status, options = {}) - hash = options.dup - hash[:in_reply_to_status_id] = hash.delete(:in_reply_to_status).id unless hash[:in_reply_to_status].nil? - hash[:place_id] = hash.delete(:place).woeid unless hash[:place].nil? - perform_with_object(:post, '/1.1/statuses/update.json', hash.merge(:status => status), Twitter::Tweet) - rescue Twitter::Error::Forbidden => error - handle_forbidden_error(Twitter::Error::AlreadyPosted, error) - end - - # Retweets the specified Tweets as the authenticating user - # - # @see https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/:id - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] The original tweets with retweet details embedded. - # @overload retweet(*tweets) - # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @overload retweet(*tweets, options) - # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @param options [Hash] A customizable set of options. - # @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. - def retweet(*args) - arguments = Twitter::Arguments.new(args) - parallel_map(arguments) do |tweet| - begin - post_retweet(extract_id(tweet), arguments.options) - rescue Twitter::Error::Forbidden => error - raise unless error.message == Twitter::Error::AlreadyRetweeted::MESSAGE - end - end.compact - end - - # Retweets the specified Tweets as the authenticating user and raises an error if one has already been retweeted - # - # @see https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/:id - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::AlreadyRetweeted] Error raised when tweet has already been retweeted. - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Array] The original tweets with retweet details embedded. - # @overload retweet!(*tweets) - # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @overload retweet!(*tweets, options) - # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @param options [Hash] A customizable set of options. - # @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. - def retweet!(*args) - arguments = Twitter::Arguments.new(args) - parallel_map(arguments) do |tweet| - begin - post_retweet(extract_id(tweet), arguments.options) - rescue Twitter::Error::Forbidden => error - handle_forbidden_error(Twitter::Error::AlreadyRetweeted, error) - end - end.compact - end - - # Updates the authenticating user's status with media - # - # @see https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media - # @note A status update with text/media identical to the authenticating user's current status will NOT be ignored - # @rate_limited No - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::Tweet] The created Tweet. - # @param status [String] The text of your status update, up to 140 characters. - # @param media [File, Hash] A File object with your picture (PNG, JPEG or GIF) - # @param options [Hash] A customizable set of options. - # @option options [Boolean, String, Integer] :possibly_sensitive Set to true for content which may not be suitable for every audience. - # @option options [Twitter::Tweet] :in_reply_to_status An existing status that the update is in reply to. - # @option options [Integer] :in_reply_to_status_id The ID of an existing Tweet that the update is in reply to. - # @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. - # @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. - # @option options [Twitter::Place] :place A place in the world. These can be retrieved from {Twitter::REST::API::PlacesAndGeo#reverse_geocode}. - # @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::REST::API::PlacesAndGeo#reverse_geocode}. - # @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from. - # @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. - def update_with_media(status, media, options = {}) - hash = options.dup - hash[:in_reply_to_status_id] = hash.delete(:in_reply_to_status).id unless hash[:in_reply_to_status].nil? - hash[:place_id] = hash.delete(:place).woeid unless hash[:place].nil? - perform_with_object(:post, '/1.1/statuses/update_with_media.json', hash.merge('media[]' => media, 'status' => status), Twitter::Tweet) - rescue Twitter::Error::Forbidden => error - handle_forbidden_error(Twitter::Error::AlreadyPosted, error) - end - - # Returns oEmbed for a Tweet - # - # @see https://dev.twitter.com/docs/api/1.1/get/statuses/oembed - # @rate_limited Yes - # @authentication Requires user context - # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. - # @return [Twitter::OEmbed] OEmbed for the requested Tweet. - # @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object. - # @param options [Hash] A customizable set of options. - # @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. - # @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. - # @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. - # @option options [Boolean, String, Integer] :omit_script Specifies whether the embedded Tweet HTML should include a `