Skip to content

Commit

Permalink
feat: Added Report Archives API endpoints (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
krm-shrftdnv authored May 30, 2024
1 parent 5199cf7 commit efe1805
Show file tree
Hide file tree
Showing 7 changed files with 794 additions and 2 deletions.
98 changes: 98 additions & 0 deletions src/CrowdinApiClient/Api/Enterprise/ReportArchiveApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace CrowdinApiClient\Api\Enterprise;

use CrowdinApiClient\Api\AbstractApi;
use CrowdinApiClient\Model\DownloadFile;
use CrowdinApiClient\Model\ReportArchive;
use CrowdinApiClient\Model\ReportArchiveExport;
use CrowdinApiClient\ModelCollection;

class ReportArchiveApi extends AbstractApi
{
/**
* List Report Archives
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.reports.archives.getMany
*
* @param array $params
* string $params[scopeType]
* integer $params[scopeId]
* integer $params[limit]
* integer $params[offset]
* @return ModelCollection
*/
public function list(array $params = []): ModelCollection
{
$path = 'reports/archives';
return $this->_list($path, ReportArchive::class, $params);
}

/**
* Get Report Archive
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.reports.archives.get
*
* @param int $archiveId
* @return ReportArchive|null
*/
public function get(int $archiveId): ?ReportArchive
{
$path = sprintf('reports/archives/%d', $archiveId);
return $this->_get($path, ReportArchive::class);
}

/**
* Delete Report Archive
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.reports.archives.delete
*
* @param int $archiveId
* @return void
*/
public function delete(int $archiveId): void
{
$path = sprintf('reports/archives/%d', $archiveId);
$this->_delete($path);
}

/**
* Export Report Archive
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.reports.archives.exports.post
*
* @param int $archiveId
* @param array $params
* string $params[format] Enum: "xlsx" "csv" "json"
* @return ReportArchiveExport|null
*/
public function export(int $archiveId, array $params = []): ?ReportArchiveExport
{
$path = sprintf('reports/archives/%d/exports', $archiveId);
return $this->_post($path, ReportArchiveExport::class, $params);
}

/**
* Check Report Archive Export Status
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.reports.archives.exports.get
*
* @param int $archiveId
* @param string $exportId
* @return ReportArchiveExport|null
*/
public function checkExportStatus(int $archiveId, string $exportId): ?ReportArchiveExport
{
$path = sprintf('reports/archives/%d/exports/%s', $archiveId, $exportId);
return $this->_get($path, ReportArchiveExport::class);
}

/**
* Download Report Archive
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.reports.archives.exports.download.get
*
* @param int $archiveId
* @param string $exportId
* @return DownloadFile|null
*/
public function downloadReportArchive(int $archiveId, string $exportId): ?DownloadFile
{
$path = sprintf('reports/archives/%d/exports/%s/download', $archiveId, $exportId);
return $this->_get($path, DownloadFile::class);
}
}
106 changes: 106 additions & 0 deletions src/CrowdinApiClient/Api/ReportArchiveApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

namespace CrowdinApiClient\Api;

use CrowdinApiClient\Model\DownloadFile;
use CrowdinApiClient\Model\ReportArchive;
use CrowdinApiClient\Model\ReportArchiveExport;
use CrowdinApiClient\ModelCollection;

/**
* @package Crowdin\Api
*/
class ReportArchiveApi extends AbstractApi
{
/**
* List Report Archives
* @link https://developer.crowdin.com/api/v2/#operation/api.reports.archives.getMany
*
* @param int $userId
* @param array $params
* string $params[scopeType]
* integer $params[scopeId]
* integer $params[limit]
* integer $params[offset]
* @return ModelCollection
*/
public function list(int $userId, array $params = []): ModelCollection
{
$path = sprintf('users/%d/reports/archives', $userId);
return $this->_list($path, ReportArchive::class, $params);
}

/**
* Get Report Archive
* @link https://developer.crowdin.com/api/v2/#operation/api.users.reports.archives.get
*
* @param int $userId
* @param int $archiveId
* @return ReportArchive|null
*/
public function get(int $userId, int $archiveId): ?ReportArchive
{
$path = sprintf('users/%d/reports/archives/%d', $userId, $archiveId);
return $this->_get($path, ReportArchive::class);
}

/**
* Delete Report Archive
* @link https://developer.crowdin.com/api/v2/#operation/api.users.reports.archives.delete
*
* @param int $userId
* @param int $archiveId
* @return void
*/
public function delete(int $userId, int $archiveId): void
{
$path = sprintf('users/%d/reports/archives/%d', $userId, $archiveId);
$this->_delete($path);
}

/**
* Export Report Archive
* @link https://developer.crowdin.com/api/v2/#operation/api.reports.archives.exports.post
*
* @param int $userId
* @param int $archiveId
* @param array $params
* string $params[format] Enum: "xlsx" "csv" "json"
* @return ReportArchiveExport|null
*/
public function export(int $userId, int $archiveId, array $params = []): ?ReportArchiveExport
{
$path = sprintf('users/%d/reports/archives/%d/exports', $userId, $archiveId);
return $this->_post($path, ReportArchiveExport::class, $params);
}

/**
* Check Report Archive Export Status
* @link https://developer.crowdin.com/api/v2/#operation/api.users.reports.archives.exports.get
*
* @param int $userId
* @param int $archiveId
* @param string $exportId
* @return ReportArchiveExport|null
*/
public function checkExportStatus(int $userId, int $archiveId, string $exportId): ?ReportArchiveExport
{
$path = sprintf('users/%d/reports/archives/%d/exports/%s', $userId, $archiveId, $exportId);
return $this->_get($path, ReportArchiveExport::class);
}

/**
* Download Report Archive
* @link https://developer.crowdin.com/api/v2/#operation/api.users.reports.archives.exports.download.get
*
* @param int $userId
* @param int $archiveId
* @param string $exportId
* @return DownloadFile|null
*/
public function downloadReportArchive(int $userId, int $archiveId, string $exportId): ?DownloadFile
{
$path = sprintf('users/%d/reports/archives/%d/exports/%s/download', $userId, $archiveId, $exportId);
return $this->_get($path, DownloadFile::class);
}
}
7 changes: 5 additions & 2 deletions src/CrowdinApiClient/Crowdin.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* @property \CrowdinApiClient\Api\BundleApi bundle
* @property \CrowdinApiClient\Api\NotificationApi|\CrowdinApiClient\Api\Enterprise\NotificationApi notification
* @property \CrowdinApiClient\Api\OrganizationWebhookApi organizationWebhook
* @property \CrowdinApiClient\Api\ReportArchiveApi|\CrowdinApiClient\Api\Enterprise\ReportArchiveApi reportArchive
*/
class Crowdin
{
Expand Down Expand Up @@ -112,7 +113,8 @@ class Crowdin
'distribution',
'bundle',
'notification',
'organizationWebhook'
'organizationWebhook',
'reportArchive'
];

protected $servicesEnterprise = [
Expand Down Expand Up @@ -148,7 +150,8 @@ class Crowdin
'teamMember',
'bundle',
'notification',
'organizationWebhook'
'organizationWebhook',
'reportArchive'
];

/**
Expand Down
127 changes: 127 additions & 0 deletions src/CrowdinApiClient/Model/ReportArchive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

namespace CrowdinApiClient\Model;

class ReportArchive extends BaseModel
{
/**
* @var integer
*/
protected $id;
/**
* @var string
*/
protected $scopeType;
/**
* @var integer
*/
protected $scopeId;
/**
* @var integer
*/
protected $userId;
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $webUrl;
/**
* @var array
*/
protected $scheme;
/**
* @var string
*/
protected $createdAt;

public function __construct(array $data = [])
{
parent::__construct($data);
$this->id = (integer)$this->getDataProperty('id');
$this->scopeType = (string)$this->getDataProperty('scopeType');
$this->scopeId = (integer)$this->getDataProperty('scopeId');
$this->userId = (integer)$this->getDataProperty('userId');
$this->name = (string)$this->getDataProperty('name');
$this->webUrl = (string)$this->getDataProperty('webUrl');
$this->scheme = (array)$this->getDataProperty('scheme');
$this->createdAt = (string)$this->getDataProperty('createdAt');
}

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

public function getScopeType(): string
{
return $this->scopeType;
}

public function setScopeType(string $scopeType): void
{
$this->scopeType = $scopeType;
}

public function getScopeId(): int
{
return $this->scopeId;
}

public function setScopeId(int $scopeId): void
{
$this->scopeId = $scopeId;
}

public function getUserId(): int
{
return $this->userId;
}

public function setUserId(int $userId): void
{
$this->userId = $userId;
}

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

public function setName(string $name): void
{
$this->name = $name;
}

public function getWebUrl(): string
{
return $this->webUrl;
}

public function setWebUrl(string $webUrl): void
{
$this->webUrl = $webUrl;
}

public function getScheme(): array
{
return $this->scheme;
}

public function setScheme(array $scheme): void
{
$this->scheme = $scheme;
}

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

public function setCreatedAt(string $createdAt): void
{
$this->createdAt = $createdAt;
}
}
Loading

0 comments on commit efe1805

Please sign in to comment.