/ Request data $data = array(); $data['website_url'] = $website->getURL(); $data['website_name'] = $website->getName(); // Do the request $httpResponse = $this->makeRequest($url->getPath(), $headers, array(), "POST", $data, false, true); // Read the response body if (null === $responseBody = @json_decode($httpResponse->getBody())) { $errorMessage = "No response body!"; throw new \RuntimeException(sprintf($errorTemplate, $errorMessage), ResponseStatus::RUNTIME_ERROR); } // React according to the status code $statusCode = ResponseStatus::getStatus($httpResponse->getStatusCode()); switch ($statusCode) { case ResponseStatus::OK: // All is well, return a result return $this->websiteFromStruct($responseBody->data->site, $errorTemplate, $keys->privateKey); default: // An error has occurred, throw an exception with the status code throw new \RuntimeException(sprintf($errorTemplate, $responseBody->message), $statusCode); } } public function remove($apikey) { // Provide target site_id $additional_params = array( 'target_site_id' => $apikey ); // Prepare the request URL $url = new IntegrationUrl("website_remove", $this->siteId, $this->siteSecret, null, $additional_params); // Error template $errorTemplate = "Error while removing website: %s"; // Do the request $httpResponse = $this->makeRequest($url->getPath(), array(), array(), "DELETE", array(), false, true); // Read the response body if (null === $responseBody = @json_decode($httpResponse->getBody())) { $errorMessage = "No response body!"; throw new \RuntimeException(sprintf($errorTemplate, $errorMessage), ResponseStatus::RUNTIME_ERROR); } // React according to the status code $statusCode = ResponseStatus::getStatus($httpResponse->getStatusCode()); switch ($statusCode) { case ResponseStatus::OK: // All is well, return a result return true; default: // An error has occurred, throw an exception with the status code throw new \RuntimeException(sprintf($errorTemplate, $responseBody->message), $statusCode); } } public function readByAPIKey($apikey) { // Prepare keys $keys = $this->keysInstance(); // Provide target site_id $additional_params = array( 'target_site_id' => $apikey ); // Prepare the request URL $url = new IntegrationUrl("website_read", $this->siteId, $this->siteSecret, null, $additional_params); // Error template $errorTemplate = "Error while reading website: %s"; // Request headers $headers = array(); $headers['X-Nitro-Public-Key'] = base64_encode($keys->publicKey); // Do the request $httpResponse = $this->makeRequest($url->getPath(), $headers, array(), "GET", array(), false, true); // Read the response body if (null === $responseBody = @json_decode($httpResponse->getBody())) { $errorMessage = "No response body!"; throw new \RuntimeException(sprintf($errorTemplate, $errorMessage), ResponseStatus::RUNTIME_ERROR); } // React according to the status code $statusCode = ResponseStatus::getStatus($httpResponse->getStatusCode()); switch ($statusCode) { case ResponseStatus::OK: // All is well, return a result return $this->websiteFromStruct($responseBody->data->site, $errorTemplate, $keys->privateKey); default: // An error has occurred, throw an exception with the status code throw new \RuntimeException(sprintf($errorTemplate, $responseBody->message), $statusCode); } } public function readPaginated($page, $limit = 250) { // Prepare keys $keys = $this->keysInstance(); // Provide target site_id $additional_params = array( 'page' => $page, 'limit' => $limit ); // Prepare the request URL $url = new IntegrationUrl("website_read", $this->siteId, $this->siteSecret, null, $additional_params); // Error template $errorTemplate = "Error while reading website: %s"; // Request headers $headers = array(); $headers['X-Nitro-Public-Key'] = base64_encode($keys->publicKey); // Do the request $httpResponse = $this->makeRequest($url->getPath(), $headers, array(), "GET", array(), false, true); // Read the response body if (null === $responseBody = @json_decode($httpResponse->getBody())) { $errorMessage = "No response body!"; throw new \RuntimeException(sprintf($errorTemplate, $errorMessage), ResponseStatus::RUNTIME_ERROR); } // React according to the status code $statusCode = ResponseStatus::getStatus($httpResponse->getStatusCode()); switch ($statusCode) { case ResponseStatus::OK: // All is well, return a result $result = new \stdClass; $result->websites = array(); foreach ($responseBody->data->sites as $site) { $result->websites[] = $this->websiteFromStruct($site, $errorTemplate, $keys->privateKey); } $result->pagination = $responseBody->data->pagination; return $result; default: // An error has occurred, throw an exception with the status code throw new \RuntimeException(sprintf($errorTemplate, $responseBody->message), $statusCode); } } }