Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
112 changes: 112 additions & 0 deletions src/CrowdinApiClient/Api/Enterprise/StringCorrectionApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace CrowdinApiClient\Api\Enterprise;

use CrowdinApiClient\Api\AbstractApi;
use CrowdinApiClient\Model\StringCorrection;
use CrowdinApiClient\ModelCollection;

/**
* Use API to manage string corrections in Source Text Review workflow
*
* @package Crowdin\Api\Enterprise
*/
class StringCorrectionApi extends AbstractApi
{
/**
* List Corrections
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.getMany API Documentation
*
* @param int $projectId
* @param array $params
* integer $params[stringId] required<br>
* integer $params[limit] default: 25<br>
* integer $params[offset] default: 0<br>
* string $params[orderBy]<br>
* integer $params[denormalizePlaceholders]
*
* @return ModelCollection
*/
public function list(int $projectId, array $params = []): ModelCollection
{
$path = sprintf('projects/%d/corrections', $projectId);
return $this->_list($path, StringCorrection::class, $params);
}

/**
* Get Correction
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.get API Documentation
*
* @param int $projectId
* @param int $correctionId
* @param array $params
* integer $params[denormalizePlaceholders] default: 0
*
* @return StringCorrection|null
*/
public function get(int $projectId, int $correctionId, array $params = []): ?StringCorrection
{
$path = sprintf('projects/%d/corrections/%d', $projectId, $correctionId);
return $this->_get($path, StringCorrection::class, $params);
}

/**
* Add Correction
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.post API Documentation
*
* @param int $projectId
* @param array $data
* integer $data[stringId] required<br>
* string $data[text] required<br>
* string $data[pluralCategoryName]
*
* @return StringCorrection|null
*/
public function create(int $projectId, array $data): ?StringCorrection
{
$path = sprintf('projects/%d/corrections', $projectId);
return $this->_create($path, StringCorrection::class, $data);
}

/**
* Restore Correction
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.put API Documentation
*
* @param int $projectId
* @param int $correctionId
* @return StringCorrection|null
*/
public function restore(int $projectId, int $correctionId): ?StringCorrection
{
$path = sprintf('projects/%d/corrections/%d', $projectId, $correctionId);
return $this->_put($path, StringCorrection::class, []);
}

/**
* Delete Correction
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.delete API Documentation
*
* @param int $projectId
* @param int $correctionId
* @return mixed
*/
public function delete(int $projectId, int $correctionId)
{
$path = sprintf('projects/%d/corrections/%d', $projectId, $correctionId);
return $this->_delete($path);
}

/**
* Delete Corrections
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Corrections/operation/api.projects.corrections.deleteMany API Documentation
*
* @param int $projectId
* @param int $stringId
* @return mixed
*/
public function deleteAll(int $projectId, int $stringId)
{
$path = sprintf('projects/%d/corrections', $projectId);
return $this->_delete($path, ['stringId' => $stringId]);
}
}
2 changes: 2 additions & 0 deletions src/CrowdinApiClient/Crowdin.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* @property \CrowdinApiClient\Api\ReportArchiveApi|\CrowdinApiClient\Api\Enterprise\ReportArchiveApi $reportArchive
* @property \CrowdinApiClient\Api\GraphqlApi $graphql
* @property \CrowdinApiClient\Api\SecurityLogApi|\CrowdinApiClient\Api\Enterprise\SecurityLogApi $securityLog
* @property \CrowdinApiClient\Api\Enterprise\StringCorrectionApi $stringCorrection
*/
class Crowdin
{
Expand Down Expand Up @@ -160,6 +161,7 @@ class Crowdin
'reportArchive',
'graphql',
'securityLog',
'stringCorrection',
];

public function __construct(array $config)
Expand Down
109 changes: 109 additions & 0 deletions src/CrowdinApiClient/Model/StringCorrection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

namespace CrowdinApiClient\Model;

