mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-06 08:19:25 +03:00
Removal of all classes. No OOP. :(
This commit is contained in:
parent
1ff4357810
commit
1b3720a339
@ -16,16 +16,12 @@ use Mailgun\Connection\Exceptions\MissingEndpoint;
|
|||||||
class RestClient{
|
class RestClient{
|
||||||
|
|
||||||
private $apiKey;
|
private $apiKey;
|
||||||
protected $workingDomain;
|
|
||||||
protected $debugMode;
|
|
||||||
protected $mgClient;
|
protected $mgClient;
|
||||||
|
|
||||||
public function __construct($apiKey, $workingDomain, $debugMode = false){
|
public function __construct($apiKey, $apiEndpoint){
|
||||||
|
|
||||||
$this->apiKey = $apiKey;
|
$this->apiKey = $apiKey;
|
||||||
$this->workingDomain = $workingDomain;
|
$this->mgClient = new Guzzle('https://' . $apiEndpoint . '/' . API_VERSION . '/');
|
||||||
$this->debugMode = $debugMode;
|
|
||||||
$this->mgClient = new Guzzle('https://' . API_ENDPOINT . '/' . API_VERSION . '/');
|
|
||||||
$this->mgClient->setDefaultOption('curl.options', array('CURLOPT_FORBID_REUSE' => true));
|
$this->mgClient->setDefaultOption('curl.options', array('CURLOPT_FORBID_REUSE' => true));
|
||||||
$this->mgClient->setDefaultOption('auth', array (API_USER, $this->apiKey));
|
$this->mgClient->setDefaultOption('auth', array (API_USER, $this->apiKey));
|
||||||
$this->mgClient->setDefaultOption('exceptions', false);
|
$this->mgClient->setDefaultOption('exceptions', false);
|
||||||
@ -102,10 +98,6 @@ class RestClient{
|
|||||||
$result->http_response_code = $httpResponeCode;
|
$result->http_response_code = $httpResponeCode;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function returnWorkingDomain(){
|
|
||||||
return $this->workingDomain;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -2,164 +2,45 @@
|
|||||||
|
|
||||||
namespace Mailgun;
|
namespace Mailgun;
|
||||||
|
|
||||||
use Mailgun\Logs\Logs;
|
|
||||||
use Mailgun\Stats\Stats;
|
|
||||||
use Mailgun\Lists\Lists;
|
|
||||||
use Mailgun\Routes\Routes;
|
|
||||||
use Mailgun\Bounces\Bounces;
|
|
||||||
use Mailgun\Address\Address;
|
|
||||||
use Mailgun\Messages\Messages;
|
|
||||||
use Mailgun\Campaigns\Campaigns;
|
|
||||||
use Mailgun\Complaints\Complaints;
|
|
||||||
use Mailgun\Connection\RestClient;
|
use Mailgun\Connection\RestClient;
|
||||||
use Mailgun\Unsubscribes\Unsubscribes;
|
|
||||||
|
use Mailgun\Messages\Messages;
|
||||||
|
use Mailgun\Messages\BatchMessage;
|
||||||
|
use Mailgun\Messages\MessageBuilder;
|
||||||
|
|
||||||
class Mailgun{
|
class Mailgun{
|
||||||
|
|
||||||
/*
|
|
||||||
* Instantiate the RestClient to make it available to all
|
|
||||||
* classes created from here.
|
|
||||||
*/
|
|
||||||
|
|
||||||
private $apiKey;
|
private $apiKey;
|
||||||
protected $workingDomain;
|
protected $workingDomain;
|
||||||
protected $restClient;
|
protected $restClient;
|
||||||
protected $debugMode;
|
|
||||||
|
|
||||||
public function __construct($apiKey = null, $workingDomain = null, $debugMode = false){
|
public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net"){
|
||||||
if(isset($apiKey) && isset($workingDomain)){
|
$this->restClient = new RestClient($apiKey, $apiEndpoint);
|
||||||
$this->restClient = new RestClient($apiKey, $workingDomain, $debugMode);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$this->apiKey = $apiKey;
|
|
||||||
$this->workingDomain = $workingDomain;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function post($endpointUrl, $postData = array(), $files = array()){
|
||||||
|
return $this->restClient->postRequest($endpointUrl, $postData, $files);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get($endpointUrl, $queryString = array()){
|
||||||
|
return $this->restClient->getRequest($endpointUrl, $queryString);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($endpointUrl){
|
||||||
|
return $this->restClient->getRequest($endpointUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function put($endpointUrl, $putData){
|
||||||
|
return $this->restClient->putRequest($endpointUrl, $putData);
|
||||||
|
}
|
||||||
|
|
||||||
private function InstantiateNewClient($workingDomain, $apiKey){
|
public function MessageBuilder(){
|
||||||
if(isset($workingDomain) || isset($apiKey)){
|
return new MessageBuilder();
|
||||||
if(isset($workingDomain)){
|
}
|
||||||
$this->workingDomain = $workingDomain;
|
|
||||||
}
|
public function BatchMessage($autoSend = true){
|
||||||
if(isset($apiKey)){
|
return new BatchMessage($this->restClient, $autoSend);
|
||||||
$this->apiKey = $apiKey;
|
}
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(isset($this->restClient)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
throw new Exception("A valid set of credentials is required to work with this endpoint.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Factory methods for instantiating each endpoint class.
|
|
||||||
* If a new endpoint is added, create a factory method here.
|
|
||||||
* Each endpoint can accept a new domain and API key if you want to
|
|
||||||
* switch accounts or domains after instantiating the MailgunClient.
|
|
||||||
* This is for future support of RBAC.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public function Messages($workingDomain = null, $apiKey = null){
|
|
||||||
if($this->InstantiateNewClient($workingDomain, $apiKey)){
|
|
||||||
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
|
|
||||||
return new Messages($newClient);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return new Messages($this->restClient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Unsubscribes($workingDomain = null, $apiKey = null){
|
|
||||||
if($this->InstantiateNewClient($workingDomain, $apiKey)){
|
|
||||||
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
|
|
||||||
return new Unsubscribes($newClient);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return new Unsubscribes($this->restClient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Complaints($workingDomain = null, $apiKey = null){
|
|
||||||
if($this->InstantiateNewClient($workingDomain, $apiKey)){
|
|
||||||
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
|
|
||||||
return new Complaints($newClient);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return new Complaints($this->restClient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Bounces($workingDomain = null, $apiKey = null){
|
|
||||||
if($this->InstantiateNewClient($workingDomain, $apiKey)){
|
|
||||||
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
|
|
||||||
return new Bounces($newClient);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return new Bounces($this->restClient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Stats($workingDomain = null, $apiKey = null){
|
|
||||||
if($this->InstantiateNewClient($workingDomain, $apiKey)){
|
|
||||||
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
|
|
||||||
return new Stats($newClient);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return new Stats($this->restClient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Logs($workingDomain = null, $apiKey = null){
|
|
||||||
if($this->InstantiateNewClient($workingDomain, $apiKey)){
|
|
||||||
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
|
|
||||||
return new Logs($newClient);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return new Logs($this->restClient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Routes($workingDomain = null, $apiKey = null){
|
|
||||||
if($this->InstantiateNewClient($workingDomain, $apiKey)){
|
|
||||||
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
|
|
||||||
return new Routes($newClient);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return new Routes($this->restClient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Campaigns($workingDomain = null, $apiKey = null){
|
|
||||||
if($this->InstantiateNewClient($workingDomain, $apiKey)){
|
|
||||||
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
|
|
||||||
return new Campaigns($newClient);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return new Campaigns($this->restClient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Lists($workingDomain = null, $apiKey = null){
|
|
||||||
if($this->InstantiateNewClient($workingDomain, $apiKey)){
|
|
||||||
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
|
|
||||||
return new Lists($newClient);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return new Lists($this->restClient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public function Address($workingDomain = null, $apiKey = null){
|
|
||||||
if($this->InstantiateNewClient($workingDomain, $apiKey)){
|
|
||||||
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
|
|
||||||
return new Address($newClient);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return new Address($this->restClient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -6,18 +6,19 @@ use Mailgun\Messages\Exceptions\TooManyParameters;
|
|||||||
use Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters;
|
use Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters;
|
||||||
|
|
||||||
|
|
||||||
class BatchMessage extends MessageBuilder{
|
class BatchMessage{
|
||||||
|
|
||||||
protected $batchRecipientAttributes;
|
protected $batchRecipientAttributes;
|
||||||
protected $autoSend;
|
protected $autoSend;
|
||||||
|
protected $restClient;
|
||||||
|
|
||||||
public function __construct($restClient, $autoSend){
|
public function __construct($restClient, $autoSend){
|
||||||
parent::__construct($restClient);
|
|
||||||
$this->batchRecipientAttributes = array();
|
$this->batchRecipientAttributes = array();
|
||||||
$this->autoSend = $autoSend;
|
$this->autoSend = $autoSend;
|
||||||
|
$this->restClient = $restClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addBatchRecipient($address, $attributes){
|
public function addToRecipient($address, $attributes){
|
||||||
//Check for maximum recipient count
|
//Check for maximum recipient count
|
||||||
if($this->toRecipientCount == 1000){
|
if($this->toRecipientCount == 1000){
|
||||||
//If autoSend is off, do things here.
|
//If autoSend is off, do things here.
|
||||||
|
@ -6,7 +6,7 @@ use Mailgun\Messages\Expcetions\InvalidParameter;
|
|||||||
use Mailgun\Messages\Exceptions\TooManyParameters;
|
use Mailgun\Messages\Exceptions\TooManyParameters;
|
||||||
use Mailgun\Messages\Expcetions\InvalidParameterType;
|
use Mailgun\Messages\Expcetions\InvalidParameterType;
|
||||||
|
|
||||||
class MessageBuilder extends Messages{
|
class MessageBuilder{
|
||||||
|
|
||||||
protected $message = array();
|
protected $message = array();
|
||||||
protected $files = array();
|
protected $files = array();
|
||||||
@ -18,11 +18,10 @@ class MessageBuilder extends Messages{
|
|||||||
protected $campaignIdCount = 0;
|
protected $campaignIdCount = 0;
|
||||||
protected $customOptionCount = 0;
|
protected $customOptionCount = 0;
|
||||||
protected $tagCount = 0;
|
protected $tagCount = 0;
|
||||||
protected $restClient;
|
|
||||||
|
|
||||||
public function __construct($restClient){
|
|
||||||
parent::__construct($restClient);
|
public function __get($name){
|
||||||
$this->restClient = $restClient;
|
return $this->message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addToRecipient($address, $attributes){
|
public function addToRecipient($address, $attributes){
|
||||||
@ -318,10 +317,17 @@ class MessageBuilder extends Messages{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMessage(){
|
public function addCustomParameter($parameterName, $data){
|
||||||
return $this->message;
|
if(isset($this->message[$parameterName])){
|
||||||
|
array_push($this->message[$parameterName], $data);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$this->message[$parameterName] = array($data);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFiles(){
|
public function getFiles(){
|
||||||
return $this->files;
|
return $this->files;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user