-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Strings Exporter Settings API (#153)
- Loading branch information
1 parent
f410b93
commit 0808bfa
Showing
5 changed files
with
419 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace CrowdinApiClient\Api; | ||
|
||
use CrowdinApiClient\Model\StringsExporterSetting; | ||
use CrowdinApiClient\ModelCollection; | ||
|
||
/** | ||
* Manage project strings exporter settings | ||
* | ||
* @package Crowdin\Api | ||
*/ | ||
class StringsExporterSettingApi extends AbstractApi | ||
{ | ||
/** | ||
* List Project Strings Exporter Settings | ||
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.strings-exporter-settings.getMany API Documentation | ||
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.strings-exporter-settings.getMany API Documentation Enterprise | ||
* | ||
* @param int $projectId | ||
* | ||
* @return ModelCollection | ||
*/ | ||
public function list(int $projectId): ModelCollection | ||
{ | ||
$path = sprintf('projects/%d/strings-exporter-settings', $projectId); | ||
return $this->_list($path, StringsExporterSetting::class); | ||
} | ||
|
||
/** | ||
* Get Strings Exporter Settings | ||
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.strings-exporter-settings.get API Documentation | ||
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.strings-exporter-settings.get API Documentation Enterprise | ||
* | ||
* @param int $projectId | ||
* @param int $strExporterSettingsId | ||
* @return StringsExporterSetting|null | ||
*/ | ||
public function get(int $projectId, int $strExporterSettingsId): ?StringsExporterSetting | ||
{ | ||
$path = sprintf('projects/%d/strings-exporter-settings/%d', $projectId, $strExporterSettingsId); | ||
return $this->_get($path, StringsExporterSetting::class); | ||
} | ||
|
||
/** | ||
* Add Strings Exporter Settings | ||
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.strings-exporter-settings.post API Documentation | ||
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.strings-exporter-settings.post API Documentation Enterprise | ||
* | ||
* @param int $projectId | ||
* @param array $data | ||
* string $data[format] required Enum: "android" "macosx" "xliff" | ||
* array $data[settings] required | ||
* @return StringsExporterSetting|null | ||
*/ | ||
public function create(int $projectId, array $data): ?StringsExporterSetting | ||
{ | ||
$path = sprintf('projects/%d/strings-exporter-settings', $projectId); | ||
return $this->_create($path, StringsExporterSetting::class, $data); | ||
} | ||
|
||
/** | ||
* Edit Strings Exporter Settings | ||
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.strings-exporter-settings.patch API Documentation | ||
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.strings-exporter-settings.patch API Documentation Enterprise | ||
* | ||
* @param int $projectId | ||
* @param StringsExporterSetting $stringsExporterSetting | ||
* | ||
* @return StringsExporterSetting|null | ||
*/ | ||
public function update(int $projectId, StringsExporterSetting $stringsExporterSetting): ?StringsExporterSetting | ||
{ | ||
$path = sprintf('projects/%d/strings-exporter-settings/%d', $projectId, $stringsExporterSetting->getId()); | ||
|
||
return $this->_update($path, $stringsExporterSetting); | ||
} | ||
|
||
/** | ||
* Delete Strings Exporter Settings | ||
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.strings-exporter-settings.delete API Documentation | ||
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.strings-exporter-settings.delete API Documentation Enterprise | ||
* | ||
* @param int $projectId | ||
* @param int $strExporterSettingsId | ||
* @return mixed | ||
*/ | ||
public function delete(int $projectId, int $strExporterSettingsId) | ||
{ | ||
$path = sprintf('projects/%d/strings-exporter-settings/%d', $projectId, $strExporterSettingsId); | ||
return $this->_delete($path); | ||
} | ||
} |
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,109 @@ | ||
<?php | ||
|
||
namespace CrowdinApiClient\Model; | ||
|
||
/** | ||
* @package Crowdin\Model | ||
*/ | ||
class StringsExporterSetting extends BaseModel | ||
{ | ||
/** | ||
* @var integer | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $format; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $settings; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $updatedAt; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $createdAt; | ||
|
||
public function __construct(array $data = []) | ||
{ | ||
parent::__construct($data); | ||
|
||
$this->id = (integer)$this->getDataProperty('id'); | ||
$this->format = (string)$this->getDataProperty('format'); | ||
$this->settings = (array)$this->getDataProperty('settings'); | ||
$this->createdAt = (string)$this->getDataProperty('createdAt'); | ||
$this->updatedAt = (string)$this->getDataProperty('updatedAt'); | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @param int $id | ||
*/ | ||
public function setId(int $id): void | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getFormat(): string | ||
{ | ||
return $this->format; | ||
} | ||
|
||
/** | ||
* @param string $format | ||
*/ | ||
public function setFormat(string $format): void | ||
{ | ||
$this->format = $format; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getSettings(): array | ||
{ | ||
return $this->settings; | ||
} | ||
|
||
/** | ||
* @param array $settings | ||
*/ | ||
public function setSettings(array $settings): void | ||
{ | ||
$this->settings = $settings; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCreatedAt(): string | ||
{ | ||
return $this->createdAt; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getUpdatedAt(): string | ||
{ | ||
return $this->updatedAt; | ||
} | ||
} |
157 changes: 157 additions & 0 deletions
157
tests/CrowdinApiClient/Api/StringsExporterSettingApiTest.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,157 @@ | ||
<?php | ||
|
||
namespace CrowdinApiClient\Tests\Api; | ||
|
||
use CrowdinApiClient\Model\StringsExporterSetting; | ||
use CrowdinApiClient\ModelCollection; | ||
|
||
class StringsExporterSettingApiTest extends AbstractTestApi | ||
{ | ||
public function testList() | ||
{ | ||
$this->mockRequest([ | ||
'path' => '/projects/2/strings-exporter-settings', | ||
'method' => 'get', | ||
'response' => '{ | ||
"data": [ | ||
{ | ||
"data": { | ||
"id": 2, | ||
"format": "android", | ||
"settings": { | ||
"convertPlaceholders": false | ||
}, | ||
"createdAt": "2019-09-19T15:10:43+00:00", | ||
"updatedAt": "2019-09-19T15:10:46+00:00" | ||
} | ||
} | ||
], | ||
"pagination": { | ||
"offset": 0, | ||
"limit": 25 | ||
} | ||
}' | ||
]); | ||
|
||
$data = $this->crowdin->stringsExporterSetting->list(2); | ||
|
||
$this->assertInstanceOf(ModelCollection::class, $data); | ||
$this->assertCount(1, $data); | ||
/** | ||
* @var StringsExporterSetting $stringsExporterSetting | ||
*/ | ||
$stringsExporterSetting = $data[0]; | ||
$this->assertInstanceOf(StringsExporterSetting::class, $stringsExporterSetting); | ||
|
||
$this->assertEquals(2, $stringsExporterSetting->getId()); | ||
$this->assertEquals('android', $stringsExporterSetting->getFormat()); | ||
} | ||
|
||
public function testGet() | ||
{ | ||
$this->mockRequestGet( | ||
'/projects/2/strings-exporter-settings/2', | ||
'{ | ||
"data": { | ||
"id": 2, | ||
"format": "android", | ||
"settings": { | ||
"convertPlaceholders": false | ||
}, | ||
"createdAt": "2019-09-19T15:10:43+00:00", | ||
"updatedAt": "2019-09-19T15:10:46+00:00" | ||
} | ||
}' | ||
); | ||
|
||
$stringsExporterSetting = $this->crowdin->stringsExporterSetting->get(2, 2); | ||
|
||
$this->assertInstanceOf(StringsExporterSetting::class, $stringsExporterSetting); | ||
|
||
$this->assertEquals(2, $stringsExporterSetting->getId()); | ||
$this->assertEquals('android', $stringsExporterSetting->getFormat()); | ||
} | ||
|
||
public function testCreate() | ||
{ | ||
$params = [ | ||
'format' => 'android', | ||
"settings" => [ | ||
"convertPlaceholders" => false | ||
] | ||
]; | ||
|
||
$this->mockRequest([ | ||
'path' => '/projects/2/strings-exporter-settings', | ||
'method' => 'post', | ||
'body' => json_encode($params), | ||
'response' => '{ | ||
"data": { | ||
"id": 2, | ||
"format": "android", | ||
"settings": { | ||
"convertPlaceholders": false | ||
}, | ||
"createdAt": "2019-09-19T15:10:43+00:00", | ||
"updatedAt": "2019-09-19T15:10:46+00:00" | ||
} | ||
}' | ||
]); | ||
|
||
$stringsExporterSetting = $this->crowdin->stringsExporterSetting->create(2, $params); | ||
|
||
$this->assertInstanceOf(StringsExporterSetting::class, $stringsExporterSetting); | ||
$this->assertEquals(2, $stringsExporterSetting->getId()); | ||
$this->assertEquals('android', $stringsExporterSetting->getFormat()); | ||
} | ||
|
||
public function testDelete() | ||
{ | ||
$this->mockRequest([ | ||
'path' => '/projects/2/strings-exporter-settings/2', | ||
'method' => 'delete', | ||
]); | ||
|
||
$this->crowdin->stringsExporterSetting->delete(2, 2); | ||
} | ||
|
||
public function testGetAndUpdate() | ||
{ | ||
$this->mockRequestGet('/projects/2/strings-exporter-settings/2', '{ | ||
"data": { | ||
"id": 2, | ||
"format": "android", | ||
"settings": { | ||
"convertPlaceholders": false | ||
}, | ||
"createdAt": "2019-09-19T15:10:43+00:00", | ||
"updatedAt": "2019-09-19T15:10:46+00:00" | ||
} | ||
}'); | ||
|
||
$stringsExporterSetting = $this->crowdin->stringsExporterSetting->get(2, 2); | ||
|
||
$this->assertInstanceOf(StringsExporterSetting::class, $stringsExporterSetting); | ||
$this->assertEquals(2, $stringsExporterSetting->getId()); | ||
$this->assertEquals('android', $stringsExporterSetting->getFormat()); | ||
|
||
$stringsExporterSetting->setFormat('macosx'); | ||
|
||
$this->mockRequestPath('/projects/2/strings-exporter-settings/2', '{ | ||
"data": { | ||
"id": 2, | ||
"format": "macosx", | ||
"settings": { | ||
"convertPlaceholders": false | ||
}, | ||
"createdAt": "2019-09-19T15:10:43+00:00", | ||
"updatedAt": "2019-09-19T15:10:46+00:00" | ||
} | ||
}'); | ||
|
||
$stringsExporterSetting = $this->crowdin->stringsExporterSetting->update(2, $stringsExporterSetting); | ||
$this->assertInstanceOf(StringsExporterSetting::class, $stringsExporterSetting); | ||
$this->assertEquals(2, $stringsExporterSetting->getId()); | ||
$this->assertEquals('macosx', $stringsExporterSetting->getFormat()); | ||
} | ||
} |
Oops, something went wrong.