Skip to content

Commit

Permalink
Unify naming of boolean methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Jun 4, 2011
1 parent 52e37ba commit b139e91
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 84 deletions.
3 changes: 2 additions & 1 deletion lib/twitter/base.rb
Expand Up @@ -6,6 +6,7 @@ class Base
# @deprecated {Twitter::Base} is deprecated and will be permanently removed in the next major version. Please use {Twitter::Client} instead.
# @return [Twitter::Client]
def client(options={})
warn "#{Kernel.caller.first}: [DEPRECATION] Twitter::Base is deprecated and will be permanently removed in the next major version. Please use Twitter::Client instead."
Twitter::Client.new(options)
end

Expand All @@ -15,7 +16,7 @@ def client(options={})
def method_missing(method, *args, &block)
return super unless client.respond_to?(method)
warn "#{Kernel.caller.first}: [DEPRECATION] Twitter::Base##{method} is deprecated and will be permanently removed in the next major version. Please use Twitter::Client##{method} instead."
client.send(method, *args, &block)
Twitter::Client.new.send(method, *args, &block)
end
end
end
34 changes: 24 additions & 10 deletions lib/twitter/client/block.rb
Expand Up @@ -44,24 +44,38 @@ def unblock(user, options={})

# Returns true if the authenticating user is blocking a target user
#
# @format :json, :xml
# @authenticated true
# @rate_limited true
# @param user [Integer, String] A Twitter user ID or screen name.
# @param options [Hash] A customizable set of options.
# @return [Boolean] true if the authenticating user is blocking the target user, otherwise false.
# @see http://dev.twitter.com/doc/get/blocks/exists
# @example Check whether the authenticating user is blocking @sferik
# Twitter.block_exists?("sferik")
# Twitter.block_exists?(7505382) # Same as above
def block_exists?(user, options={})
# Twitter.block?("sferik")
# Twitter.block?(7505382) # Same as above
def block?(user, options={})
merge_user_into_options!(user, options)
begin
get('blocks/exists', options)
true
rescue Twitter::NotFound
false
end
get('blocks/exists', options, true)
true
rescue Twitter::NotFound
false
end

# Returns true if the authenticating user is blocking a target user
#
# @deprecated {Twitter::Client::Block#block_exists?} is deprecated and will be removed in the next major version. Please use {Twitter::Client::Block#block?} instead.
# @authenticated true
# @rate_limited true
# @param user [Integer, String] A Twitter user ID or screen name.
# @param options [Hash] A customizable set of options.
# @return [Boolean] true if the authenticating user is blocking the target user, otherwise false.
# @see http://dev.twitter.com/doc/get/blocks/exists
# @example Check whether the authenticating user is blocking @sferik
# Twitter.block?("sferik")
# Twitter.block?(7505382) # Same as above
def block_exists?(user, options={})
warn "#{Kernel.caller.first}: [DEPRECATION] #block_exists? is deprecated and will be removed in the next major version. Please use #block? instead."
block?(user, options)
end

# Returns an array of user objects that the authenticating user is blocking
Expand Down
22 changes: 20 additions & 2 deletions lib/twitter/client/friendship.rb
Expand Up @@ -56,12 +56,30 @@ def unfollow(user, options={})
# @return [Boolean] true if user_a follows user_b, otherwise false.
# @see http://dev.twitter.com/doc/get/friendships/exists
# @example Return true if @sferik follows @pengwynn
# Twitter.friendship_exists?("sferik", "pengwynn")
def friendship_exists?(user_a, user_b, options={})
# Twitter.friendship?("sferik", "pengwynn")
def friendship?(user_a, user_b, options={})
response = get('friendships/exists', options.merge(:user_a => user_a, :user_b => user_b))
format.to_s.downcase == 'xml' ? !%w(0 false).include?(response['friends']) : response
end

# Test for the existence of friendship between two users
#
# @deprecated {Twitter::Client::Friendship#friendship_exists?} is deprecated and will be removed in the next major version. Please use {Twitter::Client::Friendship#friendship?} instead.
# @format :json, :xml
# @authenticated false unless user_a or user_b is protected
# @rate_limited true
# @param user_a [Integer, String] The ID or screen_name of the subject user.
# @param user_b [Integer, String] The ID or screen_name of the user to test for following.
# @param options [Hash] A customizable set of options.
# @return [Boolean] true if user_a follows user_b, otherwise false.
# @see http://dev.twitter.com/doc/get/friendships/exists
# @example Return true if @sferik follows @pengwynn
# Twitter.friendship_exists?("sferik", "pengwynn")
def friendship_exists?(user_a, user_b, options={})
warn "#{Kernel.caller.first}: [DEPRECATION] #friendship_exists? is deprecated and will be removed in the next major version. Please use #friendship? instead."
friendship?(user_a, user_b, options={})
end

