diff --git a/src/Api/Tag.php b/src/Api/Tag.php index 12602ae1..8b7f00f8 100644 --- a/src/Api/Tag.php +++ b/src/Api/Tag.php @@ -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; @@ -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); } @@ -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); } @@ -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); + } } diff --git a/src/Model/Tag/TagLimitResponse.php b/src/Model/Tag/TagLimitResponse.php new file mode 100644 index 00000000..20d49993 --- /dev/null +++ b/src/Model/Tag/TagLimitResponse.php @@ -0,0 +1,98 @@ +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(), + ]; + } +} diff --git a/tests/Api/TagTest.php b/tests/Api/TagTest.php index 2d578cbb..1866f2dc 100644 --- a/tests/Api/TagTest.php +++ b/tests/Api/TagTest.php @@ -127,10 +127,10 @@ 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() @@ -138,7 +138,7 @@ 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');