From 50420752c3db50842b2a4af57f607d1ab427382c Mon Sep 17 00:00:00 2001 From: fadkeabhi <31249309+fadkeabhi@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:23:59 +0530 Subject: [PATCH 1/3] Added Mobivate API Added Support for Mobivate. Also Added and performed tests for same. --- .../Messaging/Adapters/SMS/Mobivate.php | 64 +++++++++++++++++++ tests/e2e/SMS/MobivateTest.php | 34 ++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/Utopia/Messaging/Adapters/SMS/Mobivate.php create mode 100644 tests/e2e/SMS/MobivateTest.php diff --git a/src/Utopia/Messaging/Adapters/SMS/Mobivate.php b/src/Utopia/Messaging/Adapters/SMS/Mobivate.php new file mode 100644 index 00000000..f1f149f8 --- /dev/null +++ b/src/Utopia/Messaging/Adapters/SMS/Mobivate.php @@ -0,0 +1,64 @@ +getTo() as $to){ + $temp = array( + "originator" => $message->getFrom(), + "recipient" => \ltrim($to, '+'), + "text" => $message->getContent() + ); + array_push($messages,$temp); + } + + return $this->request( + method: 'POST', + url: "https://api.mobivatebulksms.com/send/batch", + headers: [ + 'content-type: application/json', + 'Authorization: Bearer '.$this->apiKey, + ], + body: \json_encode([ + "routeId" => $this->routeId, + "messages" => $messages + ]), + ); + } +} \ No newline at end of file diff --git a/tests/e2e/SMS/MobivateTest.php b/tests/e2e/SMS/MobivateTest.php new file mode 100644 index 00000000..1bee04d3 --- /dev/null +++ b/tests/e2e/SMS/MobivateTest.php @@ -0,0 +1,34 @@ +send($message)); + + $this->assertNotEmpty($result); + $this->assertCount(\count($to),$result->recipients); + $this->assertEquals($result->routeId, getenv('MOBIVATE_ROUTE_ID')) + + } +} From 78ed2bb0c403fa8bc4037002ac090681fd298703 Mon Sep 17 00:00:00 2001 From: ABHISHEK FADAKE <31249309+fadkeabhi@users.noreply.github.com> Date: Wed, 1 Nov 2023 14:26:31 +0530 Subject: [PATCH 2/3] remove lint error --- tests/e2e/SMS/MobivateTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/SMS/MobivateTest.php b/tests/e2e/SMS/MobivateTest.php index 1bee04d3..5dfdb89a 100644 --- a/tests/e2e/SMS/MobivateTest.php +++ b/tests/e2e/SMS/MobivateTest.php @@ -28,7 +28,7 @@ public function testSendSMS() $this->assertNotEmpty($result); $this->assertCount(\count($to),$result->recipients); - $this->assertEquals($result->routeId, getenv('MOBIVATE_ROUTE_ID')) + $this->assertEquals($result->routeId, getenv('MOBIVATE_ROUTE_ID')); } } From a0b0439a918d0bc2b898f38f81819d7440e724e0 Mon Sep 17 00:00:00 2001 From: fadkeabhi <31249309+fadkeabhi@users.noreply.github.com> Date: Thu, 2 Nov 2023 10:24:05 +0530 Subject: [PATCH 3/3] remove lint issue --- .../Messaging/Adapters/SMS/Mobivate.php | 26 +++++++++---------- tests/e2e/SMS/MobivateTest.php | 5 +--- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/Mobivate.php b/src/Utopia/Messaging/Adapters/SMS/Mobivate.php index f1f149f8..04103ce1 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Mobivate.php +++ b/src/Utopia/Messaging/Adapters/SMS/Mobivate.php @@ -36,29 +36,27 @@ public function getMaxMessagesPerRequest(): int */ protected function process(SMS $message): string { - - $messages = array(); - - foreach($message->getTo() as $to){ - $temp = array( - "originator" => $message->getFrom(), - "recipient" => \ltrim($to, '+'), - "text" => $message->getContent() - ); - array_push($messages,$temp); + $messages = []; + foreach ($message->getTo() as $to) { + $temp = [ + 'originator' => $message->getFrom(), + 'recipient' => \ltrim($to, '+'), + 'text' => $message->getContent(), + ]; + array_push($messages, $temp); } return $this->request( method: 'POST', - url: "https://api.mobivatebulksms.com/send/batch", + url: 'https://api.mobivatebulksms.com/send/batch', headers: [ 'content-type: application/json', 'Authorization: Bearer '.$this->apiKey, ], body: \json_encode([ - "routeId" => $this->routeId, - "messages" => $messages + 'routeId' => $this->routeId, + 'messages' => $messages, ]), ); } -} \ No newline at end of file +} diff --git a/tests/e2e/SMS/MobivateTest.php b/tests/e2e/SMS/MobivateTest.php index 5dfdb89a..c54426ef 100644 --- a/tests/e2e/SMS/MobivateTest.php +++ b/tests/e2e/SMS/MobivateTest.php @@ -12,7 +12,6 @@ class MobivateTest extends Base */ public function testSendSMS() { - $sender = new Mobivate(getenv('MOBIVATE_API_KEY'), getenv('MOBIVATE_ROUTE_ID')); $to = [getenv('MOBIVATE_TO')]; $from = getenv('MOBIVATE_FROM'); @@ -22,13 +21,11 @@ public function testSendSMS() content: 'Test Content', from: $from ); - $result = \json_decode($sender->send($message)); $this->assertNotEmpty($result); - $this->assertCount(\count($to),$result->recipients); + $this->assertCount(\count($to), $result->recipients); $this->assertEquals($result->routeId, getenv('MOBIVATE_ROUTE_ID')); - } }