Skip to content
Open
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
174 changes: 174 additions & 0 deletions src/CrowdinApiClient/Api/ApplicationApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?php

declare(strict_types=1);

namespace CrowdinApiClient\Api;

use CrowdinApiClient\Model\ApplicationData;
use CrowdinApiClient\Model\ApplicationInstallation;
use CrowdinApiClient\ModelCollection;

/**
* Use API to manage custom application data.
*
* @package Crowdin\Api
*/
class ApplicationApi extends AbstractApi
{
/**
* Get Application Data
* @link https://developer.crowdin.com/api/v2/#operation/api.applications.api.get API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.applications.api.get API Documentation Enterprise
*
* @param string $applicationIdentifier
* @param string $path
* @param array $params
* @return ApplicationData|null
*/
public function getApplicationData(string $applicationIdentifier, string $path, array $params = []): ?ApplicationData
{
$url = sprintf('applications/%s/api/%s', $applicationIdentifier, $path);
return $this->_get($url, ApplicationData::class, $params);
}

/**
* Add Application Data
* @link https://developer.crowdin.com/api/v2/#operation/api.applications.api.post API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.applications.api.post API Documentation Enterprise
*
* @param string $applicationIdentifier
* @param string $path
* @param array $data
* @return ApplicationData|null
*/
public function addApplicationData(string $applicationIdentifier, string $path, array $data): ?ApplicationData
{
$url = sprintf('applications/%s/api/%s', $applicationIdentifier, $path);
return $this->_post($url, ApplicationData::class, $data);
}

/**
* Update or Restore Application Data
* @link https://developer.crowdin.com/api/v2/#operation/api.applications.api.put API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.applications.api.put API Documentation Enterprise
*
* @param string $applicationIdentifier
* @param string $path
* @param array $data
* @return ApplicationData|null
*/
public function updateOrRestoreApplicationData(string $applicationIdentifier, string $path, array $data): ?ApplicationData
{
$url = sprintf('applications/%s/api/%s', $applicationIdentifier, $path);
return $this->_put($url, ApplicationData::class, $data);
}

/**
* Delete Application Data
* @link https://developer.crowdin.com/api/v2/#operation/api.applications.api.delete API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.applications.api.delete API Documentation Enterprise
*
* @param string $applicationIdentifier
* @param string $path
* @return mixed
*/
public function deleteApplicationData(string $applicationIdentifier, string $path)
{
$url = sprintf('applications/%s/api/%s', $applicationIdentifier, $path);
return $this->_delete($url);
}

/**
* List Application Installations
* @link https://developer.crowdin.com/api/v2/#operation/api.applications.installations.getMany API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.applications.installations.getMany API Documentation Enterprise
*
* @param array $params
* integer $params[limit]<br>
* integer $params[offset]<br>
* integer $params[installedBy]<br>
* string $params[orderBy]
* @return ModelCollection
*/
public function listInstallations(array $params = []): ModelCollection
{
return $this->_list('applications/installations', ApplicationInstallation::class, $params);
}

/**
* Install Application
* @link https://developer.crowdin.com/api/v2/#operation/api.applications.installations.post API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.applications.installations.post API Documentation Enterprise
*
* @param array $data
* string $data[url] required<br>
* array $data[permissions]<br>
* array $data[modules]<br>
* bool $data[assignAgent]
* @return ApplicationInstallation|null
*/
public function installApplication(array $data): ?ApplicationInstallation
{
return $this->_create('applications/installations', ApplicationInstallation::class, $data);
}

/**
* Get Application Installation
* @link https://developer.crowdin.com/api/v2/#operation/api.applications.installations.get API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.applications.installations.get API Documentation Enterprise
*
* @param string $identifier
* @return ApplicationInstallation|null
*/
public function getInstallation(string $identifier): ?ApplicationInstallation
{
return $this->_get('applications/installations/' . $identifier, ApplicationInstallation::class);
}

/**
* Delete Application Installation
* @link https://developer.crowdin.com/api/v2/#operation/api.applications.installations.delete API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.applications.installations.delete API Documentation Enterprise
*
* @param string $identifier
* @param bool $force
* @return mixed
*/
public function deleteInstallation(string $identifier, bool $force = false)
{
$params = $force ? ['force' => true] : [];
return $this->_delete('applications/installations/' . $identifier, $params);
}

/**
* Edit Application Installation
* @link https://developer.crowdin.com/api/v2/#operation/api.applications.installations.patch API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.applications.installations.patch API Documentation Enterprise
*
* @param ApplicationInstallation $installation
* @return ApplicationInstallation|null
*/
public function updateInstallation(ApplicationInstallation $installation): ?ApplicationInstallation
{
return $this->_update('applications/installations/' . $installation->getIdentifier(), $installation);
}

/**
* Edit Application Data
* @link https://developer.crowdin.com/api/v2/#operation/api.applications.api.patch API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.applications.api.patch API Documentation Enterprise
*
* @param string $applicationIdentifier
* @param string $path
* @param array $data Application-specific key-value payload (free-form, not RFC 6902 patch operations)
* string $data[op] required Patch operation to perform (replace, add, remove, test)<br>
* string <json-pointer> $data[path] required<br>
* mixed $data[value] The value to be used within the operation (string, int, bool, or object)
* @return ApplicationData|null
*/
Comment thread
innomaxx marked this conversation as resolved.
public function editApplicationData(string $applicationIdentifier, string $path, array $data): ?ApplicationData
{
$url = sprintf('applications/%s/api/%s', $applicationIdentifier, $path);
return $this->_patch($url, ApplicationData::class, $data);
}
}
3 changes: 3 additions & 0 deletions src/CrowdinApiClient/Crowdin.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
* @property \CrowdinApiClient\Api\AiApi|\CrowdinApiClient\Api\Enterprise\AiApi $ai
* @property \CrowdinApiClient\Api\Enterprise\FieldApi $field
* @property \CrowdinApiClient\Api\StyleGuideApi $styleGuide
* @property \CrowdinApiClient\Api\ApplicationApi $application
*/
class Crowdin
{
Expand Down Expand Up @@ -126,6 +127,7 @@ class Crowdin
'securityLog',
'ai',
'styleGuide',
'application',
];

