Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
11.11% |
2 / 18 |
| SyncCall | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
15.24 | |
11.11% |
2 / 18 |
| dial | |
0.00% |
0 / 1 |
1.36 | |
28.57% |
2 / 7 |
|||
| getCallStatus | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| getNewMissedCalls | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| saveCallAutoResponseText | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace CeculaSyncApiClient; |
| 4 | |
| 5 | use Requests; |
| 6 | |
| 7 | |
| 8 | class SyncCall extends SyncApiClient implements SyncCallInterface |
| 9 | { |
| 10 | |
| 11 | |
| 12 | /** |
| 13 | * Dial Number |
| 14 | * This method dials the supplied mobile phone number |
| 15 | * |
| 16 | * @param string $receiver Mobile number of recipient prefixed with country code. |
| 17 | * @return object |
| 18 | * @throws \Exception |
| 19 | */ |
| 20 | public function dial(string $receiver): object |
| 21 | { |
| 22 | // Validate number before dialling. Will throw exception if number is invalid. |
| 23 | $mobileNumberValidator = new RecipientValidator(); |
| 24 | $mobileNumberValidator->validate($receiver); |
| 25 | |
| 26 | $endpoint = sprintf("%s/%s", $this->apiManager->base, $this->apiManager->endpoints->call->dial->endpoint); |
| 27 | $data = [ |
| 28 | "receiver" => $receiver |
| 29 | ]; |
| 30 | $response = Requests::post($endpoint, $this->requestHeader, json_encode($data)); |
| 31 | return json_decode($response->body); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Get Call Status |
| 36 | * This method uses the trackingID returned by the dial() method to fetch the status of a call. |
| 37 | * |
| 38 | * @param string $callTrackingId The tracking ID that was returned when call request by sendMissedCall() |
| 39 | * @return object |
| 40 | */ |
| 41 | public function getCallStatus(string $callTrackingId): object |
| 42 | { |
| 43 | $endpoint = sprintf("%s/%s/%s", $this->apiManager->base, $this->apiManager->endpoints->call->dialledCallStatus->endpoint, $callTrackingId); |
| 44 | $response = Requests::get($endpoint, $this->requestHeader); |
| 45 | return json_decode($response->body); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Get New Missed CallS |
| 50 | * This method fetches a collection of new missed calls. |
| 51 | * |
| 52 | * @return array |
| 53 | */ |
| 54 | public function getNewMissedCalls(): array |
| 55 | { |
| 56 | $endpoint = sprintf("%s/%s", $this->apiManager->base, $this->apiManager->endpoints->call->newMissedCalls->endpoint); |
| 57 | $response = Requests::get($endpoint, $this->requestHeader); |
| 58 | return json_decode($response->body); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Save Call Auto-Response Text |
| 63 | * This method is used to set an auto-response message that should be sent to mobile phone number that attempts |
| 64 | * to dial the hosted SIM. |
| 65 | * |
| 66 | * @param string $text A billable auto-response sms for callers |
| 67 | * @return object |
| 68 | */ |
| 69 | public function saveCallAutoResponseText(string $text): object |
| 70 | { |
| 71 | $endpoint = sprintf("%s/%s", $this->apiManager->base, $this->apiManager->endpoints->call->setAutoResponse->endpoint); |
| 72 | $data = [ |
| 73 | "text" => $text |
| 74 | ]; |
| 75 | $response = Requests::patch($endpoint, $this->requestHeader, json_encode($data)); |
| 76 | return json_decode($response->body); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | } |