From a5af75086d607a373347d9ae363a92aa8907b44d Mon Sep 17 00:00:00 2001 From: mbbx6spp Date: Mon, 25 Jun 2007 17:12:07 +0000 Subject: [PATCH] Updated example documentation --- examples/configure.rb | 50 ++++++++++++++++++------------ examples/direct_message.rb | 8 ----- examples/follower_statuses.rb | 10 ------ examples/friend_statuses.rb | 10 ------ examples/friend_timeline.rb | 10 ------ examples/friendship.rb | 23 ++++++++++++++ examples/messaging.rb | 21 +++++++++++++ examples/model.rb | 7 +++++ examples/public_timeline.rb | 10 ------ examples/status.rb | 23 ++++++++++++++ examples/timeline.rb | 72 +++++++++++++++++++++++++++++++++++++++++++ examples/update.rb | 9 ------ examples/user.rb | 21 +++++++++++++ 13 files changed, 197 insertions(+), 77 deletions(-) rewrite examples/configure.rb (72%) delete mode 100755 examples/direct_message.rb delete mode 100644 examples/follower_statuses.rb delete mode 100644 examples/friend_statuses.rb delete mode 100644 examples/friend_timeline.rb create mode 100644 examples/friendship.rb create mode 100644 examples/messaging.rb create mode 100644 examples/model.rb delete mode 100644 examples/public_timeline.rb create mode 100644 examples/status.rb create mode 100644 examples/timeline.rb delete mode 100644 examples/update.rb create mode 100644 examples/user.rb diff --git a/examples/configure.rb b/examples/configure.rb dissimilarity index 72% index 3d98d82..a1f1d04 100644 --- a/examples/configure.rb +++ b/examples/configure.rb @@ -1,20 +1,30 @@ -require 'twitter' - -# Here we setup configuration for all Twitter::Client instances -# This looks much like Rails' Initializer code that can be found -# in config/environment in Rails applications by design. -Twitter::Client.configure do |conf| - # We can set Twitter4R to use :ssl or :http to connect to the Twitter API. - # Defaults to :ssl - conf.protocol = :ssl - - # We can set Twitter4R to use another host name (perhaps for internal - # testing purposes). - # Defaults to 'twitter.com' - conf.host = 'twitter.com' - - # We can set Twitter4R to use another port (also for internal - # testing purposes). - # Defaults to 443 - conf.port = 443 -end +# = Configuration API Examples +# require('rubygems') +# gem('twitter4r', '0.2.0') +# require('twitter') +# +# Here we setup configuration for all Twitter::Client instances +# This looks much like Rails' Initializer code that can be found +# in config/environment in Rails applications by design. +# Twitter::Client.configure do |conf| +# # We can set Twitter4R to use :ssl or :http to connect to the Twitter API. +# # Defaults to :ssl +# conf.protocol = :ssl +# +# # We can set Twitter4R to use another host name (perhaps for internal +# # testing purposes). +# # Defaults to 'twitter.com' +# conf.host = 'twitter.com' +# +# # We can set Twitter4R to use another port (also for internal +# # testing purposes). +# # Defaults to 443 +# conf.port = 443 +# +# # We can set proxy information for Twitter4R +# # By default all following values are set to nil. +# conf.proxy_host = 'myproxy.host' +# conf.proxy_port = 8080 +# conf.proxy_user = 'myuser' +# conf.proxy_pass = 'mypass' +# end diff --git a/examples/direct_message.rb b/examples/direct_message.rb deleted file mode 100755 index 8b4ea5d..0000000 --- a/examples/direct_message.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'twitter' - -client = Twitter::Client.new(:login => 'mylogin', :password => 'mypassword') -begin - client.send_direct_message('friend_screen_name', 'Twitter4R is so cool, check it out at http://twitter4r.rubyforge.org') -rescue Twitter::RESTError => re - puts re # perhaps try again also? left as exercise. -end diff --git a/examples/follower_statuses.rb b/examples/follower_statuses.rb deleted file mode 100644 index ebf7bbd..0000000 --- a/examples/follower_statuses.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'twitter' - -client = Twitter::Client.new(:login => 'mylogin', :password => 'mypassword') -statuses = client.follower_statuses -# statuses is an array of Twitter::Status objects -# you can query Status objects like so... -statuses.each do |stat| - puts stat.user.screen_name, stat.text - puts -end diff --git a/examples/friend_statuses.rb b/examples/friend_statuses.rb deleted file mode 100644 index 9e7e110..0000000 --- a/examples/friend_statuses.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'twitter' - -client = Twitter::Client.new(:login => 'mylogin', :password => 'mypassword') -statuses = client.friend_statuses -# statuses is an array of Twitter::Status objects -# you can query Status objects like so... -statuses.each do |stat| - puts stat.user.screen_name, stat.text - puts -end diff --git a/examples/friend_timeline.rb b/examples/friend_timeline.rb deleted file mode 100644 index a4decb6..0000000 --- a/examples/friend_timeline.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'twitter' - -client = Twitter::Client.new(:login => 'mylogin', :password => 'mypassword') -statuses = client.friend_timeline -# statuses is an array of Twitter::Status objects -# you can query Status objects like so... -statuses.each do |stat| - puts stat.user.screen_name, stat.text - puts -end diff --git a/examples/friendship.rb b/examples/friendship.rb new file mode 100644 index 0000000..0637068 --- /dev/null +++ b/examples/friendship.rb @@ -0,0 +1,23 @@ +# = Friendship API Examples +# require('rubygems') +# gem('twitter4r', '0.2.0') +# require('twitter') +# +# The following is only required if you want to use some configuration +# helper methods like Twitte4R::Client.from_config for +# sensitive/instance context. +# require 'twitter/console' +# +# config_file = File.join(File.dirname(__FILE__), '..', 'config', 'twitter.yml') +# +# Not configuring Twitter::Client for global features such as overriding: +# * protocol +# * host +# * port +# * user agent +# * proxy information +# Since the defaults are satisfactory, but if you need to, please refer to +# the {configure.rb}[file:configure_rb.html] example code. +# twitter = Twitter::Client.from_config(config_file) +# +# diff --git a/examples/messaging.rb b/examples/messaging.rb new file mode 100644 index 0000000..c40876e --- /dev/null +++ b/examples/messaging.rb @@ -0,0 +1,21 @@ +# = Messaging API Examples +# require('rubygems') +# gem('twitter4r', '0.2.0') +# require('twitter') +# +# only required if you want to use some configuration helper methods like +# Twitte4R::Client.from_config for sensitive/instance context. +# require 'twitter/console' +# config_file = File.join(File.dirname(__FILE__), '..', 'config', 'twitter.yml') +# +# Not configuring Twitter::Client for global features such as overriding: +# * protocol +# * host +# * port +# * user agent +# * proxy information +# Since the defaults are satisfactory, but if you need to, please refer to +# the {configure.rb}[file:configure_rb.html] example code. +# +# twitter = Twitter::Client.from_config(config_file) + diff --git a/examples/model.rb b/examples/model.rb new file mode 100644 index 0000000..cf53de7 --- /dev/null +++ b/examples/model.rb @@ -0,0 +1,7 @@ +# = Model API Examples +# +# require('rubygems') +# gem('twitter4r', '0.2.0') +# require('twitter') +# +# diff --git a/examples/public_timeline.rb b/examples/public_timeline.rb deleted file mode 100644 index 7ba6a5e..0000000 --- a/examples/public_timeline.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'twitter' - -client = Twitter::Client.new(:login => 'mylogin', :password => 'mypassword') -statuses = client.public_timeline -# statuses is an array of Twitter::Status objects -# you can query Status objects like so... -statuses.each do |stat| - puts stat.user.screen_name, stat.text - puts -end diff --git a/examples/status.rb b/examples/status.rb new file mode 100644 index 0000000..b306138 --- /dev/null +++ b/examples/status.rb @@ -0,0 +1,23 @@ +# = Status API Examples +# require('rubygems') +# gem('twitter4r', '0.2.0') +# require('twitter') +# +# only required if you want to use some configuration helper methods like +# Twitte4R::Client.from_config for sensitive/instance context. +# +# require 'twitter/console' +# config_file = File.join(File.dirname(__FILE__), '..', 'config', 'twitter.yml') +# +# Not configuring Twitter::Client for global features such as overriding: +# * protocol +# * host +# * port +# * user agent +# * proxy information +# Since the defaults are satisfactory, but if you need to, please refer to +# the {configure.rb}[file:configure_rb.html] example code. +# +# twitter = Twitter::Client.from_config(config_file) +# +# diff --git a/examples/timeline.rb b/examples/timeline.rb new file mode 100644 index 0000000..d7c8186 --- /dev/null +++ b/examples/timeline.rb @@ -0,0 +1,72 @@ +# = Timeline API Examples +# require('rubygems') +# gem('twitter4r', '0.2.0') +# require('twitter') +# +# Only required if you want to use some configuration helper methods like +# Twitte4R::Client.from_config for sensitive/instance context. +# require 'twitter/console' +# +# config_file = File.join(File.dirname(__FILE__), '..', 'config', 'twitter.yml') +# +# Not configuring Twitter::Client for global features such as overriding: +# * protocol +# * host +# * port +# * user agent +# * proxy information +# Since the defaults are satisfactory, but if you need to, please refer to +# the {configure.rb}[file:configure_rb.html] example code. +# +# twitter = Twitter::Client.from_config(config_file) +# +# This returns the public timeline as an Array. +# +# We pass a block in to do something with each status returned inline. +# However, we still get to keep the public_timeline array after +# the method returns, for our application's safe keeping. +# +# It is not necessary to pass in a block to this method, so don't worry if +# you don't want to do that. All calls to Twitter::Client#timeline_for +# can pass in a block that works the same way as explained here. +# public_timeline = twitter.timeline_for(:public) do |status| +# puts status.user.screen_name, status.text +# end +# +# This returns the timeline for all your friends as an Array. +# See public timeline example above for discussion about passing in block, +# which is possible to all calls to Twitter::Client#timeline_for. +# all_friends_timeline = twitter.timeline_for(:friends) +# +# This returns the timeline for a particular friend. +# myfriend_timeline = twitter.timeline_for(:friend, :id => 'dictionary') +# +# This returns the timeline for a particular user (who may or may not be a friend). +# user_timeline = twitter.timeline_for(:user, :id => 'twitter4r') +# +# This returns the authenticated user's timeline +# +# We can also use the following code snippet, which is equivalent to the example below: +# my_timeline = twitter.my(:timeline) +# See Status API examples in status.rb file. +# my_timeline = twitter.timeline_for(:me) +# +# Below we demonstrate how to use more interesting parameters to the +# Twitter::Client#timeline_for method +# +# Returns all public statuses since the status id returned by: +# public_timeline.first.id +# latest_timeline = twitter.timeline_for(:public, :since_id => public_timeline.first.id) +# +# Returns all friend statuses in the last 24 hours: +# yesterday = Time.now - 60*60*24 +# new_friends_timeline = twitter.timeline_for(:friends, :since => yesterday) +# +# Returns last three statuses from user 'twitter4r': +# latest_twitter4r_timeline = twitter.timeline_for(:user, :id => 'twitter4', :count => 3) +# +# Returns timeline from user 'dictionary' since yesterday at this time, +# with block: +# new_dictionary_timeline = twitter.timeline_for(:user, :id => 'dictionary', :since => yesterday) do |status| +# puts status.text +# end diff --git a/examples/update.rb b/examples/update.rb deleted file mode 100644 index 5b703d2..0000000 --- a/examples/update.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'twitter' - - -client = Twitter::Client.new(:login => 'mylogin', :password => 'mypassword') -begin - client.update('Twitter4R is so cool') -rescue Twitter::RESTError => re - puts re -end diff --git a/examples/user.rb b/examples/user.rb new file mode 100644 index 0000000..eb0ac97 --- /dev/null +++ b/examples/user.rb @@ -0,0 +1,21 @@ +# = User API Examples +# require('rubygems') +# gem('twitter4r', '0.2.0') +# require('twitter') +# +# Only required if you want to use some configuration helper methods like +# Twitte4R::Client.from_config for sensitive/instance context. +# require 'twitter/console' +# config_file = File.join(File.dirname(__FILE__), '..', 'config', 'twitter.yml') +# +# Not configuring Twitter::Client for global features such as overriding: +# * protocol +# * host +# * port +# * user agent +# * proxy information +# Since the defaults are satisfactory, but if you need to, please refer to +# the {configure.rb}[file:configure_rb.html] example code. +# +# twitter = Twitter::Client.from_config(config_file) + -- 2.11.4.GIT