Sha256: 8a992815431f40d8e02f53b39e5be925464edc50831f0075ca772553f43c8064
Contents?: true
Size: 1.82 KB
Versions: 2
Compression:
Stored size: 1.82 KB
Contents
class Twitter::Client @@FRIENDSHIP_URIS = { :add => '/friendships/create', :remove => '/friendships/destroy', :exists => '/friendships/exists' } # 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_post_request(uri) } bless_model(Twitter::User.unmarshal(response.body)) end # Tests if a friendship exists between two users. # # Examples: # client.are_friends?(user1,user2) #=> returns true if user1 follows user2 # #=> returns false if user1 does not follower user2 def are_friends?(user1,user2) uri = "#{@@FRIENDSHIP_URIS[:exists]}.json" response = http_connect {|conn| create_http_get_request(uri, {:user_a => "#{user1}", :user_b => "#{user2}" })} response.body.rindex('true') ? true : false end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dambalah-twitter4r-0.3.2 | lib/twitter/client/friendship.rb |
dambalah-twitter4r-0.3.3 | lib/twitter/client/friendship.rb |