class Twitter::Client
@@TIMELINE_URIS = {
:public => '/statuses/public_timeline.json',
:friends => '/statuses/friends_timeline.json',
:friend => '/statuses/friends_timeline.json',
:user => '/statuses/user_timeline.json',
:me => '/statuses/user_timeline.json',
}
# Provides access to Twitter's Timeline APIs
#
# Returns timeline for given type.
#
# type can take the following values:
# * public
# * friends or friend
# * user or me
#
# :id is on key applicable to be defined in options:
# * the id or screen name (aka login) for :friends
# * the id or screen name (aka login) for :user
# * meaningless for the :me case, since twitter.timeline_for(:user, 'mylogin') and twitter.timeline_for(:me) are the same assuming 'mylogin' is the authenticated user's screen name (aka login).
#
# Examples:
# # returns the public statuses since status with id of 6543210
# twitter.timeline_for(:public, id => 6543210)
# # returns the statuses for friend with user id 43210
# twitter.timeline_for(:friend, :id => 43210)
# # returns the statuses for friend with screen name (aka login) of 'otherlogin'
# twitter.timeline_for(:friend, :id => 'otherlogin')
# # returns the statuses for user with screen name (aka login) of 'otherlogin'
# twitter.timeline_for(:user, :id => 'otherlogin')
#
# options can also include the following keys:
# * :id is the user ID, screen name of Twitter::User representation of a Twitter user.
# * :since is a Time object specifying the date-time from which to return results for. Applicable for the :friend, :friends, :user and :me cases.
# * :count specifies the number of statuses to retrieve. Only applicable for the :user case.
# * since_id is the status id of the public timeline from which to retrieve statuses for :public. Only applicable for the :public case.
#
# You can also pass this method a block, which will iterate through the results
# of the requested timeline and apply the block logic for each status returned.
#
# Example:
# twitter.timeline_for(:public) do |status|
# puts status.user.screen_name, status.text
# end
#
# twitter.timeline_for(:friend, :id => 'myfriend', :since => 30.minutes.ago) do |status|
# puts status.user.screen_name, status.text
# end
#
# timeline = twitter.timeline_for(:me) do |status|
# puts status.text
# end
#
# An ArgumentError will be raised if an invalid type
# is given. Valid types are:
# * +:public+
# * +:friends+
# * +:friend+
# * +:user+
# * +:me+
def timeline_for(type, options = {}, &block)
raise ArgumentError, "Invalid timeline type: #{type}" unless @@TIMELINE_URIS.keys.member?(type)
uri = @@TIMELINE_URIS[type]
response = http_connect {|conn| create_http_get_request(uri, options) }
timeline = Twitter::Status.unmarshal(response.body)
timeline.each {|status| bless_model(status); yield status if block_given? }
timeline
end
end