mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-06 08:19:25 +03:00
Adding tag aggregates
This commit is contained in:
parent
fb9892f1f8
commit
b619b66732
@ -10,8 +10,11 @@
|
|||||||
namespace Mailgun\Api;
|
namespace Mailgun\Api;
|
||||||
|
|
||||||
use Mailgun\Assert;
|
use Mailgun\Assert;
|
||||||
|
use Mailgun\Model\Tag\CountryResponse;
|
||||||
use Mailgun\Model\Tag\DeleteResponse;
|
use Mailgun\Model\Tag\DeleteResponse;
|
||||||
|
use Mailgun\Model\Tag\DeviceResponse;
|
||||||
use Mailgun\Model\Tag\IndexResponse;
|
use Mailgun\Model\Tag\IndexResponse;
|
||||||
|
use Mailgun\Model\Tag\ProviderResponse;
|
||||||
use Mailgun\Model\Tag\ShowResponse;
|
use Mailgun\Model\Tag\ShowResponse;
|
||||||
use Mailgun\Model\Tag\StatisticsResponse;
|
use Mailgun\Model\Tag\StatisticsResponse;
|
||||||
use Mailgun\Model\Tag\UpdateResponse;
|
use Mailgun\Model\Tag\UpdateResponse;
|
||||||
@ -108,4 +111,43 @@ class Tag extends HttpApi
|
|||||||
|
|
||||||
return $this->hydrateResponse($response, DeleteResponse::class);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
60
src/Model/Tag/CountryResponse.php
Normal file
60
src/Model/Tag/CountryResponse.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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\Tag;
|
||||||
|
|
||||||
|
use Mailgun\Model\ApiResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
60
src/Model/Tag/DeviceResponse.php
Normal file
60
src/Model/Tag/DeviceResponse.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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\Tag;
|
||||||
|
|
||||||
|
use Mailgun\Model\ApiResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
60
src/Model/Tag/ProviderResponse.php
Normal file
60
src/Model/Tag/ProviderResponse.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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\Tag;
|
||||||
|
|
||||||
|
use Mailgun\Model\ApiResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
44
tests/Model/Tag/CountryResponseTest.php
Normal file
44
tests/Model/Tag/CountryResponseTest.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Mailgun\Tests\Model\Tag;
|
||||||
|
|
||||||
|
use Mailgun\Model\Tag\CountryResponse;
|
||||||
|
use Mailgun\Model\Tag\ProviderResponse;
|
||||||
|
use Mailgun\Tests\Model\BaseModelTest;
|
||||||
|
|
||||||
|
class CountryResponseTest extends BaseModelTest
|
||||||
|
{
|
||||||
|
public function testCreate()
|
||||||
|
{
|
||||||
|
$json =
|
||||||
|
<<<'JSON'
|
||||||
|
{
|
||||||
|
"countries": {
|
||||||
|
"ad": {
|
||||||
|
"clicked": 7,
|
||||||
|
"complained": 4,
|
||||||
|
"opened": 18,
|
||||||
|
"unique_clicked": 0,
|
||||||
|
"unique_opened": 2,
|
||||||
|
"unsubscribed": 0
|
||||||
|
},
|
||||||
|
"ck": {
|
||||||
|
"clicked": 13,
|
||||||
|
"complained": 2,
|
||||||
|
"opened": 1,
|
||||||
|
"unique_clicked": 1,
|
||||||
|
"unique_opened": 0,
|
||||||
|
"unsubscribed": 2
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"tag": "exampletag"
|
||||||
|
}
|
||||||
|
JSON;
|
||||||
|
$model = CountryResponse::create(json_decode($json, true));
|
||||||
|
|
||||||
|
$this->assertCount(2, $model->getCountries());
|
||||||
|
$this->assertEquals('exampletag', $model->getTag());
|
||||||
|
}
|
||||||
|
}
|
44
tests/Model/Tag/DeviceResponseTest.php
Normal file
44
tests/Model/Tag/DeviceResponseTest.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Mailgun\Tests\Model\Tag;
|
||||||
|
|
||||||
|
use Mailgun\Model\Tag\DeviceResponse;
|
||||||
|
use Mailgun\Model\Tag\ProviderResponse;
|
||||||
|
use Mailgun\Tests\Model\BaseModelTest;
|
||||||
|
|
||||||
|
class ProviderResponseTest extends BaseModelTest
|
||||||
|
{
|
||||||
|
public function testCreate()
|
||||||
|
{
|
||||||
|
$json =
|
||||||
|
<<<'JSON'
|
||||||
|
{
|
||||||
|
"devices": {
|
||||||
|
"desktop": {
|
||||||
|
"clicked": 8,
|
||||||
|
"complained": 1,
|
||||||
|
"opened": 8,
|
||||||
|
"unique_clicked": 0,
|
||||||
|
"unique_opened": 0,
|
||||||
|
"unsubscribed": 0
|
||||||
|
},
|
||||||
|
"mobile": {
|
||||||
|
"clicked": 3,
|
||||||
|
"complained": 1,
|
||||||
|
"opened": 5,
|
||||||
|
"unique_clicked": 0,
|
||||||
|
"unique_opened": 0,
|
||||||
|
"unsubscribed": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tag": "exampletag"
|
||||||
|
}
|
||||||
|
JSON;
|
||||||
|
$model = DeviceResponse::create(json_decode($json, true));
|
||||||
|
|
||||||
|
$this->assertCount(2, $model->getDevices());
|
||||||
|
$this->assertEquals('exampletag', $model->getTag());
|
||||||
|
}
|
||||||
|
}
|
47
tests/Model/Tag/ProviderResponseTest.php
Normal file
47
tests/Model/Tag/ProviderResponseTest.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Mailgun\Tests\Model\Tag;
|
||||||
|
|
||||||
|
use Mailgun\Model\Tag\ProviderResponse;
|
||||||
|
use Mailgun\Tests\Model\BaseModelTest;
|
||||||
|
|
||||||
|
class ProviderResponseTest extends BaseModelTest
|
||||||
|
{
|
||||||
|
public function testCreate()
|
||||||
|
{
|
||||||
|
$json =
|
||||||
|
<<<'JSON'
|
||||||
|
{
|
||||||
|
"providers": {
|
||||||
|
"gmail.com": {
|
||||||
|
"accepted": 23,
|
||||||
|
"clicked": 15,
|
||||||
|
"complained": 0,
|
||||||
|
"delivered": 23,
|
||||||
|
"opened": 19,
|
||||||
|
"unique_clicked": 2,
|
||||||
|
"unique_opened": 7,
|
||||||
|
"unsubscribed": 1
|
||||||
|
},
|
||||||
|
"yahoo.com": {
|
||||||
|
"accepted": 16,
|
||||||
|
"clicked": 8,
|
||||||
|
"complained": 2,
|
||||||
|
"delivered": 8,
|
||||||
|
"opened": 4,
|
||||||
|
"unique_clicked": 0,
|
||||||
|
"unique_opened": 0,
|
||||||
|
"unsubscribed": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tag": "exampletag"
|
||||||
|
}
|
||||||
|
JSON;
|
||||||
|
$model = ProviderResponse::create(json_decode($json, true));
|
||||||
|
|
||||||
|
$this->assertCount(2, $model->getProviders());
|
||||||
|
$this->assertEquals('exampletag', $model->getTag());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user