summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzach <zach@copley.name>2008-07-17 22:55:54 -0400
committerzach <zach@copley.name>2008-07-17 22:55:54 -0400
commit6a47e89c945f9e6e08fdbfb81aa2a13eae0d9944 (patch)
tree0a59e6acd36543804fc31160abb9aaa00ac689b8
parent6125785064c3a3aafb4ed91c408cb45d90a0d9a6 (diff)
Twitter-compatible API - first crack at /statuses/followers.format
darcs-hash:20080718025554-ca946-1e4b5aa5570c15f4e71df58c41d16f6ece1e359b.gz
-rw-r--r--actions/twitapistatuses.php86
1 files changed, 85 insertions, 1 deletions
diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php
index 5e0f29aaf..b8ee47eb0 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