diff --git a/src/CrowdinApiClient/Api/BranchApi.php b/src/CrowdinApiClient/Api/BranchApi.php index b4083b04..35f4f24f 100644 --- a/src/CrowdinApiClient/Api/BranchApi.php +++ b/src/CrowdinApiClient/Api/BranchApi.php @@ -35,6 +35,24 @@ public function list(int $projectId, array $params = []): ModelCollection return $this->_list($path, Branch::class, $params); } + /** + * Search Branches + * @link https://developer.crowdin.com/api/v2/#operation/api.branches.getMany API Documentation + * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.branches.getMany API Documentation Enterprise + * + * @param array $params + * string $params[filter] required, max 128 characters
+ * string $params[projectIds] Comma-separated project identifiers, max 50 projects
+ * integer $params[userId] Crowdin API only
+ * integer $params[limit]
+ * integer $params[offset] + * @return ModelCollection + */ + public function search(array $params = []): ModelCollection + { + return $this->_list('branches', Branch::class, $params); + } + /** * Get Branch Info * @link https://developer.crowdin.com/api/v2/#operation/api.projects.branches.get API Documentation diff --git a/src/CrowdinApiClient/Api/DirectoryApi.php b/src/CrowdinApiClient/Api/DirectoryApi.php index c3e6d2e0..fe2cf141 100644 --- a/src/CrowdinApiClient/Api/DirectoryApi.php +++ b/src/CrowdinApiClient/Api/DirectoryApi.php @@ -32,6 +32,24 @@ public function list(int $projectId, array $params = []): ModelCollection return $this->_list($path, Directory::class, $params); } + /** + * Search Directories + * @link https://developer.crowdin.com/api/v2/#operation/api.directories.getMany API Documentation + * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.directories.getMany API Documentation Enterprise + * + * @param array $params + * string $params[filter] required, max 128 characters
+ * string $params[projectIds] Comma-separated project identifiers, max 50 projects
+ * integer $params[userId] Crowdin API only
+ * integer $params[limit]
+ * integer $params[offset] + * @return ModelCollection + */ + public function search(array $params = []): ModelCollection + { + return $this->_list('directories', Directory::class, $params); + } + /** * Get Directory Info * @link https://developer.crowdin.com/api/v2/#operation/api.projects.directories.get API Documentation diff --git a/src/CrowdinApiClient/Api/FileApi.php b/src/CrowdinApiClient/Api/FileApi.php index 8b291f0c..bfb89674 100644 --- a/src/CrowdinApiClient/Api/FileApi.php +++ b/src/CrowdinApiClient/Api/FileApi.php @@ -36,6 +36,24 @@ public function list(int $projectId, array $params = []): ModelCollection return $this->_list($path, File::class, $params); } + /** + * Search Files + * @link https://developer.crowdin.com/api/v2/#operation/api.files.getMany API Documentation + * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.files.getMany API Documentation Enterprise + * + * @param array $params + * string $params[filter] required, max 128 characters
+ * string $params[projectIds] Comma-separated project identifiers, max 50 projects
+ * integer $params[userId] Crowdin API only
+ * integer $params[limit]
+ * integer $params[offset] + * @return ModelCollection + */ + public function search(array $params = []): ModelCollection + { + return $this->_list('files', File::class, $params); + } + /** * Add File * @link https://developer.crowdin.com/api/v2/#operation/api.projects.files.post API Documentation diff --git a/src/CrowdinApiClient/Api/SourceStringApi.php b/src/CrowdinApiClient/Api/SourceStringApi.php index a951b312..5c4d5c42 100644 --- a/src/CrowdinApiClient/Api/SourceStringApi.php +++ b/src/CrowdinApiClient/Api/SourceStringApi.php @@ -29,6 +29,26 @@ public function list(int $projectId, array $params = []): ModelCollection return $this->_list($path, SourceString::class, $params); } + /** + * Search Strings + * @link https://developer.crowdin.com/api/v2/#operation/api.strings.getMany API Documentation + * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.strings.getMany API Documentation Enterprise + * + * @param array $params + * string $params[filter] required, max 128 characters
+ * string $params[projectIds] Comma-separated project identifiers, max 50 projects
+ * integer $params[userId] Crowdin API only
+ * string $params[scope] Enum: "all" "text" "context" "key", default: "all"
+ * integer $params[denormalizePlaceholders] Enum: 0 1
+ * integer $params[limit]
+ * integer $params[offset] + * @return ModelCollection + */ + public function search(array $params = []): ModelCollection + { + return $this->_list('strings', SourceString::class, $params); + } + /** * Get String * @link https://developer.crowdin.com/api/v2/#operation/api.projects.strings.get API Documentation diff --git a/src/CrowdinApiClient/Api/StringTranslationApi.php b/src/CrowdinApiClient/Api/StringTranslationApi.php index ace80f6f..90c2fede 100644 --- a/src/CrowdinApiClient/Api/StringTranslationApi.php +++ b/src/CrowdinApiClient/Api/StringTranslationApi.php @@ -142,6 +142,26 @@ public function list(int $projectId, array $params = []): ModelCollection return $this->_list($path, StringTranslation::class, $params); } + /** + * Search Translations + * @link https://developer.crowdin.com/api/v2/#operation/api.translations.getMany API Documentation + * @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.translations.getMany API Documentation Enterprise + * + * @param array $params + * string $params[filter] required, max 128 characters
+ * string $params[projectIds] Comma-separated project identifiers, max 50 projects
+ * integer $params[userId] Crowdin API only
+ * string $params[languageIds] Comma-separated language identifiers
+ * integer $params[denormalizePlaceholders] Enum: 0 1
+ * integer $params[limit]
+ * integer $params[offset] + * @return ModelCollection + */ + public function search(array $params = []): ModelCollection + { + return $this->_list('translations', StringTranslation::class, $params); + } + /** * Add Translation * @link https://developer.crowdin.com/api/v2/#operation/api.projects.translations.add API Documentation diff --git a/src/CrowdinApiClient/Model/StringTranslation.php b/src/CrowdinApiClient/Model/StringTranslation.php index 04196b62..e7d0921d 100644 --- a/src/CrowdinApiClient/Model/StringTranslation.php +++ b/src/CrowdinApiClient/Model/StringTranslation.php @@ -12,6 +12,21 @@ class StringTranslation extends BaseModel */ protected $id; + /** + * @var integer|null + */ + protected $projectId; + + /** + * @var integer|null + */ + protected $stringId; + + /** + * @var string|null + */ + protected $languageId; + /** * @var string */ @@ -42,6 +57,15 @@ public function __construct(array $data = []) parent::__construct($data); $this->id = (int)$this->getDataProperty('id'); + $this->projectId = $this->getDataProperty('projectId') !== null + ? (int)$this->getDataProperty('projectId') + : null; + $this->stringId = $this->getDataProperty('stringId') !== null + ? (int)$this->getDataProperty('stringId') + : null; + $this->languageId = $this->getDataProperty('languageId') !== null + ? (string)$this->getDataProperty('languageId') + : null; $this->text = (string)$this->getDataProperty('text'); $this->pluralCategoryName = (string)$this->getDataProperty('pluralCategoryName'); $this->user = (array)$this->getDataProperty('user'); @@ -64,6 +88,30 @@ public function setId(int $id): void $this->id = $id; } + /** + * @return int|null + */ + public function getProjectId(): ?int + { + return $this->projectId; + } + + /** + * @return int|null + */ + public function getStringId(): ?int + { + return $this->stringId; + } + + /** + * @return string|null + */ + public function getLanguageId(): ?string + { + return $this->languageId; + } + /** * @return string */ diff --git a/tests/CrowdinApiClient/Api/BranchApiTest.php b/tests/CrowdinApiClient/Api/BranchApiTest.php index 47d0b14d..0e67d67c 100644 --- a/tests/CrowdinApiClient/Api/BranchApiTest.php +++ b/tests/CrowdinApiClient/Api/BranchApiTest.php @@ -59,6 +59,46 @@ public function testList() $this->assertEquals('2019-09-19T13:25:27+00:00', $branchModel->getUpdatedAt()); } + public function testSearch(): void + { + $this->mockRequest([ + 'path' => '/branches?filter=master&projectIds=2%2C3&userId=6&limit=10&offset=20', + 'method' => 'get', + 'response' => json_encode([ + 'data' => [ + [ + 'data' => [ + 'id' => 34, + 'projectId' => 2, + 'name' => 'develop-master', + 'title' => 'Master branch', + ], + ], + ], + 'pagination' => [ + [ + 'offset' => 20, + 'limit' => 10, + ], + ], + ]), + ]); + + $branches = $this->crowdin->branch->search([ + 'filter' => 'master', + 'projectIds' => '2,3', + 'userId' => 6, + 'limit' => 10, + 'offset' => 20, + ]); + + $this->assertInstanceOf(ModelCollection::class, $branches); + $this->assertCount(1, $branches); + $this->assertInstanceOf(Branch::class, $branches[0]); + $this->assertEquals(34, $branches[0]->getId()); + $this->assertEquals(2, $branches[0]->getProjectId()); + } + public function testGet() { $this->mockRequestGet('/projects/2/branches/34', diff --git a/tests/CrowdinApiClient/Api/DirectoryApiTest.php b/tests/CrowdinApiClient/Api/DirectoryApiTest.php index 95695f47..ba425015 100644 --- a/tests/CrowdinApiClient/Api/DirectoryApiTest.php +++ b/tests/CrowdinApiClient/Api/DirectoryApiTest.php @@ -46,6 +46,48 @@ public function testList() $this->assertEquals(4, $directories[0]->getId()); } + public function testSearch(): void + { + $this->mockRequest([ + 'path' => '/directories?filter=main&projectIds=2%2C3&userId=6&limit=10&offset=20', + 'method' => 'get', + 'response' => json_encode([ + 'data' => [ + [ + 'data' => [ + 'id' => 4, + 'projectId' => 2, + 'branchId' => 34, + 'directoryId' => 0, + 'name' => 'main', + 'title' => '', + ], + ], + ], + 'pagination' => [ + [ + 'offset' => 20, + 'limit' => 10, + ], + ], + ]), + ]); + + $directories = $this->crowdin->directory->search([ + 'filter' => 'main', + 'projectIds' => '2,3', + 'userId' => 6, + 'limit' => 10, + 'offset' => 20, + ]); + + $this->assertInstanceOf(ModelCollection::class, $directories); + $this->assertCount(1, $directories); + $this->assertInstanceOf(Directory::class, $directories[0]); + $this->assertEquals(4, $directories[0]->getId()); + $this->assertEquals(2, $directories[0]->getProjectId()); + } + public function testGetAndUpdate() { $this->mockRequestGet('/projects/2/directories/34', '{ diff --git a/tests/CrowdinApiClient/Api/Enterprise/OrganizationSearchApiTest.php b/tests/CrowdinApiClient/Api/Enterprise/OrganizationSearchApiTest.php new file mode 100644 index 00000000..a4f84772 --- /dev/null +++ b/tests/CrowdinApiClient/Api/Enterprise/OrganizationSearchApiTest.php @@ -0,0 +1,130 @@ +mockRequest([ + 'path' => '/branches?filter=master', + 'method' => 'get', + 'response' => json_encode([ + 'data' => [ + [ + 'data' => [ + 'id' => 34, + 'projectId' => 2, + ], + ], + ], + ]), + ]); + + $branches = $this->crowdin->branch->search(['filter' => 'master']); + + $this->assertInstanceOf(ModelCollection::class, $branches); + $this->assertInstanceOf(Branch::class, $branches[0]); + } + + public function testSearchDirectories(): void + { + $this->mockRequest([ + 'path' => '/directories?filter=main', + 'method' => 'get', + 'response' => json_encode([ + 'data' => [ + [ + 'data' => [ + 'id' => 4, + 'projectId' => 2, + ], + ], + ], + ]), + ]); + + $directories = $this->crowdin->directory->search(['filter' => 'main']); + + $this->assertInstanceOf(ModelCollection::class, $directories); + $this->assertInstanceOf(Directory::class, $directories[0]); + } + + public function testSearchFiles(): void + { + $this->mockRequest([ + 'path' => '/files?filter=source', + 'method' => 'get', + 'response' => json_encode([ + 'data' => [ + [ + 'data' => [ + 'id' => 44, + 'projectId' => 2, + ], + ], + ], + ]), + ]); + + $files = $this->crowdin->file->search(['filter' => 'source']); + + $this->assertInstanceOf(ModelCollection::class, $files); + $this->assertInstanceOf(File::class, $files[0]); + } + + public function testSearchStrings(): void + { + $this->mockRequest([ + 'path' => '/strings?filter=hello', + 'method' => 'get', + 'response' => json_encode([ + 'data' => [ + [ + 'data' => [ + 'id' => 2814, + 'projectId' => 2, + ], + ], + ], + ]), + ]); + + $sourceStrings = $this->crowdin->sourceString->search(['filter' => 'hello']); + + $this->assertInstanceOf(ModelCollection::class, $sourceStrings); + $this->assertInstanceOf(SourceString::class, $sourceStrings[0]); + } + + public function testSearchTranslations(): void + { + $this->mockRequest([ + 'path' => '/translations?filter=translated', + 'method' => 'get', + 'response' => json_encode([ + 'data' => [ + [ + 'data' => [ + 'id' => 190695, + 'projectId' => 2, + 'stringId' => 2814, + 'languageId' => 'uk', + ], + ], + ], + ]), + ]); + + $stringTranslations = $this->crowdin->stringTranslation->search(['filter' => 'translated']); + + $this->assertInstanceOf(ModelCollection::class, $stringTranslations); + $this->assertInstanceOf(StringTranslation::class, $stringTranslations[0]); + } +} diff --git a/tests/CrowdinApiClient/Api/FileApiTest.php b/tests/CrowdinApiClient/Api/FileApiTest.php index 6deafe93..f1a123ba 100644 --- a/tests/CrowdinApiClient/Api/FileApiTest.php +++ b/tests/CrowdinApiClient/Api/FileApiTest.php @@ -65,6 +65,50 @@ public function testList(): void $this->assertEquals(44, $files[0]->getId()); } + public function testSearch(): void + { + $this->mockRequest([ + 'path' => '/files?filter=source&projectIds=2%2C3&userId=6&limit=10&offset=20', + 'method' => 'get', + 'response' => json_encode([ + 'data' => [ + [ + 'data' => [ + 'id' => 44, + 'projectId' => 2, + 'branchId' => 34, + 'directoryId' => 4, + 'name' => 'source.json', + 'title' => 'Source file', + 'path' => '/source.json', + 'status' => 'active', + ], + ], + ], + 'pagination' => [ + [ + 'offset' => 20, + 'limit' => 10, + ], + ], + ]), + ]); + + $files = $this->crowdin->file->search([ + 'filter' => 'source', + 'projectIds' => '2,3', + 'userId' => 6, + 'limit' => 10, + 'offset' => 20, + ]); + + $this->assertInstanceOf(ModelCollection::class, $files); + $this->assertCount(1, $files); + $this->assertInstanceOf(File::class, $files[0]); + $this->assertEquals(44, $files[0]->getId()); + $this->assertEquals(2, $files[0]->getProjectId()); + } + public function testGetAndEdit(): void { $this->mockRequestGet( diff --git a/tests/CrowdinApiClient/Api/SourceStringApiTest.php b/tests/CrowdinApiClient/Api/SourceStringApiTest.php index c7633f99..64b9b4ee 100644 --- a/tests/CrowdinApiClient/Api/SourceStringApiTest.php +++ b/tests/CrowdinApiClient/Api/SourceStringApiTest.php @@ -53,6 +53,52 @@ public function testList() $this->assertEquals(12, $sourceStrings[0]->getBranchId()); } + public function testSearch(): void + { + $this->mockRequest([ + 'path' => '/strings?filter=hello&projectIds=2%2C3&userId=6&scope=text&denormalizePlaceholders=1&limit=10&offset=20', + 'method' => 'get', + 'response' => json_encode([ + 'data' => [ + [ + 'data' => [ + 'id' => 2814, + 'projectId' => 2, + 'fileId' => 48, + 'branchId' => 12, + 'identifier' => 'greeting', + 'text' => 'Hello', + 'type' => 'text', + 'context' => 'welcome message', + ], + ], + ], + 'pagination' => [ + [ + 'offset' => 20, + 'limit' => 10, + ], + ], + ]), + ]); + + $sourceStrings = $this->crowdin->sourceString->search([ + 'filter' => 'hello', + 'projectIds' => '2,3', + 'userId' => 6, + 'scope' => 'text', + 'denormalizePlaceholders' => 1, + 'limit' => 10, + 'offset' => 20, + ]); + + $this->assertInstanceOf(ModelCollection::class, $sourceStrings); + $this->assertCount(1, $sourceStrings); + $this->assertInstanceOf(SourceString::class, $sourceStrings[0]); + $this->assertEquals(2814, $sourceStrings[0]->getId()); + $this->assertEquals(2, $sourceStrings[0]->getProjectId()); + } + public function testGetAndUpdate() { $this->mockRequestGet('/projects/2/strings/2814', '{ diff --git a/tests/CrowdinApiClient/Api/StringTranslationApiTest.php b/tests/CrowdinApiClient/Api/StringTranslationApiTest.php index 9456340f..6d311f00 100644 --- a/tests/CrowdinApiClient/Api/StringTranslationApiTest.php +++ b/tests/CrowdinApiClient/Api/StringTranslationApiTest.php @@ -45,6 +45,52 @@ public function testList(): void $this->assertEquals(190695, $stringTranslations[0]->getId()); } + public function testSearch(): void + { + $this->mockRequest([ + 'path' => '/translations?filter=translated&projectIds=2%2C3&userId=6&languageIds=uk%2Cpl&denormalizePlaceholders=1&limit=10&offset=20', + 'method' => 'get', + 'response' => json_encode([ + 'data' => [ + [ + 'data' => [ + 'id' => 190695, + 'projectId' => 2, + 'stringId' => 2814, + 'languageId' => 'uk', + 'text' => 'Перекладено', + 'pluralCategoryName' => 'few', + ], + ], + ], + 'pagination' => [ + [ + 'offset' => 20, + 'limit' => 10, + ], + ], + ]), + ]); + + $stringTranslations = $this->crowdin->stringTranslation->search([ + 'filter' => 'translated', + 'projectIds' => '2,3', + 'userId' => 6, + 'languageIds' => 'uk,pl', + 'denormalizePlaceholders' => 1, + 'limit' => 10, + 'offset' => 20, + ]); + + $this->assertInstanceOf(ModelCollection::class, $stringTranslations); + $this->assertCount(1, $stringTranslations); + $this->assertInstanceOf(StringTranslation::class, $stringTranslations[0]); + $this->assertEquals(190695, $stringTranslations[0]->getId()); + $this->assertEquals(2, $stringTranslations[0]->getProjectId()); + $this->assertEquals(2814, $stringTranslations[0]->getStringId()); + $this->assertEquals('uk', $stringTranslations[0]->getLanguageId()); + } + public function testGet(): void { $this->mockRequestGet( diff --git a/tests/CrowdinApiClient/Model/StringTranslationTest.php b/tests/CrowdinApiClient/Model/StringTranslationTest.php index 9d5f0ba8..f5a71cd1 100644 --- a/tests/CrowdinApiClient/Model/StringTranslationTest.php +++ b/tests/CrowdinApiClient/Model/StringTranslationTest.php @@ -40,6 +40,19 @@ public function testLoadData() $this->checkData(); } + public function testLoadSearchData(): void + { + $stringTranslation = new StringTranslation([ + 'projectId' => 2, + 'stringId' => 2814, + 'languageId' => 'uk', + ]); + + $this->assertEquals(2, $stringTranslation->getProjectId()); + $this->assertEquals(2814, $stringTranslation->getStringId()); + $this->assertEquals('uk', $stringTranslation->getLanguageId()); + } + public function checkData() { $this->assertEquals($this->data['id'], $this->stringTranslation->getId());