Revert "Converted to use PEAR's HTTP_Request2, since, according to http://pear.php.net/package/HTTP_Request/ HTTP_Request has been superceded by Request2. "
This reverts commit fecdce4db3
.
There's no debian package for HTTP_Request2 and it's difficult to
install the package without updating a bunch of other stuff. I'm
making the executive decision that it's too new to switch over to this
version of the library; if I'm having these problems others will as
well. Tell me if you think I'm wrong and we can roll forward again.
This commit is contained in:
parent
8aa1876987
commit
b21689eb14
@ -19,7 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
include("Mail.php");
|
include("Mail.php");
|
||||||
include("Mail/mime.php");
|
include("Mail/mime.php");
|
||||||
include("HTTP/Request2.php");
|
include("HTTP/Request.php");
|
||||||
|
|
||||||
class Gallery3 {
|
class Gallery3 {
|
||||||
var $url;
|
var $url;
|
||||||
@ -170,32 +170,30 @@ class Gallery3 {
|
|||||||
|
|
||||||
class Gallery3_Helper {
|
class Gallery3_Helper {
|
||||||
static function request($method, $url, $token=null, $params=array(), $file=null) {
|
static function request($method, $url, $token=null, $params=array(), $file=null) {
|
||||||
$req = new HTTP_Request2($url);
|
$req = new HTTP_Request($url);
|
||||||
$req->setMethod($method == "get" ? 'GET' : 'POST');
|
$req->setMethod($method == "get" ? HTTP_REQUEST_METHOD_GET : HTTP_REQUEST_METHOD_POST);
|
||||||
$req->setHeader("X-Gallery-Request-Method", $method);
|
$req->addHeader("X-Gallery-Request-Method", $method);
|
||||||
if ($token) {
|
if ($token) {
|
||||||
$req->setHeader("X-Gallery-Request-Key", $token);
|
$req->addHeader("X-Gallery-Request-Key", $token);
|
||||||
}
|
}
|
||||||
foreach ($params as $key => $value) {
|
foreach ($params as $key => $value) {
|
||||||
// $req->addPostParameter($key, is_string($value) ? $value : json_encode($value));
|
$req->addPostData($key, is_string($value) ? $value : json_encode($value));
|
||||||
$req->addPostParameter($key, $value);
|
|
||||||
}
|
}
|
||||||
if ($file) {
|
if ($file) {
|
||||||
$req->addFile("file", $file, mime_content_type($file));
|
$req->addFile("file", $file, mime_content_type($file));
|
||||||
}
|
}
|
||||||
$response = $req->send();
|
$req->sendRequest();
|
||||||
$status = $response->getStatus();
|
|
||||||
|
|
||||||
switch ($status) {
|
switch ($req->getResponseCode()) {
|
||||||
case 200:
|
case 200:
|
||||||
case 201:
|
case 201:
|
||||||
return json_decode($response->getBody());
|
return json_decode($req->getResponseBody());
|
||||||
|
|
||||||
case 403:
|
case 403:
|
||||||
throw new Gallery3_Forbidden_Exception($response->getBody(),$status);
|
throw new Gallery3_Forbidden_Exception($req->getResponseBody());
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Gallery3_Exception($response->getBody(),$status);
|
throw new Gallery3_Exception($req->getResponseBody());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user