From 6d3dfc648b25b0c123ac53a2032da69edf0a00f7 Mon Sep 17 00:00:00 2001 From: thefosk Date: Tue, 23 Apr 2013 14:20:02 -0700 Subject: [PATCH] renaming to unirest --- lib/{Unicorn.php => Unirest.php} | 38 +++++++------------------------- 1 file changed, 8 insertions(+), 30 deletions(-) rename lib/{Unicorn.php => Unirest.php} (78%) diff --git a/lib/Unicorn.php b/lib/Unirest.php similarity index 78% rename from lib/Unicorn.php rename to lib/Unirest.php index 6de0f3a..864a8e6 100644 --- a/lib/Unicorn.php +++ b/lib/Unirest.php @@ -28,48 +28,26 @@ require_once(dirname(__FILE__) . "/Chunked.php"); require_once(dirname(__FILE__) . "/HttpResponse.php"); require_once(dirname(__FILE__) . "/HttpMethod.php"); -class Unicorn { - - // Use it like: Unicorn::getCallbackFunction(func_get_args()); - /* - private static function getCallbackFunction($arg_list) { - $argCount = count($arg_list); - if ($argCount > 1) { - $lastArgument = $arg_list[$argCount - 1]; - if (is_callable($lastArgument)) { - return $lastArgument; - } - } - return NULL; - } - - private static function doAsync($operation, $callback) { - require_once(dirname(__FILE__) . "/Thread.php"); - $id = ThreadStore::add(Unicorn::random(), $operation, $callback); - $thread = new UnicornThread($id); - $thread->start(); - return $thread; - } - */ +class Unirest { public static function get($url, $headers = array()) { - return Unicorn::request(HttpMethod::GET, $url, NULL, $headers); + return Unirest::request(HttpMethod::GET, $url, NULL, $headers); } public static function post($url, $headers = array(), $body = NULL) { - return Unicorn::request(HttpMethod::POST, $url, $body, $headers); + return Unirest::request(HttpMethod::POST, $url, $body, $headers); } public static function delete($url, $headers = array()) { - return Unicorn::request(HttpMethod::DELETE, $url, NULL, $headers); + return Unirest::request(HttpMethod::DELETE, $url, NULL, $headers); } public static function put($url, $headers = array(), $body = NULL) { - return Unicorn::request(HttpMethod::PUT, $url, $body, $headers); + return Unirest::request(HttpMethod::PUT, $url, $body, $headers); } public static function patch($url, $headers = array(), $body = NULL) { - return Unicorn::request(HttpMethod::PATCH, $url, $body, $headers); + return Unirest::request(HttpMethod::PATCH, $url, $body, $headers); } private static function request($httpMethod, $url, $body = NULL, $headers = array()) { @@ -79,7 +57,7 @@ class Unicorn { if ($key == "user-agent" || key == "expect") continue; $lowercaseHeaders[] = $key . ": " . $val; } - $lowercaseHeaders[] = "user-agent: unicorn-php/1.0"; + $lowercaseHeaders[] = "user-agent: unirest-php/1.0"; $lowercaseHeaders[] = "expect:"; $ch = curl_init(); @@ -88,7 +66,7 @@ class Unicorn { curl_setopt ($ch, CURLOPT_POSTFIELDS, $body); } - curl_setopt ($ch, CURLOPT_URL , Unicorn::encodeUrl($url)); + curl_setopt ($ch, CURLOPT_URL , Unirest::encodeUrl($url)); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt ($ch, CURLOPT_MAXREDIRS, 10);