Example #1
0
 /**
  * The costructor for the Service
  *
  * @params apiKey
  * @params secretKey
  * @params baseURL
  *
  */
 public function __construct($apiKey, $secretKey)
 {
     //$this->resource = "charge";
     $this->apiKey = $apiKey;
     $this->secretKey = $secretKey;
     $this->url = $this->version . "/" . $this->resource;
     $this->config = App42Config::getInstance()->getBaseURL();
 }
Example #2
0
 public static function getInstance()
 {
     if (self::$config == null) {
         try {
             self::$config = new App42Config();
         } catch (ConfigurationException $e) {
             throw new RuntimeException(" Instance Cannot be created due to wrong config.");
         }
     }
     return self::$config;
 }
Example #3
0
 public function setBaseURL($protocol, $host, $port)
 {
     App42Config::getInstance()->setBaseURL($protocol, $host, $port);
 }
Example #4
0
 /**
  * Set Api Key and Secret Key of your App
  *
  * @param apiKey
  * @param secretKey
  */
 public static function initialize($apiKey, $secretKey)
 {
     self::$config = App42Config::getInstance();
     App42API::$apiKey = $apiKey;
     App42API::$secretKey = $secretKey;
 }
 /**
  * Convenience method wrapping a commom delete call
  * @param string $url
  * @param array params
  * @param string $user=null [optional]
  * @param string $password=null [optional]
  * @return RestClient
  */
 public static function delete($url, array $params = null, $user = null, $pwd = null, $contentType = "", $accept = null, $headerParams = null)
 {
     $currURL = App42Config::getInstance()->getBaseURL() . $url;
     try {
         $returnResult = self::call("DELETE", $currURL, $params, $user, $pwd, $contentType, $accept, null, $headerParams);
         $appErrorCode = null;
         $httpErrorCode = null;
         $errorPayLoad = null;
         if ($accept == "application/json") {
             $jsonBody = json_decode($returnResult->response);
             if (isset($jsonBody->app42Fault)) {
                 $appErrorCode = $jsonBody->app42Fault->appErrorCode;
                 $httpErrorCode = $jsonBody->app42Fault->httpErrorCode;
                 $errorPayLoad = $jsonBody->app42Fault->details;
             }
         } else {
             if ($accept == "application/xml") {
                 $xmlBody = simplexml_load_string($returnResult->response);
                 $appErrorCode = "{$xmlBody['appErrorCode']}";
                 $httpErrorCode = "{$xmlBody['httpErrorCode']}";
                 $errorPayLoad = "{$xmlBody->details}";
             }
         }
         if ($httpErrorCode == 404) {
             throw new App42NotFoundException($errorPayLoad, $httpErrorCode, $appErrorCode);
         } else {
             if ($httpErrorCode == 400) {
                 throw new App42BadParameterException($errorPayLoad, $httpErrorCode, $appErrorCode);
             } else {
                 if ($httpErrorCode == 401) {
                     throw new App42SecurityException($errorPayLoad, $httpErrorCode, $appErrorCode);
                 } else {
                     if ($httpErrorCode == 413) {
                         throw new App42LimitException($errorPayLoad, $httpErrorCode, 1413);
                     } else {
                         if ($httpErrorCode == 500) {
                             throw new App42Exception($errorPayLoad, $httpErrorCode, $appErrorCode);
                         }
                     }
                 }
             }
         }
         return $returnResult;
     } catch (HttpResponseException $e) {
         throw $e;
     }
 }