From 6a47e89c945f9e6e08fdbfb81aa2a13eae0d9944 Mon Sep 17 00:00:00 2001 From: zach Date: Thu, 17 Jul 2008 22:55:54 -0400 Subject: [PATCH] Twitter-compatible API - first crack at /statuses/followers.format darcs-hash:20080718025554-ca946-1e4b5aa5570c15f4e71df58c41d16f6ece1e359b.gz --- actions/twitapistatuses.php | 86 ++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index 5e0f29aaff..b8ee47eb0e 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -630,9 +630,93 @@ class TwitapistatusesAction extends TwitterapiAction { */ function followers($args, $apidata) { parent::handle($args); - common_server_error("API method under construction.", $code=501); + + $user = null; + + // function was called with an argument /statuses/user_timeline/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']; + } + + 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']; + } + + $profile = $user->getProfile(); + + if (!$profile) { + common_server_error(_('User has no profile.')); + return; + } + + if (!$page) { + $page = 1; + } + + $sub = new Subscription(); + $sub->subscribed = $profile->id; + $sub->orderBy('created DESC'); + + $followers = array(); + + if ($sub->find()) { + while ($sub->fetch()) { + + $other = null; + + if ($sub->token) { + $other = Remote_profile::staticGet('id', $sub->subscriber); + } else { + $other = User::staticGet('id', $sub->subscriber); + } + if (!$other) { + common_debug('Got a bad subscription: '.print_r($sub,TRUE)); + continue; + } + + $notice = DB_DataObject::factory('notice'); + $notice->whereAdd('profile_id = ' . $other->id); + $notice->orderBy('created DESC, notice.id DESC'); + $notice->limit(1); + $notice->find(); + + if ($notice->fetch()) { + $follower = array($other, $notice); + + } else { + $follower = array($other, ""); + } + + array_push($followers, $follower); + + } + } else { + // user has no followers + } + + foreach ($followers as $follower) { + // + } + + exit(); + } + + + /* Returns a list of the users currently featured on the site with their current statuses inline. URL: http://server/api/statuses/featured.format