Skip to content

Commit 8b0af4a

Browse files
committed
- Project File Format Settings API update
1 parent 8fcfcc7 commit 8b0af4a

File tree

5 files changed

+755
-309
lines changed

5 files changed

+755
-309
lines changed

src/CrowdinApiClient/Api/ProjectApi.php

+83-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace CrowdinApiClient\Api;
44

5+
use CrowdinApiClient\Model\DownloadFile;
6+
use CrowdinApiClient\Model\FileFormatSettings;
57
use CrowdinApiClient\Model\Project;
68
use CrowdinApiClient\ModelCollection;
79

@@ -13,7 +15,6 @@
1315
*/
1416
class ProjectApi extends AbstractApi
1517
{
16-
1718
/**
1819
* List Projects
1920
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.getMany API Documentation
@@ -36,9 +37,6 @@ public function list(array $params = []): ModelCollection
3637
* Get Project Info
3738
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.get API Documentation
3839
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.get API Documentation Enterprise
39-
*
40-
* @param int $projectId
41-
* @return Project|null
4240
*/
4341
public function get(int $projectId): ?Project
4442
{
@@ -81,9 +79,6 @@ public function create(array $data): ?Project
8179
* Edit Project Info
8280
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.patch API Documentation
8381
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.patch API Documentation Enterprise
84-
*
85-
* @param Project $project
86-
* @return mixed
8782
*/
8883
public function update(Project $project): ?Project
8984
{
@@ -102,4 +97,85 @@ public function delete(int $projectId)
10297
{
10398
return $this->client->apiRequest('delete', 'projects/' . $projectId);
10499
}
100+
101+
/**
102+
* Download Project File Format Settings Custom Segmentation
103+
* @link https://support.crowdin.com/developer/api/v2/#tag/Projects/operation/api.projects.file-format-settings.custom-segmentations.get
104+
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Projects-and-Groups/operation/api.projects.file-format-settings.custom-segmentations.get
105+
*/
106+
public function downloadFileFormatSettingsCustomSegmentation(
107+
int $projectId,
108+
int $fileFormatSettingsId
109+
): ?DownloadFile {
110+
$path = sprintf('projects/%d/file-format-settings/%d/custom-segmentations', $projectId, $fileFormatSettingsId);
111+
return $this->_get($path, DownloadFile::class);
112+
}
113+
114+
/**
115+
* Reset Project File Format Settings Custom Segmentation
116+
* @link https://support.crowdin.com/developer/api/v2/#tag/Projects/operation/api.projects.file-format-settings.custom-segmentations.delete
117+
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Projects-and-Groups/operation/api.projects.file-format-settings.custom-segmentations.delete
118+
*/
119+
public function resetFileFormatSettingsCustomSegmentation(int $projectId, int $fileFormatSettingsId): void
120+
{
121+
$this->_delete(
122+
sprintf('projects/%d/file-format-settings/%d/custom-segmentations', $projectId, $fileFormatSettingsId)
123+
);
124+
}
125+
126+
/**
127+
* List Project File Format Settings
128+
* @link https://support.crowdin.com/developer/api/v2/#tag/Projects/operation/api.projects.file-format-settings.getMany
129+
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Projects-and-Groups/operation/api.projects.file-format-settings.getMany
130+
*/
131+
public function listFileFormatSettings(int $projectId, array $params = []): ModelCollection
132+
{
133+
$path = sprintf('projects/%d/file-format-settings', $projectId);
134+
return $this->_list($path, FileFormatSettings::class, $params);
135+
}
136+
137+
/**
138+
* Add Project File Format Settings
139+
* @link https://support.crowdin.com/developer/api/v2/#tag/Projects/operation/api.projects.file-format-settings.post
140+
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Projects-and-Groups/operation/api.projects.file-format-settings.post
141+
*/
142+
public function createFileFormatSettings(int $projectId, array $data): ?FileFormatSettings
143+
{
144+
$path = sprintf('projects/%d/file-format-settings', $projectId);
145+
return $this->_create($path, FileFormatSettings::class, $data);
146+
}
147+
148+
/**
149+
* Get Project File Format Settings
150+
* @link https://support.crowdin.com/developer/api/v2/#tag/Projects/operation/api.projects.file-format-settings.get
151+
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Projects-and-Groups/operation/api.projects.file-format-settings.get
152+
*/
153+
public function getFileFormatSettings(int $projectId, int $fileFormatSettingsId): ?FileFormatSettings
154+
{
155+
$path = sprintf('projects/%d/file-format-settings/%d', $projectId, $fileFormatSettingsId);
156+
return $this->_get($path, FileFormatSettings::class);
157+
}
158+
159+
/**
160+
* Delete Project File Format Settings
161+
* @link https://support.crowdin.com/developer/api/v2/#tag/Projects/operation/api.projects.file-format-settings.delete
162+
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Projects-and-Groups/operation/api.projects.file-format-settings.delete
163+
*/
164+
public function deleteFileFormatSettings(int $projectId, int $fileFormatSettingsId): void
165+
{
166+
$this->_delete(sprintf('projects/%d/file-format-settings/%d', $projectId, $fileFormatSettingsId));
167+
}
168+
169+
/**
170+
* Edit Project File Format Settings
171+
* @link https://support.crowdin.com/developer/api/v2/#tag/Projects/operation/api.projects.file-format-settings.patch
172+
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Projects-and-Groups/operation/api.projects.file-format-settings.patch
173+
*/
174+
public function updateFileFormatSettings(
175+
int $projectId,
176+
FileFormatSettings $fileFormatSettings
177+
): ?FileFormatSettings {
178+
$path = sprintf('projects/%d/file-format-settings/%d', $projectId, $fileFormatSettings->getId());
179+
return $this->_update($path, $fileFormatSettings);
180+
}
105181
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CrowdinApiClient\Model;
6+
7+
/**
8+
* @package Crowdin\Model
9+
*/
10+
class FileFormatSettings extends BaseModel
11+
{
12+
/**
13+
* @var int
14+
*/
15+
protected $id;
16+
17+
/**
18+
* @var string
19+
*/
20+
protected $name;
21+
22+
/**
23+
* @var string
24+
*/
25+
protected $format;
26+
27+
/**
28+
* @var string[]
29+
*/
30+
protected $extensions;
31+
32+
/**
33+
* @var array
34+
*/
35+
protected $settings;
36+
37+
/**
38+
* @var string
39+
*/
40+
protected $createdAt;
41+
42+
/**
43+
* @var string
44+
*/
45+
protected $updatedAt;
46+
47+
public function __construct(array $data = [])
48+
{
49+
parent::__construct($data);
50+
51+
$this->id = (int)$this->getDataProperty('id');
52+
$this->name = (string)$this->getDataProperty('name');
53+
$this->format = (string)$this->getDataProperty('format');
54+
$this->extensions = (array)$this->getDataProperty('extensions');
55+
$this->settings = (array)$this->getDataProperty('settings');
56+
$this->createdAt = (string)$this->getDataProperty('createdAt');
57+
$this->updatedAt = (string)$this->getDataProperty('updatedAt');
58+
}
59+
60+
public function getId(): int
61+
{
62+
return $this->id;
63+
}
64+
65+
public function getName(): string
66+
{
67+
return $this->name;
68+
}
69+
70+
public function getFormat(): string
71+
{
72+
return $this->format;
73+
}
74+
75+
public function setFormat(string $format): void
76+
{
77+
$this->format = $format;
78+
}
79+
80+
/**
81+
* @return string[]
82+
*/
83+
public function getExtensions(): array
84+
{
85+
return $this->extensions;
86+
}
87+
88+
public function getSettings(): array
89+
{
90+
return $this->settings;
91+
}
92+
93+
public function setSettings(array $settings): void
94+
{
95+
$this->settings = $settings;
96+
}
97+
98+
public function getCreatedAt(): string
99+
{
100+
return $this->createdAt;
101+
}
102+
103+
public function getUpdatedAt(): string
104+
{
105+
return $this->updatedAt;
106+
}
107+
}

tests/CrowdinApiClient/Api/AbstractTestApi.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function mockRequestPatch(string $path, string $response, array $options
5757
'uri' => 'https://api.crowdin.com/api/v2' . $path,
5858
'method' => 'patch',
5959
'response' => $response,
60-
'options' => $options
60+
'options' => $options,
6161
]);
6262
}
6363

@@ -67,7 +67,7 @@ public function mockRequestPut(string $path, string $response, array $options =
6767
'uri' => 'https://api.crowdin.com/api/v2' . $path,
6868
'method' => 'put',
6969
'response' => $response,
70-
'options' => $options
70+
'options' => $options,
7171
]);
7272
}
7373

@@ -77,7 +77,17 @@ public function mockRequestGet(string $path, string $response, array $options =
7777
'uri' => 'https://api.crowdin.com/api/v2' . $path,
7878
'method' => 'get',
7979
'response' => $response,
80-
'options' => $options
80+
'options' => $options,
81+
]);
82+
}
83+
84+
public function mockRequestPost(string $path, string $body, string $response)
85+
{
86+
return $this->mockRequest([
87+
'uri' => 'https://api.crowdin.com/api/v2' . $path,
88+
'method' => 'post',
89+
'body' => $body,
90+
'response' => $response,
8191
]);
8292
}
8393

0 commit comments

Comments
 (0)