diff --git a/CHANGELOG.md b/CHANGELOG.md index cd2171a5..3f1595c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 4.3.2 + - Added new API endpoint for getting metrics @see https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Metrics/ + +## 4.3.1 + - Add method for retrieving stored messages by @oleksandr-mykhailenko in #920 + - Add missed params to the create method for DomainV4.php by @oleksandr-mykhailenko in #921 + ## 4.3.0 - End of support php 7.3 - Updated properties and added types to the classes properties diff --git a/README.md b/README.md index 5414dcc8..7d24d13d 100644 --- a/README.md +++ b/README.md @@ -189,6 +189,38 @@ $configurator->setApiKey('key-example'); $configurator->setSubAccountId($subAccountId) ``` +### Load data from the Analytics API + +```php +metrics()->loadMetrics([ + 'start' => 'Wed, 11 Sep 2024 18:29:02 +0300', + 'end' => 'Wed, 25 Sep 2024 18:29:02 +0300', + 'metrics' => [ + "failed_count", "opened_count", "sent_count", "delivered_count" + ], + 'resolution' => 'month', + 'precision' => 'day', + 'dimensions' => [ + 'time', + ], + 'include_aggregates' => true, + 'include_subaccounts' => true, +]); + +print_r($result->getItems()); + +```` + ### All usage examples You will find more detailed documentation at [/doc](doc/index.md) and on diff --git a/src/Api/Metrics.php b/src/Api/Metrics.php new file mode 100644 index 00000000..43da0622 --- /dev/null +++ b/src/Api/Metrics.php @@ -0,0 +1,71 @@ +httpPost('/v1/analytics/metrics', $payload, $requestHeaders); + + return $this->hydrateResponse($response, MetricsResponse::class); + } +} diff --git a/src/Mailgun.php b/src/Mailgun.php index b64b3696..7821320e 100644 --- a/src/Mailgun.php +++ b/src/Mailgun.php @@ -22,6 +22,7 @@ use Mailgun\Api\Mailboxes; use Mailgun\Api\MailingList; use Mailgun\Api\Message; +use Mailgun\Api\Metrics; use Mailgun\Api\Route; use Mailgun\Api\Stats; use Mailgun\Api\SubAccounts; @@ -254,4 +255,12 @@ public function templates(): Templates { return new Templates($this->httpClient, $this->requestBuilder, $this->hydrator); } + + /** + * @return Metrics + */ + public function metrics(): Metrics + { + return new Metrics($this->httpClient, $this->requestBuilder, $this->hydrator); + } } diff --git a/src/Model/Metrics/MetricsResponse.php b/src/Model/Metrics/MetricsResponse.php new file mode 100644 index 00000000..302c2b82 --- /dev/null +++ b/src/Model/Metrics/MetricsResponse.php @@ -0,0 +1,161 @@ +setDimensions($data['dimensions'] ?? []); + $model->setStart($data['start']); + $model->setEnd($data['end']); + $model->setAggregates($data['aggregates'] ?? []); + $model->setItems($data['items'] ?? []); + $model->setPagination($data['pagination'] ?? []); + $model->setResolution($data['resolution']); + + return $model; + } + + /** + * @return string + */ + public function getStart(): string + { + return $this->start; + } + + /** + * @param string $start + */ + public function setStart(string $start): void + { + $this->start = $start; + } + + /** + * @return string + */ + public function getEnd(): string + { + return $this->end; + } + + /** + * @param string $end + */ + public function setEnd(string $end): void + { + $this->end = $end; + } + + /** + * @return string + */ + public function getResolution(): string + { + return $this->resolution; + } + + /** + * @param string $resolution + */ + public function setResolution(string $resolution): void + { + $this->resolution = $resolution; + } + + /** + * @return array + */ + public function getDimensions(): array + { + return $this->dimensions; + } + + /** + * @param array $dimensions + */ + public function setDimensions(array $dimensions): void + { + $this->dimensions = $dimensions; + } + + /** + * @return array + */ + public function getPagination(): array + { + return $this->pagination; + } + + /** + * @param array $pagination + */ + public function setPagination(array $pagination): void + { + $this->pagination = $pagination; + } + + /** + * @return array + */ + public function getItems(): array + { + return $this->items; + } + + /** + * @param array $items + */ + public function setItems(array $items): void + { + $this->items = $items; + } + + /** + * @return array + */ + public function getAggregates(): array + { + return $this->aggregates; + } + + /** + * @param array $aggregates + */ + public function setAggregates(array $aggregates): void + { + $this->aggregates = $aggregates; + } +}