Added v 0.2.2 snapshot.
[twitter4r-core.git] / examples / timeline.rb
blob2d6b67b55cbd47ba018d22be3930879316a700a8
1 # = Timeline API Examples
2 #  require('rubygems')
3 #  gem('twitter4r', '0.2.0')
4 #  require('twitter')
5
6 # The following is only required if you want to use some configuration 
7 # helper methods like <tt>Twitte4R::Client.from_config</tt> for 
8 # sensitive/instance context.
9 #  require 'twitter/console'
10 #  config_file = File.join(File.dirname(__FILE__), '..', 'config', 'twitter.yml')
11 #  
12
13 # To override client connection configuration please refer to 
14 # the {<tt>configure.rb</tt>}[file:configure_rb.html] example code.
15 #  twitter = Twitter::Client.from_config(config_file)
16
17 # This returns the public timeline as an <tt>Array</tt>.
18
19 # We pass a block in to do something with each status returned inline.
20 # However, we still get to keep the <tt>public_timeline</tt> array after 
21 # the method returns, for our application's safe keeping.
22
23 # It is not necessary to pass in a block to this method, so don't worry if 
24 # you don't want to do that.  All calls to <tt>Twitter::Client#timeline_for</tt>
25 # can pass in a block that works the same way as explained here.
26 #  public_timeline = twitter.timeline_for(:public) do |status|
27 #    puts status.user.screen_name, status.text
28 #  end
29
30 # This returns the timeline for all your friends as an <tt>Array</tt>.
31 # See public timeline example above for discussion about passing in block,
32 # which is possible to all calls to <tt>Twitter::Client#timeline_for</tt>.
33 #  all_friends_timeline = twitter.timeline_for(:friends)
34
35 # This returns the timeline for a particular friend.
36 #  myfriend_timeline = twitter.timeline_for(:friend, :id => 'dictionary')
37
38 # This returns the timeline for a particular user (who may or may not be a friend).
39 #  user_timeline = twitter.timeline_for(:user, :id => 'twitter4r')
40
41 # This returns the authenticated user's timeline
42
43 # We can also use the following code snippet, which is equivalent to the example below:
44 #  my_timeline = twitter.my(:timeline)
45 # See Status API examples in <tt>status.rb</tt> file.
46 #  my_timeline = twitter.timeline_for(:me)
47
48 # Below we demonstrate how to use more interesting parameters to the 
49 # <tt>Twitter::Client#timeline_for</tt> method
50
51 # Returns all public statuses since the status id returned by:
52 #  public_timeline.first.id
53 #  latest_timeline = twitter.timeline_for(:public, :since_id => public_timeline.first.id)
54
55 # Returns all friend statuses in the last 24 hours:
56 #  yesterday = Time.now - 60*60*24
57 #  new_friends_timeline = twitter.timeline_for(:friends, :since => yesterday)
58
59 # Returns last three statuses from user <tt>'twitter4r'</tt>:
60 #  latest_twitter4r_timeline = twitter.timeline_for(:user, :id => 'twitter4', :count => 3)
61
62 # Returns timeline from user <tt>'dictionary'</tt> since yesterday at this time, 
63 # with block:
64 #  new_dictionary_timeline = twitter.timeline_for(:user, :id => 'dictionary', :since => yesterday) do |status|
65 #    puts status.text
66 #  end