From 831ef730e412071810cb4d8f539c16991c7ce76e Mon Sep 17 00:00:00 2001 From: Sumitmaithani Date: Sat, 7 Oct 2023 12:56:58 +0530 Subject: [PATCH 1/7] added pushbullet adapter --- .github/workflows/tests.yml | 75 ++++++++++--------- docker-compose.yml | 61 +++++++-------- .../Messaging/Adapters/Push/PushBullet.php | 65 ++++++++++++++++ tests/e2e/Push/PushBulletTest.php | 34 +++++++++ 4 files changed, 168 insertions(+), 67 deletions(-) create mode 100644 src/Utopia/Messaging/Adapters/Push/PushBullet.php create mode 100644 tests/e2e/Push/PushBulletTest.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 552b207d..bc7dc67e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,40 +7,41 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v2 - with: - fetch-depth: 2 - - run: git checkout HEAD^2 - - name: Run Tests - env: - MAILGUN_API_KEY: ${{ secrets.MAILGUN_API_KEY }} - MAILGUN_DOMAIN: ${{ secrets.MAILGUN_DOMAIN }} - SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }} - FCM_SERVER_KEY: ${{ secrets.FCM_SERVER_KEY }} - FCM_SERVER_TO: ${{ secrets.FCM_SERVER_TO }} - TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }} - TWILIO_AUTH_TOKEN: ${{ secrets.TWILIO_AUTH_TOKEN }} - TWILIO_TO: ${{ secrets.TWILIO_TO }} - TWILIO_FROM: ${{ secrets.TWILIO_FROM }} - TELNYX_API_KEY: ${{ secrets.TELNYX_API_KEY }} - TELNYX_PUBLIC_KEY: ${{ secrets.TELNYX_PUBLIC_KEY }} - APNS_AUTHKEY_8KVVCLA3HL: ${{ secrets.APNS_AUTHKEY_8KVVCLA3HL }} - APNS_AUTH_ID: ${{ secrets.APNS_AUTH_ID }} - APNS_TEAM_ID: ${{ secrets.APNS_TEAM_ID }} - APNS_BUNDLE_ID: ${{ secrets.APNS_BUNDLE_ID }} - APNS_TO: ${{ secrets.APNS_TO }} - MSG_91_SENDER_ID: ${{ secrets.MSG_91_SENDER_ID }} - MSG_91_AUTH_KEY: ${{ secrets.MSG_91_AUTH_KEY }} - MSG_91_TO: ${{ secrets.MSG_91_TO }} - MSG_91_FROM: ${{ secrets.MSG_91_FROM }} - TEST_EMAIL: ${{ secrets.TEST_EMAIL }} - TEST_FROM_EMAIL: ${{ secrets.TEST_FROM_EMAIL }} - VONAGE_API_KEY: ${{ secrets.VONAGE_API_KEY }} - VONAGE_API_SECRET: ${{ secrets.VONAGE_API_SECRET }} - VONAGE_TO: ${{ secrets.VONAGE_TO }} - VONAGE_FROM: ${{ secrets.VONAGE_FROM }} - run: | - docker compose up -d --build - sleep 5 - docker compose exec tests vendor/bin/phpunit \ No newline at end of file + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 2 + - run: git checkout HEAD^2 + - name: Run Tests + env: + MAILGUN_API_KEY: ${{ secrets.MAILGUN_API_KEY }} + MAILGUN_DOMAIN: ${{ secrets.MAILGUN_DOMAIN }} + SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }} + FCM_SERVER_KEY: ${{ secrets.FCM_SERVER_KEY }} + FCM_SERVER_TO: ${{ secrets.FCM_SERVER_TO }} + TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }} + TWILIO_AUTH_TOKEN: ${{ secrets.TWILIO_AUTH_TOKEN }} + TWILIO_TO: ${{ secrets.TWILIO_TO }} + TWILIO_FROM: ${{ secrets.TWILIO_FROM }} + TELNYX_API_KEY: ${{ secrets.TELNYX_API_KEY }} + TELNYX_PUBLIC_KEY: ${{ secrets.TELNYX_PUBLIC_KEY }} + APNS_AUTHKEY_8KVVCLA3HL: ${{ secrets.APNS_AUTHKEY_8KVVCLA3HL }} + APNS_AUTH_ID: ${{ secrets.APNS_AUTH_ID }} + APNS_TEAM_ID: ${{ secrets.APNS_TEAM_ID }} + APNS_BUNDLE_ID: ${{ secrets.APNS_BUNDLE_ID }} + APNS_TO: ${{ secrets.APNS_TO }} + MSG_91_SENDER_ID: ${{ secrets.MSG_91_SENDER_ID }} + MSG_91_AUTH_KEY: ${{ secrets.MSG_91_AUTH_KEY }} + MSG_91_TO: ${{ secrets.MSG_91_TO }} + MSG_91_FROM: ${{ secrets.MSG_91_FROM }} + TEST_EMAIL: ${{ secrets.TEST_EMAIL }} + TEST_FROM_EMAIL: ${{ secrets.TEST_FROM_EMAIL }} + VONAGE_API_KEY: ${{ secrets.VONAGE_API_KEY }} + VONAGE_API_SECRET: ${{ secrets.VONAGE_API_SECRET }} + VONAGE_TO: ${{ secrets.VONAGE_TO }} + VONAGE_FROM: ${{ secrets.VONAGE_FROM }} + PUSHBULLET_API_KEY: ${{ secrets.PUSHBULLET_API_KEY }} + run: | + docker compose up -d --build + sleep 5 + docker compose exec tests vendor/bin/phpunit diff --git a/docker-compose.yml b/docker-compose.yml index 80d626d9..e9c5267e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,47 +1,48 @@ -version: '3.9' +version: "3.9" services: tests: environment: - - MAILGUN_API_KEY - - MAILGUN_DOMAIN - - SENDGRID_API_KEY - - FCM_SERVER_KEY - - FCM_SERVER_TO - - TWILIO_ACCOUNT_SID - - TWILIO_AUTH_TOKEN - - TWILIO_TO - - TWILIO_FROM - - TELNYX_API_KEY - - TELNYX_PUBLIC_KEY - - APNS_AUTHKEY_8KVVCLA3HL - - APNS_AUTH_ID - - APNS_TEAM_ID - - APNS_BUNDLE_ID - - APNS_TO - - MSG_91_SENDER_ID - - MSG_91_AUTH_KEY - - MSG_91_TO - - MSG_91_FROM - - TEST_EMAIL - - TEST_FROM_EMAIL - - VONAGE_API_KEY - - VONAGE_API_SECRET - - VONAGE_TO - - VONAGE_FROM + - MAILGUN_API_KEY + - MAILGUN_DOMAIN + - SENDGRID_API_KEY + - FCM_SERVER_KEY + - FCM_SERVER_TO + - TWILIO_ACCOUNT_SID + - TWILIO_AUTH_TOKEN + - TWILIO_TO + - TWILIO_FROM + - TELNYX_API_KEY + - TELNYX_PUBLIC_KEY + - APNS_AUTHKEY_8KVVCLA3HL + - APNS_AUTH_ID + - APNS_TEAM_ID + - APNS_BUNDLE_ID + - APNS_TO + - MSG_91_SENDER_ID + - MSG_91_AUTH_KEY + - MSG_91_TO + - MSG_91_FROM + - TEST_EMAIL + - TEST_FROM_EMAIL + - VONAGE_API_KEY + - VONAGE_API_SECRET + - VONAGE_TO + - VONAGE_FROM + - PUSHBULLET_API_KEY build: context: . volumes: - ./src:/usr/local/src/src - ./tests:/usr/local/src/tests - ./phpunit.xml:/usr/local/src/phpunit.xml - + maildev: image: appwrite/mailcatcher:1.0.0 ports: - - '10000:1080' + - "10000:1080" request-catcher: image: appwrite/requestcatcher:1.0.0 ports: - - '10001:5000' \ No newline at end of file + - "10001:5000" diff --git a/src/Utopia/Messaging/Adapters/Push/PushBullet.php b/src/Utopia/Messaging/Adapters/Push/PushBullet.php new file mode 100644 index 00000000..6dcdf46b --- /dev/null +++ b/src/Utopia/Messaging/Adapters/Push/PushBullet.php @@ -0,0 +1,65 @@ + 'note', + 'title' => $message->getTitle(), + 'body' => $message->getBody(), + ]; + + try { + $client = new Client(); + $response = $client->request('POST', 'https://api.pushbullet.com/v2/pushes', [ + 'headers' => [ + 'Access-Token' => $this->apiKey, + 'Content-Type' => 'application/json', + ], + 'json' => $payload, + ]); + + return $response->getStatusCode() === 200; + } catch (Exception $e) { + return false; + } + } +} diff --git a/tests/e2e/Push/PushBulletTest.php b/tests/e2e/Push/PushBulletTest.php new file mode 100644 index 00000000..74241fbf --- /dev/null +++ b/tests/e2e/Push/PushBulletTest.php @@ -0,0 +1,34 @@ +process($message)); + + $this->assertNotEmpty($response); + $this->assertEquals('success', $response->status); + } +} From 512cd376d1b0b3d0ed5e63ea456f23df8c9b1abc Mon Sep 17 00:00:00 2001 From: Sumitmaithani Date: Sun, 15 Oct 2023 18:16:12 +0530 Subject: [PATCH 2/7] fixed lint error --- src/Utopia/Messaging/Adapters/Push/PushBullet.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/Push/PushBullet.php b/src/Utopia/Messaging/Adapters/Push/PushBullet.php index 6dcdf46b..3622d154 100644 --- a/src/Utopia/Messaging/Adapters/Push/PushBullet.php +++ b/src/Utopia/Messaging/Adapters/Push/PushBullet.php @@ -3,19 +3,17 @@ namespace Utopia\Messaging\Adapters\Push; use Exception; - +use GuzzleHttp\Client; use Utopia\Messaging\Adapters\Push as PushAdapter; use Utopia\Messaging\Messages\Push; -use GuzzleHttp\Client; class PushBullet extends PushAdapter { /** * @param string $apiKey The PushBullet API key. */ - public function __construct(string $apiKey) + public function __construct(private string $apiKey) { - private string $apiKey; } /** @@ -35,6 +33,7 @@ public function getName(): string */ public function getMaxMessagesPerRequest(): int { + //TODO:: Didn't find the limit in PushBullet documentation return 1000; } @@ -57,7 +56,7 @@ public function process(Push $message): bool 'json' => $payload, ]); - return $response->getStatusCode() === 200; + return $response; } catch (Exception $e) { return false; } From 7d08600e4a9ffef9d96aaf5d81721adfa93bed95 Mon Sep 17 00:00:00 2001 From: Sumit Maithani <86047367+Sumitmaithani@users.noreply.github.com> Date: Fri, 27 Oct 2023 22:16:39 +0530 Subject: [PATCH 3/7] Update src/Utopia/Messaging/Adapters/Push/PushBullet.php Co-authored-by: Steven Nguyen <1477010+stnguyen90@users.noreply.github.com> --- src/Utopia/Messaging/Adapters/Push/PushBullet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utopia/Messaging/Adapters/Push/PushBullet.php b/src/Utopia/Messaging/Adapters/Push/PushBullet.php index 3622d154..b7684f03 100644 --- a/src/Utopia/Messaging/Adapters/Push/PushBullet.php +++ b/src/Utopia/Messaging/Adapters/Push/PushBullet.php @@ -7,7 +7,7 @@ use Utopia\Messaging\Adapters\Push as PushAdapter; use Utopia\Messaging\Messages\Push; -class PushBullet extends PushAdapter +class Pushbullet extends PushAdapter { /** * @param string $apiKey The PushBullet API key. From 5e3cf14143f623377dde38237c288fa91fff0b0a Mon Sep 17 00:00:00 2001 From: Sumit Maithani <86047367+Sumitmaithani@users.noreply.github.com> Date: Fri, 27 Oct 2023 22:17:12 +0530 Subject: [PATCH 4/7] Rename PushBullet.php to Pushbullet.php --- .../Messaging/Adapters/Push/{PushBullet.php => Pushbullet.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Utopia/Messaging/Adapters/Push/{PushBullet.php => Pushbullet.php} (100%) diff --git a/src/Utopia/Messaging/Adapters/Push/PushBullet.php b/src/Utopia/Messaging/Adapters/Push/Pushbullet.php similarity index 100% rename from src/Utopia/Messaging/Adapters/Push/PushBullet.php rename to src/Utopia/Messaging/Adapters/Push/Pushbullet.php From beceb408f9c62fd4ba057d5c6f2668b517dd5358 Mon Sep 17 00:00:00 2001 From: Sumitmaithani Date: Tue, 31 Oct 2023 16:41:41 +0530 Subject: [PATCH 5/7] changed file name --- src/Utopia/Messaging/Adapters/Push/Pushbullet.php | 2 +- tests/e2e/Push/PushBulletTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/Push/Pushbullet.php b/src/Utopia/Messaging/Adapters/Push/Pushbullet.php index b7684f03..c0ee49e7 100644 --- a/src/Utopia/Messaging/Adapters/Push/Pushbullet.php +++ b/src/Utopia/Messaging/Adapters/Push/Pushbullet.php @@ -23,7 +23,7 @@ public function __construct(private string $apiKey) */ public function getName(): string { - return 'PushBullet'; + return 'Pushbullet'; } /** diff --git a/tests/e2e/Push/PushBulletTest.php b/tests/e2e/Push/PushBulletTest.php index 74241fbf..38a597b8 100644 --- a/tests/e2e/Push/PushBulletTest.php +++ b/tests/e2e/Push/PushBulletTest.php @@ -5,7 +5,7 @@ use Utopia\Messaging\Adapters\Push\Pushbullet as PushbulletAdapter; use Utopia\Messaging\Messages\Push; -class PushBulletTest extends Base +class PushbulletTest extends Base { public function testSend(): void { From 44ed9fc0cdc8f0d950dec72678189fbfc46660bd Mon Sep 17 00:00:00 2001 From: Sumit Maithani <86047367+Sumitmaithani@users.noreply.github.com> Date: Tue, 14 Nov 2023 13:20:13 +0530 Subject: [PATCH 6/7] Update src/Utopia/Messaging/Adapters/Push/Pushbullet.php Co-authored-by: Steven Nguyen <1477010+stnguyen90@users.noreply.github.com> --- src/Utopia/Messaging/Adapters/Push/Pushbullet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utopia/Messaging/Adapters/Push/Pushbullet.php b/src/Utopia/Messaging/Adapters/Push/Pushbullet.php index c0ee49e7..1c233aba 100644 --- a/src/Utopia/Messaging/Adapters/Push/Pushbullet.php +++ b/src/Utopia/Messaging/Adapters/Push/Pushbullet.php @@ -10,7 +10,7 @@ class Pushbullet extends PushAdapter { /** - * @param string $apiKey The PushBullet API key. + * @param string $apiKey The Pushbullet API key. */ public function __construct(private string $apiKey) { From 2bcfdbe78c06d0ad875d055d2999b23490e501a0 Mon Sep 17 00:00:00 2001 From: Sumitmaithani Date: Tue, 14 Nov 2023 13:22:47 +0530 Subject: [PATCH 7/7] changes PushBullet to Pushbullet --- src/Utopia/Messaging/Adapters/Push/Pushbullet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utopia/Messaging/Adapters/Push/Pushbullet.php b/src/Utopia/Messaging/Adapters/Push/Pushbullet.php index 1c233aba..2eef5260 100644 --- a/src/Utopia/Messaging/Adapters/Push/Pushbullet.php +++ b/src/Utopia/Messaging/Adapters/Push/Pushbullet.php @@ -33,7 +33,7 @@ public function getName(): string */ public function getMaxMessagesPerRequest(): int { - //TODO:: Didn't find the limit in PushBullet documentation + //TODO:: Didn't find the limit in Pushbullet documentation return 1000; }