-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
245 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/Handler/DeeplGlossariesListRetrievalRequestHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Scn\DeeplApiConnector\Handler; | ||
|
||
use Psr\Http\Message\StreamFactoryInterface; | ||
use Psr\Http\Message\StreamInterface; | ||
|
||
final class DeeplGlossariesListRetrievalRequestHandler implements DeeplRequestHandlerInterface | ||
{ | ||
public const API_ENDPOINT = '/v2/glossaries'; | ||
|
||
private string $authKey; | ||
|
||
private StreamFactoryInterface $streamFactory; | ||
|
||
public function __construct( | ||
string $authKey, | ||
StreamFactoryInterface $streamFactory | ||
) { | ||
$this->authKey = $authKey; | ||
$this->streamFactory = $streamFactory; | ||
} | ||
|
||
public function getMethod(): string | ||
{ | ||
return DeeplRequestHandlerInterface::METHOD_GET; | ||
} | ||
|
||
public function getPath(): string | ||
{ | ||
return static::API_ENDPOINT; | ||
} | ||
|
||
public function getBody(): StreamInterface | ||
{ | ||
return $this->streamFactory->createStream( | ||
http_build_query( | ||
array_filter( | ||
[ | ||
'auth_key' => $this->authKey, | ||
] | ||
) | ||
) | ||
); | ||
} | ||
|
||
public function getContentType(): string | ||
{ | ||
return 'application/x-www-form-urlencoded'; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/Handler/DeeplGlossariesSupportedLanguagesPairsRetrievalRequestHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Scn\DeeplApiConnector\Handler; | ||
|
||
use Psr\Http\Message\StreamFactoryInterface; | ||
use Psr\Http\Message\StreamInterface; | ||
|
||
final class DeeplGlossariesSupportedLanguagesPairsRetrievalRequestHandler implements DeeplRequestHandlerInterface | ||
{ | ||
public const API_ENDPOINT = '/v2/glossary-language-pairs'; | ||
|
||
private string $authKey; | ||
|
||
private StreamFactoryInterface $streamFactory; | ||
|
||
public function __construct( | ||
string $authKey, | ||
StreamFactoryInterface $streamFactory | ||
) { | ||
$this->authKey = $authKey; | ||
$this->streamFactory = $streamFactory; | ||
} | ||
|
||
public function getMethod(): string | ||
{ | ||
return DeeplRequestHandlerInterface::METHOD_GET; | ||
} | ||
|
||
public function getPath(): string | ||
{ | ||
return static::API_ENDPOINT; | ||
} | ||
|
||
public function getBody(): StreamInterface | ||
{ | ||
return $this->streamFactory->createStream( | ||
http_build_query( | ||
array_filter( | ||
[ | ||
'auth_key' => $this->authKey, | ||
] | ||
) | ||
) | ||
); | ||
} | ||
|
||
public function getContentType(): string | ||
{ | ||
return 'application/x-www-form-urlencoded'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Scn\DeeplApiConnector\Model; | ||
|
||
use DateTimeImmutable; | ||
use stdClass; | ||
|
||
final class GlossariesList extends AbstractResponseModel implements GlossariesListInterface | ||
{ | ||
/** @var array<stdClass> */ | ||
private array $list; | ||
|
||
public function hydrate(stdClass $responseModel): ResponseModelInterface | ||
{ | ||
$this->list = $responseModel->content->supported_languages; | ||
|
||
return $this; | ||
} | ||
|
||
public function getList(): array | ||
{ | ||
return array_map( | ||
fn (stdClass $item): array => [ | ||
'glossary_id' => $item->glossary_id, | ||
'name' => $item->name, | ||
'ready' => $item->ready, | ||
'source_lang' => $item->source_lang, | ||
'target_lang' => $item->target_lang, | ||
'creation_time' => new DateTimeImmutable($item->creation_time), | ||
'entry_count' => $item->entry_count, | ||
], | ||
$this->list | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
namespace Scn\DeeplApiConnector\Model; | ||
|
||
interface GlossariesListInterfaces | ||
{ | ||
/** | ||
* @return array<array{ | ||
* glossary_id: string, | ||
* name: string, | ||
* ready: boolean, | ||
* source_lang: string, | ||
* target_lang: string, | ||
* creation_time: DateTimeImmutable, | ||
* entry_count: int | ||
* }> | ||
*/ | ||
public function getList(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Scn\DeeplApiConnector\Model; | ||
|
||
use stdClass; | ||
|
||
final class GlossariesSupportedLanguagesPairs extends AbstractResponseModel implements GlossariesSupportedLanguagesPairsInterface | ||
{ | ||
/** @var array<stdClass> */ | ||
private array $list; | ||
|
||
public function hydrate(stdClass $responseModel): ResponseModelInterface | ||
{ | ||
$this->list = $responseModel->content->supported_languages; | ||
|
||
return $this; | ||
} | ||
|
||
public function getList(): array | ||
{ | ||
return array_map( | ||
fn (stdClass $item): array => [ | ||
'source_lang' => $item->source_lang, | ||
'target_lang' => $item->target_lang, | ||
], | ||
$this->list | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
namespace Scn\DeeplApiConnector\Model; | ||
|
||
interface GlossariesSupportedLanguagesPairsInterfaces | ||
{ | ||
/** | ||
* @return array<array{ | ||
* source_lang: string, | ||
* target_lang: string | ||
* }> | ||
*/ | ||
public function getList(): array; | ||
} |