Skip to content

Commit

Permalink
added endpoint for getting one template
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-mykhailenko committed Feb 27, 2024
1 parent 20c9895 commit aa923e2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
18 changes: 18 additions & 0 deletions src/Api/Templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Mailgun\Assert;
use Mailgun\Model\Domain\CreateResponse;
use Mailgun\Model\Templates\GetResponse;
use Mailgun\Model\Templates\ShowResponse;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Message\ResponseInterface;

Expand Down Expand Up @@ -55,6 +56,23 @@ public function get(string $domain, int $limit, string $page, string $pivot, arr
return $this->hydrateResponse($response, GetResponse::class);
}

/**
* @param string $domain
* @param string $templateId
* @param array $requestHeaders
* @return mixed|ResponseInterface
* @throws ClientExceptionInterface
*/
public function show(string $domain, string $templateId, array $requestHeaders = [])
{
Assert::notEmpty($domain);
Assert::notEmpty($templateId);

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

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



/**
Expand Down
21 changes: 21 additions & 0 deletions src/Model/Templates/ShowResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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\Templates;

use Mailgun\Model\ApiResponse;

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
final class ShowResponse extends Template implements ApiResponse
{
}
11 changes: 6 additions & 5 deletions src/Model/Templates/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ private function __construct()
*/
public static function create(array $data): self
{
$template = $data['template'] ?? $data;
$model = new self();

$model->setId($data['id']);
$model->setName($data['name']);
$model->setDescription($data['description'] ?? '');
$model->setCreatedAt($data['createdAt'] ?? '');
$model->setCreatedBy($data['createdBy'] ?? '');
$model->setId($template['id']);
$model->setName($template['name']);
$model->setDescription($template['description'] ?? '');
$model->setCreatedAt($template['createdAt'] ?? '');
$model->setCreatedBy($template['createdBy'] ?? '');

return $model;

Check failure on line 49 in src/Model/Templates/Template.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Mailgun\Model\Templates\Template::create() should return static(Mailgun\Model\Templates\Template) but returns Mailgun\Model\Templates\Template.

Check failure on line 49 in src/Model/Templates/Template.php

View workflow job for this annotation

GitHub Actions / Psalm

The type 'Mailgun\Model\Templates\Template' is more general than the declared return type 'Mailgun\Model\Templates\Template&static' for Mailgun\Model\Templates\Template::create (see https://psalm.dev/129)
}
Expand Down

0 comments on commit aa923e2

Please sign in to comment.