Skip to content

Commit

Permalink
Merge pull request #83 from crowdin/update-api-endpoints
Browse files Browse the repository at this point in the history
API Updates
  • Loading branch information
andrii-bodnar authored Oct 4, 2021
2 parents 29a7f42 + 749b246 commit ab5ef43
Show file tree
Hide file tree
Showing 12 changed files with 643 additions and 27 deletions.
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,13 @@ Before sending your pull requests, make sure you followed the list below:

- Include unit tests when you contribute new features, as they help to a) prove that your code works correctly, and b) guard against future breaking changes to lower the maintenance cost.
- Bug fixes also generally require unit tests, because the presence of bugs usually indicates insufficient test coverage.

#### Running Unit tests

To run all tests use the following command:

`vendor/bin/phpunit`

To run a specific test:

`vendor/bin/phpunit tests/CrowdinApiClient/Model/ProjectTest.php`
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "crowdin/crowdin-api-client",
"description": "PHP client library for Crowdin API v2",
"version": "1.5.2",
"version": "1.6.0",
"keywords": [
"crowdin",
"sdk",
Expand Down
56 changes: 55 additions & 1 deletion src/CrowdinApiClient/Api/Enterprise/UserApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use CrowdinApiClient\Api\AbstractApi;
use CrowdinApiClient\Model\Enterprise\ProjectTeamMemberAddedStatistics;
use CrowdinApiClient\Model\Enterprise\ProjectTeamMemberResource;
use CrowdinApiClient\Model\Enterprise\User;
use CrowdinApiClient\ModelCollection;

Expand All @@ -14,7 +15,7 @@
class UserApi extends AbstractApi
{
/**
* Add Project Team Member
* Add Project Member
* @link https://support.crowdin.com/enterprise/api/#operation/api.projects.members.post API Documentation
*
* @param int $projectId
Expand All @@ -26,6 +27,59 @@ public function addProjectTeamMember(int $projectId, array $data): ProjectTeamMe
return $this->_post(sprintf('projects/%d/members', $projectId), ProjectTeamMemberAddedStatistics::class, $data);
}

/**
* List Project Members
* @link https://support.crowdin.com/enterprise/api/#operation/api.projects.members.getMany API Documentation
*
* @param int $projectId
* @param array $data
* @return ModelCollection
*/
public function listProjectMembers(int $projectId, array $data): ModelCollection
{
return $this->_list(sprintf('projects/%d/members', $projectId), ProjectTeamMemberResource::class, $data);
}

/**
* Get Project Member Permissions
* @link https://support.crowdin.com/enterprise/api/#operation/api.projects.members.post API Documentation
*
* @param int $projectId
* @param int $memberId
* @return ProjectTeamMemberResource
*/
public function getProjectMemberPermissions(int $projectId, int $memberId): ProjectTeamMemberResource
{
return $this->_get(sprintf('projects/%d/members/%d', $projectId, $memberId), ProjectTeamMemberResource::class);
}

/**
* Replace Project Member Permissions
* @link https://support.crowdin.com/enterprise/api/#operation/api.projects.members.put API Documentation
*
* @param int $projectId
* @param int $memberId
* @param array $data
* @return ProjectTeamMemberResource
*/
public function replaceProjectMemberPermissions(int $projectId, int $memberId, array $data): ProjectTeamMemberResource
{
return $this->_put(sprintf('projects/%d/members/%d', $projectId, $memberId), ProjectTeamMemberResource::class, $data);
}

/**
* Delete Member From Project
* @link https://support.crowdin.com/enterprise/api/#operation/api.projects.members.delete API Documentation
*
* @param int $projectId
* @param int $memberId
*/
public function deleteMemberFromProject(int $projectId, int $memberId): void
{
$path = sprintf('projects/%d/members/%s', $projectId, $memberId);
$this->_delete($path);
}

/**
* List Users
* @link https://support.crowdin.com/enterprise/api/#operation/api.users.getMany API Documentation
Expand Down
171 changes: 171 additions & 0 deletions src/CrowdinApiClient/Model/Enterprise/ProjectTeamMemberResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<?php

declare(strict_types=1);

namespace CrowdinApiClient\Model\Enterprise;

use CrowdinApiClient\Model\BaseModel;

class ProjectTeamMemberResource extends BaseModel
{
/**
* @var int
*/
protected $id;

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

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

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

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

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

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

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

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

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

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

$this->id = (int)$this->getDataProperty('id');
$this->username = (string)$this->getDataProperty('username');
$this->firstName = (string)$this->getDataProperty('firstName');
$this->lastName = (string)$this->getDataProperty('lastName');
$this->isManager = (bool)$this->getDataProperty('isManager');
$this->managerOfGroup = (array)$this->getDataProperty('managerOfGroup');
$this->accessToAllWorkflowSteps = (bool)$this->getDataProperty('accessToAllWorkflowSteps');
$this->permissions = (array)$this->getDataProperty('permissions');
$this->givenAccessAt = (string)$this->getDataProperty('givenAccessAt');
}

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

/**
* @return string
*/
public function getUsername(): string
{
return $this->username;
}

/**
* @return string
*/
public function getFirstName(): string
{
return $this->firstName;
}

/**
* @return string
*/
public function getLastName(): string
{
return $this->lastName;
}

/**
* @return bool
*/
public function isManager(): bool
{
return $this->isManager;
}

/**
* @return array
*/
public function getManagerOfGroup(): array
{
return $this->managerOfGroup;
}

/**
* @return bool
*/
public function isAccessToAllWorkflowSteps(): bool
{
return $this->accessToAllWorkflowSteps;
}

/**
* @param bool $accessToAllWorkflowSteps
*/
public function setAccessToAllWorkflowSteps(bool $accessToAllWorkflowSteps): void
{
$this->accessToAllWorkflowSteps = $accessToAllWorkflowSteps;
}

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

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

/**
* @return string
*/
public function getGivenAccessAt(): string
{
return $this->givenAccessAt;
}

/**
* @param bool $managerAccess
*/
public function setManagerAccess(bool $managerAccess): void
{
$this->managerAccess = $managerAccess;
}
}
Loading

0 comments on commit ab5ef43

Please sign in to comment.