-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for the Notifications API
- Loading branch information
Elliot Bruneel
committed
Oct 1, 2023
1 parent
811b26f
commit 09d1527
Showing
5 changed files
with
160 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace CrowdinApiClient\Api\Enterprise; | ||
|
||
use CrowdinApiClient\Api\AbstractApi; | ||
|
||
/** | ||
* Send notifications | ||
* | ||
* @package Crowdin\Api\Entreprise | ||
*/ | ||
class NotificationApi extends AbstractApi | ||
{ | ||
|
||
/** | ||
* Send Notification To Organization Members | ||
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.notify.post API Documentation Enterprise | ||
* | ||
* @param array $data | ||
* string $data[message] required<br> | ||
* string $data[role] Enum: "owner" "admin"<br> | ||
* integer[] $data[userIds] | ||
* @return mixed | ||
*/ | ||
public function sendNotificationToOrganizationMembers(array $data) | ||
{ | ||
$path = 'notify'; | ||
|
||
$options = [ | ||
'body' => json_encode($data), | ||
'headers' => ['Content-Type' => 'application/json'] | ||
]; | ||
|
||
return $this->client->apiRequest('post', $path, null, $options); | ||
} | ||
} |
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,55 @@ | ||
<?php | ||
|
||
namespace CrowdinApiClient\Api; | ||
|
||
/** | ||
* Send notifications | ||
* | ||
* @package Crowdin\Api | ||
*/ | ||
class NotificationApi extends AbstractApi | ||
{ | ||
/** | ||
* Send Notification to Authenticated User | ||
* @link https://developer.crowdin.com/api/v2/#operation/api.notify.post API Documentation | ||
* | ||
* @param array $data | ||
* string $data[message] required | ||
* @return mixed | ||
*/ | ||
public function sendToAuthenticatedUser(array $data) | ||
{ | ||
$path = 'notify'; | ||
|
||
$options = [ | ||
'body' => json_encode($data), | ||
'headers' => ['Content-Type' => 'application/json'] | ||
]; | ||
|
||
return $this->client->apiRequest('post', $path, null, $options); | ||
|
||
} | ||
|
||
/** | ||
* Send Notification To Project Members | ||
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.notify.post API Documentation | ||
* | ||
* @param int $projectId | ||
* @param array $data | ||
* string $data[message] required<br> | ||
* string $data[role] Enum: "owner" "manager"<br> | ||
* integer[] $data[userIds] | ||
* @return mixed | ||
*/ | ||
public function sendNotificationToProjectMembers(int $projectId, array $data) | ||
{ | ||
$path = sprintf('projects/%s/notify', $projectId); | ||
|
||
$options = [ | ||
'body' => json_encode($data), | ||
'headers' => ['Content-Type' => 'application/json'] | ||
]; | ||
|
||
return $this->client->apiRequest('post', $path, null, $options); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
tests/CrowdinApiClient/Api/Enterprise/NotificationApiTest.php
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,24 @@ | ||
<?php | ||
|
||
namespace CrowdinApiClient\Tests\Api\Enterprise; | ||
|
||
class NotificationApiTest extends AbstractTestApi | ||
{ | ||
|
||
public function testSendNotificationToOrganizationMembers() | ||
{ | ||
$params = [ | ||
'message' => 'New notification message', | ||
'userIds' => [1] | ||
]; | ||
|
||
$this->mockRequest([ | ||
'method' => 'post', | ||
'uri' => 'https://organization_domain.crowdin.com/api/v2/notify', | ||
'body' => $params, | ||
'response' => null | ||
]); | ||
|
||
$this->crowdin->notification->sendNotificationToOrganizationMembers($params); | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace CrowdinApiClient\Tests\Api; | ||
|
||
class NotificationApiTest extends AbstractTestApi | ||
{ | ||
|
||
public function testSendToAuthenticatedUser() | ||
{ | ||
$params = [ | ||
'message' => 'New notification message', | ||
]; | ||
|
||
$this->mockRequest([ | ||
'method' => 'post', | ||
'uri' => 'https://api.crowdin.com/api/v2/notify', | ||
'body' => $params, | ||
'response' => null | ||
]); | ||
|
||
$this->crowdin->notification->sendToAuthenticatedUser($params); | ||
} | ||
|
||
public function testSendNotificationToProjectMembers() | ||
{ | ||
$params = [ | ||
'message' => 'New notification message', | ||
'userIds' => [1] | ||
]; | ||
|
||
$this->mockRequest([ | ||
'method' => 'post', | ||
'uri' => 'https://api.crowdin.com/api/v2/projects/2/notify', | ||
'body' => $params, | ||
'response' => null | ||
]); | ||
|
||
$this->crowdin->notification->sendNotificationToProjectMembers(2, $params); | ||
} | ||
} |