Example #1
0
 /**
  * @param $http_status_code
  * HTTP status code message as predefined.
  * @param $error
  * A single error code.
  * @param $error_description
  * (optional) A human-readable text providing additional information,
  * used to assist in the understanding and resolution of the error
  * occurred.
  */
 public function __construct($http_status_code, $error, $error_description = NULL)
 {
     parent::__construct($error);
     $this->httpCode = $http_status_code;
     $this->errorData['error'] = $error;
     if ($error_description) {
         $this->errorData['error_description'] = $error_description;
     }
 }
 /**
  * @param string $code              HTTP error code
  * @param string $error             Short name of the error
  * @param string $error_description Description of the error (optional)
  * @param string $error_uri         Uri of the error (optional)
  */
 public function __construct($code, $error, $error_description = null, $error_uri = null)
 {
     parent::__construct($error, $code);
     //Check %x20-21 / %x23-5B / %x5D-7E for error and error_description
     //Check %x21 / %x23-5B / %x5D-7E for error_uri
     $this->errorData['error'] = $error;
     if (null !== $error_description) {
         $this->errorData['error_description'] = $error_description;
     }
     if (null !== $error_uri) {
         $this->errorData['error_uri'] = urlencode($error_uri);
     }
 }
Example #3
0
 /**
  * Make an API call.
  *
  * Support both OAuth2.0 or normal GET/POST API call, with relative
  * or absolute URI.
  *
  * If no valid OAuth2.0 access token found in session object, this function
  * will automatically switch as normal remote API call without "oauth_token"
  * parameter.
  *
  * Assume server reply in JSON object and always decode during return. If
  * you hope to issue a raw query, please use makeRequest().
  *
  * @param $path
  * The target path, relative to base_path/service_uri or an absolute URI.
  * @param $method
  * (optional) The HTTP method (default 'GET').
  * @param $params
  * (optional The GET/POST parameters.
  *
  * @return
  * The JSON decoded response object.
  *
  * @throws Exception
  */
 public function api($path, $method = 'GET', $params = array())
 {
     if (is_array($method) && empty($params)) {
         $params = $method;
         $method = 'GET';
     }
     // json_encode all params values that are not strings.
     foreach ($params as $key => $value) {
         if (!is_string($value)) {
             $params[$key] = json_encode($value);
         }
     }
     $result = json_decode($this->makeOAuth2Request($this->getUri($path), $method, $params), TRUE);
     // Results are returned, errors are thrown.
     if (is_array($result) && isset($result['error'])) {
         $e = new Exception($result);
         switch ($e->getType()) {
             // OAuth 2.0 Draft 10 style.
             case 'invalid_token':
                 $this->setSession(NULL);
             default:
                 $this->setSession(NULL);
         }
         throw $e;
     }
     return $result;
 }