Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De 1300 mailgun sdk endpoint not correct for tag stats #913

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/Api/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Mailgun\Model\Tag\ProviderResponse;
use Mailgun\Model\Tag\ShowResponse;
use Mailgun\Model\Tag\StatisticsResponse;
use Mailgun\Model\Tag\TagLimitResponse;
use Mailgun\Model\Tag\UpdateResponse;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -97,19 +98,19 @@ public function update(string $domain, string $tag, string $description, array $

/**
* Returns statistics for a single tag.
* @param string $domain
* @param string $tag
* @param array $params
* @param array $requestHeaders
* @param string $domain
* @param array $params
* @param array $requestHeaders
* @return StatisticsResponse|ResponseInterface
* @throws ClientExceptionInterface
*/
public function stats(string $domain, string $tag, array $params, array $requestHeaders = [])
public function stats(string $domain, array $params, array $requestHeaders = [])
{
Assert::stringNotEmpty($domain);
Assert::stringNotEmpty($tag);
Assert::stringNotEmpty($params['event']);
Assert::stringNotEmpty($params['tag']);

$response = $this->httpGet(sprintf('/v3/%s/tags/%s/stats', $domain, $tag), $params, $requestHeaders);
$response = $this->httpGet(sprintf('/v3/%s/tag/stats', $domain), $params, $requestHeaders);

return $this->hydrateResponse($response, StatisticsResponse::class);
}
Expand All @@ -127,7 +128,7 @@ public function delete(string $domain, string $tag, array $requestHeaders = [])
Assert::stringNotEmpty($domain);
Assert::stringNotEmpty($tag);

$response = $this->httpDelete(sprintf('/v3/%s/tags/%s', $domain, $tag), [], $requestHeaders);
$response = $this->httpDelete(sprintf('/v3/%s/tag', $domain), ['tag' => $tag], $requestHeaders);

return $this->hydrateResponse($response, DeleteResponse::class);
}
Expand Down Expand Up @@ -182,4 +183,19 @@ public function devices(string $domain, string $tag, array $requestHeaders = [])

return $this->hydrateResponse($response, DeviceResponse::class);
}

/**
* @param string $domain
* @param array $requestHeaders
* @return TagLimitResponse
* @throws ClientExceptionInterface
*/
public function getTagLimits(string $domain, array $requestHeaders = []): TagLimitResponse
{
Assert::stringNotEmpty($domain);

$response = $this->httpGet(sprintf('/v3/domains/%s/limits/tag', $domain), [], $requestHeaders);

return $this->hydrateResponse($response, TagLimitResponse::class);
}
}
98 changes: 98 additions & 0 deletions src/Model/Tag/TagLimitResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?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\Tag;

use Mailgun\Model\ApiResponse;

final class TagLimitResponse implements ApiResponse
{
private string $id;
private int $limit;
private int $count;

/**
* @param array $data
* @return self
*/
public static function create(array $data): TagLimitResponse
{
$item = new self();
$item->setId($data['id'] ?? '');
$item->setLimit($data['limit'] ?? 0);
$item->setCount($data['count'] ?? 0);

return $item;
}

/**
* @return string
*/
public function getId(): string
{
return $this->id;
}

/**
* @param string $id
* @return void
*/
public function setId(string $id): void
{
$this->id = $id;
}

/**
* @return int
*/
public function getLimit(): int
{
return $this->limit;
}

/**
* @param int $limit
* @return void
*/
public function setLimit(int $limit): void
{
$this->limit = $limit;
}

/**
* @return int
*/
public function getCount(): int
{
return $this->count;
}

/**
* @param int $count
* @return void
*/
public function setCount(int $count): void
{
$this->count = $count;
}

/**
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->getId(),
'limit' => $this->getLimit(),
'count' => $this->getCount(),
];
}
}
6 changes: 3 additions & 3 deletions tests/Api/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,18 @@ public function testStats()
$api = $this->getApiMock();
$api->expects($this->once())
->method('httpGet')
->with('/v3/domain/tags/foo/stats', ['event' => 'foo'])
->with('/v3/domain/tag/stats', ['event' => 'foo', 'tag' => 'tag'])
->willReturn(new Response());

$api->stats('domain', 'foo', ['event' => 'foo']);
$api->stats('domain', ['event' => 'foo', 'tag' => 'tag']);
}

public function testDelete()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('httpDelete')
->with('/v3/domain/tags/foo')
->with('/v3/domain/tag')
->willReturn(new Response());

$api->delete('domain', 'foo');
Expand Down
Loading