diff --git a/lib/twitter.rb b/lib/twitter.rb index 702892c35..8b825c8ce 100644 --- a/lib/twitter.rb +++ b/lib/twitter.rb @@ -1,9 +1,7 @@ require 'twitter/action_factory' require 'twitter/client' -require 'twitter/configurable' require 'twitter/configuration' require 'twitter/cursor' -require 'twitter/default' require 'twitter/direct_message' require 'twitter/entity' require 'twitter/entity/hashtag' @@ -31,29 +29,3 @@ require 'twitter/tweet' require 'twitter/user' require 'uri' - -module Twitter - extend Twitter::Configurable - - # Delegate to a Twitter::Client - # - # @return [Twitter::Client] - def new - return @client if instance_variable_defined?(:@client) && @client.hash == options.hash - @client = Twitter::Client.new(options) - end - module_function :new - - def method_missing(method_name, *args, &block) - return super unless respond_to_missing?(method_name) - new.send(method_name, *args, &block) - end - module_function :method_missing - - def respond_to_missing?(method_name, include_private=false) - new.respond_to?(method_name, include_private) - end - module_function :respond_to_missing? - - setup -end diff --git a/lib/twitter/api/direct_messages.rb b/lib/twitter/api/direct_messages.rb index a26e48f89..b8af5da63 100644 --- a/lib/twitter/api/direct_messages.rb +++ b/lib/twitter/api/direct_messages.rb @@ -21,8 +21,6 @@ module DirectMessages # @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. - # @example Return the 20 most recent direct messages sent to the authenticating user - # Twitter.direct_messages_received def direct_messages_received(options={}) objects_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages.json", options) end @@ -40,8 +38,6 @@ def direct_messages_received(options={}) # @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. - # @example Return the 20 most recent direct messages sent by the authenticating user - # Twitter.direct_messages_sent def direct_messages_sent(options={}) objects_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages/sent.json", options) end @@ -56,8 +52,6 @@ def direct_messages_sent(options={}) # @return [Twitter::DirectMessage] The requested messages. # @param id [Integer] A direct message ID. # @param options [Hash] A customizable set of options. - # @example Return the direct message with the id 1825786345 - # Twitter.direct_message(1825786345) def direct_message(id, options={}) options[:id] = id object_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages/show.json", options) @@ -77,15 +71,11 @@ def direct_message(id, options={}) # @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. - # @example Return the 20 most recent direct messages sent to the authenticating user - # Twitter.direct_messages # @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. - # @example Return the direct message with the id 1825786345 - # Twitter.direct_messages(1825786345) # @overload direct_messages(*ids, options) # Returns direct messages # @@ -113,8 +103,6 @@ def direct_messages(*args) # @return [Array] Deleted direct message. # @overload direct_message_destroy(*ids) # @param ids [Enumerable] A collection of direct message IDs. - # @example Destroys the direct message with the ID 1825785544 - # Twitter.direct_message_destroy(1825785544) # @overload direct_message_destroy(*ids, options) # @param ids [Enumerable] A collection of direct message IDs. # @param options [Hash] A customizable set of options. @@ -132,9 +120,6 @@ def direct_message_destroy(*args) # @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. - # @example Send a direct message to @sferik from the authenticating user - # Twitter.direct_message_create('sferik', "I'm sending you this message via @gem!") - # Twitter.direct_message_create(7505382, "I'm sending you this message via @gem!") # Same as above def direct_message_create(user, text, options={}) merge_user!(options, user) options[:text] = text diff --git a/lib/twitter/api/favorites.rb b/lib/twitter/api/favorites.rb index 2179a830e..a5b813908 100644 --- a/lib/twitter/api/favorites.rb +++ b/lib/twitter/api/favorites.rb @@ -21,8 +21,6 @@ module Favorites # @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. - # @example Return the 20 most recent favorite Tweets for the authenticating user - # Twitter.favorites # @overload favorites(user, options={}) # Returns the 20 most recent favorite Tweets for the specified user # @@ -30,8 +28,6 @@ module Favorites # @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. - # @example Return the 20 most recent favorite Tweets for @sferik - # Twitter.favorites('sferik') def favorites(*args) arguments = Twitter::API::Arguments.new(args) if user = arguments.pop @@ -50,8 +46,6 @@ def favorites(*args) # @return [Array] The un-favorited Tweets. # @overload unfavorite(*tweets) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @example Un-favorite the tweet with the ID 25938088801 - # Twitter.unfavorite(25938088801) # @overload unfavorite(*tweets, options) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. # @param options [Hash] A customizable set of options. @@ -71,8 +65,6 @@ def unfavorite(*args) # @return [Array] The favorited Tweets. # @overload favorite(*tweets) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @example Favorite the Tweet with the ID 25938088801 - # Twitter.favorite(25938088801) # @overload favorite(*tweets, options) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. # @param options [Hash] A customizable set of options. @@ -102,8 +94,6 @@ def favorite(*args) # @return [Array] The favorited Tweets. # @overload favorite(*tweets) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @example Favorite the Tweet with the ID 25938088801 - # Twitter.favorite(25938088801) # @overload favorite(*tweets, options) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. # @param options [Hash] A customizable set of options. diff --git a/lib/twitter/api/friends_and_followers.rb b/lib/twitter/api/friends_and_followers.rb index f5e8c0bb3..afc796058 100644 --- a/lib/twitter/api/friends_and_followers.rb +++ b/lib/twitter/api/friends_and_followers.rb @@ -20,17 +20,12 @@ module FriendsAndFollowers # # @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. - # @example Return the authenticated user's friends' IDs - # Twitter.friend_ids # @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. - # @example Return @sferik's friends' IDs - # Twitter.friend_ids('sferik') - # Twitter.friend_ids(7505382) # Same as above def friend_ids(*args) cursor_from_response_with_user(:ids, nil, :get, "/1.1/friends/ids.json", args) end @@ -45,17 +40,12 @@ def friend_ids(*args) # # @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. - # @example Return the authenticated user's followers' IDs - # Twitter.follower_ids # @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. - # @example Return @sferik's followers' IDs - # Twitter.follower_ids('sferik') - # Twitter.follower_ids(7505382) # Same as above def follower_ids(*args) cursor_from_response_with_user(:ids, nil, :get, "/1.1/followers/ids.json", args) end @@ -69,10 +59,6 @@ def follower_ids(*args) # @return [Array] The requested users. # @overload friendships(*users) # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @example Return extended information for @sferik and @pengwynn - # Twitter.friendships('sferik', 'pengwynn') - # Twitter.friendships('sferik', 14100886) # Same as above - # Twitter.friendships(7505382, 14100886) # Same as above # @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. @@ -91,8 +77,6 @@ def friendships(*args) # @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. - # @example Return an array of numeric IDs for every user who has a pending request to follow the authenticating user - # Twitter.friendships_incoming def friendships_incoming(options={}) cursor_from_response(:ids, nil, :get, "/1.1/friendships/incoming.json", options) end @@ -106,8 +90,6 @@ def friendships_incoming(options={}) # @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. - # @example Return an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request - # Twitter.friendships_outgoing def friendships_outgoing(options={}) cursor_from_response(:ids, nil, :get, "/1.1/friendships/outgoing.json", options) end @@ -121,8 +103,6 @@ def friendships_outgoing(options={}) # @return [Array] The followed users. # @overload follow(*users) # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @example Follow @sferik - # Twitter.follow('sferik') # @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. @@ -151,8 +131,6 @@ def follow(*args) # @return [Array] The followed users. # @overload follow!(*users) # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @example Follow @sferik - # Twitter.follow!('sferik') # @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. @@ -182,8 +160,6 @@ def follow!(*args) # @return [Array] The unfollowed users. # @overload unfollow(*users) # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @example Unfollow @sferik - # Twitter.unfollow('sferik') # @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. @@ -203,8 +179,6 @@ def unfollow(*args) # @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. - # @example Enable rewteets and devise notifications for @sferik - # Twitter.friendship_update('sferik', :device => true, :retweets => true) def friendship_update(user, options={}) merge_user!(options, user) object_from_response(Twitter::Relationship, :post, "/1.1/friendships/update.json", options) @@ -220,10 +194,6 @@ def friendship_update(user, options={}) # @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. - # @example Return the relationship between @sferik and @pengwynn - # Twitter.friendship('sferik', 'pengwynn') - # Twitter.friendship('sferik', 14100886) # Same as above - # Twitter.friendship(7505382, 14100886) # Same as above def friendship(source, target, options={}) merge_user!(options, source, "source") options[:source_id] = options.delete(:source_user_id) unless options[:source_user_id].nil? @@ -244,10 +214,6 @@ def friendship(source, target, options={}) # @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. - # @example Return true if @sferik follows @pengwynn - # Twitter.friendship?('sferik', 'pengwynn') - # Twitter.friendship?('sferik', 14100886) # Same as above - # Twitter.friendship?(7505382, 14100886) # Same as above def friendship?(source, target, options={}) friendship(source, target, options).source.following? end @@ -266,8 +232,6 @@ def friendship?(source, target, 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. - # @example Return the authenticated user's friends' IDs - # Twitter.followers # @overload followers(user, options={}) # Returns a cursored collection of user objects for users following the specified user. # @@ -276,9 +240,6 @@ def friendship?(source, target, 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. - # @example Return the cursored collection of users following @sferik - # Twitter.followers('sferik') - # Twitter.followers(7505382) # Same as above def followers(*args) cursor_from_response_with_user(:users, Twitter::User, :get, "/1.1/followers/list.json", args) end @@ -297,8 +258,6 @@ def followers(*args) # @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. - # @example Return the authenticated user's friends' IDs - # Twitter.friends # @overload friends(user, options={}) # Returns a cursored collection of user objects for every user the specified user is following (otherwise known as their "friends"). # @@ -307,9 +266,6 @@ def followers(*args) # @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. - # @example Return the cursored collection of users @sferik is following - # Twitter.friends('sferik') - # Twitter.friends(7505382) # Same as above def friends(*args) cursor_from_response_with_user(:users, Twitter::User, :get, "/1.1/friends/list.json", args) end @@ -322,8 +278,6 @@ def friends(*args) # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. # @return [Array] # @param options [Hash] A customizable set of options. - # @example Return a collection of user IDs that the currently authenticated user does not want to receive retweets from - # Twitter.no_retweet_ids def no_retweet_ids(options={}) get("/1.1/friendships/no_retweets/ids.json", options)[:body].map(&:to_i) end diff --git a/lib/twitter/api/help.rb b/lib/twitter/api/help.rb index e7f6aa38c..532cc0e26 100644 --- a/lib/twitter/api/help.rb +++ b/lib/twitter/api/help.rb @@ -14,8 +14,6 @@ module Help # @authentication Requires user context # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. # @return [Twitter::Configuration] Twitter's configuration. - # @example Return the current configuration used by Twitter - # Twitter.configuration def configuration(options={}) object_from_response(Twitter::Configuration, :get, "/1.1/help/configuration.json", options) end @@ -27,8 +25,6 @@ def configuration(options={}) # @authentication Requires user context # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. # @return [Array] - # @example Return the list of languages Twitter supports - # Twitter.languages def languages(options={}) objects_from_response(Twitter::Language, :get, "/1.1/help/languages.json", options) end @@ -40,8 +36,6 @@ def languages(options={}) # @authentication Requires user context # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. # @return [String] - # @example Return {https://twitter.com/privacy Twitter's Privacy Policy} - # Twitter.privacy def privacy(options={}) get("/1.1/help/privacy.json", options)[:body][:privacy] end @@ -53,8 +47,6 @@ def privacy(options={}) # @authentication Requires user context # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. # @return [String] - # @example Return {https://twitter.com/tos Twitter's Terms of Service} - # Twitter.tos def tos(options={}) get("/1.1/help/tos.json", options)[:body][:tos] end diff --git a/lib/twitter/api/lists.rb b/lib/twitter/api/lists.rb index 77c14ac92..691afefed 100644 --- a/lib/twitter/api/lists.rb +++ b/lib/twitter/api/lists.rb @@ -25,15 +25,10 @@ module Lists # @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. - # @example Return all lists the authenticating user subscribes to - # Twitter.lists # @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. - # @example Return all lists that @sferik subscribes to - # Twitter.lists('sferik') - # Twitter.lists(7505382) def lists(*args) objects_from_response_with_user(Twitter::List, :get, "/1.1/lists/list.json", args) end @@ -52,9 +47,6 @@ def lists(*args) # @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. - # @example Show tweet timeline for members of the authenticated user's "presidents" list - # Twitter.list_timeline('presidents') - # Twitter.list_timeline(8863586) # @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. @@ -62,11 +54,6 @@ def lists(*args) # @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. - # @example Show tweet timeline for members of @sferik's "presidents" list - # Twitter.list_timeline('sferik', 'presidents') - # Twitter.list_timeline('sferik', 8863586) - # Twitter.list_timeline(7505382, 'presidents') - # Twitter.list_timeline(7505382, 8863586) def list_timeline(*args) arguments = Twitter::API::Arguments.new(args) merge_list!(arguments.options, arguments.pop) @@ -85,20 +72,11 @@ def list_timeline(*args) # @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. - # @example Remove @BarackObama from the authenticated user's "presidents" list - # Twitter.list_remove_member('presidents', 813286) - # Twitter.list_remove_member('presidents', 'BarackObama') - # Twitter.list_remove_member(8863586, 'BarackObama') # @overload list_remove_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. - # @example Remove @BarackObama from @sferik's "presidents" list - # Twitter.list_remove_member('sferik', 'presidents', 813286) - # Twitter.list_remove_member('sferik', 'presidents', 'BarackObama') - # Twitter.list_remove_member('sferik', 8863586, 'BarackObama') - # Twitter.list_remove_member(7505382, 'presidents', 813286) def list_remove_member(*args) list_from_response_with_user(:post, "/1.1/lists/members/destroy.json", args) end @@ -114,16 +92,11 @@ def list_remove_member(*args) # @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. - # @example List the lists the authenticated user has been added to - # Twitter.memberships # @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. - # @example List the lists that @sferik has been added to - # Twitter.memberships('sferik') - # Twitter.memberships(7505382) def memberships(*args) cursor_from_response_with_user(:lists, Twitter::List, :get, "/1.1/lists/memberships.json", args) end @@ -139,18 +112,11 @@ def memberships(*args) # @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. - # @example Return the subscribers of the authenticated user's "presidents" list - # Twitter.list_subscribers('presidents') - # Twitter.list_subscribers(8863586) # @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. - # @example Return the subscribers of @sferik's "presidents" list - # Twitter.list_subscribers('sferik', 'presidents') - # Twitter.list_subscribers('sferik', 8863586) - # Twitter.list_subscribers(7505382, 'presidents') def list_subscribers(*args) cursor_from_response_with_list(:get, "/1.1/lists/subscribers.json", args) end @@ -165,17 +131,10 @@ def list_subscribers(*args) # @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. - # @example Subscribe to the authenticated user's "presidents" list - # Twitter.list_subscribe('presidents') - # Twitter.list_subscribe(8863586) # @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. - # @example Subscribe to @sferik's "presidents" list - # Twitter.list_subscribe('sferik', 'presidents') - # Twitter.list_subscribe('sferik', 8863586) - # Twitter.list_subscribe(7505382, 'presidents') def list_subscribe(*args) list_from_response(:post, "/1.1/lists/subscribers/create.json", args) end @@ -191,20 +150,11 @@ def list_subscribe(*args) # @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. - # @example Check if @BarackObama is a subscriber of the authenticated user's "presidents" list - # Twitter.list_subscriber?('presidents', 813286) - # Twitter.list_subscriber?(8863586, 813286) - # Twitter.list_subscriber?('presidents', 'BarackObama') # @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. - # @example Check if @BarackObama is a subscriber of @sferik's "presidents" list - # Twitter.list_subscriber?('sferik', 'presidents', 813286) - # Twitter.list_subscriber?('sferik', 8863586, 813286) - # Twitter.list_subscriber?(7505382, 'presidents', 813286) - # Twitter.list_subscriber?('sferik', 'presidents', 'BarackObama') # @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) @@ -220,17 +170,10 @@ def list_subscriber?(*args) # @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. - # @example Unsubscribe from the authenticated user's "presidents" list - # Twitter.list_unsubscribe('presidents') - # Twitter.list_unsubscribe(8863586) # @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. - # @example Unsubscribe from @sferik's "presidents" list - # Twitter.list_unsubscribe('sferik', 'presidents') - # Twitter.list_unsubscribe('sferik', 8863586) - # Twitter.list_unsubscribe(7505382, 'presidents') def list_unsubscribe(*args) list_from_response(:post, "/1.1/lists/subscribers/destroy.json", args) end @@ -247,23 +190,11 @@ def list_unsubscribe(*args) # @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. - # @example Add @BarackObama and @pengwynn to the authenticated user's "presidents" list - # Twitter.list_add_members('presidents', ['BarackObama', 'pengwynn']) - # Twitter.list_add_members('presidents', [813286, 18755393]) - # Twitter.list_add_members(8863586, ['BarackObama', 'pengwynn']) - # Twitter.list_add_members(8863586, [813286, 18755393]) # @overload list_add_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. - # @example Add @BarackObama and @pengwynn to @sferik's "presidents" list - # Twitter.list_add_members('sferik', 'presidents', ['BarackObama', 'pengwynn']) - # Twitter.list_add_members('sferik', 'presidents', [813286, 18755393]) - # Twitter.list_add_members(7505382, 'presidents', ['BarackObama', 'pengwynn']) - # Twitter.list_add_members(7505382, 'presidents', [813286, 18755393]) - # Twitter.list_add_members(7505382, 8863586, ['BarackObama', 'pengwynn']) - # Twitter.list_add_members(7505382, 8863586, [813286, 18755393]) def list_add_members(*args) list_from_response_with_users(:post, "/1.1/lists/members/create_all.json", args) end @@ -279,18 +210,11 @@ def list_add_members(*args) # @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. - # @example Check if @BarackObama is a member of the authenticated user's "presidents" list - # Twitter.list_member?('presidents', 813286) - # Twitter.list_member?(8863586, 'BarackObama') # @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. - # @example Check if @BarackObama is a member of @sferik's "presidents" list - # Twitter.list_member?('sferik', 'presidents', 813286) - # Twitter.list_member?('sferik', 8863586, 'BarackObama') - # Twitter.list_member?(7505382, 'presidents', 813286) def list_member?(*args) list_user?(:get, "/1.1/lists/members/show.json", args) end @@ -306,19 +230,11 @@ def list_member?(*args) # @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. - # @example Return the members of the authenticated user's "presidents" list - # Twitter.list_members('presidents') - # Twitter.list_members(8863586) # @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. - # @example Return the members of @sferik's "presidents" list - # Twitter.list_members('sferik', 'presidents') - # Twitter.list_members('sferik', 8863586) - # Twitter.list_members(7505382, 'presidents') - # Twitter.list_members(7505382, 8863586) def list_members(*args) cursor_from_response_with_list(:get, "/1.1/lists/members.json", args) end @@ -335,19 +251,11 @@ def list_members(*args) # @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. - # @example Add @BarackObama to the authenticated user's "presidents" list - # Twitter.list_add_member('presidents', 813286) - # Twitter.list_add_member(8863586, 813286) # @overload list_add_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. - # @example Add @BarackObama to @sferik's "presidents" list - # Twitter.list_add_member('sferik', 'presidents', 813286) - # Twitter.list_add_member('sferik', 8863586, 813286) - # Twitter.list_add_member(7505382, 'presidents', 813286) - # Twitter.list_add_member(7505382, 8863586, 813286) def list_add_member(*args) list_from_response_with_user(:post, "/1.1/lists/members/create.json", args) end @@ -363,18 +271,10 @@ def list_add_member(*args) # @overload list_destroy(list, options={}) # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object. # @param options [Hash] A customizable set of options. - # @example Delete the authenticated user's "presidents" list - # Twitter.list_destroy('presidents') - # Twitter.list_destroy(8863586) # @overload list_destroy(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. - # @example Delete @sferik's "presidents" list - # Twitter.list_destroy('sferik', 'presidents') - # Twitter.list_destroy('sferik', 8863586) - # Twitter.list_destroy(7505382, 'presidents') - # Twitter.list_destroy(7505382, 8863586) def list_destroy(*args) list_from_response(:post, "/1.1/lists/destroy.json", args) end @@ -391,20 +291,12 @@ def list_destroy(*args) # @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. - # @example Update the authenticated user's "presidents" list to have the description "Presidents of the United States of America" - # Twitter.list_update('presidents', :description => "Presidents of the United States of America") - # Twitter.list_update(8863586, :description => "Presidents of the United States of America") # @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. - # @example Update the @sferik's "presidents" list to have the description "Presidents of the United States of America" - # Twitter.list_update('sferik', 'presidents', :description => "Presidents of the United States of America") - # Twitter.list_update(7505382, 'presidents', :description => "Presidents of the United States of America") - # Twitter.list_update('sferik', 8863586, :description => "Presidents of the United States of America") - # Twitter.list_update(7505382, 8863586, :description => "Presidents of the United States of America") def list_update(*args) list_from_response(:post, "/1.1/lists/update.json", args) end @@ -421,8 +313,6 @@ def list_update(*args) # @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. - # @example Create a list named 'presidents' - # Twitter.list_create('presidents') def list_create(name, options={}) object_from_response(Twitter::List, :post, "/1.1/lists/create.json", options.merge(:name => name)) end @@ -438,18 +328,10 @@ def list_create(name, options={}) # @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. - # @example Show the authenticated user's "presidents" list - # Twitter.list('presidents') - # Twitter.list(8863586) # @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. - # @example Show @sferik's "presidents" list - # Twitter.list('sferik', 'presidents') - # Twitter.list('sferik', 8863586) - # Twitter.list(7505382, 'presidents') - # Twitter.list(7505382, 8863586) def list(*args) list_from_response(:get, "/1.1/lists/show.json", args) end @@ -464,15 +346,10 @@ def list(*args) # @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. - # @example List the lists the authenticated user follows - # Twitter.subscriptions # @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. - # @example List the lists that @sferik follows - # Twitter.subscriptions('sferik') - # Twitter.subscriptions(7505382) def subscriptions(*args) cursor_from_response_with_user(:lists, Twitter::List, :get, "/1.1/lists/subscriptions.json", args) end @@ -488,23 +365,11 @@ def subscriptions(*args) # @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. - # @example Remove @BarackObama and @pengwynn from the authenticated user's "presidents" list - # Twitter.list_remove_members('presidents', ['BarackObama', 'pengwynn']) - # Twitter.list_remove_members('presidents', [813286, 18755393]) - # Twitter.list_remove_members(8863586, ['BarackObama', 'pengwynn']) - # Twitter.list_remove_members(8863586, [813286, 18755393]) # @overload list_remove_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. - # @example Remove @BarackObama and @pengwynn from @sferik's "presidents" list - # Twitter.list_remove_members('sferik', 'presidents', ['BarackObama', 'pengwynn']) - # Twitter.list_remove_members('sferik', 'presidents', [813286, 18755393]) - # Twitter.list_remove_members(7505382, 'presidents', ['BarackObama', 'pengwynn']) - # Twitter.list_remove_members(7505382, 'presidents', [813286, 18755393]) - # Twitter.list_remove_members(7505382, 8863586, ['BarackObama', 'pengwynn']) - # Twitter.list_remove_members(7505382, 8863586, [813286, 18755393]) def list_remove_members(*args) list_from_response_with_users(:post, "/1.1/lists/members/destroy_all.json", args) end @@ -519,15 +384,10 @@ def list_remove_members(*args) # @overload lists_owned(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. - # @example Return all lists the authenticating user owns - # Twitter.lists_owend # @overload lists_owned(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. - # @example Return all lists that @sferik owns - # Twitter.lists_owned('sferik') - # Twitter.lists_owned(7505382) def lists_owned(*args) cursor_from_response_with_user(:lists, Twitter::List, :get, "/1.1/lists/ownerships.json", args) end diff --git a/lib/twitter/api/oauth.rb b/lib/twitter/api/oauth.rb index d9a7c2a76..44485b130 100644 --- a/lib/twitter/api/oauth.rb +++ b/lib/twitter/api/oauth.rb @@ -33,8 +33,6 @@ def token # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. # @param access_token [String, Twitter::Token] The bearer token to revoke. # @return [Twitter::Token] The invalidated token. token_type should be nil. - # @example Revoke a token - # Twitter.invalidate_token("AAAA%2FAAA%3DAAAAAAAA") def invalidate_token(access_token) access_token = access_token.access_token if access_token.is_a?(Twitter::Token) object_from_response(Twitter::Token, :post, "/oauth2/invalidate_token", :access_token => access_token) diff --git a/lib/twitter/api/places_and_geo.rb b/lib/twitter/api/places_and_geo.rb index 9087bd161..8b5ff583e 100644 --- a/lib/twitter/api/places_and_geo.rb +++ b/lib/twitter/api/places_and_geo.rb @@ -16,8 +16,6 @@ module PlacesAndGeo # @param place_id [String] A place in the world. These IDs can be retrieved from {Twitter::API::PlacesAndGeo#reverse_geocode}. # @param options [Hash] A customizable set of options. # @return [Twitter::Place] The requested place. - # @example Return all the information about Twitter HQ - # Twitter.place("247f43d441defc03") def place(place_id, options={}) object_from_response(Twitter::Place, :get, "/1.1/geo/id/#{place_id}.json", options) end @@ -36,8 +34,6 @@ def place(place_id, options={}) # @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] - # @example Return an array of places within the specified region - # Twitter.reverse_geocode(:lat => "37.7821120598956", :long => "-122.400612831116") def reverse_geocode(options={}) object_from_response(Twitter::GeoResults, :get, "/1.1/geo/reverse_geocode.json", options) end @@ -59,8 +55,6 @@ def reverse_geocode(options={}) # @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] - # @example Return an array of places near the IP address 74.125.19.104 - # Twitter.geo_search(:ip => "74.125.19.104") def geo_search(options={}) object_from_response(Twitter::GeoResults, :get, "/1.1/geo/search.json", options) end @@ -80,8 +74,6 @@ def geo_search(options={}) # @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] - # @example Return an array of places similar to Twitter HQ - # Twitter.similar_places(:lat => "37.7821120598956", :long => "-122.400612831116", :name => "Twitter HQ") def similar_places(options={}) object_from_response(Twitter::GeoResults, :get, "/1.1/geo/similar_places.json", options) end @@ -101,8 +93,6 @@ def similar_places(options={}) # @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] :"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 [Twitter::Place] The created place. - # @example Create a new place - # Twitter.place_create(:name => "@sferik's Apartment", :token => "22ff5b1f7159032cf69218c4d8bb78bc", :contained_within => "41bcb736f84a799e", :lat => "37.783699", :long => "-122.393581") def place_create(options={}) object_from_response(Twitter::Place, :post, "/1.1/geo/place.json", options) end diff --git a/lib/twitter/api/saved_searches.rb b/lib/twitter/api/saved_searches.rb index 5f131ff1f..cc7155c74 100644 --- a/lib/twitter/api/saved_searches.rb +++ b/lib/twitter/api/saved_searches.rb @@ -16,15 +16,11 @@ module SavedSearches # # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/list # @param options [Hash] A customizable set of options. - # @example Return the authenticated user's saved search queries - # Twitter.saved_searches # @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. - # @example Retrieve the data for a saved search owned by the authenticating user with the ID 16129012 - # Twitter.saved_search(16129012) # @overload saved_search(*ids, options) # Retrieve the data for saved searches owned by the authenticating user # @@ -51,8 +47,6 @@ def saved_searches(*args) # @return [Twitter::SavedSearch] The saved searches. # @param id [Integer] The ID of the saved search. # @param options [Hash] A customizable set of options. - # @example Retrieve the data for a saved search owned by the authenticating user with the ID 16129012 - # Twitter.saved_search(16129012) def saved_search(id, options={}) object_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/show/#{id}.json", options) end @@ -66,8 +60,6 @@ def saved_search(id, options={}) # @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. - # @example Create a saved search for the authenticated user with the query "twitter" - # Twitter.saved_search_create("twitter") def saved_search_create(query, options={}) object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/create.json", options.merge(:query => query)) end @@ -82,8 +74,6 @@ def saved_search_create(query, options={}) # @return [Array] The deleted saved searches. # @overload saved_search_destroy(*ids) # @param ids [Enumerable] A collection of saved search IDs. - # @example Destroys a saved search for the authenticated user with the ID 16129012 - # Twitter.saved_search_destroy(16129012) # @overload saved_search_destroy(*ids, options) # @param ids [Enumerable] A collection of saved search IDs. # @param options [Hash] A customizable set of options. diff --git a/lib/twitter/api/search.rb b/lib/twitter/api/search.rb index e8254387a..60b535293 100644 --- a/lib/twitter/api/search.rb +++ b/lib/twitter/api/search.rb @@ -26,8 +26,6 @@ module Search # @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 - # @example Return tweets related to twitter - # Twitter.search('twitter') def search(q, options={}) object_from_response(Twitter::SearchResults, :get, "/1.1/search/tweets.json", options.merge(:q => q)) end diff --git a/lib/twitter/api/spam_reporting.rb b/lib/twitter/api/spam_reporting.rb index 699e5d28b..09032a0c4 100644 --- a/lib/twitter/api/spam_reporting.rb +++ b/lib/twitter/api/spam_reporting.rb @@ -15,9 +15,6 @@ module SpamReporting # @return [Array] The reported users. # @overload report_spam(*users) # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @example Report @spam for spam - # Twitter.report_spam("spam") - # Twitter.report_spam(14589771) # Same as above # @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. diff --git a/lib/twitter/api/suggested_users.rb b/lib/twitter/api/suggested_users.rb index 1442f54a1..1f02bba48 100644 --- a/lib/twitter/api/suggested_users.rb +++ b/lib/twitter/api/suggested_users.rb @@ -17,16 +17,12 @@ module SuggestedUsers # # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions # @param options [Hash] A customizable set of options. - # @example Return the list of suggested user categories - # Twitter.suggestions # @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. - # @example Return the users in the Art & Design category - # Twitter.suggestions("art-design") def suggestions(*args) arguments = Twitter::API::Arguments.new(args) if slug = arguments.pop @@ -44,8 +40,6 @@ def suggestions(*args) # @param slug [String] The short name of list or a category. # @param options [Hash] A customizable set of options. # @return [Array] - # @example Return the users in the Art & Design category and their most recent Tweet if they are not a protected user - # Twitter.suggest_users("art-design") def suggest_users(slug, options={}) objects_from_response(Twitter::User, :get, "/1.1/users/suggestions/#{slug}/members.json", options) end diff --git a/lib/twitter/api/timelines.rb b/lib/twitter/api/timelines.rb index c226313b9..d6896be84 100644 --- a/lib/twitter/api/timelines.rb +++ b/lib/twitter/api/timelines.rb @@ -22,8 +22,6 @@ module Timelines # @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. - # @example Return the 20 most recent mentions (statuses containing @username) for the authenticating user - # Twitter.mentions def mentions_timeline(options={}) objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/mentions_timeline.json", options) end @@ -47,8 +45,6 @@ def mentions_timeline(options={}) # @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. - # @example Return the 20 most recent Tweets posted by @sferik - # Twitter.user_timeline('sferik') def user_timeline(*args) objects_from_response_with_user(Twitter::Tweet, :get, "/1.1/statuses/user_timeline.json", args) end @@ -69,8 +65,6 @@ def user_timeline(*args) # @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. - # @example Return the 20 most recent retweets posted by @sferik - # Twitter.retweeted_by_user('sferik') def retweeted_by_user(user, options={}) retweets_from_timeline(options) do |opts| user_timeline(user, opts) @@ -93,8 +87,6 @@ def retweeted_by_user(user, 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. # @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. - # @example Return the 20 most recent retweets posted by the authenticating user - # Twitter.retweeted_by_me def retweeted_by_me(options={}) retweets_from_timeline(options) do |opts| user_timeline(opts) @@ -118,8 +110,6 @@ def retweeted_by_me(options={}) # @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. - # @example Return the 20 most recent Tweets, including retweets if they exist, posted by the authenticating user and the users they follow - # Twitter.home_timeline def home_timeline(options={}) objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/home_timeline.json", options) end @@ -140,8 +130,6 @@ def home_timeline(options={}) # @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. - # @example Return the 20 most recent retweets posted by users followed by the authenticating user - # Twitter.retweeted_to_me def retweeted_to_me(options={}) retweets_from_timeline(options) do |opts| home_timeline(opts) @@ -162,8 +150,6 @@ def retweeted_to_me(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. # @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. - # @example Return the 20 most recent tweets of the authenticated user that have been retweeted by others - # Twitter.retweets_of_me def retweets_of_me(options={}) objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/retweets_of_me.json", options) end diff --git a/lib/twitter/api/trends.rb b/lib/twitter/api/trends.rb index d2bd0a142..6a72eb8c5 100644 --- a/lib/twitter/api/trends.rb +++ b/lib/twitter/api/trends.rb @@ -17,8 +17,6 @@ module Trends # @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] - # @example Return the top 10 trending topics for San Francisco - # Twitter.trends(2487956) def trends(id=1, options={}) options[:id] = id object_from_response(Twitter::TrendResults, :get, "/1.1/trends/place.json", options) @@ -34,8 +32,6 @@ def trends(id=1, options={}) # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. # @param options [Hash] A customizable set of options. # @return [Array] - # @example Return the locations that Twitter has trending topic information for - # Twitter.trends_available def trends_available(options={}) objects_from_response(Twitter::Place, :get, "/1.1/trends/available.json", options) end @@ -51,8 +47,6 @@ def trends_available(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] - # @example Return the locations that Twitter has trending topic information for - # Twitter.trends_closest def trends_closest(options={}) objects_from_response(Twitter::Place, :get, "/1.1/trends/closest.json", options) end diff --git a/lib/twitter/api/tweets.rb b/lib/twitter/api/tweets.rb index 017dcbbf5..53cb246f2 100644 --- a/lib/twitter/api/tweets.rb +++ b/lib/twitter/api/tweets.rb @@ -22,8 +22,6 @@ module Tweets # @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. - # @example Return up to 100 of the first retweets of the Tweet with the ID 28561922516 - # Twitter.retweets(28561922516) def retweets(tweet, options={}) id = extract_id(tweet) objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/retweets/#{id}.json", options) @@ -41,8 +39,6 @@ def retweets(tweet, 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. - # @example Show up to 100 users who retweeted the Tweet with the ID 28561922516 - # Twitter.retweeters_of(28561922516) def retweeters_of(tweet, options={}) ids_only = !!options.delete(:ids_only) retweeters = retweets(tweet, options).map(&:user) @@ -64,8 +60,6 @@ def retweeters_of(tweet, options={}) # @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. - # @example Return the Tweet with the ID 25938088801 - # Twitter.status(25938088801) def status(tweet, options={}) id = extract_id(tweet) object_from_response(Twitter::Tweet, :get, "/1.1/statuses/show/#{id}.json", options) @@ -80,8 +74,6 @@ def status(tweet, options={}) # @return [Array] The requested Tweets. # @overload statuses(*tweets) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @example Return the Tweet with the ID 25938088801 - # Twitter.statuses(25938088801) # @overload statuses(*tweets, options) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. # @param options [Hash] A customizable set of options. @@ -100,8 +92,6 @@ def statuses(*args) # @return [Array] The deleted Tweets. # @overload status_destroy(*tweets) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @example Destroy the Tweet with the ID 25938088801 - # Twitter.status_destroy(25938088801) # @overload status_destroy(*tweets, options) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. # @param options [Hash] A customizable set of options. @@ -127,8 +117,6 @@ def status_destroy(*args) # @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::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. - # @example Update the authenticating user's status - # Twitter.update("I'm tweeting with @gem!") def update(status, options={}) object_from_response(Twitter::Tweet, :post, "/1.1/statuses/update.json", options.merge(:status => status)) rescue Twitter::Error::Forbidden => error @@ -144,8 +132,6 @@ def update(status, options={}) # @return [Array] The original tweets with retweet details embedded. # @overload retweet(*tweets) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @example Retweet the Tweet with the ID 28561922516 - # Twitter.retweet(28561922516) # @overload retweet(*tweets, options) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. # @param options [Hash] A customizable set of options. @@ -172,8 +158,6 @@ def retweet(*args) # @return [Array] The original tweets with retweet details embedded. # @overload retweet!(*tweets) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @example Retweet the Tweet with the ID 28561922516 - # Twitter.retweet!(28561922516) # @overload retweet!(*tweets, options) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. # @param options [Hash] A customizable set of options. @@ -207,8 +191,6 @@ def retweet!(*args) # @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::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. - # @example Update the authenticating user's status - # Twitter.update_with_media("I'm tweeting with @gem!", File.new('my_awesome_pic.jpeg')) def update_with_media(status, media, options={}) object_from_response(Twitter::Tweet, :post, "/1.1/statuses/update_with_media.json", options.merge('media[]' => media, 'status' => status)) rescue Twitter::Error::Forbidden => error @@ -231,8 +213,6 @@ def update_with_media(status, media, options={}) # @option options [String] :align Specifies whether the embedded Tweet should be left aligned, right aligned, or centered in the page. Valid values are left, right, center, and none. Defaults to none, meaning no alignment styles are specified for the Tweet. # @option options [String] :related A value for the TWT related parameter, as described in {https://dev.twitter.com/docs/intents Web Intents}. This value will be forwarded to all Web Intents calls. # @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML. - # @example Return oEmbeds for Tweet with the ID 25938088801 - # Twitter.status_with_activity(25938088801) def oembed(tweet, options={}) options[:id] = extract_id(tweet) object_from_response(Twitter::OEmbed, :get, "/1.1/statuses/oembed.json", options) @@ -247,8 +227,6 @@ def oembed(tweet, options={}) # @return [Array] OEmbeds for the requested Tweets. # @overload oembed(*tweets) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. - # @example Return oEmbeds for Tweets with the ID 25938088801 - # Twitter.status_with_activity(25938088801) # @overload oembed(*tweets, options) # @param tweets [Enumerable] A collection of Tweet IDs, URIs, or objects. # @param options [Hash] A customizable set of options. @@ -276,13 +254,9 @@ def oembeds(*args) # @return [Array] # @overload retweeters_ids(options) # @param options [Hash] A customizable set of options. - # @example Return a collection of up to 100 user IDs belonging to users who have retweeted the tweet specified by the id parameter - # Twitter.retweeters_ids({:id => 25938088801}) # @overload retweeters_ids(id, options={}) # @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object. # @param options [Hash] A customizable set of options. - # @example Return a collection of up to 100 user IDs belonging to users who have retweeted the tweet specified by the id parameter - # Twitter.retweeters_ids(25938088801) def retweeters_ids(*args) arguments = Twitter::API::Arguments.new(args) arguments.options[:id] ||= extract_id(arguments.first) diff --git a/lib/twitter/api/undocumented.rb b/lib/twitter/api/undocumented.rb index 53f9029d9..ee5c83523 100644 --- a/lib/twitter/api/undocumented.rb +++ b/lib/twitter/api/undocumented.rb @@ -21,8 +21,6 @@ module Undocumented # @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. # @return [Twitter::Cursor] - # @example Return users follow followers of @sferik - # Twitter.following_followers_of # # @overload following_followers_of(user, options={}) # Returns users following followers of the authenticated user @@ -31,9 +29,6 @@ module Undocumented # @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. # @return [Twitter::Cursor] - # @example Return users follow followers of @sferik - # Twitter.following_followers_of('sferik') - # Twitter.following_followers_of(7505382) # Same as above def following_followers_of(*args) cursor_from_response_with_user(:users, Twitter::User, :get, "/users/following_followers_of.json", args) end @@ -46,10 +41,8 @@ def following_followers_of(*args) # @return [Integer] # @param uri [String, URI] A URI. # @param options [Hash] A customizable set of options. - # @example Return Tweet count for http://twitter.com - # Twitter.tweet_count("http://twitter.com/") def tweet_count(uri, options={}) - connection = Faraday.new("https://cdn.api.twitter.com", @connection_options.merge(:builder => @middleware)) + connection = Faraday.new("https://cdn.api.twitter.com", connection_options.merge(:builder => middleware)) connection.get("/1/urls/count.json", options.merge(:url => uri.to_s)).body[:count] end diff --git a/lib/twitter/api/users.rb b/lib/twitter/api/users.rb index f371a86d7..47410c7a5 100644 --- a/lib/twitter/api/users.rb +++ b/lib/twitter/api/users.rb @@ -28,8 +28,6 @@ module Users # @option options [Integer] :end_sleep_time The hour that sleep time should end if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting. # @option options [String] :time_zone The timezone dates and times should be displayed in for the user. The timezone must be one of the {http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html Rails TimeZone} names. # @option options [String] :lang The language which Twitter should render in for this user. The language must be specified by the appropriate two letter ISO 639-1 representation. Currently supported languages are provided by {https://dev.twitter.com/docs/api/1.1/get/help/languages GET help/languages}. - # @example Return the settings for the authenticating user. - # Twitter.settings def settings(options={}) request_method = options.size.zero? ? :get : :post settings = object_from_response(Twitter::Settings, request_method, "/1.1/account/settings.json", options) @@ -48,8 +46,6 @@ def settings(options={}) # @return [Twitter::User] The authenticated user. # @param options [Hash] A customizable set of options. # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1. - # @example Return the requesting user if authentication was successful - # Twitter.verify_credentials def verify_credentials(options={}) object_from_response(Twitter::User, :get, "/1.1/account/verify_credentials.json", options) end @@ -64,8 +60,6 @@ def verify_credentials(options={}) # @return [Twitter::User] The authenticated user. # @param device [String] Must be one of: 'sms', 'none'. # @param options [Hash] A customizable set of options. - # @example Turn SMS updates on for the authenticating user - # Twitter.update_delivery_device('sms') def update_delivery_device(device, options={}) object_from_response(Twitter::User, :post, "/1.1/account/update_delivery_device.json", options.merge(:device => device)) end @@ -83,8 +77,6 @@ def update_delivery_device(device, options={}) # @option options [String] :url URL associated with the profile. Will be prepended with "http://" if not present. Maximum of 100 characters. # @option options [String] :location The city or country describing where the user of the account is located. The contents are not normalized or geocoded in any way. Maximum of 30 characters. # @option options [String] :description A description of the user owning the account. Maximum of 160 characters. - # @example Set authenticating user's name to Erik Michaels-Ober - # Twitter.update_profile(:name => "Erik Michaels-Ober") def update_profile(options={}) object_from_response(Twitter::User, :post, "/1.1/account/update_profile.json", options) end @@ -99,8 +91,6 @@ def update_profile(options={}) # @param image [File] The background image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 800 kilobytes in size. Images with width larger than 2048 pixels will be forcibly scaled down. The image must be provided as raw multipart data, not a URL. # @param options [Hash] A customizable set of options. # @option options [Boolean] :tile Whether or not to tile the background image. If set to true the background image will be displayed tiled. The image will not be tiled otherwise. - # @example Update the authenticating user's profile background image - # Twitter.update_profile_background_image(File.new("we_concept_bg2.png")) def update_profile_background_image(image, options={}) object_from_response(Twitter::User, :post, "/1.1/account/update_profile_background_image.json", options.merge(:image => image)) end @@ -118,8 +108,6 @@ def update_profile_background_image(image, options={}) # @option options [String] :profile_link_color Profile link color. # @option options [String] :profile_sidebar_fill_color Profile sidebar's background color. # @option options [String] :profile_sidebar_border_color Profile sidebar's border color. - # @example Set authenticating user's profile background to black - # Twitter.update_profile_colors(:profile_background_color => '000000') def update_profile_colors(options={}) object_from_response(Twitter::User, :post, "/1.1/account/update_profile_colors.json", options) end @@ -135,8 +123,6 @@ def update_profile_colors(options={}) # @return [Twitter::User] The authenticated user. # @param image [File] The avatar image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size. Images with width larger than 500 pixels will be scaled down. Animated GIFs will be converted to a static GIF of the first frame, removing the animation. # @param options [Hash] A customizable set of options. - # @example Update the authenticating user's profile image - # Twitter.update_profile_image(File.new("me.jpeg")) def update_profile_image(image, options={}) object_from_response(Twitter::User, :post, "/1.1/account/update_profile_image.json", options.merge(:image => image)) end @@ -150,8 +136,6 @@ def update_profile_image(image, options={}) # @return [Array] User objects that the authenticating user is blocking. # @param options [Hash] A customizable set of options. # @option options [Integer] :page Specifies the page of results to retrieve. - # @example Return an array of user objects that the authenticating user is blocking - # Twitter.blocking def blocking(options={}) cursor_from_response(:users, Twitter::User, :get, "/1.1/blocks/list.json", options) end @@ -163,8 +147,6 @@ def blocking(options={}) # @authentication Requires user context # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. # @return [Array] Numeric user ids the authenticating user is blocking. - # @example Return an array of numeric user ids the authenticating user is blocking - # Twitter.blocking_ids # @overload block(options={}) # @param options [Hash] A customizable set of options. def blocked_ids(*args) @@ -182,9 +164,6 @@ def blocked_ids(*args) # @return [Boolean] true if the authenticating user is blocking the target user, otherwise false. # @param user [Integer, String, URI, Twitter::User] A Twitter user ID, screen name, URI, or object. # @param options [Hash] A customizable set of options. - # @example Check whether the authenticating user is blocking @sferik - # Twitter.block?('sferik') - # Twitter.block?(7505382) # Same as above def block?(user, options={}) merge_default_cursor!(options) user_id = case user @@ -208,9 +187,6 @@ def block?(user, options={}) # @return [Array] The blocked users. # @overload block(*users) # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @example Block and unfriend @sferik as the authenticating user - # Twitter.block('sferik') - # Twitter.block(7505382) # Same as above # @overload block(*users, options) # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. # @param options [Hash] A customizable set of options. @@ -227,9 +203,6 @@ def block(*args) # @return [Array] The un-blocked users. # @overload unblock(*users) # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @example Un-block @sferik as the authenticating user - # Twitter.unblock('sferik') - # Twitter.unblock(7505382) # Same as above # @overload unblock(*users, options) # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. # @param options [Hash] A customizable set of options. @@ -246,17 +219,11 @@ def unblock(*args) # @return [Array] The requested users. # @overload users(*users) # @param users [Enumerable] A collection of Twitter user IDs, screen names, or objects. - # @example Return extended information for @sferik and @pengwynn - # Twitter.users('sferik', 'pengwynn') # Retrieve users with a POST request using screen_names - # Twitter.users(7505382, 14100886) # Same as above using twitter_ids # @overload users(*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 [Symbol, String] :method Requests users via a GET request instead of the standard POST request if set to ':get'. # @option options [Boolean] :include_entities The tweet entities node will be disincluded when set to false. - # @example Return extended information for @sferik and @pengwynn - # Twitter.users('sferik', 'pengwynn', :method => :get) # Retrieve users with a GET request - # Twitter.users(7505382, 14100886, :method => :get) # Same as above def users(*args) arguments = Twitter::API::Arguments.new(args) method = arguments.options.delete(:method) || :post @@ -276,8 +243,6 @@ def users(*args) # @param options [Hash] A customizable set of options. # @option options [Boolean] :include_entities The tweet entities node will be disincluded when set to false. # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1. - # @example Return extended information for the authenticated user - # Twitter.user # @overload user(user, options={}) # Returns extended information for a given user # @@ -285,9 +250,6 @@ def users(*args) # @param options [Hash] A customizable set of options. # @option options [Boolean] :include_entities The tweet entities node will be disincluded when set to false. # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1. - # @example Return extended information for @sferik - # Twitter.user('sferik') - # Twitter.user(7505382) # Same as above def user(*args) arguments = Twitter::API::Arguments.new(args) if user = arguments.pop @@ -305,9 +267,6 @@ def user(*args) # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. # @return [Boolean] true if the user exists, otherwise false. # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @example Return true if @sferik exists - # Twitter.user?('sferik') - # Twitter.user?(7505382) # Same as above def user?(user, options={}) merge_user!(options, user) get("/1.1/users/show.json", options) @@ -327,8 +286,6 @@ def user?(user, options={}) # @param options [Hash] A customizable set of options. # @option options [Integer] :count The number of people to retrieve. Maxiumum of 20 allowed per page. # @option options [Integer] :page Specifies the page of results to retrieve. - # @example Return users that match "Erik Michaels-Ober" - # Twitter.user_search("Erik Michaels-Ober") def user_search(query, options={}) objects_from_response(Twitter::User, :get, "/1.1/users/search.json", options.merge(:q => query)) end @@ -343,15 +300,10 @@ def user_search(query, options={}) # @overload contributees(options={}) # @param options [Hash] A customizable set of options. # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1. - # @example Return the authenticated user's contributees - # Twitter.contributees # @overload contributees(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, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1. - # @example Return users @sferik can contribute to - # Twitter.contributees('sferik') - # Twitter.contributees(7505382) # Same as above def contributees(*args) user_objects_from_response(:get, "/1.1/users/contributees.json", args) end @@ -366,15 +318,10 @@ def contributees(*args) # @overload contributors(options={}) # @param options [Hash] A customizable set of options. # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1. - # @example Return the authenticated user's contributors - # Twitter.contributors # @overload contributors(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, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1. - # @example Return users who can contribute to @sferik's account - # Twitter.contributors('sferik') - # Twitter.contributors(7505382) # Same as above def contributors(*args) user_objects_from_response(:get, "/1.1/users/contributors.json", args) end @@ -387,8 +334,6 @@ def contributors(*args) # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. # @return [nil] # @param options [Hash] A customizable set of options. - # @example Remove the authenticating user's profile banner image - # Twitter.remove_profile_banner def remove_profile_banner(options={}) post("/1.1/account/remove_profile_banner.json", options)[:body] end @@ -410,8 +355,6 @@ def remove_profile_banner(options={}) # @option options [Integer] :height The height of the preferred section of the image being uploaded in pixels. Use with width, offset_left, and offset_top to select the desired region of the image to use. # @option options [Integer] :offset_left The number of pixels by which to offset the uploaded image from the left. Use with height, width, and offset_top to select the desired region of the image to use. # @option options [Integer] :offset_top The number of pixels by which to offset the uploaded image from the top. Use with height, width, and offset_left to select the desired region of the image to use. - # @example Update the authenticating user's profile banner - # Twitter.update_profile_banner(File.new("me.jpeg")) def update_profile_banner(banner, options={}) post("/1.1/account/update_profile_banner.json", options.merge(:banner => banner))[:body] end @@ -425,13 +368,8 @@ def update_profile_banner(banner, options={}) # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid. # @return [Twitter::ProfileBanner] # @overload profile_banner(options={}) - # @example Return the authenticated user's profile banner - # Twitter.profile_banner # @overload profile_banner(user, options={}) # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object. - # @example Return the specified user's profile banner - # Twitter.profile_banner('sferik') - # Twitter.profile_banner(7505382) # Same as above def profile_banner(*args) arguments = Twitter::API::Arguments.new(args) merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name] diff --git a/lib/twitter/client.rb b/lib/twitter/client.rb index 69c96d3d1..86612cf37 100644 --- a/lib/twitter/client.rb +++ b/lib/twitter/client.rb @@ -1,5 +1,8 @@ +require 'base64' require 'faraday' +require 'faraday/request/multipart' require 'json' +require 'simple_oauth' require 'twitter/api/direct_messages' require 'twitter/api/favorites' require 'twitter/api/friends_and_followers' @@ -16,10 +19,12 @@ require 'twitter/api/tweets' require 'twitter/api/undocumented' require 'twitter/api/users' -require 'twitter/configurable' require 'twitter/error' -require 'simple_oauth' -require 'base64' +require 'twitter/error/configuration_error' +require 'twitter/request/multipart_with_file' +require 'twitter/response/parse_json' +require 'twitter/response/raise_error' +require 'twitter/version' require 'uri' module Twitter @@ -44,16 +49,82 @@ class Client include Twitter::API::Tweets include Twitter::API::Undocumented include Twitter::API::Users - include Twitter::Configurable + + attr_writer :bearer_token, :connection_options, :consumer_key, + :consumer_secret, :endpoint, :middleware, :oauth_token, + :oauth_token_secret + + ENDPOINT = 'https://api.twitter.com' + + # @return [String] + def consumer_key + @consumer_key || ENV['TWITTER_CONSUMER_KEY'] + end + + # @return [String] + def consumer_secret + @consumer_secret || ENV['TWITTER_CONSUMER_SECRET'] + end + + # @return [String] + def oauth_token + @oauth_token || ENV['TWITTER_oauth_token'] + end + + # @return [String] + def oauth_token_secret + @oauth_token_secret || ENV['TWITTER_oauth_token_SECRET'] + end + + # @return [String] + def bearer_token + @bearer_token || ENV['TWITTER_BEARER_TOKEN'] + end + + def connection_options + @connection_options ||= { + :headers => { + :accept => 'application/json', + :user_agent => "Twitter Ruby Gem #{Twitter::Version}", + }, + :request => { + :open_timeout => 5, + :timeout => 10, + }, + } + end + + # @note Faraday's middleware stack implementation is comparable to that of Rack middleware. The order of middleware is important: the first middleware on the list wraps all others, while the last middleware is the innermost one. + # @see https://github.com/technoweenie/faraday#advanced-middleware-usage + # @see http://mislav.uniqpath.com/2011/07/faraday-advanced-http/ + # @return [Faraday::Builder] + def middleware + @middleware ||= Faraday::Builder.new do |builder| + # Convert file uploads to Faraday::UploadIO objects + builder.use Twitter::Request::MultipartWithFile + # Checks for files in the payload + builder.use Faraday::Request::Multipart + # Convert request params to "www-form-urlencoded" + builder.use Faraday::Request::UrlEncoded + # Handle error responses + builder.use Twitter::Response::RaiseError, Twitter::Error + # Parse JSON response bodies + builder.use Twitter::Response::ParseJson + # Set Faraday's HTTP adapter + builder.adapter Faraday.default_adapter + end + end # Initializes a new Client object # # @param options [Hash] # @return [Twitter::Client] def initialize(options={}) - Twitter::Configurable.keys.each do |key| - instance_variable_set(:"@#{key}", options[key] || Twitter.instance_variable_get(:"@#{key}")) + options.each do |key, value| + send(:"#{key}=", value) end + yield self if block_given? + validate_credential_type! end # Perform an HTTP DELETE request @@ -77,6 +148,31 @@ def put(path, params={}) request(:put, path, params) end + # @return [Boolean] + def user_token? + !!(oauth_token && oauth_token_secret) + end + + # @return [Boolean] + def bearer_token? + !!bearer_token + end + + # @return [Hash] + def credentials + { + :consumer_key => consumer_key, + :consumer_secret => consumer_secret, + :token => oauth_token, + :token_secret => oauth_token_secret, + } + end + + # @return [Boolean] + def credentials? + credentials.values.all? || bearer_token? + end + private # Returns a proc that can be used to setup the Faraday::Request headers @@ -111,7 +207,7 @@ def request(method, path, params={}, signature_params=params) # # @return [Faraday::Connection] def connection - @connection ||= Faraday.new(@endpoint, @connection_options.merge(:builder => @middleware)) + @connection ||= Faraday.new(ENDPOINT, connection_options.merge(:builder => middleware)) end # Generates authentication header for a bearer token request @@ -123,16 +219,29 @@ def bearer_token_credentials_auth_header end def bearer_auth_header - if @bearer_token.is_a?(Twitter::Token) && @bearer_token.token_type == "bearer" - "Bearer #{@bearer_token.access_token}" + if bearer_token.is_a?(Twitter::Token) && bearer_token.token_type == "bearer" + "Bearer #{bearer_token.access_token}" else - "Bearer #{@bearer_token}" + "Bearer #{bearer_token}" end end def oauth_auth_header(method, path, params={}) - uri = ::URI.parse(@endpoint + path) + uri = ::URI.parse(ENDPOINT + path) SimpleOAuth::Header.new(method, uri, params, credentials) end + + # Ensures that all credentials set during configuration are of a + # valid type. Valid types are String and Symbol. + # + # @raise [Twitter::Error::ConfigurationError] Error is raised when + # supplied twitter credentials are not a String or Symbol. + def validate_credential_type! + credentials.each do |credential, value| + next if value.nil? + raise(Error::ConfigurationError, "Invalid #{credential} specified: #{value.inspect} must be a string or symbol.") unless value.is_a?(String) || value.is_a?(Symbol) + end + end + end end diff --git a/lib/twitter/configurable.rb b/lib/twitter/configurable.rb deleted file mode 100644 index b4cae1de0..000000000 --- a/lib/twitter/configurable.rb +++ /dev/null @@ -1,94 +0,0 @@ -require 'forwardable' -require 'twitter/error/configuration_error' - -module Twitter - module Configurable - extend Forwardable - attr_writer :consumer_secret, :oauth_token, :oauth_token_secret, :bearer_token - attr_accessor :consumer_key, :endpoint, :connection_options, :middleware - def_delegator :options, :hash - - class << self - - def keys - @keys ||= [ - :consumer_key, - :consumer_secret, - :oauth_token, - :oauth_token_secret, - :bearer_token, - :endpoint, - :connection_options, - :middleware, - ] - end - - end - - # Convenience method to allow configuration options to be set in a block - # - # @raise [Twitter::Error::ConfigurationError] Error is raised when supplied - # twitter credentials are not a String or Symbol. - def configure - yield self - validate_credential_type! - self - end - - def reset! - Twitter::Configurable.keys.each do |key| - instance_variable_set(:"@#{key}", Twitter::Default.options[key]) - end - self - end - alias setup reset! - - # @return [Boolean] - def user_token? - !!(@oauth_token && @oauth_token_secret) - end - - # @return [Boolean] - def bearer_token? - !!@bearer_token - end - - # @return [Boolean] - def credentials? - credentials.values.all? || bearer_token? - end - - private - - # @return [Hash] - def credentials - { - :consumer_key => @consumer_key, - :consumer_secret => @consumer_secret, - :token => @oauth_token, - :token_secret => @oauth_token_secret, - } - end - - # @return [Hash] - def options - Hash[Twitter::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}] - end - - # Ensures that all credentials set during configuration are of a - # valid type. Valid types are String and Symbol. - # - # @raise [Twitter::Error::ConfigurationError] Error is raised when - # supplied twitter credentials are not a String or Symbol. - def validate_credential_type! - credentials.each do |credential, value| - next if value.nil? - - unless value.is_a?(String) || value.is_a?(Symbol) - raise(Error::ConfigurationError, "Invalid #{credential} specified: #{value} must be a string or symbol.") - end - end - end - - end -end diff --git a/lib/twitter/default.rb b/lib/twitter/default.rb deleted file mode 100644 index 4b0245f8c..000000000 --- a/lib/twitter/default.rb +++ /dev/null @@ -1,93 +0,0 @@ -require 'faraday' -require 'faraday/request/multipart' -require 'twitter/error' -require 'twitter/request/multipart_with_file' -require 'twitter/response/parse_json' -require 'twitter/response/raise_error' -require 'twitter/version' - -module Twitter - module Default - ENDPOINT = 'https://api.twitter.com' unless defined? Twitter::Default::ENDPOINT - CONNECTION_OPTIONS = { - :headers => { - :accept => 'application/json', - :user_agent => "Twitter Ruby Gem #{Twitter::Version}", - }, - :request => { - :open_timeout => 5, - :timeout => 10, - }, - } unless defined? Twitter::Default::CONNECTION_OPTIONS - MIDDLEWARE = Faraday::Builder.new do |builder| - # Convert file uploads to Faraday::UploadIO objects - builder.use Twitter::Request::MultipartWithFile - # Checks for files in the payload - builder.use Faraday::Request::Multipart - # Convert request params to "www-form-urlencoded" - builder.use Faraday::Request::UrlEncoded - # Handle error responses - builder.use Twitter::Response::RaiseError, Twitter::Error - # Parse JSON response bodies - builder.use Twitter::Response::ParseJson - # Set Faraday's HTTP adapter - builder.adapter Faraday.default_adapter - end unless defined? Twitter::Default::MIDDLEWARE - - class << self - - # @return [Hash] - def options - Hash[Twitter::Configurable.keys.map{|key| [key, send(key)]}] - end - - # @return [String] - def consumer_key - ENV['TWITTER_CONSUMER_KEY'] - end - - # @return [String] - def consumer_secret - ENV['TWITTER_CONSUMER_SECRET'] - end - - # @return [String] - def oauth_token - ENV['TWITTER_OAUTH_TOKEN'] - end - - # @return [String] - def oauth_token_secret - ENV['TWITTER_OAUTH_TOKEN_SECRET'] - end - - # @return [String] - def bearer_token - ENV['TWITTER_BEARER_TOKEN'] - end - - # @note This is configurable in case you want to use a Twitter-compatible endpoint. - # @see http://status.net/wiki/Twitter-compatible_API - # @see http://en.blog.wordpress.com/2009/12/12/twitter-api/ - # @see http://staff.tumblr.com/post/287703110/api - # @see http://developer.typepad.com/typepad-twitter-api/twitter-api.html - # @return [String] - def endpoint - ENDPOINT - end - - def connection_options - CONNECTION_OPTIONS - end - - # @note Faraday's middleware stack implementation is comparable to that of Rack middleware. The order of middleware is important: the first middleware on the list wraps all others, while the last middleware is the innermost one. - # @see https://github.com/technoweenie/faraday#advanced-middleware-usage - # @see http://mislav.uniqpath.com/2011/07/faraday-advanced-http/ - # @return [Faraday::Builder] - def middleware - MIDDLEWARE - end - - end - end -end diff --git a/spec/helper.rb b/spec/helper.rb index 5902060fb..8ea46a0f2 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -23,35 +23,35 @@ end def a_delete(path) - a_request(:delete, Twitter::Default::ENDPOINT + path) + a_request(:delete, Twitter::Client::ENDPOINT + path) end def a_get(path) - a_request(:get, Twitter::Default::ENDPOINT + path) + a_request(:get, Twitter::Client::ENDPOINT + path) end def a_post(path) - a_request(:post, Twitter::Default::ENDPOINT + path) + a_request(:post, Twitter::Client::ENDPOINT + path) end def a_put(path) - a_request(:put, Twitter::Default::ENDPOINT + path) + a_request(:put, Twitter::Client::ENDPOINT + path) end def stub_delete(path) - stub_request(:delete, Twitter::Default::ENDPOINT + path) + stub_request(:delete, Twitter::Client::ENDPOINT + path) end def stub_get(path) - stub_request(:get, Twitter::Default::ENDPOINT + path) + stub_request(:get, Twitter::Client::ENDPOINT + path) end def stub_post(path) - stub_request(:post, Twitter::Default::ENDPOINT + path) + stub_request(:post, Twitter::Client::ENDPOINT + path) end def stub_put(path) - stub_request(:put, Twitter::Default::ENDPOINT + path) + stub_request(:put, Twitter::Client::ENDPOINT + path) end def fixture_path diff --git a/spec/twitter/client_spec.rb b/spec/twitter/client_spec.rb index 5104ec282..b4096cfd9 100644 --- a/spec/twitter/client_spec.rb +++ b/spec/twitter/client_spec.rb @@ -2,69 +2,40 @@ describe Twitter::Client do - subject do - Twitter::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :oauth_token => "OT", :oauth_token_secret => "OS") + before do + @client = Twitter::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :oauth_token => "OT", :oauth_token_secret => "OS") end - context "with module configuration" do - - before do - Twitter.configure do |config| - Twitter::Configurable.keys.each do |key| - config.send("#{key}=", key) - end + describe ".new" do + context "when invalid credentials are provided" do + it "raises a ConfigurationError exception" do + expect { + Twitter::Client.new(:consumer_key => [12345, 54321]) + }.to raise_exception(Twitter::Error::ConfigurationError) end end - after do - Twitter.reset! - end - - it "inherits the module configuration" do - client = Twitter::Client.new - Twitter::Configurable.keys.each do |key| - expect(client.instance_variable_get(:"@#{key}")).to eq(key) + context "when no credentials are provided" do + it "does not raise an exception" do + expect { + Twitter::Client.new + }.not_to raise_error end end + end - context "with class configuration" do - - before do - @configuration = { - :connection_options => {:timeout => 10}, - :consumer_key => "CK", - :consumer_secret => "CS", - :endpoint => "http://tumblr.com/", - :middleware => Proc.new{}, - :oauth_token => "OT", - :oauth_token_secret => "OS", - :bearer_token => "BT", - } - end - - context "during initialization" do - it "overrides the module configuration" do - client = Twitter::Client.new(@configuration) - Twitter::Configurable.keys.each do |key| - expect(client.instance_variable_get(:"@#{key}")).to eq(@configuration[key]) - end - end - end - - context "after initialization" do - it "overrides the module configuration after initialization" do - client = Twitter::Client.new - client.configure do |config| - @configuration.each do |key, value| - config.send("#{key}=", value) - end - end - Twitter::Configurable.keys.each do |key| - expect(client.instance_variable_get(:"@#{key}")).to eq(@configuration[key]) - end - end - end - + describe ".credentials?" do + it "returns true if only bearer_token is supplied" do + client = Twitter::Client.new(:bearer_token => "BT") + expect(client.credentials?).to be_true + end + it "returns true if all OAuth credentials are present" do + client = Twitter::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :oauth_token => "OT", :oauth_token_secret => "OS") + expect(client.credentials?).to be_true + end + it "returns false if any credentials are missing" do + client = Twitter::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :oauth_token => "OT") + expect(client.credentials?).to be_false end end @@ -81,7 +52,7 @@ stub_delete("/custom/delete").with(:query => {:deleted => "object"}) end it "allows custom delete requests" do - subject.delete("/custom/delete", {:deleted => "object"}) + @client.delete("/custom/delete", {:deleted => "object"}) expect(a_delete("/custom/delete").with(:query => {:deleted => "object"})).to have_been_made end end @@ -91,7 +62,7 @@ stub_put("/custom/put").with(:body => {:updated => "object"}) end it "allows custom put requests" do - subject.put("/custom/put", {:updated => "object"}) + @client.put("/custom/put", {:updated => "object"}) expect(a_put("/custom/put").with(:body => {:updated => "object"})).to have_been_made end end @@ -131,10 +102,10 @@ describe "#connection" do it "looks like Faraday connection" do - expect(subject.send(:connection)).to respond_to(:run_request) + expect(@client.send(:connection)).to respond_to(:run_request) end it "memoizes the connection" do - c1, c2 = subject.send(:connection), subject.send(:connection) + c1, c2 = @client.send(:connection), @client.send(:connection) expect(c1.object_id).to eq(c2.object_id) end end @@ -142,28 +113,28 @@ describe "#request" do it "encodes the entire body when no uploaded media is present" do stub_post("/1.1/statuses/update.json").with(:body => {:status => "Update"}).to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - subject.update("Update") + @client.update("Update") expect(a_post("/1.1/statuses/update.json").with(:body => {:status => "Update"})).to have_been_made end it "encodes none of the body when uploaded media is present" do stub_post("/1.1/statuses/update_with_media.json").to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - subject.update_with_media("Update", fixture("pbjt.gif")) + @client.update_with_media("Update", fixture("pbjt.gif")) expect(a_post("/1.1/statuses/update_with_media.json")).to have_been_made end it "catches Faraday errors" do - allow(subject).to receive(:connection).and_raise(Faraday::Error::ClientError.new("Oops")) - expect{subject.send(:request, :get, "/path")}.to raise_error Twitter::Error + allow(@client).to receive(:connection).and_raise(Faraday::Error::ClientError.new("Oops")) + expect{@client.send(:request, :get, "/path")}.to raise_error Twitter::Error end it "catches JSON::ParserError errors" do - allow(subject).to receive(:connection).and_raise(JSON::ParserError.new("unexpected token")) - expect{subject.send(:request, :get, "/path")}.to raise_error Twitter::Error + allow(@client).to receive(:connection).and_raise(JSON::ParserError.new("unexpected token")) + expect{@client.send(:request, :get, "/path")}.to raise_error Twitter::Error end end describe "#oauth_auth_header" do it "creates the correct auth headers" do uri = "/1.1/direct_messages.json" - authorization = subject.send(:oauth_auth_header, :get, uri) + authorization = @client.send(:oauth_auth_header, :get, uri) expect(authorization.options[:signature_method]).to eq("HMAC-SHA1") expect(authorization.options[:version]).to eq("1.0") expect(authorization.options[:consumer_key]).to eq("CK") @@ -178,9 +149,9 @@ :nonce => "b6ebe4c2a11af493f8a2290fe1296965", :timestamp => "1370968658"} header = {"Authorization" => /oauth_signature="FbthwmgGq02iQw%2FuXGEWaL6V6eM%3D"/} - allow(subject).to receive(:credentials).and_return(secret) + allow(@client).to receive(:credentials).and_return(secret) stub_post("/1.1/statuses/update.json").with(:body => {:status => "Just a test"}).to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - subject.update("Just a test") + @client.update("Just a test") expect(a_post("/1.1/statuses/update.json"). with(:headers => header)).to have_been_made end @@ -191,28 +162,28 @@ :nonce => "e08201ad0dab4897c99445056feefd95", :timestamp => "1370967652"} header = {"Authorization" => /oauth_signature="9ziouUPwZT9IWWRbJL8r0BerKYA%3D"/} - allow(subject).to receive(:credentials).and_return(secret) + allow(@client).to receive(:credentials).and_return(secret) stub_post("/1.1/statuses/update_with_media.json").to_return(:body => fixture("status.json"), :headers => header) - subject.update_with_media("Just a test", fixture("pbjt.gif")) + @client.update_with_media("Just a test", fixture("pbjt.gif")) expect(a_post("/1.1/statuses/update_with_media.json"). with(:headers => header)).to have_been_made end end describe "#bearer_auth_header" do - subject do - Twitter::Client.new(:bearer_token => "BT") + before do + @client = Twitter::Client.new(:bearer_token => "BT") end it "creates the correct auth headers with supplied bearer_token" do - authorization = subject.send(:bearer_auth_header) + authorization = @client.send(:bearer_auth_header) expect(authorization).to eq("Bearer BT") end end describe "#bearer_token_credentials_auth_header" do it "creates the correct auth header with supplied consumer_key and consumer_secret" do - authorization = subject.send(:bearer_token_credentials_auth_header) + authorization = @client.send(:bearer_token_credentials_auth_header) expect(authorization).to eq("Basic Q0s6Q1M=") end end diff --git a/spec/twitter_spec.rb b/spec/twitter_spec.rb index 9cd4f92c7..e69de29bb 100644 --- a/spec/twitter_spec.rb +++ b/spec/twitter_spec.rb @@ -1,125 +0,0 @@ -require 'helper' - -describe Twitter do - - after do - Twitter.reset! - end - - context "when delegating to a client" do - - before do - Twitter.configure do |config| - config.consumer_key = 'CK' - config.consumer_secret = 'CS' - config.oauth_token = 'OT' - config.oauth_token_secret = 'OS' - end - stub_get("/1.1/statuses/user_timeline.json").with(:query => {:screen_name => "sferik"}).to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - end - - it "requests the correct resource" do - Twitter.user_timeline('sferik') - expect(a_get("/1.1/statuses/user_timeline.json").with(:query => {:screen_name => "sferik"})).to have_been_made - end - - it "returns the same results as a client" do - expect(Twitter.user_timeline('sferik')).to eq(Twitter::Client.new.user_timeline('sferik')) - end - - end - - describe ".respond_to?" do - it "delegates to Twitter::Client" do - expect(Twitter.respond_to?(:user)).to be_true - end - it "takes an optional argument" do - expect(Twitter.respond_to?(:new, true)).to be_true - end - end - - describe ".client" do - it "returns a Twitter::Client" do - expect(Twitter.new).to be_a Twitter::Client - end - - context "when the options don't change" do - it "caches the client" do - expect(Twitter.new).to eq(Twitter.new) - end - end - context "when the options change" do - it "busts the cache" do - client1 = Twitter.new - Twitter.configure do |config| - config.consumer_key = 'abc' - config.consumer_secret = '123' - end - client2 = Twitter.new - expect(client1).not_to eq(client2) - end - end - end - - describe ".configure" do - Twitter::Configurable.keys.each do |key| - it "sets the #{key.to_s.gsub('_', ' ')}" do - Twitter.configure do |config| - config.send("#{key}=", key) - end - expect(Twitter.instance_variable_get(:"@#{key}")).to eq(key) - end - end - - context "when invalid credentials are provided" do - it "raises a ConfigurationError exception" do - expect { - Twitter.configure do |config| - config.consumer_key = [12345, 54321] - config.consumer_secret = 'valid_data' - end - }.to raise_exception(Twitter::Error::ConfigurationError) - end - end - - context "when no credentials are provided" do - it "does not raise an exception" do - expect { - Twitter.configure do |config| - config.consumer_key = nil - config.consumer_secret = nil - config.oauth_token = nil - config.oauth_token_secret = nil - end - }.not_to raise_error - end - end - end - - describe ".credentials?" do - it "returns true if only bearer_token is supplied" do - Twitter.configure do |config| - config.bearer_token = 'BT' - end - expect(Twitter.credentials?).to be_true - end - it "returns true if all oauth credentials are present" do - Twitter.configure do |config| - config.consumer_key = 'CK' - config.consumer_secret = 'CS' - config.oauth_token = 'OT' - config.oauth_token_secret = 'OS' - end - expect(Twitter.credentials?).to be_true - end - it "returns false if any credentials are missing" do - Twitter.configure do |config| - config.consumer_key = 'CK' - config.consumer_secret = 'CS' - config.oauth_token = 'OT' - end - expect(Twitter.credentials?).to be_false - end - end - -end