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

63 lines
1.8 KiB
PHP
Raw Normal View History

2013-07-25 03:25:24 +04:00
<?php
namespace Mailgun\Tests\Mock\Connection;
2013-07-25 03:25:24 +04:00
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
2013-08-13 23:26:34 +04:00
public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net", $apiVersion = "v2"){
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
}
2013-08-13 23:26:34 +04:00
public function post($endpointUrl, $postData = array(), $files = array()){
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
2013-07-25 03:25:24 +04:00
}
2013-08-13 23:26:34 +04:00
public function get($endpointUrl, $queryString = array()){
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
2013-07-25 03:25:24 +04:00
}
2013-08-13 23:26:34 +04:00
public function delete($endpointUrl){
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
2013-07-25 03:25:24 +04:00
}
2013-08-13 23:26:34 +04:00
public function put($endpointUrl, $queryString){
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
2013-07-25 03:25:24 +04:00
}
2013-08-13 23:26:34 +04:00
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();
$jsonResponseData = json_decode('{"message": "Some JSON Response Data", "id": "1234"}');
2013-07-26 02:42:06 +04:00
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;
2013-08-13 23:26:34 +04:00
$result->http_endpoint_url = $endpointUrl;
2013-07-26 02:42:06 +04:00
return $result;
}
2013-07-25 03:25:24 +04:00
}
?>