-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from lokalise/SPHP-5_webhooks
SPHP-5 Webhook endpoints
- Loading branch information
Showing
8 changed files
with
445 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?php | ||
|
||
namespace Lokalise\Endpoints; | ||
|
||
use \Lokalise\LokaliseApiResponse; | ||
use \Lokalise\Exceptions\LokaliseApiException; | ||
use \Lokalise\Exceptions\LokaliseResponseException; | ||
|
||
/** | ||
* Class Webhooks | ||
* @package Lokalise\Endpoints | ||
* @link https://app.lokalise.com/api2docs/curl/#resource-webhooks | ||
*/ | ||
class Webhooks extends Endpoint implements EndpointInterface | ||
{ | ||
|
||
/** | ||
* @link https://app.lokalise.com/api2docs/curl/#transition-list-all-webhooks-get | ||
* | ||
* @param string $projectId | ||
* @param array $queryParams | ||
* | ||
* @return LokaliseApiResponse | ||
* | ||
* @throws LokaliseApiException | ||
* @throws LokaliseResponseException | ||
*/ | ||
public function list($projectId, $queryParams = []) | ||
{ | ||
return $this->request( | ||
'GET', | ||
"projects/$projectId/webhooks", | ||
$queryParams | ||
); | ||
} | ||
|
||
/** | ||
* @link https://app.lokalise.com/api2docs/curl/#transition-list-all-webhooks-get | ||
* | ||
* @param string $projectId | ||
* @param array $queryParams | ||
* | ||
* @return LokaliseApiResponse | ||
* | ||
* @throws LokaliseApiException | ||
* @throws LokaliseResponseException | ||
*/ | ||
public function fetchAll($projectId, $queryParams = []) | ||
{ | ||
return $this->requestAll( | ||
'GET', | ||
"projects/$projectId/webhooks", | ||
$queryParams, | ||
[], | ||
'webhooks' | ||
); | ||
} | ||
|
||
/** | ||
* @link https://app.lokalise.com/api2docs/curl/#transition-create-a-webhook-post | ||
* | ||
* @param string $projectId | ||
* @param array $body | ||
* | ||
* @return LokaliseApiResponse | ||
* | ||
* @throws LokaliseApiException | ||
* @throws LokaliseResponseException | ||
*/ | ||
public function create($projectId, $body) | ||
{ | ||
return $this->request( | ||
'POST', | ||
"projects/$projectId/webhooks", | ||
[], | ||
$body | ||
); | ||
} | ||
|
||
/** | ||
* @link https://app.lokalise.com/api2docs/curl/#transition-retrieve-a-webhook-get | ||
* | ||
* @param string $projectId | ||
* @param int $webhookId | ||
* | ||
* @return LokaliseApiResponse | ||
* | ||
* @throws LokaliseApiException | ||
* @throws LokaliseResponseException | ||
*/ | ||
public function retrieve($projectId, $webhookId) | ||
{ | ||
return $this->request( | ||
'GET', | ||
"projects/$projectId/webhooks/$webhookId" | ||
); | ||
} | ||
|
||
/** | ||
* @link https://app.lokalise.com/api2docs/curl/#transition-update-a-webhook-put | ||
* | ||
* @param string $projectId | ||
* @param int $webhookId | ||
* @param array $body | ||
* | ||
* @return LokaliseApiResponse | ||
* | ||
* @throws LokaliseApiException | ||
* @throws LokaliseResponseException | ||
*/ | ||
public function update($projectId, $webhookId, $body) | ||
{ | ||
return $this->request( | ||
'PUT', | ||
"projects/$projectId/webhooks/$webhookId", | ||
[], | ||
$body | ||
); | ||
} | ||
|
||
/** | ||
* @link https://app.lokalise.com/api2docs/curl/#transition-delete-a-webhook-delete | ||
* | ||
* @param string $projectId | ||
* @param int $webhookId | ||
* | ||
* @return LokaliseApiResponse | ||
* | ||
* @throws LokaliseApiException | ||
* @throws LokaliseResponseException | ||
*/ | ||
public function delete($projectId, $webhookId) | ||
{ | ||
return $this->request( | ||
'DELETE', | ||
"projects/$projectId/webhooks/$webhookId" | ||
); | ||
} | ||
|
||
/** | ||
* @link https://app.lokalise.com/api2docs/curl/#transition-regenerate-a-webhook-secret-patch | ||
* | ||
* @param string $projectId | ||
* @param int $webhookId | ||
* | ||
* @return LokaliseApiResponse | ||
* | ||
* @throws LokaliseApiException | ||
* @throws LokaliseResponseException | ||
*/ | ||
public function regenerateSecret($projectId, $webhookId) | ||
{ | ||
return $this->request( | ||
'PATCH', | ||
"projects/$projectId/webhooks/$webhookId/secret/regenerate" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Webhooks API | ||
|
||
### List all webhooks | ||
https://app.lokalise.com/api2docs/curl/#transition-list-all-webhooks-get | ||
|
||
```php | ||
$response = $client->webhooks->list( | ||
$projectId, | ||
[ | ||
'limit' => 20, | ||
'page' => 1, | ||
] | ||
); | ||
``` | ||
|
||
```php | ||
$response = $client->webhooks->fetchAll( | ||
$projectId | ||
); | ||
``` | ||
|
||
### Create a webhook | ||
https://app.lokalise.com/api2docs/curl/#transition-create-a-webhook-post | ||
|
||
```php | ||
$response = $client->webhooks->create( | ||
$projectId, | ||
[ | ||
'url' => 'https://my.domain.com/webhook', | ||
'events' => [ | ||
'project.translation.proofread', | ||
'project.translation.updated', | ||
], | ||
'event_lang_map' => [ | ||
[ | ||
'event' => 'project.translation.updated', | ||
'lang_iso_codes' => [ | ||
'en_GB', | ||
], | ||
], | ||
], | ||
] | ||
); | ||
``` | ||
|
||
### Retrieve a webhook | ||
https://app.lokalise.com/api2docs/curl/#transition-retrieve-a-webhook-get | ||
|
||
```php | ||
$response = $client->webhooks->retrieve($projectId, $webhookId); | ||
``` | ||
|
||
### Update a webhook | ||
https://app.lokalise.com/api2docs/curl/#transition-update-a-webhook-put | ||
|
||
```php | ||
$response = $client->webhooks->update( | ||
$projectId, | ||
$webhookId, | ||
[ | ||
'events' => [ | ||
'project.translation.proofread', | ||
'project.translation.updated', | ||
'project.imported', | ||
], | ||
'event_lang_map' => [ | ||
[ | ||
'event' => 'project.translation.proofread', | ||
'lang_iso_codes' => [ | ||
'en_GB', | ||
], | ||
], | ||
[ | ||
'event' => 'project.translation.updated', | ||
'lang_iso_codes' => [ | ||
'en_GB' | ||
], | ||
], | ||
], | ||
] | ||
); | ||
``` | ||
|
||
|
||
### Delete a webhook | ||
https://app.lokalise.com/api2docs/curl/#transition-delete-a-webhook-delete | ||
|
||
```php | ||
$response = $client->webhooks->delete($projectId, $webhookId); | ||
``` | ||
|
||
### Regenerate a webhook secret | ||
https://app.lokalise.com/api2docs/curl/#transition-regenerate-a-webhook-secret-patch | ||
|
||
```php | ||
$response = $client->webhooks->regenerateSecret($projectId, $webhookId); | ||
``` | ||
|
||
<br/><br/><br/> | ||
<div align="right"> | ||
<b><a href="/README.md#request">⇚ Back</a></b> | ||
</div> | ||
<br/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.