-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updating Base controller and Other Endpoints
- Loading branch information
1 parent
4674439
commit 36a9b84
Showing
15 changed files
with
1,707 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
/* | ||
* PepipostLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
|
||
namespace PepipostLib\Controllers; | ||
|
||
use PepipostLib\APIException; | ||
use PepipostLib\APIHelper; | ||
use PepipostLib\Configuration; | ||
use PepipostLib\Models; | ||
use PepipostLib\Exceptions; | ||
use PepipostLib\Http\HttpRequest; | ||
use PepipostLib\Http\HttpResponse; | ||
use PepipostLib\Http\HttpMethod; | ||
use PepipostLib\Http\HttpContext; | ||
use Unirest\Request; | ||
|
||
/** | ||
* @todo Add a general description for this controller. | ||
*/ | ||
class DomainController extends BaseController | ||
{ | ||
/** | ||
* @var DomainController The reference to *Singleton* instance of this class | ||
*/ | ||
private static $instance; | ||
|
||
/** | ||
* Returns the *Singleton* instance of this class. | ||
* @return DomainController The *Singleton* instance. | ||
*/ | ||
public static function getInstance() | ||
{ | ||
if (null === static::$instance) { | ||
static::$instance = new static(); | ||
} | ||
|
||
return static::$instance; | ||
} | ||
|
||
/** | ||
* This endpoint enables you to add a sending domain which is one of the pre-requisites for sending | ||
* emails. | ||
* | ||
* @param Models\DomainStruct $body Add new domain | ||
* @return object response from the API call | ||
* @throws APIException Thrown if API call fails | ||
*/ | ||
public function adddomain( | ||
$body | ||
) { | ||
|
||
//prepare query string for API call | ||
$_queryBuilder = '/domain'; | ||
|
||
//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::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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
/* | ||
* PepipostLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
|
||
namespace PepipostLib\Controllers; | ||
|
||
use PepipostLib\APIException; | ||
use PepipostLib\APIHelper; | ||
use PepipostLib\Configuration; | ||
use PepipostLib\Models; | ||
use PepipostLib\Exceptions; | ||
use PepipostLib\Http\HttpRequest; | ||
use PepipostLib\Http\HttpResponse; | ||
use PepipostLib\Http\HttpMethod; | ||
use PepipostLib\Http\HttpContext; | ||
use Unirest\Request; | ||
|
||
/** | ||
* @todo Add a general description for this controller. | ||
*/ | ||
class DomainDeleteController extends BaseController | ||
{ | ||
/** | ||
* @var DomainDeleteController The reference to *Singleton* instance of this class | ||
*/ | ||
private static $instance; | ||
|
||
/** | ||
* Returns the *Singleton* instance of this class. | ||
* @return DomainDeleteController The *Singleton* instance. | ||
*/ | ||
public static function getInstance() | ||
{ | ||
if (null === static::$instance) { | ||
static::$instance = new static(); | ||
} | ||
|
||
return static::$instance; | ||
} | ||
|
||
/** | ||
* This endpoint allows you to delete a domain from your Pepipost account. | ||
* | ||
* @param Models\Deletedomain $body delete domain | ||
* @return object response from the API call | ||
* @throws APIException Thrown if API call fails | ||
*/ | ||
public function deletedomain( | ||
$body | ||
) { | ||
|
||
//prepare query string for API call | ||
$_queryBuilder = '/domain/delete'; | ||
|
||
//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; | ||
} | ||
} |
Oops, something went wrong.