Skip to content

Commit

Permalink
Merge pull request #25 from lokalise/feature/TAPPS-563_support_branches
Browse files Browse the repository at this point in the history
TAPPS-563 Add branches support
  • Loading branch information
Aleksey Kankov authored May 4, 2022
2 parents c2dcdc3 + 37c545e commit fdcd1fc
Show file tree
Hide file tree
Showing 8 changed files with 863 additions and 436 deletions.
134 changes: 134 additions & 0 deletions Api/Endpoints/Branches.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

declare(strict_types=1);


namespace Lokalise\Endpoints;

use Lokalise\Exceptions\LokaliseApiException;
use Lokalise\Exceptions\LokaliseResponseException;
use Lokalise\LokaliseApiResponse;

/**
* @link https://app.lokalise.com/api2docs/curl/#object-branches
*/
class Branches extends Endpoint
{
/**
* @link https://app.lokalise.com/api2docs/curl/#transition-list-all-branches-get
*
* @param string $projectId
* @param array $queryParams
*
* @return LokaliseApiResponse
*
* @throws LokaliseApiException
* @throws LokaliseResponseException
*/
public function listBranches(string $projectId, array $queryParams = []): LokaliseApiResponse
{
return $this->request(
'GET',
"projects/$projectId/branches",
$queryParams
);
}

/**
* @link https://app.lokalise.com/api2docs/curl/#transition-retrieve-a-branch-get
*
* @param string $projectId
* @param int $branchId
*
* @return LokaliseApiResponse
* @throws LokaliseApiException
* @throws LokaliseResponseException
*/
public function retrieve(string $projectId, int $branchId): LokaliseApiResponse
{
return $this->request(
'GET',
"projects/$projectId/branches/$branchId"
);
}

/**
* @link https://app.lokalise.com/api2docs/curl/#transition-create-a-branch-post
*
* @param string $projectId
* @param array $body
*
* @return LokaliseApiResponse
* @throws LokaliseApiException
* @throws LokaliseResponseException
*/
public function create(string $projectId, array $body): LokaliseApiResponse
{
return $this->request(
'POST',
"projects/$projectId/branches",
[],
$body
);
}

/**
* @link https://app.lokalise.com/api2docs/curl/#transition-update-a-branch-put
*
* @param string $projectId
* @param int $branchId
* @param array $body
*
* @return LokaliseApiResponse
* @throws LokaliseApiException
* @throws LokaliseResponseException
*/
public function update(string $projectId, int $branchId, array $body): LokaliseApiResponse
{
return $this->request(
'PUT',
"projects/$projectId/branches/$branchId",
[],
$body
);
}

/**
* @link https://app.lokalise.com/api2docs/curl/#transition-delete-a-branch-delete
*
* @param string $projectId
* @param int $branchId
*
* @return LokaliseApiResponse
* @throws LokaliseApiException
* @throws LokaliseResponseException
*/
public function delete(string $projectId, int $branchId): LokaliseApiResponse
{
return $this->request(
'DELETE',
"projects/$projectId/branches/$branchId"
);
}

/**
* @link https://app.lokalise.com/api2docs/curl/#transition-merge-a-branch-post
*
* @param string $projectId
* @param int $branchId
* @param array $body
*
* @return LokaliseApiResponse
* @throws LokaliseApiException
* @throws LokaliseResponseException
*/
public function merge(string $projectId, int $branchId, array $body): LokaliseApiResponse
{
return $this->request(
'POST',
"projects/$projectId/branches/$branchId/merge",
[],
$body
);
}
}
24 changes: 15 additions & 9 deletions Api/Endpoints/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Lokalise\Endpoints;

use \GuzzleHttp\Client;
use \GuzzleHttp\Exception\RequestException;
use \GuzzleHttp\Exception\GuzzleException;
use \Lokalise\Exceptions\LokaliseApiException;
use \Lokalise\Exceptions\LokaliseResponseException;
use \Lokalise\LokaliseApiResponse;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use Lokalise\Exceptions\LokaliseApiException;
use Lokalise\Exceptions\LokaliseResponseException;
use Lokalise\LokaliseApiResponse;

class Endpoint implements EndpointInterface
{
Expand All @@ -34,7 +34,7 @@ public function __construct(string $baseUrl, string $apiToken)
}

