Added v 0.2.2 snapshot.
[twitter4r-core.git] / lib / twitter / extras.rb
blobc1b39a4a9cc73d7215443c48e4836f9208241c40
1 # extra.rb contains features that are not considered part of the core library.
2 # This file is not imported by doing <tt>require('twitter')</tt>, so you will 
3 # need to import this file separately like:
4 #  require('twitter')
5 #  require('twitter/extras')
7 require('twitter')
9 class Twitter::Client
10   @@FEATURED_URIS = {
11     :users => 'http://twitter.com/statuses/featured.json'
12   }
13   
14   # Provides access to the Featured Twitter API.
15   # 
16   # Currently the only value for <tt>type</tt> accepted is <tt>:users</tt>,
17   # which will return an Array of blessed Twitter::User objects that 
18   # represent Twitter's featured users.
19   def featured(type)
20     uri = @@FEATURED_URIS[type]
21     response = http_connect {|conn| create_http_get_request(uri) }
22     bless_models(Twitter::User.unmarshal(response.body))
23   end
24 end
26 class Twitter::User
27   class << self
28     # Provides access to the Featured Twitter API via the Twitter4R Model 
29     # interface.
30     # 
31     # The following lines of code are equivalent to each other:
32     #  users1 = Twitter::User.features(client)
33     #  users2 = client.featured(:users)
34     # where <tt>users1</tt> and <tt>users2</tt> would be logically equivalent.
35     def featured(client)
36       client.featured(:users)
37     end
38   end
39 end