/**
* @package Crowdin\Model
*/
class StringCorrection extends BaseModel
{
/**
* @var integer
*/
protected $id;

/**
* @var string
*/
protected $text;

/**
* @var string
*/
protected $pluralCategoryName;

/**
* @var array
*/
protected $user;

/**
* @var string
*/
protected $createdAt;

public function __construct(array $data = [])
{
parent::__construct($data);

$this->id = (integer)$this->getDataProperty('id');
$this->text = (string)$this->getDataProperty('text');
$this->pluralCategoryName = (string)$this->getDataProperty('pluralCategoryName');
$this->user = (array)$this->getDataProperty('user');
$this->createdAt = (string)$this->getDataProperty('createdAt');
}

/**
* @return int
*/
public function getId(): int
{
return $this->id;
}

/**
* @return string
*/
public function getText(): string
{
return $this->text;
}

/**
* @param string $text
*/
public function setText(string $text): void
{
$this->text = $text;
}

/**
* @return string
*/
public function getPluralCategoryName(): string
{
return $this->pluralCategoryName;
}

/**
* @param string $pluralCategoryName
*/
public function setPluralCategoryName(string $pluralCategoryName): void
{
$this->pluralCategoryName = $pluralCategoryName;
}

/**
* @return array
*/
public function getUser(): array
{
return $this->user;
}

/**
* @param array $user
*/
public function setUser(array $user): void
{
$this->user = $user;
}

/**
* @return string
*/
public function getCreatedAt(): string
{
return $this->createdAt;
}
}
147 changes: 147 additions & 0 deletions tests/CrowdinApiClient/Api/Enterprise/StringCorrectionApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php

namespace CrowdinApiClient\Tests\Api\Enterprise;

use CrowdinApiClient\Model\StringCorrection;
use CrowdinApiClient\ModelCollection;

class StringCorrectionApiTest extends AbstractTestApi
{
public function testList(): void
{
$this->mockRequest([
'path' => '/projects/2/corrections',
'method' => 'get',
'response' => '{
"data": [
{
"data": {
"id": 190695,
"text": "This string has been corrected",
"pluralCategoryName": "few",
"user": {
"id": 19,
"username": "john_doe",
"fullName": "John Smith",
"avatarUrl": ""
},
"createdAt": "2019-09-23T11:26:54+00:00"
}
}
],
"pagination": {
"offset": 0,
"limit": 25
}
}',
]);

$corrections = $this->crowdin->stringCorrection->list(2);

$this->assertInstanceOf(ModelCollection::class, $corrections);
$this->assertCount(1, $corrections);
$this->assertInstanceOf(StringCorrection::class, $corrections[0]);
$this->assertEquals(190695, $corrections[0]->getId());
}

public function testGet(): void
{
$this->mockRequestGet(
'/projects/2/corrections/190695',
'{
"data": {
"id": 190695,
"text": "This string has been corrected",
"pluralCategoryName": "few",
"user": {
"id": 19,
"username": "john_doe",
"fullName": "John Smith",
"avatarUrl": ""
},
"createdAt": "2019-09-23T11:26:54+00:00"
}
}'
);

$correction = $this->crowdin->stringCorrection->get(2, 190695);

$this->assertInstanceOf(StringCorrection::class, $correction);
$this->assertEquals(190695, $correction->getId());
$this->assertEquals('This string has been corrected', $correction->getText());
}

public function testCreate(): void
{
$params = [
'stringId' => 123,
'text' => 'Corrected string text',
'pluralCategoryName' => 'few',
];

$this->mockRequest([
'path' => '/projects/2/corrections',
'method' => 'post',
'body' => json_encode($params),
'response' => '{
"data": {
"id": 190696,
"text": "Corrected string text",
"pluralCategoryName": "few",
"user": {
"id": 19,
"username": "john_doe",
"fullName": "John Smith",
"avatarUrl": ""
},
"createdAt": "2019-09-23T11:26:54+00:00"
}
}',
]);

$correction = $this->crowdin->stringCorrection->create(2, $params);

$this->assertInstanceOf(StringCorrection::class, $correction);
$this->assertEquals(190696, $correction->getId());
$this->assertEquals('Corrected string text', $correction->getText());
}

public function testRestore(): void
{
$this->mockRequest([
'path' => '/projects/2/corrections/190695',
'method' => 'put',
'response' => '{
"data": {
"id": 190695,
"text": "This string has been corrected",
"pluralCategoryName": "few",
"user": {
"id": 19,
"username": "john_doe",
"fullName": "John Smith",
"avatarUrl": ""
},
"createdAt": "2019-09-23T11:26:54+00:00"
}
}',
]);

$correction = $this->crowdin->stringCorrection->restore(2, 190695);

$this->assertInstanceOf(StringCorrection::class, $correction);
$this->assertEquals(190695, $correction->getId());
}

public function testDelete(): void
{
$this->mockRequestDelete('/projects/2/corrections/190695');
$this->crowdin->stringCorrection->delete(2, 190695);
}

public function testDeleteAll(): void
{
$this->mockRequestDelete('/projects/2/corrections?stringId=123');
$this->crowdin->stringCorrection->deleteAll(2, 123);
}
}
Loading