Skip to content

Commit

Permalink
Merge pull request #10 from pryznar/master
Browse files Browse the repository at this point in the history
Added priority optional argument
  • Loading branch information
Jan authored Nov 29, 2018
2 parents 19af306 + 64acffa commit dafb0bf
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/SmsConnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class SmsConnect

const USER_AGENT = 'SmsConnect PHP v2.0';

private $priorities = array(-1, 0, 1, 2, 3);


/**
* @param string $login
Expand Down Expand Up @@ -69,9 +71,10 @@ public function getInbox()
* @param string $sender
* @param string|NULL $userId
* @param int $deliveryReport
* @param int $priority
* @return array
*/
public function sendSms($number, $text, $sender = '', $userId = NULL, $deliveryReport = 1)
public function sendSms($number, $text, $sender = '', $userId = NULL, $deliveryReport = 1, $priority = 1)
{
$authData = $this->getAuth($this->login, $this->password);
$authData['action'] = self::ACTION_SEND_SMS;
Expand All @@ -80,6 +83,10 @@ public function sendSms($number, $text, $sender = '', $userId = NULL, $deliveryR
$authData['sender_id'] = $sender;
$authData['user_id'] = $userId;
$authData['delivery_report'] = $deliveryReport;
if (in_array($priority, $this->priorities)) {
throw new InvalidArgumentException('Incorrect priority argument');
}
$authData['priority'] = $priority;

$requestUrl = $this->getRequestUrl($authData);
$response = $this->getRequest($requestUrl);
Expand All @@ -94,8 +101,9 @@ public function sendSms($number, $text, $sender = '', $userId = NULL, $deliveryR
* @param string $sender
* @param string|NULL $userId
* @param int $deliveryReport
* @param int $priority
*/
public function addRecipient($number, $text, $time = NULL, $sender = '', $userId = NULL, $deliveryReport = 1)
public function addRecipient($number, $text, $time = NULL, $sender = '', $userId = NULL, $deliveryReport = 1, $priority = 1)
{
if (!$this->queue) {
$this->queue = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><queue></queue>');
Expand All @@ -107,6 +115,10 @@ public function addRecipient($number, $text, $time = NULL, $sender = '', $userId
$sms->addChild("sender_id", $this->xmlEncode($sender));
$sms->addChild("delivery_report", $deliveryReport);
$sms->addChild('user_id', $userId);
if (in_array($priority, $this->priorities)) {
throw new InvalidArgumentException('Incorrect priority argument');
}
$sms->addChild('priority', $priority);
}


Expand Down

0 comments on commit dafb0bf

Please sign in to comment.