Skip to content

Commit 87540d4

Browse files
author
Glamazda Sergey
committed
add method sendSms
1 parent d9cfacc commit 87540d4

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/ApiClient.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,4 +1203,48 @@ public function startEventAutomation360($eventName, array $variables)
12031203

12041204
return $this->handleResult($requestResult);
12051205
}
1206+
1207+
/**
1208+
* @param array $data
1209+
* Parameter keys:
1210+
* Required parameters:
1211+
* string 'sender' => Sender name
1212+
* string 'body' => Message text
1213+
* array|string 'phones' => ['1234565', '4567895', ...] or '{"1234565","4567895", ...}'
1214+
*
1215+
* Optional parameters:
1216+
* int 'transliterate' => 1 or 0
1217+
* string 'date' => 'Y-m-d H:i:s' or null
1218+
* array|string 'route' => ['UA'=>'international', 'BY' => 'national', ...]
1219+
* or '{"UA":"international","BY":"international", ...}'
1220+
*
1221+
* @return stdClass
1222+
* @throws \InvalidArgumentException
1223+
*/
1224+
public function sendSms(array $data)
1225+
{
1226+
//Required parameters
1227+
$request['sender'] = isset($data['sender']) ? trim( (string)$data['sender']) : '';
1228+
$request['body'] = isset($data['body']) ? trim( (string)$data['body']) : '';
1229+
$request['phones'] = isset($data['phones'])
1230+
? (\is_array($data['phones']) ? \json_encode($data['phones']) : trim( (string)$data['phones']) )
1231+
: '';
1232+
1233+
//Optional parameters
1234+
$request['transliterate'] = empty($data['transliterate']) ? 0 : 1;
1235+
$request['date'] = isset($data['date']) ? trim( (string)$data['date']) : null;
1236+
$request['route'] = isset($data['route'])
1237+
? (\is_array($data['route']) ? \json_encode($data['route']) : trim( (string)$data['route']) )
1238+
: null;
1239+
1240+
if(empty($request['sender']) || empty($request['body']) || empty($request['phones']) )
1241+
{
1242+
$msg = print_r($request, true);
1243+
throw new \InvalidArgumentException("One or more required parameters are missing:\n$msg");
1244+
}
1245+
1246+
$requestResult = $this->sendRequest('sms/send', 'POST', $request);
1247+
1248+
return $this->handleResult($requestResult);
1249+
}
12061250
}

src/ApiInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,12 @@ public function getPushIntegrationCode($websiteID);
386386
* @return \stdClass
387387
*/
388388
public function startEventAutomation360($eventName, array $variables);
389+
390+
/**
391+
* @param array $data
392+
*
393+
* @return \stdClass
394+
* @throws \InvalidArgumentException
395+
*/
396+
public function sendSms(array $data);
389397
}

0 commit comments

Comments
 (0)