Sha256: ce68218e09fd9708715c0dfa42f86617eedf8d52ba82f56813c7c79c10f7d81a

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 KB

Contents

class Twitter::Client
	@@FRIENDSHIP_URIS = {
		:add => '/friendships/create',
		:remove => '/friendships/destroy',
	}
	
	# Provides access to the Twitter Friendship API.
	# 
	# You can add and remove friends using this method.
	# 
	# <tt>action</tt> can be any of the following values:
	# * <tt>:add</tt> - to add a friend, you would use this <tt>action</tt> value
	# * <tt>:remove</tt> - to remove an existing friend from your friends list use this.
	# 
	# The <tt>value</tt> must be either the user to befriend or defriend's 
	# screen name, integer unique user ID or Twitter::User object representation.
	# 
	# Examples:
	#  screen_name = 'dictionary'
	#  client.friend(:add, 'dictionary')
	#  client.friend(:remove, 'dictionary')
	#  id = 1260061
	#  client.friend(:add, id)
	#  client.friend(:remove, id)
	#  user = Twitter::User.find(id, client)
	#  client.friend(:add, user)
	#  client.friend(:remove, user)
	def friend(action, value)
	  raise ArgumentError, "Invalid friend action provided: #{action}" unless @@FRIENDSHIP_URIS.keys.member?(action)
		value = value.to_i unless value.is_a?(String)
		uri = "#{@@FRIENDSHIP_URIS[action]}/#{value}.json"
		response = http_connect {|conn| create_http_get_request(uri) }
		bless_model(Twitter::User.unmarshal(response.body))
	end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
twitter4r-0.2.4 lib/twitter/client/friendship.rb
twitter4r-0.2.3 lib/twitter/client/friendship.rb
twitter4r-0.2.2 lib/twitter/client/friendship.rb
twitter4r-0.2.5 lib/twitter/client/friendship.rb
twitter4r-0.3.0 lib/twitter/client/friendship.rb