diff options
author | zach <zach@copley.name> | 2008-07-16 02:09:22 -0400 |
---|---|---|
committer | zach <zach@copley.name> | 2008-07-16 02:09:22 -0400 |
commit | 8977032e112ee09c8c95a838b46dbb14f5aee0be (patch) | |
tree | 669258a6026fe7adcece20c64b70c9ac240e6c16 /actions | |
parent | 110ce8c811fb6f48e17b5bd78eaa0741a26e55a5 (diff) |
Twitter-compatible API: public_timeline.json now works
darcs-hash:20080716060922-ca946-6e973c6fb40ab8c8c930b6dfd916e20f40545471.gz
Diffstat (limited to 'actions')
-rw-r--r-- | actions/twitapistatuses.php | 35 |
1 files changed, 26 insertions, 9 deletions
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(); |