|
@@ -82,7 +82,7 @@ class HTTPUnexpectedResponse extends \Exception {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-class NotAutorizedException extends \Exception{}
|
|
|
+class NotAuthorizedException extends \Exception{}
|
|
|
|
|
|
trait Curl {
|
|
|
protected $url;
|
|
@@ -93,13 +93,7 @@ trait Curl {
|
|
|
protected $max_redirects = 4;
|
|
|
|
|
|
protected function method(&$req, $scope, $params, $post, $ret) {
|
|
|
- echo sprintf(
|
|
|
- "URL: %s{%s} Token: %s\n",
|
|
|
- $this->url,
|
|
|
- $scope,
|
|
|
- $this->token
|
|
|
- );
|
|
|
-
|
|
|
+ echo sprintf("%s: %s%s\n", $post ? "POST" : "GET", $this->url, $scope);
|
|
|
$c = curl_init();
|
|
|
|
|
|
if (!$c) {
|
|
@@ -131,18 +125,14 @@ trait Curl {
|
|
|
}
|
|
|
|
|
|
protected function authorized($scope) {
|
|
|
- if ($this->test($scope, 401)) {
|
|
|
- throw new NotAutorizedException("Not authorized", 401);
|
|
|
+ $ret = "";
|
|
|
+ if ($this->method($ret, $scope, array(), false, false) == 401) {
|
|
|
+ throw new NotAuthorizedException("Not authorized", 401);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- protected function test($scope, $code = 200) {
|
|
|
- $req = "";
|
|
|
- return $this->method($ret, $scope, array(), false, false) == $code;
|
|
|
- }
|
|
|
-
|
|
|
- private function post($scope, $params) {
|
|
|
+ private function post($scope = "", $params = array()) {
|
|
|
$req = "";
|
|
|
|
|
|
$code = $this->method($req, $scope, $params, true, true);
|
|
@@ -150,12 +140,14 @@ trait Curl {
|
|
|
switch ($code) {
|
|
|
case 200:
|
|
|
return $req;
|
|
|
+ case 401:
|
|
|
+ throw new NotAuthorizedException(HTTPUnexpectedResponse::$ecode[401], 401);
|
|
|
default:
|
|
|
throw new HTTPUnexpectedResponse(HTTPUnexpectedResponse::$ecode[$code], $code);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private function get($scope, $params) {
|
|
|
+ private function get($scope = "", $params = array()) {
|
|
|
$req = "";
|
|
|
|
|
|
$code = $this->method($req, $scope, $params, false, true);
|
|
@@ -163,6 +155,8 @@ trait Curl {
|
|
|
switch ($code) {
|
|
|
case 200:
|
|
|
return $req;
|
|
|
+ case 401:
|
|
|
+ throw new NotAuthorizedException(HTTPUnexpectedResponse::$ecode[401], 401);
|
|
|
default:
|
|
|
throw new HTTPUnexpectedResponse(HTTPUnexpectedResponse::$ecode[$code], $code);
|
|
|
|