From 414650b079dcec86ada225599e73092177e2d8e5 Mon Sep 17 00:00:00 2001 From: Oleksandr Mykhailenko Date: Thu, 21 Jul 2022 21:58:53 +0300 Subject: [PATCH 1/2] Fix issue with overwrite API version Signed-off-by: Alexander Mykhailenko --- src/Mailjet/Client.php | 7 +++++-- test/Mailjet/MailjetApiv3Test.php | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Mailjet/Client.php b/src/Mailjet/Client.php index a18d263..3303247 100644 --- a/src/Mailjet/Client.php +++ b/src/Mailjet/Client.php @@ -377,8 +377,11 @@ private function buildURL(string $resource, string $action, string $id, string $ */ private function setOptions(array $options, array $resource): void { - $this->version = (string) ($options['version'] ?? $resource[2] ?? Config::MAIN_VERSION); - $this->url = (string) ($options['url'] ?? Config::MAIN_URL); + if (isset($options['version'])) { + $this->version = $options['version']; + } + + $this->url = (string)($options['url'] ?? Config::MAIN_URL); $this->secure = $options['secured'] ?? Config::SECURED; $this->call = $options['call'] ?? true; $this->changed = true; diff --git a/test/Mailjet/MailjetApiv3Test.php b/test/Mailjet/MailjetApiv3Test.php index b804b5b..8744260 100644 --- a/test/Mailjet/MailjetApiv3Test.php +++ b/test/Mailjet/MailjetApiv3Test.php @@ -102,7 +102,7 @@ public function testPost() public function testPostV31() { - $client = new Client($this->publicKey, $this->secretKey, false); + $client = new Client($this->publicKey, $this->secretKey, false, ['version' => 'v3.1']); $email = [ 'Messages' => [[ @@ -112,7 +112,7 @@ public function testPostV31() ]], ]; - $ret = $client->post(Resources::$Email, ['body' => $email], ['version' => 'v3.1']); + $ret = $client->post(Resources::$Email, ['body' => $email], ['timeout' => 1]); $this->assertUrl('/send', $ret, 'v3.1'); $this->assertPayload($email, $ret); $this->assertHttpMethod('POST', $ret); From 0d85fc35416c8b1c31ffcba75848b0d2b5f0a10b Mon Sep 17 00:00:00 2001 From: Alexander Mykhailenko Date: Thu, 21 Jul 2022 22:02:13 +0300 Subject: [PATCH 2/2] Fix issue with overwrite API version Signed-off-by: Alexander Mykhailenko --- src/Mailjet/Client.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Mailjet/Client.php b/src/Mailjet/Client.php index 3303247..4bc27e1 100644 --- a/src/Mailjet/Client.php +++ b/src/Mailjet/Client.php @@ -379,6 +379,8 @@ private function setOptions(array $options, array $resource): void { if (isset($options['version'])) { $this->version = $options['version']; + } else if (isset($resource[2])) { + $this->version = $resource[2]; } $this->url = (string)($options['url'] ?? Config::MAIN_URL);