Twitter-compatible API - first crack at /statuses/followers.format

darcs-hash:20080718025554-ca946-1e4b5aa5570c15f4e71df58c41d16f6ece1e359b.gz
This commit is contained in:
zach 2008-07-17 22:55:54 -04:00
parent 6125785064
commit 6a47e89c94

View File

@ -630,9 +630,93 @@ class TwitapistatusesAction extends TwitterapiAction {
*/ */
function followers($args, $apidata) { function followers($args, $apidata) {
parent::handle($args); 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. Returns a list of the users currently featured on the site with their current statuses inline.
URL: http://server/api/statuses/featured.format URL: http://server/api/statuses/featured.format