From b619b66732e2215f6182e0d36ce1f2394384a4fa Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sun, 6 Jan 2019 19:07:13 +0100 Subject: [PATCH] Adding tag aggregates --- src/Api/Tag.php | 42 +++++++++++++++++ src/Model/Tag/CountryResponse.php | 60 ++++++++++++++++++++++++ src/Model/Tag/DeviceResponse.php | 60 ++++++++++++++++++++++++ src/Model/Tag/ProviderResponse.php | 60 ++++++++++++++++++++++++ tests/Model/Tag/CountryResponseTest.php | 44 +++++++++++++++++ tests/Model/Tag/DeviceResponseTest.php | 44 +++++++++++++++++ tests/Model/Tag/ProviderResponseTest.php | 47 +++++++++++++++++++ 7 files changed, 357 insertions(+) create mode 100644 src/Model/Tag/CountryResponse.php create mode 100644 src/Model/Tag/DeviceResponse.php create mode 100644 src/Model/Tag/ProviderResponse.php create mode 100644 tests/Model/Tag/CountryResponseTest.php create mode 100644 tests/Model/Tag/DeviceResponseTest.php create mode 100644 tests/Model/Tag/ProviderResponseTest.php diff --git a/src/Api/Tag.php b/src/Api/Tag.php index 6882d70..925c435 100644 --- a/src/Api/Tag.php +++ b/src/Api/Tag.php @@ -10,8 +10,11 @@ namespace Mailgun\Api; use Mailgun\Assert; +use Mailgun\Model\Tag\CountryResponse; use Mailgun\Model\Tag\DeleteResponse; +use Mailgun\Model\Tag\DeviceResponse; use Mailgun\Model\Tag\IndexResponse; +use Mailgun\Model\Tag\ProviderResponse; use Mailgun\Model\Tag\ShowResponse; use Mailgun\Model\Tag\StatisticsResponse; use Mailgun\Model\Tag\UpdateResponse; @@ -108,4 +111,43 @@ class Tag extends HttpApi return $this->hydrateResponse($response, DeleteResponse::class); } + + /** + * @return CountryResponse|ResponseInterface + */ + public function countries(string $domain, string $tag) + { + Assert::stringNotEmpty($domain); + Assert::stringNotEmpty($tag); + + $response = $this->httpGet(sprintf('/v3/%s/tags/%s/stats/aggregates/countries', $domain, $tag)); + + return $this->hydrateResponse($response, CountryResponse::class); + } + + /** + * @return ProviderResponse|ResponseInterface + */ + public function providers(string $domain, string $tag) + { + Assert::stringNotEmpty($domain); + Assert::stringNotEmpty($tag); + + $response = $this->httpGet(sprintf('/v3/%s/tags/%s/stats/aggregates/providers', $domain, $tag)); + + return $this->hydrateResponse($response, ProviderResponse::class); + } + + /** + * @return DeviceResponse|ResponseInterface + */ + public function devices(string $domain, string $tag) + { + Assert::stringNotEmpty($domain); + Assert::stringNotEmpty($tag); + + $response = $this->httpGet(sprintf('/v3/%s/tags/%s/stats/aggregates/devices', $domain, $tag)); + + return $this->hydrateResponse($response, DeviceResponse::class); + } } diff --git a/src/Model/Tag/CountryResponse.php b/src/Model/Tag/CountryResponse.php new file mode 100644 index 0000000..d9034c3 --- /dev/null +++ b/src/Model/Tag/CountryResponse.php @@ -0,0 +1,60 @@ + + */ +final class CountryResponse implements ApiResponse +{ + /** + * @var array [locale => data[]] + */ + private $countries; + + /** + * @var string + * + */ + private $tag; + + /** + * @param string $message + */ + private function __construct() + { + } + + /** + * @param array $data + */ + public static function create(array $data): self + { + $model = new self(); + $model->tag = $data['tag'] ?? ''; + $model->countries = $data['countries'] ?? []; + + return $model; + } + + public function getCountries(): array + { + return $this->countries; + } + + public function getTag(): string + { + return $this->tag; + } + + +} diff --git a/src/Model/Tag/DeviceResponse.php b/src/Model/Tag/DeviceResponse.php new file mode 100644 index 0000000..fbcfe00 --- /dev/null +++ b/src/Model/Tag/DeviceResponse.php @@ -0,0 +1,60 @@ + + */ +final class DeviceResponse implements ApiResponse +{ + /** + * @var array [name => data[]] + */ + private $devices; + + /** + * @var string + * + */ + private $tag; + + /** + * @param string $message + */ + private function __construct() + { + } + + /** + * @param array $data + */ + public static function create(array $data): self + { + $model = new self(); + $model->tag = $data['tag'] ?? ''; + $model->devices = $data['devices'] ?? []; + + return $model; + } + + public function getDevices(): array + { + return $this->devices; + } + + public function getTag(): string + { + return $this->tag; + } + + +} diff --git a/src/Model/Tag/ProviderResponse.php b/src/Model/Tag/ProviderResponse.php new file mode 100644 index 0000000..abb95f0 --- /dev/null +++ b/src/Model/Tag/ProviderResponse.php @@ -0,0 +1,60 @@ + + */ +final class ProviderResponse implements ApiResponse +{ + /** + * @var array [name => data[]] + */ + private $providers; + + /** + * @var string + * + */ + private $tag; + + /** + * @param string $message + */ + private function __construct() + { + } + + /** + * @param array $data + */ + public static function create(array $data): self + { + $model = new self(); + $model->tag = $data['tag'] ?? ''; + $model->providers = $data['providers'] ?? []; + + return $model; + } + + public function getProviders(): array + { + return $this->providers; + } + + public function getTag(): string + { + return $this->tag; + } + + +} diff --git a/tests/Model/Tag/CountryResponseTest.php b/tests/Model/Tag/CountryResponseTest.php new file mode 100644 index 0000000..9a3d0ce --- /dev/null +++ b/tests/Model/Tag/CountryResponseTest.php @@ -0,0 +1,44 @@ +assertCount(2, $model->getCountries()); + $this->assertEquals('exampletag', $model->getTag()); + } +} diff --git a/tests/Model/Tag/DeviceResponseTest.php b/tests/Model/Tag/DeviceResponseTest.php new file mode 100644 index 0000000..3d37e98 --- /dev/null +++ b/tests/Model/Tag/DeviceResponseTest.php @@ -0,0 +1,44 @@ +assertCount(2, $model->getDevices()); + $this->assertEquals('exampletag', $model->getTag()); + } +} diff --git a/tests/Model/Tag/ProviderResponseTest.php b/tests/Model/Tag/ProviderResponseTest.php new file mode 100644 index 0000000..f10caa4 --- /dev/null +++ b/tests/Model/Tag/ProviderResponseTest.php @@ -0,0 +1,47 @@ +assertCount(2, $model->getProviders()); + $this->assertEquals('exampletag', $model->getTag()); + } +}