mailgun-php/tests/Mailgun/Tests/Connection/TestBroker.php

128 lines
4.2 KiB
PHP
Raw Normal View History

2013-07-25 03:25:24 +04:00
<?php
namespace Mailgun\Tests\Connection;
use Mailgun\Connection\RestClient;
2013-07-25 03:25:24 +04:00
class TestBroker extends RestClient{
2013-07-25 03:25:24 +04:00
private $apiKey;
2013-08-08 21:39:44 +04:00
protected $apiEndpoint;
2013-07-25 03:25:24 +04:00
protected $apiVersion = API_VERSION;
protected $apiUser = API_USER;
protected $sdkVersion = SDK_VERSION;
protected $sdkUserAgent = SDK_USER_AGENT;
2013-08-08 21:39:44 +04:00
public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net"){
2013-07-25 03:25:24 +04:00
$this->apiKey = $apiKey;
2013-08-08 21:39:44 +04:00
$this->apiEndpoint = $apiEndpoint;
2013-07-25 03:25:24 +04:00
}
public function postRequest($endpointUrl, $postData = array(), $files = array()){
if(preg_match("/\/messages$/", $endpointUrl)){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
2013-07-25 03:25:24 +04:00
}
elseif(preg_match("/\/unsubscribes$/", $endpointUrl)){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
2013-07-25 03:25:24 +04:00
}
elseif(preg_match("/\/complaints$/", $endpointUrl)){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
elseif(preg_match("/\/bounces$/", $endpointUrl)){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
2013-07-25 03:25:24 +04:00
else{
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
2013-07-25 03:25:24 +04:00
}
return $result;
}
public function getRequest($endpointUrl, $queryString = array()){
if($endpointUrl == "domains"){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
2013-07-25 03:25:24 +04:00
}
elseif(preg_match("/\/unsubscribes\//", $endpointUrl)){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
2013-07-25 03:25:24 +04:00
}
elseif(preg_match("/\/unsubscribes/", $endpointUrl)){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
elseif(preg_match("/\/complaints/", $endpointUrl)){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
elseif(preg_match("/\/bounces/", $endpointUrl)){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
elseif(preg_match("/\/stats/", $endpointUrl)){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
elseif(preg_match("/\/log/", $endpointUrl)){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
else{
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
2013-07-25 03:25:24 +04:00
}
return $result;
}
public function deleteRequest($endpointUrl){
if($endpointUrl == "domains"){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
2013-07-25 03:25:24 +04:00
}
elseif(preg_match("/\/unsubscribes\//", $endpointUrl)){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
2013-07-25 03:25:24 +04:00
}
elseif(preg_match("/\/complaints\//", $endpointUrl)){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
elseif(preg_match("/\/bounces\//", $endpointUrl)){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
elseif(preg_match("/\/tags\//", $endpointUrl)){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
else{
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
2013-07-25 03:25:24 +04:00
return $result;
}
public function putRequest($endpointUrl, $queryString){
if($endpointUrl == "domains"){
2013-07-26 02:42:06 +04:00
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
}
else{
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
2013-07-25 03:25:24 +04:00
}
return $result;
}
2013-07-26 02:42:06 +04:00
public function responseHandler($endpointUrl, $httpResponseCode = 200){
if($httpResponseCode === 200){
$result = new \stdClass();
2013-07-26 03:15:20 +04:00
$result->http_response_body = new \stdClass();
2013-07-26 02:42:06 +04:00
$jsonResponseData = json_decode('{"message": "Some JSON Response Data"}');
foreach($jsonResponseData as $key => $value){
$result->http_response_body->$key = $value;
}
}
elseif($httpStatusCode == 400){
throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
}
elseif($httpStatusCode == 401){
throw new InvalidCredentials(EXCEPTION_INVALID_CREDENTIALS);
}
elseif($httpStatusCode == 401){
throw new GenericHTTPError(EXCEPTION_INVALID_CREDENTIALS);
}
elseif($httpStatusCode == 404){
throw new MissingEndpoint(EXCEPTION_MISSING_ENDPOINT);
}
else{
throw new GenericHTTPError(EXCEPTION_GENERIC_HTTP_ERROR);
return false;
}
$result->http_response_code = $httpResponseCode;
return $result;
}
2013-07-25 03:25:24 +04:00
}
?>