From b2f0ad1cccc4bebbf264c4ab61a37173c9a565cc Mon Sep 17 00:00:00 2001 From: zach Date: Thu, 16 Oct 2008 22:36:38 -0400 Subject: Twitter-compatible API: - Filled in favorites tags in statuses - Filled in more tags in user/show, including undocumented features - Better error handling and more consistent error messages - Code clean-up and refactoring - Removed huge obnoxious comments darcs-hash:20081017023638-462f3-27b5d2709e423c616723d4bcfbc9d7d30a4ad161.gz --- actions/twitapifavorites.php | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) (limited to 'actions/twitapifavorites.php') diff --git a/actions/twitapifavorites.php b/actions/twitapifavorites.php index a327cddb4..2c6c2e1d9 100644 --- a/actions/twitapifavorites.php +++ b/actions/twitapifavorites.php @@ -39,27 +39,12 @@ class TwitapifavoritesAction extends TwitterapiAction { function favorites($args, $apidata) { parent::handle($args); - $user = null; - - // function was called with an argument /favorites/api_arg.format - if (isset($apidata['api_arg'])) { - - if (is_numeric($apidata['api_arg'])) { - $user = User::staticGet($apidata['api_arg']); - } else { - $nickname = common_canonical_nickname($apidata['api_arg']); - $user = User::staticGet('nickname', $nickname); - } - } else { - - // if no user was specified, then we'll use the authenticated user - $user = $apidata['user']; - } + $this->auth_user = $apidata['user']; + $user = $this->get_user($apidata['api_arg'], $apidata); if (!$user) { - // Set the user to be the auth user if asked-for can't be found - // honestly! This is what Twitter does, I swear --Zach - $user = $apidata['user']; + $this->client_error('Not Found', 404, $apidata['content-type']); + return; } $profile = $user->getProfile(); @@ -116,11 +101,6 @@ class TwitapifavoritesAction extends TwitterapiAction { function create($args, $apidata) { parent::handle($args); - if (!in_array($apidata['content-type'], array('xml', 'json'))) { - common_user_error(_('API method not found!'), $code = 404); - return; - } - // Check for RESTfulness if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) { // XXX: Twitter just prints the err msg, no XML / JSON. @@ -128,7 +108,13 @@ class TwitapifavoritesAction extends TwitterapiAction { return; } - $user = $apidata['user']; + if (!in_array($apidata['content-type'], array('xml', 'json'))) { + common_user_error(_('API method not found!'), $code = 404); + return; + } + + $this->auth_user = $apidata['user']; + $user = $this->auth_user; $notice_id = $apidata['api_arg']; $notice = Notice::staticGet($notice_id); -- cgit v1.2.3-54-g00ecf