From 93ac0bcae3a600733045ad7a5bafabcdfd49d9e5 Mon Sep 17 00:00:00 2001 From: zach Date: Sun, 20 Jul 2008 04:34:28 -0400 Subject: Twitter-compatible API - refactoring and bug fixes darcs-hash:20080720083428-ca946-c14a92345366f2105b3c452a3899714d89692daa.gz --- actions/twitapiaccount.php | 2 +- actions/twitapifriendships.php | 21 ++++++++------------- actions/twitapihelp.php | 6 ++++-- actions/twitapistatuses.php | 23 +++++++++++------------ 4 files changed, 24 insertions(+), 28 deletions(-) (limited to 'actions') diff --git a/actions/twitapiaccount.php b/actions/twitapiaccount.php index 3a0fd8544..3a66e8885 100644 --- a/actions/twitapiaccount.php +++ b/actions/twitapiaccount.php @@ -51,7 +51,7 @@ class TwitapiaccountAction extends TwitterapiAction { if (!is_null($location) && strlen($location) > 255) { - // XXX: Twitter just truncates and runs with it. + // XXX: But Twitter just truncates and runs with it. -- Zach header('HTTP/1.1 406 Not Acceptable'); print "That's too long. Max notice size is 255 chars.\n"; exit(); diff --git a/actions/twitapifriendships.php b/actions/twitapifriendships.php index 90e890e35..19617a071 100644 --- a/actions/twitapifriendships.php +++ b/actions/twitapifriendships.php @@ -33,7 +33,6 @@ class TwitapifriendshipsAction extends TwitterapiAction { if (!$other) { $this->client_error(_('Could not follow user: User not found.'), 403, $apidata['content-type']); exit(); - return; } $user = $apidata['user']; @@ -41,7 +40,6 @@ class TwitapifriendshipsAction extends TwitterapiAction { if ($user->isSubscribed($other)) { $this->client_error("Could not follow user: $other->nickname is already on your list.", 403, $apidata['content-type']); exit(); - return; } $sub = new Subscription(); @@ -57,7 +55,6 @@ class TwitapifriendshipsAction extends TwitterapiAction { if (!$result) { $this->client_error("Could not follow user: $other->nickname.", 400, $apidata['content-type']); exit(); - return; } $sub->query('COMMIT'); @@ -66,7 +63,7 @@ class TwitapifriendshipsAction extends TwitterapiAction { $type = $apidata['content-type']; $this->init_document($type); - $this->show_profile($other); + $this->show_profile($other, $type); $this->end_document($type); exit(); } @@ -106,8 +103,8 @@ class TwitapifriendshipsAction extends TwitterapiAction { } $type = $apidata['content-type']; - $this->init_document($type); - $this->show_profile($other); + $this->init_document($type); + $this->show_profile($other, $type); $this->end_document($type); exit(); } @@ -135,10 +132,6 @@ class TwitapifriendshipsAction extends TwitterapiAction { $user_a = $this->get_profile($user_a_id); $user_b = $this->get_profile($user_b_id); - if($user_a) { print "got user a profile";} - if($user_b) { print "got user b profile";} - - if (!$user_a || !$user_b) { $this->client_error(_('Two user ids or screen_names must be supplied.'), 400, $apidata['content-type']); exit(); @@ -152,15 +145,17 @@ class TwitapifriendshipsAction extends TwitterapiAction { switch ($apidata['content-type']) { case 'xml': - common_start_xml(); + $this->init_document('xml'); common_element('friends', NULL, $result); - common_end_xml(); + $this->end_document('xml'); break; case 'json': + $this->init_document('json'); print json_encode($result); + $this->end_document('json'); break; default: - print $result; + print $result; // Really? --Zach break; } diff --git a/actions/twitapihelp.php b/actions/twitapihelp.php index 5a35d8442..9701913f1 100644 --- a/actions/twitapihelp.php +++ b/actions/twitapihelp.php @@ -30,13 +30,15 @@ class TwitapihelpAction extends TwitterapiAction { function test($args, $apidata) { global $xw; if ($apidata['content-type'] == 'xml') { - header('Content-Type: application/xml; charset=utf-8'); + $this->init_document('xml'); common_start_xml(); common_element('ok', NULL, 'true'); common_end_xml(); + $this->end_document('xml'); } elseif ($apidata['content-type'] == 'json') { - header('Content-Type: application/json; charset=utf-8'); + $this->init_document('json'); print '"ok"'; + $this->end_document('json'); } else { common_user_error("API method not found!", $code=404); } diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index d770d6ff3..670aaebf0 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -80,8 +80,7 @@ class TwitapistatusesAction extends TwitterapiAction { function show_xml_timeline($notice) { - header('Content-Type: application/xml; charset=utf-8'); - common_start_xml(); + $this->init_document('xml'); common_element_start('statuses', array('type' => 'array')); if (is_array($notice)) { @@ -97,14 +96,12 @@ class TwitapistatusesAction extends TwitterapiAction { } common_element_end('statuses'); - common_end_xml(); + $this->end_document('xml'); } function show_rss_timeline($notice, $title, $id, $link, $subtitle) { - header("Content-Type: application/rss+xml; charset=utf-8"); - - $this->init_twitter_rss(); + $this->init_document('rss'); common_element_start('channel'); common_element('title', NULL, $title); @@ -127,14 +124,12 @@ class TwitapistatusesAction extends TwitterapiAction { } common_element_end('channel'); - $this->end_twitter_rss(); + $this->end_twitter_rss(); } function show_atom_timeline($notice, $title, $id, $link, $subtitle=NULL) { - header('Content-Type: application/atom+xml; charset=utf-8'); - - $this->init_twitter_atom(); + $this->init_document('atom'); common_element('title', NULL, $title); common_element('id', NULL, $id); @@ -153,12 +148,13 @@ class TwitapistatusesAction extends TwitterapiAction { } } - $this->end_twitter_atom(); + $this->end_document('atom'); + } function show_json_timeline($notice) { - header('Content-Type: application/json; charset=utf-8'); + $this->init_document('json'); $statuses = array(); @@ -175,6 +171,8 @@ class TwitapistatusesAction extends TwitterapiAction { } $this->show_twitter_json_statuses($statuses); + + $this->end_document('json'); } /* @@ -449,6 +447,7 @@ class TwitapistatusesAction extends TwitterapiAction { ID. Ex: http://server/api/statuses/replies.xml?since_id=12345 */ function replies($args, $apidata) { + parent::handle($args); $since = $this->arg('since'); -- cgit v1.2.3-54-g00ecf