]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Twitter-compatible API - Added content-type checks to several methods. Calling an API
authorzach <zach@controlyourself.ca>
Wed, 1 Oct 2008 02:09:59 +0000 (22:09 -0400)
committerzach <zach@controlyourself.ca>
Wed, 1 Oct 2008 02:09:59 +0000 (22:09 -0400)
method with a bad content type used to return a blank page.

darcs-hash:20081001020959-462f3-83b0241ba7dc99c4e3a52148a46deb8182e005b0.gz

actions/twitapiaccount.php
actions/twitapidirect_messages.php
actions/twitapifavorites.php
actions/twitapifriendships.php
actions/twitapihelp.php
actions/twitapistatuses.php
actions/twitapiusers.php

index 3a9b8ba3e2f60db4abc96211c6b6821dc3233a20..5baf0e3e39dc591c834596f7ccefc0898c2cefee 100644 (file)
@@ -61,6 +61,11 @@ class TwitapiaccountAction extends TwitterapiAction {
        function update_location($args, $apidata) {
                parent::handle($args);
 
+               if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+                       common_user_error(_('API method not found!'), $code = 404);
+                       exit;
+               }
+
                if ($_SERVER['REQUEST_METHOD'] != 'POST') {
                        $this->client_error(_('This method requires a POST.'), 400, $apidata['content-type']);
                        exit();
index fcdf822e0465d814fe9d2c3a89bec64e7a1d6ec0..1ef543f814d3dad5961a349cf4b0d26d74c98a0e 100644 (file)
@@ -133,8 +133,6 @@ class Twitapidirect_messagesAction extends TwitterapiAction {
                        exit();
                }
 
-               common_debug($this->trimmed('user'));
-
                $other = $this->get_user($this->trimmed('user'));
 
                if (!$other) {
index 932ee79337fb9eead3aed1ea38f026d62be88a39..d7d77907dd0efe4248386b147d1340fe9af00b49 100644 (file)
@@ -117,6 +117,11 @@ class TwitapifavoritesAction extends TwitterapiAction {
        function create($args, $apidata) {
                parent::handle($args);
 
+               if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+                       common_user_error(_('API method not found!'), $code = 404);
+                       exit;
+               }
+
                // Check for RESTfulness
                if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
                        // XXX: Twitter just prints the err msg, no XML / JSON.
index d97b7c08eab7048aab5e61ec17b21e513003c64d..f9ff251d67f2a995c589ff4d2a1ff01accb68221 100644 (file)
@@ -152,6 +152,11 @@ class TwitapifriendshipsAction extends TwitterapiAction {
        function exists($args, $apidata) {
                parent::handle($args);
 
+               if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+                       common_user_error(_('API method not found!'), $code = 404);
+                       exit;
+               }
+
                $user_a_id = $this->trimmed('user_a');
                $user_b_id = $this->trimmed('user_b');
 
@@ -181,7 +186,6 @@ class TwitapifriendshipsAction extends TwitterapiAction {
                        $this->end_document('json');
                        break;
                 default:
-                       print $result;  // Really? --Zach
                        break;
                }
 
index 2ac4178de8d8ae4a83b634032433acbf0e52fc8c..d2439484c1746e1be54b23ab5da1e2278dc01403 100644 (file)
@@ -23,7 +23,7 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
 
 class TwitapihelpAction extends TwitterapiAction {
 
-       function is_readonly() {                
+       function is_readonly() {
                return true;
        }
 
@@ -32,7 +32,8 @@ class TwitapihelpAction extends TwitterapiAction {
         * Formats: xml, json
         */
        function test($args, $apidata) {
-               global $xw;
+               parent::handle($args);
+
                if ($apidata['content-type'] == 'xml') {
                        $this->init_document('xml');
                        common_element('ok', NULL, 'true');
@@ -52,5 +53,5 @@ class TwitapihelpAction extends TwitterapiAction {
                common_server_error(_('API method under construction.'), $code=501);
                exit();
        }
-       
+
 }
\ No newline at end of file
index 3271f1e2898ae56cfc4389835f594eec2845b08a..ed6c224fa5dad747c39534bee66beab6c0ee3e5b 100644 (file)
@@ -297,6 +297,11 @@ class TwitapistatusesAction extends TwitterapiAction {
 
                parent::handle($args);
 
+               if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+                       common_user_error(_('API method not found!'), $code = 404);
+                       exit;
+               }
+
                if ($_SERVER['REQUEST_METHOD'] != 'POST') {
                        $this->client_error(_('This method requires a POST.'), 400, $apidata['content-type']);
                        exit();
@@ -448,6 +453,11 @@ class TwitapistatusesAction extends TwitterapiAction {
        function show($args, $apidata) {
                parent::handle($args);
 
+               if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+                       common_user_error(_('API method not found!'), $code = 404);
+                       exit;
+               }
+
                $notice_id = $apidata['api_arg'];
                $notice = Notice::staticGet($notice_id);
 
@@ -485,6 +495,11 @@ class TwitapistatusesAction extends TwitterapiAction {
 
                parent::handle($args);
 
+               if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+                       common_user_error(_('API method not found!'), $code = 404);
+                       exit;
+               }
+
                // Check for RESTfulness
                if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
                        // XXX: Twitter just prints the err msg, no XML / JSON.
index cb682695a1ffd0827c9753c8a94e0bb0e24bc32c..b43a64152014067d22e342d26a30b80ac248f0d5 100644 (file)
@@ -51,6 +51,11 @@ class TwitapiusersAction extends TwitterapiAction {
        function show($args, $apidata) {
                parent::handle($args);
                
+               if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+                       common_user_error(_('API method not found!'), $code = 404);
+                       exit;
+               }
+               
                $user = null;
                $email = $this->arg('email');
                
@@ -118,9 +123,7 @@ class TwitapiusersAction extends TwitterapiAction {
                        $this->init_document('json');
                        $this->show_json_objects($twitter_user);
                        $this->end_document('json');
-               } else {
-                       common_user_error(_('API method not found!'), $code = 404);
-               }
+               } 
                        
                exit();
        }