From 8bab642cc7d15c6ea8bd7ecb2b597dfd874c4884 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Mon, 30 Nov 2015 02:05:06 +0100 Subject: [PATCH] quickGetJson for HTTP requests to return json objects --- lib/httpclient.php | 10 ++++++++++ 1 file changed, 10 insertions(+) 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. * -- 2.39.2