From 8977032e112ee09c8c95a838b46dbb14f5aee0be Mon Sep 17 00:00:00 2001 From: zach Date: Wed, 16 Jul 2008 02:09:22 -0400 Subject: Twitter-compatible API: public_timeline.json now works darcs-hash:20080716060922-ca946-6e973c6fb40ab8c8c930b6dfd916e20f40545471.gz --- actions/twitapistatuses.php | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'actions/twitapistatuses.php') diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index bb30049ee..83fd4b53c 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -38,16 +38,17 @@ class TwitapistatusesAction extends TwitterapiAction { function public_timeline($args, $apidata) { parent::handle($args); - if ($apidata['content-type'] == 'xml') { - header('Content-Type: application/xml; charset=utf-8'); - $notice = DB_DataObject::factory('notice'); + $notice = DB_DataObject::factory('notice'); - # FIXME: bad performance - $notice->whereAdd('EXISTS (SELECT user.id from user where user.id = notice.profile_id)'); - $notice->orderBy('created DESC, notice.id DESC'); - $notice->limit(20); - $cnt = $notice->find(); + # FIXME: bad performance + $notice->whereAdd('EXISTS (SELECT user.id from user where user.id = notice.profile_id)'); + $notice->orderBy('created DESC, notice.id DESC'); + $notice->limit(20); + $cnt = $notice->find(); + if ($apidata['content-type'] == 'xml') { + header('Content-Type: application/xml; charset=utf-8'); + common_start_xml(); // XXX: To really live up to the spec we need to build a list @@ -72,7 +73,23 @@ class TwitapistatusesAction extends TwitterapiAction { } elseif ($apidata['content-type'] == 'atom') { common_server_error("API method under construction.", $code=501); } elseif ($apidata['content-type'] == 'json') { - common_server_error("API method under construction.", $code=501); + + header('Content-Type: application/json; charset=utf-8'); + + $statuses = array(); + + if ($cnt > 0) { + for ($i = 0; $i < 20; $i++) { + if ($notice->fetch()) { + $twitter_status = $this->twitter_status_array($notice); + array_push($statuses, $twitter_status); + } else { + // shouldn't happen! + break; + } + } + } + $this->render_twitter_json_statuses($statuses); } exit(); -- cgit v1.2.3-54-g00ecf