From 2f6f7aa14a04c0f4817db102b169d890a29f6f95 Mon Sep 17 00:00:00 2001 From: Oleksandr Mykhailenko Date: Thu, 7 Mar 2024 22:22:48 +0200 Subject: [PATCH 1/3] Add dependabot. Change php-cs-fixer --- .github/workflows/dependabot.yml | 7 +++++++ .github/workflows/php.yml | 5 ----- .php-cs-fixer.php | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/dependabot.yml diff --git a/.github/workflows/dependabot.yml b/.github/workflows/dependabot.yml new file mode 100644 index 00000000..332d43f8 --- /dev/null +++ b/.github/workflows/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: +- package-ecosystem: composer + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 3 diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index a4aab629..9272130c 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -23,11 +23,6 @@ jobs: php-version: ${{ matrix.php-versions }} tools: none - #- name: Install composer dependencies - # uses: ramsey/composer-install@v2 - # with: - # dependency-versions: ${{ matrix.dependency-versions }} - - name: Install dependencies run: composer install --prefer-dist --no-progress --no-suggest diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 133e4fed..2463084f 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -16,7 +16,8 @@ ->setRiskyAllowed(true) ->setRules([ '@PSR2' => true, - '@Symfony' => true, + '@PSR12' => true, + '@Symfony' => false, 'strict_param' => true, 'array_syntax' => ['syntax' => 'short'], 'declare_strict_types' => true, From ba84fc47dde9cebff9c4b3dcb6c17d071833c9bc Mon Sep 17 00:00:00 2001 From: Oleksandr Mykhailenko Date: Mon, 22 Apr 2024 14:14:27 +0300 Subject: [PATCH 2/3] Add missing API Endpoints. In Progress --- src/Api/Ip.php | 94 +++++++++++++++++++++++---- src/Model/Ip/AvailableIpsResponse.php | 62 ++++++++++++++++++ 2 files changed, 144 insertions(+), 12 deletions(-) create mode 100644 src/Model/Ip/AvailableIpsResponse.php diff --git a/src/Api/Ip.php b/src/Api/Ip.php index 6ac31573..69440d9a 100644 --- a/src/Api/Ip.php +++ b/src/Api/Ip.php @@ -11,7 +11,9 @@ namespace Mailgun\Api; +use Exception; use Mailgun\Assert; +use Mailgun\Model\Ip\AvailableIpsResponse; use Mailgun\Model\Ip\IndexResponse; use Mailgun\Model\Ip\ShowResponse; use Mailgun\Model\Ip\UpdateResponse; @@ -27,10 +29,11 @@ class Ip extends HttpApi { /** * Returns a list of IPs. - * @param bool|null $dedicated - * @param array $requestHeaders + * @param bool|null $dedicated + * @param array $requestHeaders * @return IndexResponse|ResponseInterface * @throws ClientExceptionInterface + * @throws Exception */ public function index(?bool $dedicated = null, array $requestHeaders = []) { @@ -47,10 +50,11 @@ public function index(?bool $dedicated = null, array $requestHeaders = []) /** * Returns a list of IPs assigned to a domain. - * @param string $domain - * @param array $requestHeaders + * @param string $domain + * @param array $requestHeaders * @return IndexResponse|ResponseInterface * @throws ClientExceptionInterface + * @throws Exception */ public function domainIndex(string $domain, array $requestHeaders = []) { @@ -63,10 +67,11 @@ public function domainIndex(string $domain, array $requestHeaders = []) /** * Returns a single ip. - * @param string $ip - * @param array $requestHeaders + * @param string $ip + * @param array $requestHeaders * @return ShowResponse|ResponseInterface * @throws ClientExceptionInterface + * @throws Exception */ public function show(string $ip, array $requestHeaders = []) { @@ -79,11 +84,12 @@ public function show(string $ip, array $requestHeaders = []) /** * Assign a dedicated IP to the domain specified. - * @param string $domain - * @param string $ip - * @param array $requestHeaders + * @param string $domain + * @param string $ip + * @param array $requestHeaders * @return UpdateResponse|ResponseInterface * @throws ClientExceptionInterface + * @throws Exception */ public function assign(string $domain, string $ip, array $requestHeaders = []) { @@ -101,11 +107,12 @@ public function assign(string $domain, string $ip, array $requestHeaders = []) /** * Unassign an IP from the domain specified. - * @param string $domain - * @param string $ip - * @param array $requestHeaders + * @param string $domain + * @param string $ip + * @param array $requestHeaders * @return UpdateResponse|ResponseInterface * @throws ClientExceptionInterface + * @throws Exception */ public function unassign(string $domain, string $ip, array $requestHeaders = []) { @@ -116,4 +123,67 @@ public function unassign(string $domain, string $ip, array $requestHeaders = []) return $this->hydrateResponse($response, UpdateResponse::class); } + + /** + * Get all domains of an account where a specific IP is assigned + * @param string $ip + * @param int $limit + * @param int $skip + * @param string|null $search + * @param array $requestHeaders + * @return IndexResponse|ResponseInterface + * @throws ClientExceptionInterface + * @throws Exception + */ + public function domainsByIp(string $ip, int $limit = 10, int $skip = 0, ?string $search = null, array $requestHeaders = []) + { + Assert::stringNotEmpty($ip); + + $params = [ + 'limit' => $limit, + 'skip' => $skip, + ]; + if (null !== $search) { + $params['search'] = $search; + } + + $response = $this->httpGet(sprintf('/v3/ips/%s/domains', $ip), $params, $requestHeaders); + + return $this->hydrateResponse($response, IndexResponse::class); + } + + /** + * Place account IP into a dedicated IP band + * @param string $ip + * @param array $requestHeaders + * @return UpdateResponse|ResponseInterface + * @throws ClientExceptionInterface + * @throws Exception + */ + public function placeAccountIpToBand(string $ip, array $requestHeaders = []) + { + Assert::stringNotEmpty($ip); + Assert::ip($ip); + + $payload = [ + 'ip_band' => $ip, + ]; + + $response = $this->httpPost(sprintf('/v3/ips/%s/ip_band', $ip), $payload, $requestHeaders); + + return $this->hydrateResponse($response, UpdateResponse::class); + } + + /** + * Return the number of IPs available to the account per its billing plan + * @param array $requestHeaders + * @return AvailableIpsResponse|ResponseInterface + * @throws ClientExceptionInterface + */ + public function numberOfIps(array $requestHeaders = []) + { + $response = $this->httpGet('v3/ips/request/new', [], $requestHeaders); + + return $this->hydrateResponse($response, AvailableIpsResponse::class); + } } diff --git a/src/Model/Ip/AvailableIpsResponse.php b/src/Model/Ip/AvailableIpsResponse.php new file mode 100644 index 00000000..a2f69141 --- /dev/null +++ b/src/Model/Ip/AvailableIpsResponse.php @@ -0,0 +1,62 @@ + + */ +final class AvailableIpsResponse implements ApiResponse +{ + /** + * @var int + */ + private $dedicated; + + /** + * @var int + */ + private $shared; + + private function __construct() + { + } + + /** + * @param array $data + * @return AvailableIpsResponse + */ + public static function create(array $data) + { + $model = new self(); + $model->dedicated = $data['allowed']['dedicated'] ?? 0; + $model->shared = $data['allowed']['shared'] ?? 0; + return $model; + } + + /** + * @return int + */ + public function getDedicated(): int + { + return $this->dedicated; + } + + /** + * @return int + */ + public function getShared(): int + { + return $this->shared; + } +} From 01e71dc2f782eab44efd96a454b1ebeaddbac071 Mon Sep 17 00:00:00 2001 From: Oleksandr Mykhailenko Date: Mon, 22 Apr 2024 14:37:16 +0300 Subject: [PATCH 3/3] More endpoints --- src/Api/Ip.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Api/Ip.php b/src/Api/Ip.php index 69440d9a..c85a20b2 100644 --- a/src/Api/Ip.php +++ b/src/Api/Ip.php @@ -179,6 +179,7 @@ public function placeAccountIpToBand(string $ip, array $requestHeaders = []) * @param array $requestHeaders * @return AvailableIpsResponse|ResponseInterface * @throws ClientExceptionInterface + * @throws Exception */ public function numberOfIps(array $requestHeaders = []) { @@ -186,4 +187,37 @@ public function numberOfIps(array $requestHeaders = []) return $this->hydrateResponse($response, AvailableIpsResponse::class); } + + /** + * Add a new dedicated IP to the account + * @param array $requestHeaders + * @return UpdateResponse|ResponseInterface + * @throws ClientExceptionInterface + * @throws Exception + */ + public function addDedicatedIp(array $requestHeaders = []) + { + $response = $this->httpPost('v3/ips/request/new', [], $requestHeaders); + + return $this->hydrateResponse($response, UpdateResponse::class); + } + + /** + * Remove an IP from the domain pool, unlink a DIPP or remove the domain pool + * @param string $domain + * @param string $ip + * @param array $requestHeaders + * @return UpdateResponse|ResponseInterface + * @throws ClientExceptionInterface + * @throws Exception + */ + public function removeIpOrUnlink(string $domain, string $ip, array $requestHeaders = []) + { + Assert::stringNotEmpty($domain); + Assert::ip($ip); + + $response = $this->httpDelete(sprintf('/v3/domains/%s/pool/%s', $domain, $ip), [], $requestHeaders); + + return $this->hydrateResponse($response, UpdateResponse::class); + } }