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
18 changes: 18 additions & 0 deletions src/CrowdinApiClient/Api/StringCommentApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,22 @@ public function delete(int $projectId, int $stringCommentId)
$path = sprintf('projects/%d/comments/%d', $projectId, $stringCommentId);
return $this->_delete($path);
}

/**
* String Comment Batch Operations
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.comments.batchPatch API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.comments.batchPatch API Documentation Enterprise
*
* @param int $projectId
* @param array $data
* string $data[op] required Patch operation to perform (replace, test)<br>
* string <json-pointer> $data[path] required A JSON Pointer as defined in RFC 6901<br>
* value $data[value] required The value to be used within the operation (string, int, bool, or object)
* @return mixed
*/
public function batchOperations(int $projectId, array $data)
{
$path = sprintf('projects/%d/comments', $projectId);
return $this->_patch($path, StringComment::class, $data);
}
}
36 changes: 36 additions & 0 deletions src/CrowdinApiClient/Api/StringTranslationApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,40 @@ public function deleteVote(int $projectId, int $voteId)
$path = sprintf('projects/%d/votes/%d', $projectId, $voteId);
return $this->_delete($path);
}

/**
* Approval Batch Operations
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.approvals.patch API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.approvals.patch API Documentation Enterprise
*
* @param int $projectId
* @param array $data
* string $data[op] required Patch operation to perform (replace, test)<br>
* string <json-pointer> $data[path] required A JSON Pointer as defined in RFC 6901<br>
* value $data[value] required The value to be used within the operation (string, int, bool, or object)
* @return mixed
*/
public function approvalsBatchOperations(int $projectId, array $data)
{
$path = sprintf('projects/%d/approvals', $projectId);
return $this->_patch($path, StringTranslationApproval::class, $data);
}

/**
* Translation Batch Operations
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.translations.patch API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.translations.patch API Documentation Enterprise
*
* @param int $projectId
* @param array $data
* string $data[op] required Patch operation to perform (replace, test)<br>
* string <json-pointer> $data[path] required A JSON Pointer as defined in RFC 6901<br>
* value $data[value] required The value to be used within the operation (string, int, bool, or object)
* @return mixed
*/
public function translationsBatchOperations(int $projectId, array $data)
{
$path = sprintf('projects/%d/translations', $projectId);
return $this->_patch($path, StringTranslation::class, $data);
}
}
63 changes: 63 additions & 0 deletions tests/CrowdinApiClient/Api/StringCommentApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,67 @@ public function testDelete()
$this->mockRequestDelete('/projects/1/comments/1');
$this->crowdin->stringComment->delete(1, 1);
}

public function testBatchOperations()
{
$this->mockRequest([
'path' => '/projects/1/comments',
'method' => 'patch',
'response' => '{
"data": [
{
"data": {
"id": 2,
"text": "Updated comment text",
"userId": 6,
"stringId": 742,
"user": {
"id": 12,
"username": "john_smith",
"fullName": "John Smith",
"avatarUrl": ""
},
"string": {
"id": 123,
"text": "HTML page example",
"type": "text",
"hasPlurals": false,
"isIcu": false,
"context": "Document Title\\r\\nXPath: /html/head/title",
"fileId": 22
},
"languageId": "bg",
"type": "issue",
"issueType": "source_mistake",
"issueStatus": "resolved",
"resolverId": 6,
"resolver": {
"id": 12,
"username": "john_smith",
"fullName": "John Smith",
"avatarUrl": ""
},
"resolvedAt": "2019-09-20T11:05:24+00:00",
"createdAt": "2019-09-20T11:05:24+00:00"
}
}
]
}'
]);

$batchResult = $this->crowdin->stringComment->batchOperations(1, [
[
'op' => 'replace',
'path' => '/2/text',
'value' => 'Updated comment text'
],
[
'op' => 'replace',
'path' => '/2/issueStatus',
'value' => 'resolved'
]
]);

$this->assertInstanceOf(StringComment::class, $batchResult);
}
}
72 changes: 72 additions & 0 deletions tests/CrowdinApiClient/Api/StringTranslationApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,76 @@ public function testListLanguageTranslations(): void
$this->assertEquals(7815, $stringTranslations[1]->getStringId());
$this->assertEquals(9011, $stringTranslations[2]->getStringId());
}

public function testBatchOperationsForApprovals(): void
{
$this->mockRequest([
'path' => '/projects/2/approvals',
'method' => 'patch',
'response' => json_encode([
'data' => [
[
'data' => [
'id' => 12,
'user' => [
'id' => 12,
'username' => 'john_smith',
'fullName' => 'John Smith',
'userType' => 'translator'
],
'translationId' => 190695,
'stringId' => 35434,
'languageId' => 'uk',
'workflowStepId' => 10,
'createdAt' => '2019-09-20T11:05:24+00:00'
]
]
]
])
]);

$batchResult = $this->crowdin->stringTranslation->approvalsBatchOperations(2, [
[
'op' => 'replace',
'path' => '/12/workflowStepId',
'value' => 10
]
]);

$this->assertInstanceOf(\CrowdinApiClient\Model\StringTranslationApproval::class, $batchResult);
}

public function testBatchOperationsForTranslations(): void
{
$this->mockRequest([
'path' => '/projects/2/translations',
'method' => 'patch',
'response' => json_encode([
'data' => [
[
'data' => [
'id' => 190695,
'text' => 'Updated translation text',
'pluralCategoryName' => 'few',
'user' => [
'id' => 19,
'login' => 'john_doe',
],
'rating' => 10,
]
]
]
])
]);

$batchResult = $this->crowdin->stringTranslation->translationsBatchOperations(2, [
[
'op' => 'replace',
'path' => '/190695/text',
'value' => 'Updated translation text'
]
]);

$this->assertInstanceOf(StringTranslation::class, $batchResult);
}
}