From 36a9b84eacfa6e4f0511d850a3bc3d554b4ce37e Mon Sep 17 00:00:00 2001 From: snipperbytes Date: Wed, 26 Aug 2020 19:54:12 +0530 Subject: [PATCH] updating Base controller and Other Endpoints --- src/Controllers/BaseController.php | 84 ++++---- src/Controllers/DomainController.php | 111 +++++++++++ src/Controllers/DomainDeleteController.php | 110 +++++++++++ src/Controllers/DomainStatusController.php | 111 +++++++++++ src/Controllers/EventsController.php | 141 ++++++++++++++ src/Controllers/MailSendController.php | 111 +++++++++++ .../SetrecurringcreditddetailsController.php | 110 +++++++++++ src/Controllers/StatsController.php | 125 ++++++++++++ src/Controllers/SubaccountsController.php | 110 +++++++++++ .../SubaccountsCreateSubaccountController.php | 111 +++++++++++ .../SubaccountsDeleteController.php | 110 +++++++++++ .../SubaccountsGetSubAccountsController.php | 114 +++++++++++ ...baccountsSetsubaccountcreditController.php | 110 +++++++++++ .../SubaccountsUpdateSubaccountController.php | 110 +++++++++++ src/Controllers/SuppressionController.php | 180 ++++++++++++++++++ 15 files changed, 1707 insertions(+), 41 deletions(-) create mode 100644 src/Controllers/DomainController.php create mode 100644 src/Controllers/DomainDeleteController.php create mode 100644 src/Controllers/DomainStatusController.php create mode 100644 src/Controllers/EventsController.php create mode 100644 src/Controllers/MailSendController.php create mode 100644 src/Controllers/SetrecurringcreditddetailsController.php create mode 100644 src/Controllers/StatsController.php create mode 100644 src/Controllers/SubaccountsController.php create mode 100644 src/Controllers/SubaccountsCreateSubaccountController.php create mode 100644 src/Controllers/SubaccountsDeleteController.php create mode 100644 src/Controllers/SubaccountsGetSubAccountsController.php create mode 100644 src/Controllers/SubaccountsSetsubaccountcreditController.php create mode 100644 src/Controllers/SubaccountsUpdateSubaccountController.php create mode 100644 src/Controllers/SuppressionController.php diff --git a/src/Controllers/BaseController.php b/src/Controllers/BaseController.php index 83bf7c7..8306da2 100644 --- a/src/Controllers/BaseController.php +++ b/src/Controllers/BaseController.php @@ -16,52 +16,54 @@ use Unirest\Request; /** - * Base controller - */ +* Base controller +*/ class BaseController { - /** - * User-agent to be sent with API calls - * @var string - */ - const USER_AGENT = 'pepi-php-sdk v5'; + /** + * User-agent to be sent with API calls + * @var string + */ + const USER_AGENT = 'APIMATIC 2.0'; - /** - * HttpCallBack instance associated with this controller - * @var HttpCallBack - */ - private $httpCallBack = null; + /** + * HttpCallBack instance associated with this controller + * @var HttpCallBack + */ + private $httpCallBack = null; - /** - * Set HttpCallBack for this controller - * @param HttpCallBack $httpCallBack Http Callbacks called before/after each API call - */ - public function setHttpCallBack(HttpCallBack $httpCallBack) - { - $this->httpCallBack = $httpCallBack; - } + /** + * Set HttpCallBack for this controller + * @param HttpCallBack $httpCallBack Http Callbacks called before/after each API call + */ + public function setHttpCallBack(HttpCallBack $httpCallBack) + { + $this->httpCallBack = $httpCallBack; + } - /** - * Get HttpCallBack for this controller - * @return HttpCallBack The HttpCallBack object set for this controller - */ - public function getHttpCallBack() - { - return $this->httpCallBack; - } + /** + * Get HttpCallBack for this controller + * @return HttpCallBack The HttpCallBack object set for this controller + */ + public function getHttpCallBack() + { + return $this->httpCallBack; + } - /** - * Get a new JsonMapper instance for mapping objects - * @return \apimatic\jsonmapper\JsonMapper JsonMapper instance - */ - protected function getJsonMapper() - { - $mapper = new JsonMapper(); - return $mapper; - } + /** + * Get a new JsonMapper instance for mapping objects + * @return \apimatic\jsonmapper\JsonMapper JsonMapper instance + */ + protected function getJsonMapper() + { + $mapper = new JsonMapper(); + return $mapper; + } - protected function validateResponse(HttpResponse $response, HttpContext $_httpContext) - { - return $_httpContext; - } + protected function validateResponse(HttpResponse $response, HttpContext $_httpContext) + { + if (($response->getStatusCode() < 200) || ($response->getStatusCode() > 208)) { //[200,208] = HTTP OK + throw new APIException('HTTP Response Not OK', $_httpContext); + } + } } diff --git a/src/Controllers/DomainController.php b/src/Controllers/DomainController.php new file mode 100644 index 0000000..3466d68 --- /dev/null +++ b/src/Controllers/DomainController.php @@ -0,0 +1,111 @@ + BaseController::USER_AGENT, + 'content-type' => 'application/json; charset=utf-8', + 'api_key' => Configuration::$apiKey + ); + + //json encode body + $_bodyJson = Request\Body::Json($body); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::POST, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::post($_queryUrl, $_headers, $_bodyJson); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 401) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 403) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 405) { + throw new APIException('Invalid input', $_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + return $response->body; + } +} diff --git a/src/Controllers/DomainDeleteController.php b/src/Controllers/DomainDeleteController.php new file mode 100644 index 0000000..dd362ab --- /dev/null +++ b/src/Controllers/DomainDeleteController.php @@ -0,0 +1,110 @@ + BaseController::USER_AGENT, + 'content-type' => 'application/json; charset=utf-8', + 'api_key' => Configuration::$apiKey + ); + + //json encode body + $_bodyJson = Request\Body::Json($body); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::DELETE, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::delete($_queryUrl, $_headers, $_bodyJson); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 401) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 403) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 405) { + throw new APIException('Invalid input', $_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + return $response->body; + } +} diff --git a/src/Controllers/DomainStatusController.php b/src/Controllers/DomainStatusController.php new file mode 100644 index 0000000..e16642a --- /dev/null +++ b/src/Controllers/DomainStatusController.php @@ -0,0 +1,111 @@ + $domain, + )); + + //validate and preprocess url + $_queryUrl = APIHelper::cleanUrl(Configuration::$BASEURI . $_queryBuilder); + + //prepare headers + $_headers = array ( + 'user-agent' => BaseController::USER_AGENT, + 'api_key' => Configuration::$apiKey + ); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::get($_queryUrl, $_headers); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 401) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 403) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 405) { + throw new APIException('Invalid input', $_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + return $response->body; + } +} diff --git a/src/Controllers/EventsController.php b/src/Controllers/EventsController.php new file mode 100644 index 0000000..81325db --- /dev/null +++ b/src/Controllers/EventsController.php @@ -0,0 +1,141 @@ + DateTimeHelper::toSimpleDate($startdate), + 'events' => $events, + 'sort' => $sort, + 'enddate' => DateTimeHelper::toSimpleDate($enddate), + 'offset' => (null != $offset) ? $offset : 0, + 'limit' => (null != $limit) ? $limit : 10, + 'subject' => $subject, + 'xapiheader' => $xapiheader, + 'fromaddress' => $fromaddress, + 'email' => $email, + )); + + //validate and preprocess url + $_queryUrl = APIHelper::cleanUrl(Configuration::$BASEURI . $_queryBuilder); + + //prepare headers + $_headers = array ( + 'user-agent' => BaseController::USER_AGENT, + 'api_key' => Configuration::$apiKey + ); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::get($_queryUrl, $_headers); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 401) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 403) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 405) { + throw new APIException('Invalid input', $_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + return $response->body; + } +} diff --git a/src/Controllers/MailSendController.php b/src/Controllers/MailSendController.php new file mode 100644 index 0000000..8c730ec --- /dev/null +++ b/src/Controllers/MailSendController.php @@ -0,0 +1,111 @@ + BaseController::USER_AGENT, + 'content-type' => 'application/json; charset=utf-8', + 'api_key' => Configuration::$apiKey + ); + + //json encode body + $_bodyJson = Request\Body::Json($body); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::POST, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::post($_queryUrl, $_headers, $_bodyJson); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 401) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 403) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 405) { + throw new APIException('Invalid input', $_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + return $response->body; + } +} diff --git a/src/Controllers/SetrecurringcreditddetailsController.php b/src/Controllers/SetrecurringcreditddetailsController.php new file mode 100644 index 0000000..2289e25 --- /dev/null +++ b/src/Controllers/SetrecurringcreditddetailsController.php @@ -0,0 +1,110 @@ + BaseController::USER_AGENT, + 'content-type' => 'application/json; charset=utf-8', + 'api_key' => Configuration::$apiKey + ); + + //json encode body + $_bodyJson = Request\Body::Json($body); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::POST, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::post($_queryUrl, $_headers, $_bodyJson); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 401) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 403) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 405) { + throw new APIException('Invalid input', $_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + return $response->body; + } +} diff --git a/src/Controllers/StatsController.php b/src/Controllers/StatsController.php new file mode 100644 index 0000000..56665f9 --- /dev/null +++ b/src/Controllers/StatsController.php @@ -0,0 +1,125 @@ + DateTimeHelper::toSimpleDate($startdate), + 'enddate' => DateTimeHelper::toSimpleDate($enddate), + 'aggregated_by' => $aggregatedBy, + 'offset' => (null != $offset) ? $offset : 1, + 'limit' => (null != $limit) ? $limit : 100, + )); + + //validate and preprocess url + $_queryUrl = APIHelper::cleanUrl(Configuration::$BASEURI . $_queryBuilder); + + //prepare headers + $_headers = array ( + 'user-agent' => BaseController::USER_AGENT, + 'api_key' => Configuration::$apiKey + ); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::get($_queryUrl, $_headers); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 401) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 403) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 405) { + throw new APIException('Invalid input', $_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + return $response->body; + } +} diff --git a/src/Controllers/SubaccountsController.php b/src/Controllers/SubaccountsController.php new file mode 100644 index 0000000..4c0c08e --- /dev/null +++ b/src/Controllers/SubaccountsController.php @@ -0,0 +1,110 @@ + BaseController::USER_AGENT, + 'content-type' => 'application/json; charset=utf-8', + 'api_key' => Configuration::$apiKey + ); + + //json encode body + $_bodyJson = Request\Body::Json($body); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::PATCH, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::patch($_queryUrl, $_headers, $_bodyJson); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 401) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 403) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 405) { + throw new APIException('Invalid input', $_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + return $response->body; + } +} diff --git a/src/Controllers/SubaccountsCreateSubaccountController.php b/src/Controllers/SubaccountsCreateSubaccountController.php new file mode 100644 index 0000000..f05f981 --- /dev/null +++ b/src/Controllers/SubaccountsCreateSubaccountController.php @@ -0,0 +1,111 @@ + BaseController::USER_AGENT, + 'content-type' => 'application/json; charset=utf-8', + 'api_key' => Configuration::$apiKey + ); + + //json encode body + $_bodyJson = Request\Body::Json($body); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::POST, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::post($_queryUrl, $_headers, $_bodyJson); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 401) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 403) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 405) { + throw new APIException('Invalid input', $_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + return $response->body; + } +} diff --git a/src/Controllers/SubaccountsDeleteController.php b/src/Controllers/SubaccountsDeleteController.php new file mode 100644 index 0000000..7de9002 --- /dev/null +++ b/src/Controllers/SubaccountsDeleteController.php @@ -0,0 +1,110 @@ + BaseController::USER_AGENT, + 'content-type' => 'application/json; charset=utf-8', + 'api_key' => Configuration::$apiKey + ); + + //json encode body + $_bodyJson = Request\Body::Json($body); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::DELETE, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::delete($_queryUrl, $_headers, $_bodyJson); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 401) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 403) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 405) { + throw new APIException('Invalid input', $_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + return $response->body; + } +} diff --git a/src/Controllers/SubaccountsGetSubAccountsController.php b/src/Controllers/SubaccountsGetSubAccountsController.php new file mode 100644 index 0000000..2e7137c --- /dev/null +++ b/src/Controllers/SubaccountsGetSubAccountsController.php @@ -0,0 +1,114 @@ + $limit, + 'offset' => $offset, + )); + + //validate and preprocess url + $_queryUrl = APIHelper::cleanUrl(Configuration::$BASEURI . $_queryBuilder); + + //prepare headers + $_headers = array ( + 'user-agent' => BaseController::USER_AGENT, + 'api_key' => Configuration::$apiKey + ); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::get($_queryUrl, $_headers); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 401) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 403) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 405) { + throw new APIException('Invalid input', $_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + return $response->body; + } +} diff --git a/src/Controllers/SubaccountsSetsubaccountcreditController.php b/src/Controllers/SubaccountsSetsubaccountcreditController.php new file mode 100644 index 0000000..349e0dd --- /dev/null +++ b/src/Controllers/SubaccountsSetsubaccountcreditController.php @@ -0,0 +1,110 @@ + BaseController::USER_AGENT, + 'content-type' => 'application/json; charset=utf-8', + 'api_key' => Configuration::$apiKey + ); + + //json encode body + $_bodyJson = Request\Body::Json($body); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::POST, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::post($_queryUrl, $_headers, $_bodyJson); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 401) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 403) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 405) { + throw new APIException('Invalid input', $_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + return $response->body; + } +} diff --git a/src/Controllers/SubaccountsUpdateSubaccountController.php b/src/Controllers/SubaccountsUpdateSubaccountController.php new file mode 100644 index 0000000..10c428d --- /dev/null +++ b/src/Controllers/SubaccountsUpdateSubaccountController.php @@ -0,0 +1,110 @@ + BaseController::USER_AGENT, + 'content-type' => 'application/json; charset=utf-8', + 'api_key' => Configuration::$apiKey + ); + + //json encode body + $_bodyJson = Request\Body::Json($body); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::POST, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::post($_queryUrl, $_headers, $_bodyJson); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 401) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 403) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 405) { + throw new APIException('Invalid input', $_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + return $response->body; + } +} diff --git a/src/Controllers/SuppressionController.php b/src/Controllers/SuppressionController.php new file mode 100644 index 0000000..faa2f63 --- /dev/null +++ b/src/Controllers/SuppressionController.php @@ -0,0 +1,180 @@ + BaseController::USER_AGENT, + 'content-type' => 'application/json; charset=utf-8', + 'api_key' => Configuration::$apiKey + ); + + //json encode body + $_bodyJson = Request\Body::Json($body); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::POST, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::post($_queryUrl, $_headers, $_bodyJson); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 401) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 403) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 405) { + throw new APIException('Invalid input', $_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + return $response->body; + } + + /** + * Use this API to remove an email address or a recipient domain from the suppression list. You can + * remove multiple email addresses and recipient domains together by passing them as values & + * separating them using commas as shown below. + * + * @param Models\RemoveemailordomaintoSuppressionlist $body remove email or domain to suppression list + * @return object response from the API call + * @throws APIException Thrown if API call fails + */ + public function removedomainoremailtosuppressionlist( + $body + ) { + + //prepare query string for API call + $_queryBuilder = '/suppression'; + + //validate and preprocess url + $_queryUrl = APIHelper::cleanUrl(Configuration::$BASEURI . $_queryBuilder); + + //prepare headers + $_headers = array ( + 'user-agent' => BaseController::USER_AGENT, + 'content-type' => 'application/json; charset=utf-8', + 'api_key' => Configuration::$apiKey + ); + + //json encode body + $_bodyJson = Request\Body::Json($body); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::DELETE, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::delete($_queryUrl, $_headers, $_bodyJson); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 401) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 403) { + throw new APIException('API Response', $_httpContext); + } + + if ($response->code == 405) { + throw new APIException('Invalid input', $_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + return $response->body; + } +}