]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Added a quickGet in HTTPClient
authorMikael Nordfeldth <mmn@hethane.se>
Thu, 22 Jan 2015 11:16:01 +0000 (12:16 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Thu, 22 Jan 2015 11:16:01 +0000 (12:16 +0100)
lib/httpclient.php

index c7abe121166b7aaa72578c382048876f3ea29d5f..960cd400f4247284cfd3199c5858af8fe865d6e9 100644 (file)
@@ -170,6 +170,21 @@ class HTTPClient extends HTTP_Request2
         return new HTTPClient();
     }
 
+    /**
+     * Quick static function to GET a URL
+     */
+    public static function quickGet($url, $accept='text/html,application/xhtml+xml')
+    {
+        $client = new HTTPClient();
+        $client->setHeader('Accept', $accept);
+        $response = $client->get($url);
+        if (!$response->isOk()) {
+            // TRANS: Exception. %s is a profile URL.
+            throw new Exception(sprintf(_m('Could not GET URL %s.'), $url), $response->getStatus());
+        }
+        return $response->getBody();
+    }
+
     /**
      * Convenience function to run a GET request.
      *