Skip to content

Commit

Permalink
Merge pull request #2 from HaiD84/viber
Browse files Browse the repository at this point in the history
Viber methods
  • Loading branch information
luza authored Aug 29, 2022
2 parents 0eaa79d + 1f85984 commit 74346ed
Show file tree
Hide file tree
Showing 12 changed files with 777 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Dto/FlashCallStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

class FlashCallStatus
{
public const STATUS_QUEUED = 0; // в очереди
public const STATUS_DIALLED = 1; // дозвон
public const STATUS_NOT_DIALLED = 2; // не дозвон
public const STATUS_SENT = 4; // передано оператору

/**
* @var int
* @JMS\Type("int")
Expand Down
8 changes: 8 additions & 0 deletions src/Dto/SmsMessageResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@

class SmsMessageResult
{
public const STATUS_QUEUED = 0; // в очереди
public const STATUS_DELIVERED = 1; // доставлено
public const STATUS_NOT_DELIVERED = 2; // не доставлено
public const STATUS_SENT = 3; // передано
public const STATUS_WAITING_STATUS = 4; // ожидание статуса сообщения
public const STATUS_REJECTED = 6; // сообщение отклонено
public const STATUS_ON_MODERATION = 8; // на модерации

/**
* @var int
* @JMS\Type("int")
Expand Down
42 changes: 42 additions & 0 deletions src/Dto/ViberNumberStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Feech\SmsAero\Dto;

use JMS\Serializer\Annotation as JMS;

class ViberNumberStatus
{
public const STATUS_SENT = 0; // отправлено
public const STATUS_DELIVERED = 1; // доставлено
public const STATUS_READ = 2; // прочитано
public const STATUS_NOT_DELIVERED = 3; // не доставлено
public const STATUS_ERROR = 4; // ошибка

/**
* @var string
* @JMS\Type("string")
*/
public $number;

/**
* @var int
* @JMS\Type("int")
*/
public $status;

/**
* @var string
* @JMS\Type("string")
* @JMS\SerializedName("extendStatus")
*/
public $extendStatus;

/**
* @var int
* @JMS\Type("int")
* @JMS\SerializedName("dateSend")
*/
public $dateSend;
}
239 changes: 239 additions & 0 deletions src/Dto/ViberSendRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
<?php

declare(strict_types=1);

namespace Feech\SmsAero\Dto;

class ViberSendRequest
{
public const CHANNEL_INFO = 'INFO';
public const CHANNEL_OFFICIAL = 'OFFICIAL';
public const CHANNEL_CASCADE = 'CASCADE';

/**
* @var string|null
*/
private $number;

/**
* @var string[]|null
*/
private $numbers;

/**
* @var int|string|null
*/
private $groupId;

/**
* @var string
*/
private $sign;

/**
* @var string
*/
private $channel;

/**
* @var string
*/
private $text;

/**
* @var string|null
*/
private $imageSource;

/**
* @var string|null
*/
private $textButton;

/**
* @var string|null
*/
private $linkButton;

/**
* @var int|null
*/
private $dateSend;

/**
* @var string|null
*/
private $signSms;

/**
* @var string|null
*/
private $textSms;

/**
* @var int|null
*/
private $priceSms;

/**
* @var float|null
*/
private $timeout;

private function __construct()
{
}

public static function toSingleNumber(
string $number,
string $sign,
string $channel,
string $text
): self {
$request = new self();
$request->number = $number;
$request->sign = $sign;
$request->channel = $channel;
$request->text = $text;

return $request;
}

/**
* @param string[] $numbers
* @param string $sign
* @param string $channel
* @param string $text
*/
public static function toMultipleNumbers(
array $numbers,
string $sign,
string $channel,
string $text
): self {
assert(count($numbers) > 0 && count($numbers) <= 50);

$request = new self();
$request->numbers = $numbers;
$request->sign = $sign;
$request->channel = $channel;
$request->text = $text;

return $request;
}

/**
* @param int|string $groupId
* @param string $sign
* @param string $channel
* @param string $text
*/
public static function toGroup(
$groupId,
string $sign,
string $channel,
string $text
): self {
assert(is_int($groupId) || $groupId === 'all');

$request = new self();
$request->groupId = $groupId;
$request->sign = $sign;
$request->channel = $channel;
$request->text = $text;

return $request;
}

public function toArray(): array
{
$data = [
'number' => $this->number,
'numbers' => $this->numbers,
'groupId' => $this->groupId,
'sign' => $this->sign,
'channel' => $this->channel,
'text' => $this->text,
'imageSource' => $this->imageSource,
'textButton' => $this->textButton,
'linkButton' => $this->linkButton,
'dateSend' => $this->dateSend,
'signSms' => $this->signSms,
'textSms' => $this->textSms,
'priceSms' => $this->priceSms,
'timeout' => $this->timeout,
];

return array_filter(
$data,
function ($value) {
return $value !== null;
}
);
}

public function setImageSource(?string $imageContent, ?string $type): self
{
if ($imageContent === null) {
$this->imageSource = null;
} else {
assert(in_array($type, ['png', 'jpg', 'gif']));
$this->imageSource = $type . '#' . base64_encode($imageContent);
}

return $this;
}

public function setTextButton(?string $textButton): self
{
$this->textButton = $textButton;

return $this;
}

public function setLinkButton(?string $linkButton): self
{
$this->linkButton = $linkButton;

return $this;
}

public function setDateSend(?\DateTimeInterface $dateSend): self
{
if ($dateSend === null) {
$this->dateSend = null;
} else {
$this->dateSend = $dateSend->getTimestamp();
}

return $this;
}

public function setSignSms(?string $signSms): self
{
$this->signSms = $signSms;

return $this;
}

public function setTextSms(?string $textSms): self
{
$this->textSms = $textSms;

return $this;
}

public function setPriceSms(?int $priceSms): self
{
$this->priceSms = $priceSms;

return $this;
}

public function setTimeout(?float $timeout): self
{
$this->timeout = $timeout;

return $this;
}
}
16 changes: 16 additions & 0 deletions src/Dto/ViberSendResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Feech\SmsAero\Dto;

use JMS\Serializer\Annotation as JMS;

class ViberSendResponse extends BaseResponse
{
/**
* @var ViberStatus|null
* @JMS\Type("Feech\SmsAero\Dto\ViberStatus")
*/
public $data;
}
16 changes: 16 additions & 0 deletions src/Dto/ViberStatisticResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Feech\SmsAero\Dto;

use JMS\Serializer\Annotation as JMS;

class ViberStatisticResponse extends BaseResponse
{
/**
* @var ViberNumberStatus[]
* @JMS\Type("array<Feech\SmsAero\Dto\ViberNumberStatus>")
*/
public $data;
}
Loading

0 comments on commit 74346ed

Please sign in to comment.