protected $servicesEnterprise = [
Expand Down Expand Up @@ -170,6 +172,7 @@ class Crowdin
'ai',
'field',
'styleGuide',
'application',
];

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

declare(strict_types=1);

namespace CrowdinApiClient\Model;

class ApplicationData extends BaseModel
{
public function __construct(array $data = [])
{
parent::__construct($data);
}
}
165 changes: 165 additions & 0 deletions src/CrowdinApiClient/Model/ApplicationInstallation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php

declare(strict_types=1);

namespace CrowdinApiClient\Model;

class ApplicationInstallation extends BaseModel
{
/** @var string */
protected $identifier;

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

/** @var array|null */
protected $installedBy = null;

/** @var string|null */
protected $description = null;

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

/** @var array|null */
protected $agent = null;

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

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

/** @var string|null */
protected $createdAt = null;

/** @var array */
protected $modules = [];

/** @var array */
protected $scopes = [];

/** @var array */
protected $permissions = [];

/** @var array */
protected $defaultPermissions = [];

/** @var bool */
protected $limitReached;

/** @var bool */
protected $stringBasedAvailable;

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

$this->identifier = (string)$this->getDataProperty('identifier');
$this->name = (string)$this->getDataProperty('name');
$this->installedBy = $this->getDataProperty('installedBy');
$this->description = $this->getDataProperty('description');
$this->logo = (string)$this->getDataProperty('logo');
$this->agent = $this->getDataProperty('agent');
$this->baseUrl = (string)$this->getDataProperty('baseUrl');
$this->manifestUrl = (string)$this->getDataProperty('manifestUrl');
$this->createdAt = $this->getDataProperty('createdAt');
$this->modules = (array)$this->getDataProperty('modules');
$this->scopes = (array)$this->getDataProperty('scopes');
$this->permissions = (array)$this->getDataProperty('permissions');
$this->defaultPermissions = (array)$this->getDataProperty('defaultPermissions');
$this->limitReached = (bool)$this->getDataProperty('limitReached');
$this->stringBasedAvailable = (bool)$this->getDataProperty('stringBasedAvailable');
}

public function getIdentifier(): string
{
return $this->identifier;
}

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

/**
* @return array|null
*/
public function getInstalledBy(): ?array
{
return $this->installedBy;
}

public function getDescription(): ?string
{
return $this->description;
}

public function getLogo(): string
{
return $this->logo;
}

/**
* @return array|null
*/
public function getAgent(): ?array
{
return $this->agent;
}

public function getBaseUrl(): string
{
return $this->baseUrl;
}

public function getManifestUrl(): string
{
return $this->manifestUrl;
}

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

public function getModules(): array
{
return $this->modules;
}

public function getScopes(): array
{
return $this->scopes;
}

public function getPermissions(): array
{
return $this->permissions;
}

public function getDefaultPermissions(): array
{
return $this->defaultPermissions;
}

public function isLimitReached(): bool
{
return $this->limitReached;
}

public function isStringBasedAvailable(): bool
{
return $this->stringBasedAvailable;
}

public function setPermissions(array $permissions): void
{
$this->permissions = $permissions;
}

public function setModules(array $modules): void
{
$this->modules = $modules;
}
}
Loading
Loading