# Returns detailed information about the relationship between two users
#
# @format :json, :xml
Expand Down
26 changes: 18 additions & 8 deletions lib/twitter/client/list.rb
Expand Up @@ -7,22 +7,32 @@ module List
# Creates a new list for the authenticated user
#
# @note Accounts are limited to 20 lists.
# @overload list_create(screen_name, name, options={})
# @deprecated Calling {Twitter::Client::List#list_create} with a screen_name is deprecated and will be removed in the next major version. Please omit the screen_name argument.
# @param screen_name [String] A Twitter user name.
# @param name [String] The name for the list.
# @param options [Hash] A customizable set of options.
# @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
# @option options [String] :description The description to give the list.
# @example Create a list named "presidents"
# Twitter.list_create("sferik", "presidents")
# @overload list_create(name, options={})
# @param name [String] The name for the list.
# @param options [Hash] A customizable set of options.
# @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
# @option options [String] :description The description to give the list.
# @example Create a list named "presidents"
# Twitter.list_create("presidents")
# @return [Hashie::Rash] The created list.
# @format :json, :xml
# @authenticated true
# @rate_limited false
# @param name [String] The name for the list.
# @param options [Hash] A customizable set of options.
# @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
# @option options [String] :description The description to give the list.
# @return [Hashie::Rash] The created list.
# @see http://dev.twitter.com/doc/post/:user/lists
# @example Create a list named "presidents"
# Twitter.list_create("presidents")
def list_create(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
name = args.pop
if screen_name = args.pop
warn "#{Kernel.caller.first}: [DEPRECATION] Calling Twitter::Client#list_create with a screen_name is deprecated and will be removed in the next major version. Please omit the screen_name argument."
warn "#{Kernel.caller.first}: [DEPRECATION] Calling #list_create with a screen_name is deprecated and will be removed in the next major version. Please omit the screen_name argument."
end
response = post("lists/create", options.merge(:name => name))
format.to_s.downcase == 'xml' ? response['list'] : response
Expand Down
53 changes: 40 additions & 13 deletions lib/twitter/client/list_members.rb
Expand Up @@ -160,6 +160,44 @@ def list_remove_member(*args)

# Check if a user is a member of the specified list
#
# @overload list_member?(list, user_to_check, options={})
# @param list [Integer, String] The list_id or slug of the list.
# @param user_to_check [Integer, String] The user ID or screen name of the list member.
# @param options [Hash] A customizable set of options.
# @return [Boolean] true if user is a member of the specified list, otherwise false.
# @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] A Twitter user ID or screen name.
# @param list [Integer, String] The list_id or slug of the list.
# @param user_to_check [Integer, String] The user ID or screen name of the list member.
# @param options [Hash] A customizable set of options.
# @return [Boolean] true if user is a member of the specified list, otherwise false.
# @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)
# @return [Boolean] true if user is a member of the specified list, otherwise false.
# @authenticated true
# @rate_limited false
# @see http://dev.twitter.com/doc/get/:user/:list_id/members/:id
def list_member?(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
user_to_check, list = args.pop, args.pop
user = args.pop || get_screen_name
merge_list_into_options!(list, options)
merge_owner_into_options!(user, options)
merge_user_into_options!(user_to_check, options)
get("lists/members/show", options, true)
true
rescue Twitter::NotFound, Twitter::Forbidden
false
end

# Check if a user is a member of the specified list
#
# @deprecated {Twitter::Client::ListMembers#is_list_member?} is deprecated and will be removed in the next major version. Please use {Twitter::Client::ListMembers#list_member?} instead.
# @overload is_list_member?(list, user_to_check, options={})
# @param list [Integer, String] The list_id or slug of the list.
# @param user_to_check [Integer, String] The user ID or screen name of the list member.
Expand All @@ -179,23 +217,12 @@ def list_remove_member(*args)
# Twitter.is_list_member?('sferik', 8863586, 'BarackObama')
# Twitter.is_list_member?(7505382, "presidents", 813286)
# @return [Boolean] true if user is a member of the specified list, otherwise false.
# @format :json, :xml
# @authenticated true
# @rate_limited false
# @see http://dev.twitter.com/doc/get/:user/:list_id/members/:id
def is_list_member?(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
user_to_check, list = args.pop, args.pop
user = args.pop || get_screen_name
merge_list_into_options!(list, options)
merge_owner_into_options!(user, options)
merge_user_into_options!(user_to_check, options)
begin
get("lists/members/show", options)
true
rescue Twitter::NotFound, Twitter::Forbidden
false
end
warn "#{Kernel.caller.first}: [DEPRECATION] #is_list_member? is deprecated and will be removed in the next major version. Please use #list_member? instead."
friendship?(args)
end
end
end
Expand Down
55 changes: 43 additions & 12 deletions lib/twitter/client/list_subscribers.rb
Expand Up @@ -109,6 +109,47 @@ def list_unsubscribe(*args)

# Check if a user is a subscriber of the specified list
#
# @overload list_subscriber?(list, user_to_check, options={})
# @param list [Integer, String] The list_id or slug of the list.
# @param user_to_check [Integer, String] The user ID or screen_name of the list member.
# @param options [Hash] A customizable set of options.
# @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
# @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] A Twitter user ID or screen name.
# @param list [Integer, String] The list_id or slug of the list.
# @param user_to_check [Integer, String] The user ID or screen_name of the list member.
# @param options [Hash] A customizable set of options.
# @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
# @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.
# @format :json, :xml
# @authenticated true
# @rate_limited true
# @see http://dev.twitter.com/doc/get/:user/:list_id/subscribers/:id
def list_subscriber?(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
user_to_check, list = args.pop, args.pop
user = args.pop || get_screen_name
merge_list_into_options!(list, options)
merge_owner_into_options!(user, options)
merge_user_into_options!(user_to_check, options)
get("lists/subscribers/show", options, true)
true
rescue Twitter::NotFound, Twitter::Forbidden
false
end

# Check if a user is a subscriber of the specified list
#
# @deprecated {Twitter::Client::ListSubscribers#is_subscriber?} is deprecated and will be removed in the next major version. Please use {Twitter::Client::ListSubscribers#list_subscriber?} instead.
# @overload is_subscriber?(list, user_to_check, options={})
# @param list [Integer, String] The list_id or slug of the list.
# @param user_to_check [Integer, String] The user ID or screen_name of the list member.
Expand All @@ -135,18 +176,8 @@ def list_unsubscribe(*args)
# @rate_limited true
# @see http://dev.twitter.com/doc/get/:user/:list_id/subscribers/:id
def is_subscriber?(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
user_to_check, list = args.pop, args.pop
user = args.pop || get_screen_name
merge_list_into_options!(list, options)
merge_owner_into_options!(user, options)
merge_user_into_options!(user_to_check, options)
begin
get("lists/subscribers/show", options)
true
rescue Twitter::NotFound, Twitter::Forbidden
false
end
warn "#{Kernel.caller.first}: [DEPRECATION] #is_subscriber? is deprecated and will be removed in the next major version. Please use #list_subscriber? instead."
list_subscriber?(args)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/search.rb
Expand Up @@ -214,7 +214,7 @@ def place(place_id)

# Only include tweets from users in a given radius of a given location
#
# @deprecated Twitter::Search#near is deprecated and will be permanently removed in the next major version. Please use Twitter::Search#geocode instead.
# @deprecated {Twitter::Search#near} is deprecated and will be permanently removed in the next major version. Please use {Twitter::Search#geocode} instead.
# @param lat [Float] A latitude.
# @param long [Float] A longitude.
# @param radius [String] A search radius, specified in either 'mi' (miles) or 'km' (kilometers).
Expand All @@ -223,7 +223,7 @@ def place(place_id)
# @example Return an array of tweets within a 1-mile radius of Twitter HQ
# Twitter::Search.new.containing("twitter").geocode(37.781157, -122.398720, "1mi").fetch
def near(lat, long, radius)
warn "#{Kernel.caller.first}: [DEPRECATION] Twitter::Search#near is deprecated and will be permanently removed in the next major version. Please use Twitter::Search#geocode instead."
warn "#{Kernel.caller.first}: [DEPRECATION] #near is deprecated and will be permanently removed in the next major version. Please use #geocode instead."
@query[:geocode] = [lat, long, radius].join(",")
self
end
Expand Down
12 changes: 6 additions & 6 deletions spec/twitter/client/block_spec.rb
Expand Up @@ -50,7 +50,7 @@

end

describe ".block_exists?" do
describe ".block?" do

before do
stub_get("blocks/exists.#{format}").
Expand All @@ -62,20 +62,20 @@
end

it "should get the correct resource" do
@client.block_exists?("sferik")
@client.block?("sferik")
a_get("blocks/exists.#{format}").
with(:query => {:screen_name => "sferik"}).
should have_been_made
end

it "should return true if block exists" do
block_exists = @client.block_exists?("sferik")
block_exists.should be_true
block = @client.block?("sferik")
block.should be_true
end

it "should return false if block does not exists" do
block_exists = @client.block_exists?("pengwynn")
block_exists.should be_false
block = @client.block?("pengwynn")
block.should be_false
end

end
Expand Down
12 changes: 6 additions & 6 deletions spec/twitter/client/friendship_spec.rb
Expand Up @@ -99,7 +99,7 @@

end

describe ".friendship_exists?" do
describe ".friendship?" do

before do
stub_get("friendships/exists.#{format}").
Expand All @@ -111,20 +111,20 @@
end

it "should get the correct resource" do
@client.friendship_exists?("sferik", "pengwynn")
@client.friendship?("sferik", "pengwynn")
a_get("friendships/exists.#{format}").
with(:query => {:user_a => "sferik", :user_b => "pengwynn"}).
should have_been_made
end

it "should return true if user_a follows user_b" do
friendship_exists = @client.friendship_exists?("sferik", "pengwynn")
friendship_exists.should be_true
friendship = @client.friendship?("sferik", "pengwynn")
friendship.should be_true
end

it "should return false if user_a does not follows user_b" do
friendship_exists = @client.friendship_exists?("pengwynn", "sferik")
friendship_exists.should be_false
friendship = @client.friendship?("pengwynn", "sferik")
friendship.should be_false
end

end
Expand Down

0 comments on commit b139e91

Please sign in to comment.