Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
CRAP
10.53% covered (danger)
10.53%
2 / 19
SyncSms
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
15.46
10.53% covered (danger)
10.53%
2 / 19
 sendSMS
0.00% covered (danger)
0.00%
0 / 1
1.42
25.00% covered (danger)
25.00%
2 / 8
 getSentMessageStatus
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 getUnreadSMS
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 setSMSAutoResponseText
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 5
1<?php
2
3namespace CeculaSyncApiClient;
4
5use Requests;
6
7class SyncSms extends SyncApiClient implements SyncSmsInterface
8{
9    /**
10     * Send SMS
11     * This method sends sms using the Cecula Sync API.
12     *
13     * @param string $text Message body
14     * @param array $recipients An indexed array of recipients. eg. ["23480xxxxxxx","23490xxxxxxxx",...]
15     * @return object            A JSON object
16     * @throws \Exception
17     */
18    public function sendSMS(string $text, array $recipients): object
19    {
20        //       Validate number before dialling. Will throw exception if number is invalid.
21        $mobileNumberValidator = new RecipientValidator();
22        $mobileNumberValidator->validateAll(implode(",", $recipients));
23
24        $endpoint = sprintf("%s/%s", $this->apiManager->base, $this->apiManager->endpoints->sms->sendSms->endpoint);
25        $data = [
26            "text" => $text,
27            "recipients" => implode(",", $recipients)
28        ];
29        $response = Requests::post($endpoint, $this->requestHeader, json_encode($data));
30        return json_decode($response->body);
31    }
32
33    /**
34     * Get Sent SMS Status
35     * When sendSMS() method is called successfully, a trackingId was generated for each of the recipients. This method
36     * uses the trackingId returned to track the message status for a recipient.
37     *
38     * @param string $smsTrackingId
39     * @return object
40     */
41    public function getSentMessageStatus(string $smsTrackingId): object
42    {
43        $endpoint = sprintf("%s/%s/%s", $this->apiManager->base, $this->apiManager->endpoints->sms->sentSmsStatus->endpoint, $smsTrackingId);
44        $response = Requests::get($endpoint, $this->requestHeader);
45        return json_decode($response->body);
46    }
47
48    /**
49     * Get Unread SMS
50     * This method fetches the list of Unread SMS messages
51     *
52     * @return array
53     */
54    public function getUnreadSMS(): array
55    {
56        $endpoint = sprintf("%s/%s", $this->apiManager->base, $this->apiManager->endpoints->sms->unreadSms->endpoint);
57        $response = Requests::get($endpoint, $this->requestHeader);
58        return json_decode($response->body);
59    }
60
61    /**
62     * Set Auto-Response SMS
63     * This method will set an automated reply sms to send when your hosted sim receives an sms.
64     *
65     * @param string $text An auto-response reply for incoming sms
66     * @return object
67     */
68    public function setSMSAutoResponseText(string $text): object
69    {
70        $endpoint = sprintf("%s/%s", $this->apiManager->base, $this->apiManager->endpoints->sms->setAutoResponse->endpoint);
71        $data = [
72            "text" => $text
73        ];
74        $response = Requests::patch($endpoint, $this->requestHeader, json_encode($data));
75        return json_decode($response->body);
76    }
77}