Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Strings Exporter Settings API #147 #153

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions src/CrowdinApiClient/Api/StringsExporterSettingApi.php
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);
}
}
3 changes: 3 additions & 0 deletions src/CrowdinApiClient/Crowdin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @property \CrowdinApiClient\Api\DirectoryApi directory
* @property \CrowdinApiClient\Api\LabelApi label
* @property \CrowdinApiClient\Api\GlossaryApi glossary
* @property \CrowdinApiClient\Api\StringsExporterSettingApi stringsExporterSetting
* @property \CrowdinApiClient\Api\StringTranslationApi stringTranslation
* @property \CrowdinApiClient\Api\StringCommentApi stringComment
* @property \CrowdinApiClient\Api\Enterprise\UserApi|\CrowdinApiClient\Api\UserApi user
Expand Down Expand Up @@ -91,6 +92,7 @@ class Crowdin
'issue',
'branch',
'glossary',
'stringsExporterSetting',
'stringTranslation',
'stringComment',
'directory',
Expand Down Expand Up @@ -118,6 +120,7 @@ class Crowdin
'issue',
'branch',
'glossary',
'stringsExporterSetting',
'stringTranslation',
'stringTranslationApproval',
'stringComment',
Expand Down
109 changes: 109 additions & 0 deletions src/CrowdinApiClient/Model/StringsExporterSetting.php
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 tests/CrowdinApiClient/Api/StringsExporterSettingApiTest.php
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' => $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());
}
}
Loading
Loading