From: Mikael Nordfeldth Date: Mon, 30 Nov 2015 01:05:06 +0000 (+0100) Subject: quickGetJson for HTTP requests to return json objects X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8bab642cc7d15c6ea8bd7ecb2b597dfd874c4884;p=quix0rs-gnu-social.git quickGetJson for HTTP requests to return json objects --- diff --git a/lib/httpclient.php b/lib/httpclient.php index bc513e71d0..4b854914c9 100644 --- a/lib/httpclient.php +++ b/lib/httpclient.php @@ -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. *