-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e98711
commit d04a2f9
Showing
4 changed files
with
322 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,23 +11,35 @@ | |
|
||
namespace Mailgun\Api; | ||
|
||
use Exception; | ||
use Mailgun\Assert; | ||
use Mailgun\Model\Stats\AggregateResponse; | ||
use Mailgun\Model\Stats\TotalResponse; | ||
use Psr\Http\Client\ClientExceptionInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* @see https://documentation.mailgun.com/en/latest/api-stats.html | ||
* | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class Stats extends HttpApi | ||
{ | ||
public const EVENT_ACCEPTED = 'accepted'; | ||
public const EVENT_DELIVERED = 'delivered'; | ||
public const EVENT_FAILED = 'failed'; | ||
public const EVENT_OPENED = 'opened'; | ||
public const EVENT_CLICKED = 'clicked'; | ||
public const EVENT_UNSUBSCRIBED = 'unsubscribed'; | ||
public const EVENT_COMPLAINED = 'complained'; | ||
public const EVENT_STORED = 'stored'; | ||
|
||
/** | ||
* @param string $domain | ||
* @param array $params | ||
* @param array $requestHeaders | ||
* @param string $domain | ||
* @param array $params | ||
* @param array $requestHeaders | ||
* @return TotalResponse|array | ||
* @throws ClientExceptionInterface | ||
* @throws Exception | ||
*/ | ||
public function total(string $domain, array $params = [], array $requestHeaders = []) | ||
{ | ||
|
@@ -37,4 +49,33 @@ public function total(string $domain, array $params = [], array $requestHeaders | |
|
||
return $this->hydrateResponse($response, TotalResponse::class); | ||
} | ||
|
||
/** | ||
* @param array $params | ||
* @param array $requestHeaders | ||
* @return TotalResponse|array | ||
* @throws ClientExceptionInterface | ||
* @throws Exception | ||
*/ | ||
public function totalAccount(array $params = [], array $requestHeaders = []) | ||
{ | ||
Assert::keyExists($params, 'event', 'You must specify an event'); | ||
|
||
$response = $this->httpGet('/v3/stats/total', $params, $requestHeaders); | ||
|
||
return $this->hydrateResponse($response, TotalResponse::class); | ||
} | ||
|
||
/** | ||
* @param string $domain | ||
* @param array $requestHeaders | ||
* @return AggregateResponse | ||
* @throws ClientExceptionInterface | ||
*/ | ||
public function aggregateCountsByESP(string $domain, array $requestHeaders = []): AggregateResponse | ||
{ | ||
$response = $this->httpGet(sprintf('/v3/%s/aggregates/providers', rawurlencode($domain)), [], $requestHeaders); | ||
|
||
return $this->hydrateResponse($response, AggregateResponse::class); | ||
} | ||
} |
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* Copyright (C) 2013 Mailgun | ||
* | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
namespace Mailgun\Model\Stats; | ||
|
||
use Mailgun\Model\ApiResponse; | ||
|
||
final class AggregateResponse implements ApiResponse | ||
{ | ||
private array $providers = []; | ||
|
||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* @return self | ||
* @throws \Exception | ||
*/ | ||
public static function create(array $data): self | ||
{ | ||
$providers = []; | ||
foreach ($data['providers'] as $domain => $provider) { | ||
$providers[] = AggregateResponseItem::create($provider + ['domain' => $domain]); | ||
} | ||
$model = new self(); | ||
$model->setProviders($providers); | ||
|
||
return $model; | ||
} | ||
|
||
/** | ||
* @return array|AggregateResponseItem[] | ||
*/ | ||
public function getProviders(): array | ||
{ | ||
return $this->providers; | ||
} | ||
|
||
/** | ||
* @param array $providers | ||
* @return void | ||
*/ | ||
public function setProviders(array $providers): void | ||
{ | ||
$this->providers = $providers; | ||
} | ||
|
||
} |
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,205 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* Copyright (C) 2013 Mailgun | ||
* | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
namespace Mailgun\Model\Stats; | ||
|
||
use Mailgun\Model\ApiResponse; | ||
|
||
final class AggregateResponseItem implements ApiResponse | ||
{ | ||
private int $accepted; | ||
private int $clicked; | ||
private int $complained; | ||
private int $delivered; | ||
private int $opened; | ||
private int $uniqueClicked; | ||
private int $uniqueOpened; | ||
private int $unsubscribed; | ||
private string $domain; | ||
|
||
|
||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* @return self | ||
*/ | ||
public static function create(array $data): self | ||
{ | ||
$model = new self(); | ||
$model->setClicked($data['clicked'] ?? 0); | ||
$model->setComplained($data['complained'] ?? 0); | ||
$model->setDelivered($data['delivered'] ?? 0); | ||
$model->setOpened($data['opened'] ?? 0); | ||
$model->setUniqueClicked($data['unique_clicked'] ?? 0); | ||
$model->setUniqueOpened($data['unique_opened'] ?? 0); | ||
$model->setUnsubscribed($data['unsubscribed'] ?? 0); | ||
$model->setAccepted($data['accepted'] ?? 0); | ||
$model->setDomain($data['domain'] ?? ''); | ||
|
||
return $model; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getAccepted(): int | ||
{ | ||
return $this->accepted; | ||
} | ||
|
||
/** | ||
* @param int $accepted | ||
* @return void | ||
*/ | ||
public function setAccepted(int $accepted): void | ||
{ | ||
$this->accepted = $accepted; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getClicked(): int | ||
{ | ||
return $this->clicked; | ||
} | ||
|
||
/** | ||
* @param int $clicked | ||
* @return void | ||
*/ | ||
public function setClicked(int $clicked): void | ||
{ | ||
$this->clicked = $clicked; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getComplained(): int | ||
{ | ||
return $this->complained; | ||
} | ||
|
||
/** | ||
* @param int $complained | ||
* @return void | ||
*/ | ||
public function setComplained(int $complained): void | ||
{ | ||
$this->complained = $complained; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getDelivered(): int | ||
{ | ||
return $this->delivered; | ||
} | ||
|
||
/** | ||
* @param int $delivered | ||
* @return void | ||
*/ | ||
public function setDelivered(int $delivered): void | ||
{ | ||
$this->delivered = $delivered; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getOpened(): int | ||
{ | ||
return $this->opened; | ||
} | ||
|
||
/** | ||
* @param int $opened | ||
* @return void | ||
*/ | ||
public function setOpened(int $opened): void | ||
{ | ||
$this->opened = $opened; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getUniqueClicked(): int | ||
{ | ||
return $this->uniqueClicked; | ||
} | ||
|
||
/** | ||
* @param int $uniqueClicked | ||
* @return void | ||
*/ | ||
public function setUniqueClicked(int $uniqueClicked): void | ||
{ | ||
$this->uniqueClicked = $uniqueClicked; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getUniqueOpened(): int | ||
{ | ||
return $this->uniqueOpened; | ||
} | ||
|
||
/** | ||
* @param int $uniqueOpened | ||
* @return void | ||
*/ | ||
public function setUniqueOpened(int $uniqueOpened): void | ||
{ | ||
$this->uniqueOpened = $uniqueOpened; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getUnsubscribed(): int | ||
{ | ||
return $this->unsubscribed; | ||
} | ||
|
||
/** | ||
* @param int $unsubscribed | ||
* @return void | ||
*/ | ||
public function setUnsubscribed(int $unsubscribed): void | ||
{ | ||
$this->unsubscribed = $unsubscribed; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDomain(): string | ||
{ | ||
return $this->domain; | ||
} | ||
|
||
/** | ||
* @param string $domain | ||
* @return void | ||
*/ | ||
public function setDomain(string $domain): void | ||
{ | ||
$this->domain = $domain; | ||
} | ||
} |
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