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: Project File Format Settings API update #219

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
90 changes: 83 additions & 7 deletions src/CrowdinApiClient/Api/ProjectApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CrowdinApiClient\Api;

use CrowdinApiClient\Model\DownloadFile;
use CrowdinApiClient\Model\FileFormatSettings;
use CrowdinApiClient\Model\Project;
use CrowdinApiClient\ModelCollection;

Expand All @@ -13,7 +15,6 @@
*/
class ProjectApi extends AbstractApi
{

/**
* List Projects
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.getMany API Documentation
Expand All @@ -36,9 +37,6 @@ public function list(array $params = []): ModelCollection
* Get Project Info
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.get API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.get API Documentation Enterprise
*
* @param int $projectId
* @return Project|null
*/
public function get(int $projectId): ?Project
{
Expand Down Expand Up @@ -81,9 +79,6 @@ public function create(array $data): ?Project
* Edit Project Info
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.patch API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.patch API Documentation Enterprise
*
* @param Project $project
* @return mixed
*/
public function update(Project $project): ?Project
{
Expand All @@ -102,4 +97,85 @@ public function delete(int $projectId)
{
return $this->client->apiRequest('delete', 'projects/' . $projectId);
}

/**
* Download Project File Format Settings Custom Segmentation
* @link https://support.crowdin.com/developer/api/v2/#tag/Projects/operation/api.projects.file-format-settings.custom-segmentations.get
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Projects-and-Groups/operation/api.projects.file-format-settings.custom-segmentations.get
*/
public function downloadFileFormatSettingsCustomSegmentation(
int $projectId,
int $fileFormatSettingsId
): ?DownloadFile {
$path = sprintf('projects/%d/file-format-settings/%d/custom-segmentations', $projectId, $fileFormatSettingsId);
return $this->_get($path, DownloadFile::class);
}

/**
* Reset Project File Format Settings Custom Segmentation
* @link https://support.crowdin.com/developer/api/v2/#tag/Projects/operation/api.projects.file-format-settings.custom-segmentations.delete
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Projects-and-Groups/operation/api.projects.file-format-settings.custom-segmentations.delete
*/
public function resetFileFormatSettingsCustomSegmentation(int $projectId, int $fileFormatSettingsId): void
{
$this->_delete(
sprintf('projects/%d/file-format-settings/%d/custom-segmentations', $projectId, $fileFormatSettingsId)
);
}

/**
* List Project File Format Settings
* @link https://support.crowdin.com/developer/api/v2/#tag/Projects/operation/api.projects.file-format-settings.getMany
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Projects-and-Groups/operation/api.projects.file-format-settings.getMany
*/
public function listFileFormatSettings(int $projectId, array $params = []): ModelCollection
{
$path = sprintf('projects/%d/file-format-settings', $projectId);
return $this->_list($path, FileFormatSettings::class, $params);
}

/**
* Add Project File Format Settings
* @link https://support.crowdin.com/developer/api/v2/#tag/Projects/operation/api.projects.file-format-settings.post
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Projects-and-Groups/operation/api.projects.file-format-settings.post
*/
public function createFileFormatSettings(int $projectId, array $data): ?FileFormatSettings
{
$path = sprintf('projects/%d/file-format-settings', $projectId);
return $this->_create($path, FileFormatSettings::class, $data);
}

/**
* Get Project File Format Settings
* @link https://support.crowdin.com/developer/api/v2/#tag/Projects/operation/api.projects.file-format-settings.get
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Projects-and-Groups/operation/api.projects.file-format-settings.get
*/
public function getFileFormatSettings(int $projectId, int $fileFormatSettingsId): ?FileFormatSettings
{
$path = sprintf('projects/%d/file-format-settings/%d', $projectId, $fileFormatSettingsId);
return $this->_get($path, FileFormatSettings::class);
}

/**
* Delete Project File Format Settings
* @link https://support.crowdin.com/developer/api/v2/#tag/Projects/operation/api.projects.file-format-settings.delete
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Projects-and-Groups/operation/api.projects.file-format-settings.delete
*/
public function deleteFileFormatSettings(int $projectId, int $fileFormatSettingsId): void
{
$this->_delete(sprintf('projects/%d/file-format-settings/%d', $projectId, $fileFormatSettingsId));
}

/**
* Edit Project File Format Settings
* @link https://support.crowdin.com/developer/api/v2/#tag/Projects/operation/api.projects.file-format-settings.patch
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Projects-and-Groups/operation/api.projects.file-format-settings.patch
*/
public function updateFileFormatSettings(
int $projectId,
FileFormatSettings $fileFormatSettings
): ?FileFormatSettings {
$path = sprintf('projects/%d/file-format-settings/%d', $projectId, $fileFormatSettings->getId());
return $this->_update($path, $fileFormatSettings);
}
}
107 changes: 107 additions & 0 deletions src/CrowdinApiClient/Model/FileFormatSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

declare(strict_types=1);

namespace CrowdinApiClient\Model;

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

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

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

/**
* @var string[]
*/
protected $extensions;

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

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

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

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

$this->id = (int)$this->getDataProperty('id');
$this->name = (string)$this->getDataProperty('name');
$this->format = (string)$this->getDataProperty('format');
$this->extensions = (array)$this->getDataProperty('extensions');
$this->settings = (array)$this->getDataProperty('settings');
$this->createdAt = (string)$this->getDataProperty('createdAt');
$this->updatedAt = (string)$this->getDataProperty('updatedAt');
}

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

public function getName(): string
{
return $this->name;
}

public function getFormat(): string
{
return $this->format;
}

public function setFormat(string $format): void
{
$this->format = $format;
}

/**
* @return string[]
*/
public function getExtensions(): array
{
return $this->extensions;
}

public function getSettings(): array
{
return $this->settings;
}

public function setSettings(array $settings): void
{
$this->settings = $settings;
}

public function getCreatedAt(): string
{
return $this->createdAt;
}

public function getUpdatedAt(): string
{
return $this->updatedAt;
}
}
10 changes: 10 additions & 0 deletions tests/CrowdinApiClient/Api/AbstractTestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ public function mockRequestGet(string $path, string $response, array $options =
]);
}

public function mockRequestPost(string $path, string $body, string $response)
{
return $this->mockRequest([
'uri' => 'https://api.crowdin.com/api/v2' . $path,
'method' => 'post',
'body' => $body,
'response' => $response,
]);
}

public function mockRequestDelete(string $path)
{
return $this->mockRequest([
Expand Down
Loading