/**
* @param $client
* @param Client $client
*/
public function setClient(Client $client): void
{
Expand Down Expand Up @@ -111,8 +111,13 @@ protected function request(string $requestType, string $uri, array $queryParams
* @throws LokaliseApiException
* @throws LokaliseResponseException
*/
protected function requestAll(string $requestType, string $uri, array $queryParams = [], array $body = [], string $bodyResponseKey = ''): LokaliseApiResponse
{
protected function requestAll(
string $requestType,
string $uri,
array $queryParams = [],
array $body = [],
string $bodyResponseKey = ''
): LokaliseApiResponse {
$page = 1;
$queryParams = array_merge($queryParams, ['limit' => self::FETCH_ALL_LIMIT, 'page' => $page]);

Expand Down Expand Up @@ -160,6 +165,7 @@ private function fixArraysInQueryParams(array $queryParams): array
foreach ($queryParams as $paramName => $paramValue) {
$queryParams[$paramName] = $this->replaceArrayWithCommaSeparatedString($paramValue);
}

return $queryParams;
}

Expand Down
34 changes: 19 additions & 15 deletions Api/LokaliseApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@

namespace Lokalise;

use Lokalise\Endpoints\Branches;
use Lokalise\Endpoints\Comments;
use Lokalise\Endpoints\Contributors;
use Lokalise\Endpoints\CustomTranslationStatuses;
use Lokalise\Endpoints\PaymentCards;
use \Lokalise\Endpoints\Comments;
use \Lokalise\Endpoints\Contributors;
use \Lokalise\Endpoints\Files;
use \Lokalise\Endpoints\Keys;
use \Lokalise\Endpoints\Languages;
use Lokalise\Endpoints\Files;
use Lokalise\Endpoints\Keys;
use Lokalise\Endpoints\Languages;
use Lokalise\Endpoints\Orders;
use \Lokalise\Endpoints\Projects;
use Lokalise\Endpoints\PaymentCards;
use Lokalise\Endpoints\Projects;
use Lokalise\Endpoints\QueuedProcesses;
use Lokalise\Endpoints\TranslationProviders;
use \Lokalise\Endpoints\Screenshots;
use \Lokalise\Endpoints\Snapshots;
use \Lokalise\Endpoints\Tasks;
use \Lokalise\Endpoints\Teams;
use Lokalise\Endpoints\Screenshots;
use Lokalise\Endpoints\Snapshots;
use Lokalise\Endpoints\Tasks;
use Lokalise\Endpoints\Teams;
use Lokalise\Endpoints\TeamUserGroups;
use \Lokalise\Endpoints\TeamUsers;
use \Lokalise\Endpoints\Translations;
use Lokalise\Endpoints\TeamUsers;
use Lokalise\Endpoints\TranslationProviders;
use Lokalise\Endpoints\Translations;
use Lokalise\Endpoints\Webhooks;

class LokaliseApiClient
{
public const VERSION = '4.0.0';
public const VERSION = '4.1.0';

public const ENDPOINT = 'https://api.lokalise.com/api2/';

Expand Down Expand Up @@ -66,6 +67,8 @@ class LokaliseApiClient

public Webhooks $webhooks;

public Branches $branches;

/**
* LokaliseApiClient constructor.
*
Expand All @@ -92,6 +95,7 @@ public function __construct(string $apiToken)
$this->teamUserGroups = new TeamUserGroups(self::ENDPOINT, $apiToken);
$this->translationProviders = new TranslationProviders(self::ENDPOINT, $apiToken);
$this->webhooks = new Webhooks(self::ENDPOINT, $apiToken);
$this->branches = new Branches(self::ENDPOINT, $apiToken);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# Changelog

## 4.1.0 (March 18, 2022)

- Added [branches](Docs/branches.md) API.

## 4.0.0 (Jan 18, 2021)

- Support from 7.4 (lower in 3..)
- Response serialisation throws exceptions on failure

## 3.1.0 (Jun 3, 2020)

- Added [webhook](Docs/webhooks.md) API.

## 3.0.0 (May 25, 2020)

- Added [queued process](Docs/queuedProcesses.md) API.
- File upload now uses queued processes.
- Added support of `php-http/guzzle6-adapter` ^2.0 versions.
Expand Down
72 changes: 72 additions & 0 deletions Docs/branches.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Branches API

### List project branches
https://app.lokalise.com/api2docs/curl/#transition-list-all-branches-get

```php
$response = $client->branches->listBranches(
$projectId,
[
'limit' => 20,
'page' => 1,
]
);
```

### Retrieve project branch
https://app.lokalise.com/api2docs/curl/#transition-retrieve-a-branch-get

```php
$response = $client->branches->retrieve(
$projectId,
$branchId
);
```

### Create project branch
https://app.lokalise.com/api2docs/curl/#transition-create-a-branch-post

```php
$response = $client->branches->create(
$projectId,
[
'name' => 'hotfix/really-important',
]
);
```

### Update project branch
https://app.lokalise.com/api2docs/curl/#transition-update-a-branch-put

```php
$response = $client->branches->update(
$projectId,
$branchId,
[
'name' => 'hotfix/needed-yesterday',
]
);
```

### Delete project branch
https://app.lokalise.com/api2docs/curl/#transition-delete-a-branch-delete

```php
$response = $client->branches->delete(
$projectId,
$branchId
);
```

### Merge project branch
https://app.lokalise.com/api2docs/curl/#transition-merge-a-branch-post

```php
$response = $client->branches->merge(
$projectId,
$branchId,
[
'force_conflict_resolve_using' => 'target',
]
);
```
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ $client = new \Lokalise\LokaliseApiClient($apiToken);

[Webhooks](Docs/webhooks.md)

[Branches](Docs/branches.md)

## Response

```php
Expand Down
Loading

0 comments on commit fdcd1fc

Please sign in to comment.