-
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.
* Add dependabot. Change php-cs-fixer * Domains. V4 * Merge branch 'master' of github.com:mailgun/mailgun-php # Conflicts: # src/Api/DomainV4.php * API STATS Endpoint. In Progress * Added stats api methods * fix code
- Loading branch information
1 parent
38af3ad
commit 7a98b6f
Showing
6 changed files
with
506 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,37 @@ | |
|
||
namespace Mailgun\Api; | ||
|
||
use Exception; | ||
use Mailgun\Assert; | ||
use Mailgun\Model\Stats\AggregateCountriesResponse; | ||
use Mailgun\Model\Stats\AggregateDevicesResponse; | ||
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 +51,62 @@ 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 | ||
* @throws Exception | ||
*/ | ||
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); | ||
} | ||
|
||
/** | ||
* @param string $domain | ||
* @param array $requestHeaders | ||
* @return AggregateDevicesResponse | ||
* @throws ClientExceptionInterface | ||
* @throws Exception | ||
*/ | ||
public function aggregateByDevices(string $domain, array $requestHeaders = []): AggregateDevicesResponse | ||
{ | ||
$response = $this->httpGet(sprintf('/v3/%s/aggregates/devices', rawurlencode($domain)), [], $requestHeaders); | ||
|
||
return $this->hydrateResponse($response, AggregateDevicesResponse::class); | ||
} | ||
|
||
/** | ||
* @param string $domain | ||
* @param array $requestHeaders | ||
* @return AggregateCountriesResponse | ||
* @throws ClientExceptionInterface | ||
* @throws Exception | ||
*/ | ||
public function aggregateByCountry(string $domain, array $requestHeaders = []): AggregateCountriesResponse | ||
{ | ||
$response = $this->httpGet(sprintf('/v3/%s/aggregates/countries', rawurlencode($domain)), [], $requestHeaders); | ||
|
||
return $this->hydrateResponse($response, AggregateCountriesResponse::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 AggregateCountriesResponse implements ApiResponse | ||
{ | ||
private array $countries = []; | ||
|
||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* @return self | ||
* @throws \Exception | ||
*/ | ||
public static function create(array $data): self | ||
{ | ||
$countries = []; | ||
foreach ($data['countries'] as $country => $provider) { | ||
$countries[] = AggregateResponseItem::create($provider + ['country' => $country]); | ||
} | ||
$model = new self(); | ||
$model->setCountries($countries); | ||
return $model; | ||
} | ||
|
||
/** | ||
* @return array|AggregateResponseItem[] | ||
*/ | ||
public function getCountries(): array | ||
{ | ||
return $this->countries; | ||
} | ||
|
||
/** | ||
* @param array $countries | ||
* @return void | ||
*/ | ||
public function setCountries(array $countries): void | ||
{ | ||
$this->countries = $countries; | ||
} | ||
|
||
|
||
} |
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,57 @@ | ||
<?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 AggregateDevicesResponse implements ApiResponse | ||
{ | ||
private array $devices = []; | ||
|
||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* @return self | ||
* @throws \Exception | ||
*/ | ||
public static function create(array $data): self | ||
{ | ||
$devices = []; | ||
foreach ($data['devices'] as $domain => $provider) { | ||
$devices[] = AggregateResponseItem::create($provider + ['device' => $domain]); | ||
} | ||
$model = new self(); | ||
$model->setDevices($devices); | ||
return $model; | ||
} | ||
|
||
/** | ||
* @return array|AggregateResponseItem[] | ||
*/ | ||
public function getDevices(): array | ||
{ | ||
return $this->devices; | ||
} | ||
|
||
/** | ||
* @param array $devices | ||
* @return void | ||
*/ | ||
public function setDevices(array $devices): void | ||
{ | ||
$this->devices = $devices; | ||
} | ||
|
||
} |
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; | ||
} | ||
|
||
} |
Oops, something went wrong.