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