Added v 0.2.1 snapshot.
[twitter4r-core.git] / lib / twitter / client / friendship.rb
blob51cea574ab7cf8899c3b40979bc324a35b33068d
1 class Twitter::Client
2         @@FRIENDSHIP_URIS = {
3                 :add => 'http://twitter.com/friendships/create',
4                 :remove => 'http://twitter.com/friendships/destroy',
5         }
6         
7         # Provides access to the Twitter Friendship API.
8         # 
9         # You can add and remove friends using this method.
10         # 
11         # <tt>action</tt> can be any of the following values:
12         # * <tt>:add</tt> - to add a friend, you would use this <tt>action</tt> value
13         # * <tt>:remove</tt> - to remove an existing friend from your friends list use this.
14         # 
15         # The <tt>value</tt> must be either the user to befriend or defriend's 
16         # screen name, integer unique user ID or Twitter::User object representation.
17         # 
18         # Examples:
19         #  screen_name = 'dictionary'
20         #  client.friend(:add, 'dictionary')
21         #  client.friend(:remove, 'dictionary')
22         #  id = 1260061
23         #  client.friend(:add, id)
24         #  client.friend(:remove, id)
25         #  user = Twitter::User.find(id, client)
26         #  client.friend(:add, user)
27         #  client.friend(:remove, user)
28         def friend(action, value)
29                 value = value.to_i unless value.is_a?(String)
30                 uri = "#{@@FRIENDSHIP_URIS[action]}/#{value}.json"
31                 response = http_connect {|conn| create_http_get_request(uri) }
32                 bless_model(Twitter::User.unmarshal(response.body))
33         end
34 end