Ticket #1108 - Added 'social graph' methods to the API

This commit is contained in:
Zach Copley 2009-02-22 20:04:47 -08:00
parent 5e646ead49
commit cab322d21b
2 changed files with 74 additions and 7 deletions

View File

@ -470,19 +470,28 @@ class TwitapistatusesAction extends TwitterapiAction
return $this->subscriptions($apidata, 'subscribed', 'subscriber'); return $this->subscriptions($apidata, 'subscribed', 'subscriber');
} }
function friendsIDs($args, $apidata)
{
parent::handle($args);
return $this->subscriptions($apidata, 'subscribed', 'subscriber', true);
}
function followers($args, $apidata) function followers($args, $apidata)
{ {
parent::handle($args); parent::handle($args);
return $this->subscriptions($apidata, 'subscriber', 'subscribed'); return $this->subscriptions($apidata, 'subscriber', 'subscribed');
} }
function subscriptions($apidata, $other_attr, $user_attr) function followersIDs($args, $apidata)
{
parent::handle($args);
return $this->subscriptions($apidata, 'subscriber', 'subscribed', true);
}
function subscriptions($apidata, $other_attr, $user_attr, $onlyIDs=false)
{ {
# XXX: lite $this->auth_user = $apidata['user'];
$this->auth_user = $apidate['user'];
$user = $this->get_user($apidata['api_arg'], $apidata); $user = $this->get_user($apidata['api_arg'], $apidata);
if (!$user) { if (!$user) {
@ -514,7 +523,10 @@ class TwitapistatusesAction extends TwitterapiAction
} }
$sub->orderBy('created DESC'); $sub->orderBy('created DESC');
$sub->limit(($page-1)*100, 100);
if (!$onlyIDs) {
$sub->limit(($page-1)*100, 100);
}
$others = array(); $others = array();
@ -529,7 +541,13 @@ class TwitapistatusesAction extends TwitterapiAction
$type = $apidata['content-type']; $type = $apidata['content-type'];
$this->init_document($type); $this->init_document($type);
$this->show_profiles($others, $type);
if ($onlyIDs) {
$this->showIDs($others, $type);
} else {
$this->show_profiles($others, $type);
}
$this->end_document($type); $this->end_document($type);
} }
@ -555,6 +573,28 @@ class TwitapistatusesAction extends TwitterapiAction
} }
} }
function showIDs($profiles, $type)
{
switch ($type) {
case 'xml':
$this->elementStart('ids');
foreach ($profiles as $profile) {
$this->element('id', null, $profile->id);
}
$this->elementEnd('ids');
break;
case 'json':
$ids = array();
foreach ($profiles as $profile) {
$ids[] = (int)$profile->id;
}
print json_encode($ids);
break;
default:
$this->clientError(_('unsupported file type'));
}
}
function featured($args, $apidata) function featured($args, $apidata)
{ {
parent::handle($args); parent::handle($args);

View File

@ -265,6 +265,33 @@ class Router
'apiaction' => 'friendships'), 'apiaction' => 'friendships'),
array('method' => 'exists(\.(xml|json|rss|atom))')); array('method' => 'exists(\.(xml|json|rss|atom))'));
// Social graph
$m->connect('api/friends/ids/:argument',
array('action' => 'api',
'apiaction' => 'statuses',
'method' => 'friendsIDs'));
foreach (array('xml', 'json') as $e) {
$m->connect('api/friends/ids.'.$e,
array('action' => 'api',
'apiaction' => 'statuses',
'method' => 'friendsIDs.'.$e));
}
$m->connect('api/followers/ids/:argument',
array('action' => 'api',
'apiaction' => 'statuses',
'method' => 'followersIDs'));
foreach (array('xml', 'json') as $e) {
$m->connect('api/followers/ids.'.$e,
array('action' => 'api',
'apiaction' => 'statuses',
'method' => 'followersIDs.'.$e));
}
// account // account
$m->connect('api/account/:method', $m->connect('api/account/:method',