Twitter-API: /statuses/replies.format now works (mostly)

darcs-hash:20080717222845-ca946-f2644317a144157aaba7a38d4effb216a9c5f650.gz
This commit is contained in:
zach 2008-07-17 18:28:45 -04:00
parent 8ad7dded2c
commit c1d109dbb5
2 changed files with 121 additions and 19 deletions

View File

@ -84,9 +84,16 @@ class TwitapistatusesAction extends TwitterapiAction {
common_start_xml(); common_start_xml();
common_element_start('statuses', array('type' => 'array')); common_element_start('statuses', array('type' => 'array'));
while ($notice->fetch()) { if (is_array($notice)) {
$twitter_status = $this->twitter_status_array($notice); foreach ($notice as $n) {
$this->show_twitter_xml_status($twitter_status); $twitter_status = $this->twitter_status_array($n);
$this->show_twitter_xml_status($twitter_status);
}
} else {
while ($notice->fetch()) {
$twitter_status = $this->twitter_status_array($notice);
$this->show_twitter_xml_status($twitter_status);
}
} }
common_element_end('statuses'); common_element_end('statuses');
@ -106,9 +113,17 @@ class TwitapistatusesAction extends TwitterapiAction {
common_element('language', NULL, 'en-us'); common_element('language', NULL, 'en-us');
common_element('ttl', NULL, '40'); common_element('ttl', NULL, '40');
while ($notice->fetch()) {
$entry = $this->twitter_rss_entry_array($notice); if (is_array($notice)) {
$this->show_twitter_rss_item($entry); foreach ($notice as $n) {
$entry = $this->twitter_rss_entry_array($n);
$this->show_twitter_rss_item($entry);
}
} else {
while ($notice->fetch()) {
$entry = $this->twitter_rss_entry_array($notice);
$this->show_twitter_rss_item($entry);
}
} }
common_element_end('channel'); common_element_end('channel');
@ -126,9 +141,16 @@ class TwitapistatusesAction extends TwitterapiAction {
common_element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), NULL); common_element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), NULL);
common_element('subtitle', NULL, $subtitle); common_element('subtitle', NULL, $subtitle);
while ($notice->fetch()) { if (is_array($notice)) {
$entry = $this->twitter_rss_entry_array($notice); foreach ($notice as $n) {
$this->show_twitter_atom_entry($entry); $entry = $this->twitter_rss_entry_array($n);
$this->show_twitter_atom_entry($entry);
}
} else {
while ($notice->fetch()) {
$entry = $this->twitter_rss_entry_array($notice);
$this->show_twitter_atom_entry($entry);
}
} }
$this->end_twitter_atom(); $this->end_twitter_atom();
@ -140,9 +162,16 @@ class TwitapistatusesAction extends TwitterapiAction {
$statuses = array(); $statuses = array();
while ($notice->fetch()) { if (is_array($notice)) {
$twitter_status = $this->twitter_status_array($notice); foreach ($notice as $n) {
array_push($statuses, $twitter_status); $twitter_status = $this->twitter_status_array($n);
array_push($statuses, $twitter_status);
}
} else {
while ($notice->fetch()) {
$twitter_status = $this->twitter_status_array($notice);
array_push($statuses, $twitter_status);
}
} }
$this->show_twitter_json_statuses($statuses); $this->show_twitter_json_statuses($statuses);
@ -437,10 +466,83 @@ class TwitapistatusesAction extends TwitterapiAction {
*/ */
function replies($args, $apidata) { function replies($args, $apidata) {
parent::handle($args); parent::handle($args);
common_server_error("API method under construction.", $code=501);
$since = $this->arg('since');
$count = $this->arg('count');
$page = $this->arg('page');
$user = $apidata['user'];
$profile = $user->getProfile();
$sitename = common_config('site', 'name');
$siteserver = common_config('site', 'server');
$title = sprintf(_("%s / Updates replying to %s"), $sitename, $user->nickname);
$id = "tag:$siteserver:replies:".$user->id;
$link = common_local_url('replies', array('nickname' => $user->nickname));
$subtitle = "gar";
$subtitle = sprintf(_("%s updates that reply to updates from %s / %."), $sitename, $user->nickname, $user->nickname);
if (!$page) {
$page = 1;
}
if (!$count) {
$count = 20;
}
$reply = new Reply();
$reply->profile_id = $user->id;
$reply->orderBy('modified DESC');
$page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
$reply->limit((($page-1)*20), $count);
$cnt = $reply->find();
$notices = array();
if ($cnt) {
while ($reply->fetch()) {
$notice = new Notice();
$notice->id = $reply->notice_id;
$result = $notice->find(true);
if (!$result) {
continue;
}
$notices[] = clone($notice);
}
}
switch($apidata['content-type']) {
case 'xml':
$this->show_xml_timeline($notices);
break;
case 'rss':
$this->show_rss_timeline($notices, $title, $id, $link, $subtitle);
break;
case 'atom':
$this->show_atom_timeline($notices, $title, $id, $link, $subtitle);
break;
case 'json':
$this->show_json_timeline($notices);
break;
default:
common_user_error("API method not found!", $code = 404);
}
exit();
} }
/* /*
Destroys the status specified by the required ID parameter. The authenticating user must be Destroys the status specified by the required ID parameter. The authenticating user must be
the author of the specified status. the author of the specified status.

View File

@ -63,7 +63,7 @@ RewriteRule ^api/statuses/friends_timeline(.*)$ index.php?action=api&apiaction=s
RewriteRule ^api/statuses/user_timeline(.*)$ index.php?action=api&apiaction=statuses&method=user_timeline$1 [L,QSA] RewriteRule ^api/statuses/user_timeline(.*)$ index.php?action=api&apiaction=statuses&method=user_timeline$1 [L,QSA]
RewriteRule ^api/statuses/show/(.*)$ index.php?action=api&apiaction=statuses&method=show&argument=$1 [L,QSA] RewriteRule ^api/statuses/show/(.*)$ index.php?action=api&apiaction=statuses&method=show&argument=$1 [L,QSA]
RewriteRule ^api/statuses/update(.*)$ index.php?action=api&apiaction=statuses&method=update$1 [L,QSA] RewriteRule ^api/statuses/update(.*)$ index.php?action=api&apiaction=statuses&method=update$1 [L,QSA]
RewriteRule ^api/statuses/replies/(.*)$ index.php?action=api&apiaction=statuses&method=replies&argument=$1 [L,QSA] RewriteRule ^api/statuses/replies(.*)$ index.php?action=api&apiaction=statuses&method=replies&argument=$1 [L,QSA]
RewriteRule ^api/statuses/destroy/(.*)$ index.php?action=api&apiaction=statuses&method=destroy&argument=$1 [L,QSA] RewriteRule ^api/statuses/destroy/(.*)$ index.php?action=api&apiaction=statuses&method=destroy&argument=$1 [L,QSA]
RewriteRule ^api/statuses/friends(.*)$ index.php?action=api&apiaction=statuses&method=friends$1 [L,QSA] RewriteRule ^api/statuses/friends(.*)$ index.php?action=api&apiaction=statuses&method=friends$1 [L,QSA]
RewriteRule ^api/statuses/followers(.*)$ index.php?action=api&apiaction=statuses&method=followers$1 [L,QSA] RewriteRule ^api/statuses/followers(.*)$ index.php?action=api&apiaction=statuses&method=followers$1 [L,QSA]