class Twitter::Client
@@STATUS_URIS = {
:get => '/statuses/show.json',
:post => '/statuses/update.json',
:delete => '/statuses/destroy.json',
:reply => '/statuses/update.json'
}
# Provides access to individual statuses via Twitter's Status APIs
#
# action can be of the following values:
# * :get to retrieve status content. Assumes value given responds to :to_i message in meaningful way to yield intended status id.
# * :post to publish a new status
# * :delete to remove an existing status. Assumes value given responds to :to_i message in meaningful way to yield intended status id.
# * :reply to reply to an existing status. Assumes value given is Hash which contains :in_reply_to_status_id and :status
#
# value should be set to:
# * the status identifier for :get case
# * the status text message for :post case
# * none necessary for :delete case
#
# Examples:
# twitter.status(:get, 107786772)
# twitter.status(:post, "New Ruby open source project Twitter4R version 0.2.0 released.")
# twitter.status(:delete, 107790712)
#
# An ArgumentError will be raised if an invalid action
# is given. Valid actions are:
# * +:get+
# * +:post+
# * +:delete+
def status(action, value = nil)
return self.timeline_for(action, value || {}) if :replies == action
raise ArgumentError, "Invalid status action: #{action}" unless @@STATUS_URIS.keys.member?(action)
return nil unless value
uri = @@STATUS_URIS[action]
response = nil
case action
when :get
response = rest_oauth_connect(:get, uri, {:id => value.to_i})
when :post
response = rest_oauth_connect(:post, uri, :status => value, :source => self.class.config.source)
when :delete
response = rest_oauth_connect(:delete, uri, {:id => value.to_i})
when :reply
return nil if (!value.is_a?(Hash) || !value[:status] || !value[:in_reply_to_status_id])
params = value.merge(:source => self.class.config.source)
response = rest_oauth_connect(:post, uri, params)
end
bless_model(Twitter::Status.unmarshal(response.body))
end
end