From f71b0370fdcf189dc2d9c49761e5038aaaa3ba0f Mon Sep 17 00:00:00 2001 From: Arkadius Jonczek Date: Sun, 19 Jul 2020 23:43:20 +0200 Subject: [PATCH] use API v2 as default "Version 1 (v1) of the DeepL API is not supported by the DeepL API plan available from October 2018. Please use version 2 for all new products other than CAT tool integrations." from https://www.deepl.com/docs-api/accessing-the-api/api-versions/ --- src/DeepL.php | 4 ++-- tests/DeepLTest.php | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/DeepL.php b/src/DeepL.php index d147945..1bb0cd5 100644 --- a/src/DeepL.php +++ b/src/DeepL.php @@ -132,7 +132,7 @@ class DeepL * @param string $authKey * @param integer $apiVersion */ - public function __construct($authKey, $apiVersion = 1) + public function __construct($authKey, $apiVersion = 2) { $this->authKey = $authKey; $this->apiVersion = $apiVersion; @@ -251,7 +251,7 @@ protected function buildUrl( $url = DeepL::API_URL_V2; break; default: - $url = DeepL::API_URL_V1; + $url = DeepL::API_URL_V2; } $url .= '?' . sprintf(DeepL::API_URL_AUTH_KEY, $this->authKey); diff --git a/tests/DeepLTest.php b/tests/DeepLTest.php index 2bda4a2..a4a6041 100644 --- a/tests/DeepLTest.php +++ b/tests/DeepLTest.php @@ -106,7 +106,7 @@ public function testBuildUrl() { $authKey = '123456'; - $expectedString = 'https://api.deepl.com/v1/translate?' . http_build_query(array( + $expectedString = 'https://api.deepl.com/v2/translate?' . http_build_query(array( 'auth_key' => $authKey, 'source_lang' => 'de', 'target_lang' => 'en', @@ -128,7 +128,7 @@ public function testBuildUrl() public function testBuildUrlWithTags() { $authKey = '123456'; - $expectedString = 'https://api.deepl.com/v1/translate?' . http_build_query(array( + $expectedString = 'https://api.deepl.com/v2/translate?' . http_build_query(array( 'auth_key' => $authKey, 'source_lang' => 'de', 'target_lang' => 'en', @@ -164,7 +164,7 @@ public function testBuildBody() } /** - * Test translate() success + * Test translate() success with v2 API * * TEST REQUIRES VALID DEEPL AUTH KEY!! */ @@ -185,17 +185,17 @@ public function testTranslateSuccess() } /** - * Test translate() success with v2 API + * Test translate() success with v1 API * * TEST REQUIRES VALID DEEPL AUTH KEY!! */ - public function testTranslateV2Success() + public function testTranslateV1Success() { if (self::$authKey === false) { $this->markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.'); } - $deepl = new DeepL(self::$authKey, 2); + $deepl = new DeepL(self::$authKey, 1); $germanText = 'Hallo Welt'; $expectedText = 'Hello World';