]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
quickGetJson for HTTP requests to return json objects
authorMikael Nordfeldth <mmn@hethane.se>
Mon, 30 Nov 2015 01:05:06 +0000 (02:05 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Mon, 30 Nov 2015 01:05:06 +0000 (02:05 +0100)
lib/httpclient.php

index bc513e71d03359b893a95b75cb044b98ab332a7e..4b854914c929ac0dd54d3f7787fc4556e5e90050 100644 (file)
@@ -200,6 +200,16 @@ class HTTPClient extends HTTP_Request2
         return $response->getBody();
     }
 
+    public static function quickGetJson($url, $params=array())
+    {
+        $data = json_decode(self::quickGet($url, null, $params));
+        if (is_null($data)) {
+            common_debug('Could not decode JSON data from URL: '.$url);
+            throw new ServerException('Could not decode JSON data from URL');
+        }
+        return $data;
+    }
+
     /**
      * Convenience function to run a GET request.
      *