Example #1
0
 public function run()
 {
     if (!parent::getApiKey()) {
         throw new Exception("You need to configure API key before performing requests.");
     }
     $this->parameters = array_merge($this->parameters, array("api_key" => parent::getApiKey()));
     $client = new RestClient(array("method" => $this->method, "url" => $this->fullApiUrl($this->path), "headers" => $this->headers, "parameters" => $this->parameters));
     $response = $client->run();
     if ($response["code"] == 204) {
         return true;
     }
     $decode = json_decode($response["body"], true);
     if ($decode === null) {
         throw new Exception("Failed to decode json from response.\n\n Response: " . $response);
     } else {
         if ($response["code"] == 200 || $response["code"] == 201) {
             return $decode;
         } else {
             throw Exception::buildWithFullMessage($decode);
         }
     }
 }