-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
0 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
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,62 @@ | ||
<?php | ||
|
||
namespace Utopia\Messaging\Adapters\Push; | ||
|
||
use Utopia\Messaging\Adapters\Push as PushAdapter; | ||
use Utopia\Messaging\Messages\Push; | ||
|
||
class AWSSNS extends PushAdapter | ||
{ | ||
/** | ||
* @param string $apiGatewayUrl | ||
*/ | ||
public function __construct( | ||
private string $apiGatewayUrl | ||
) { | ||
} | ||
|
||
/** | ||
* Get adapter name. | ||
* | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return 'AWSSNS'; | ||
} | ||
|
||
/** | ||
* Get max messages per request. | ||
* | ||
* @return int | ||
*/ | ||
public function getMaxMessagesPerRequest(): int | ||
{ | ||
return 5000; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws \Exception | ||
*/ | ||
protected function process(Push $message): string | ||
{ | ||
// Create the payload | ||
$payload = [ | ||
'message' => $message->getData() | ||
]; | ||
|
||
// Make the HTTP request | ||
$response = $this->request( | ||
method: 'POST', | ||
url: $this->apiGatewayUrl, | ||
headers: [ | ||
'Content-Type: application/json', | ||
], | ||
body: json_encode($payload) | ||
); | ||
|
||
return $response; | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace Tests\E2E; | ||
|
||
use Utopia\Messaging\Adapters\Push\AWSSNS as AWSSNSAdapter; | ||
use Utopia\Messaging\Messages\Push; | ||
|
||
class AWSSNSTest extends Base | ||
{ | ||
public function testSend(): void | ||
{ | ||
$apiGatewayUrl = getenv('AWSSNS_API_GATEWAY_URL'); | ||
|
||
$adapter = new AWSSNSAdapter($apiGatewayUrl); | ||
|
||
$message = new Push( | ||
data: null | ||
); | ||
|
||
$response = json_decode($adapter->send($message), true); | ||
|
||
$this->assertNotEmpty($response); | ||
$this->assertEquals('success', $response['status'] ?? null); | ||
$this->assertNotEmpty($response['MessageId'] ?? null); | ||
} | ||
} |