Skip to content

Commit

Permalink
RCS objects and tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK committed Aug 19, 2024
1 parent 8efe7cc commit 0bb36b8
Show file tree
Hide file tree
Showing 8 changed files with 619 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/Messages/Channel/RCS/RcsCustom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Vonage\Messages\Channel\RCS;

use Vonage\Messages\MessageObjects\FileObject;
use Vonage\Messages\Channel\BaseMessage;
use Vonage\Messages\MessageTraits\TtlTrait;

class RcsCustom extends BaseMessage
{
use TtlTrait;

protected const RCS_TEXT_MIN_TTL = 300;
protected const RCS_TEXT_MAX_TTL = 259200;

protected string $subType = BaseMessage::MESSAGES_SUBTYPE_FILE;
protected string $channel = 'rcs';
protected array $custom;

public function __construct(
string $to,
string $from,
array $custom
) {
$this->to = $to;
$this->from = $from;
$this->custom = $custom;
}

public function getCustom(): array
{
return $this->custom;
}

public function setCustom(array $custom): RcsCustom
{
$this->custom = $custom;
return $this;
}

public function setTtl(?int $ttl): void
{
$range = [
'options' => [
'min_range' => self::RCS_TEXT_MIN_TTL,
'max_range' => self::RCS_TEXT_MAX_TTL
]
];

if (!filter_var($ttl, FILTER_VALIDATE_INT, $range)) {
throw new RcsInvalidTtlException('Timeout ' . $ttl . ' is not valid');
}

$this->ttl = $ttl;
}

public function toArray(): array
{
$returnArray = $this->getBaseMessageUniversalOutputArray();

$returnArray['custom'] = $this->getCustom();

if ($this->getClientRef()) {
$returnArray['client_ref'] = $this->getClientRef();
}

if ($this->getWebhookUrl()) {
$returnArray['webhook_url'] = $this->getWebhookUrl();
}

if ($this->getTtl()) {
$returnArray['ttl'] = $this->getTtl();
}

return $returnArray;
}
}
77 changes: 77 additions & 0 deletions src/Messages/Channel/RCS/RcsFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Vonage\Messages\Channel\RCS;

use Vonage\Messages\MessageObjects\FileObject;
use Vonage\Messages\Channel\BaseMessage;
use Vonage\Messages\MessageTraits\TtlTrait;

class RcsFile extends BaseMessage
{
use TtlTrait;

protected const RCS_TEXT_MIN_TTL = 300;
protected const RCS_TEXT_MAX_TTL = 259200;

protected string $subType = BaseMessage::MESSAGES_SUBTYPE_FILE;
protected string $channel = 'rcs';
protected FileObject $file;

public function __construct(
string $to,
string $from,
FileObject $file
) {
$this->to = $to;
$this->from = $from;
$this->file = $file;
}

public function setTtl(?int $ttl): void
{
$range = [
'options' => [
'min_range' => self::RCS_TEXT_MIN_TTL,
'max_range' => self::RCS_TEXT_MAX_TTL
]
];

if (!filter_var($ttl, FILTER_VALIDATE_INT, $range)) {
throw new RcsInvalidTtlException('Timeout ' . $ttl . ' is not valid');
}

$this->ttl = $ttl;
}

public function getFile(): FileObject
{
return $this->file;
}

public function setFile(FileObject $fileObject): RcsFile
{
$this->file = $fileObject;
return $this;
}

public function toArray(): array
{
$returnArray = $this->getBaseMessageUniversalOutputArray();

$returnArray['file'] = $this->getFile()->toArray();

if ($this->getClientRef()) {
$returnArray['client_ref'] = $this->getClientRef();
}

if ($this->getWebhookUrl()) {
$returnArray['webhook_url'] = $this->getWebhookUrl();
}

if ($this->getTtl()) {
$returnArray['ttl'] = $this->getTtl();
}

return $returnArray;
}
}
77 changes: 77 additions & 0 deletions src/Messages/Channel/RCS/RcsImage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Vonage\Messages\Channel\RCS;

use Vonage\Messages\MessageObjects\ImageObject;
use Vonage\Messages\Channel\BaseMessage;
use Vonage\Messages\MessageTraits\TtlTrait;

class RcsImage extends BaseMessage
{
use TtlTrait;

protected const RCS_TEXT_MIN_TTL = 300;
protected const RCS_TEXT_MAX_TTL = 259200;

protected string $subType = BaseMessage::MESSAGES_SUBTYPE_IMAGE;
protected string $channel = 'rcs';
protected ImageObject $image;

public function __construct(
string $to,
string $from,
ImageObject $image
) {
$this->to = $to;
$this->from = $from;
$this->image = $image;
}

public function setTtl(?int $ttl): void
{
$range = [
'options' => [
'min_range' => self::RCS_TEXT_MIN_TTL,
'max_range' => self::RCS_TEXT_MAX_TTL
]
];

if (!filter_var($ttl, FILTER_VALIDATE_INT, $range)) {
throw new RcsInvalidTtlException('Timeout ' . $ttl . ' is not valid');
}

$this->ttl = $ttl;
}

public function getImage(): ImageObject
{
return $this->image;
}

public function setImage(ImageObject $image): RcsImage
{
$this->image = $image;
return $this;
}

public function toArray(): array
{
$returnArray = $this->getBaseMessageUniversalOutputArray();

$returnArray['image'] = $this->getImage()->toArray();

if ($this->getClientRef()) {
$returnArray['client_ref'] = $this->getClientRef();
}

if ($this->getWebhookUrl()) {
$returnArray['webhook_url'] = $this->getWebhookUrl();
}

if ($this->getTtl()) {
$returnArray['ttl'] = $this->getTtl();
}

return $returnArray;
}
}
7 changes: 7 additions & 0 deletions src/Messages/Channel/RCS/RcsInvalidTtlException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Vonage\Messages\Channel\RCS;

class RcsInvalidTtlException extends \Exception
{
}
65 changes: 65 additions & 0 deletions src/Messages/Channel/RCS/RcsText.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Vonage\Messages\Channel\RCS;

use Vonage\Messages\MessageTraits\TextTrait;
use Vonage\Messages\Channel\BaseMessage;
use Vonage\Messages\MessageTraits\TtlTrait;

class RcsText extends BaseMessage
{
use TextTrait;
use TtlTrait;

protected const RCS_TEXT_MIN_TTL = 300;
protected const RCS_TEXT_MAX_TTL = 259200;

protected string $subType = BaseMessage::MESSAGES_SUBTYPE_TEXT;
protected string $channel = 'rcs';

public function __construct(
string $to,
string $from,
string $message
) {
$this->to = $to;
$this->from = $from;
$this->text = $message;
}

public function setTtl(?int $ttl): void
{
$range = [
'options' => [
'min_range' => self::RCS_TEXT_MIN_TTL,
'max_range' => self::RCS_TEXT_MAX_TTL
]
];

if (!filter_var($ttl, FILTER_VALIDATE_INT, $range)) {
throw new RcsInvalidTtlException('Timeout ' . $ttl . ' is not valid');
}

$this->ttl = $ttl;
}

public function toArray(): array
{
$returnArray = $this->getBaseMessageUniversalOutputArray();
$returnArray['text'] = $this->getText();

if ($this->getClientRef()) {
$returnArray['client_ref'] = $this->getClientRef();
}

if ($this->getWebhookUrl()) {
$returnArray['webhook_url'] = $this->getWebhookUrl();
}

if ($this->getTtl()) {
$returnArray['ttl'] = $this->getTtl();
}

return $returnArray;
}
}
77 changes: 77 additions & 0 deletions src/Messages/Channel/RCS/RcsVideo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Vonage\Messages\Channel\RCS;

use Vonage\Messages\MessageObjects\VideoObject;
use Vonage\Messages\Channel\BaseMessage;
use Vonage\Messages\MessageTraits\TtlTrait;

class RcsVideo extends BaseMessage
{
use TtlTrait;

protected const RCS_TEXT_MIN_TTL = 300;
protected const RCS_TEXT_MAX_TTL = 259200;

protected string $subType = BaseMessage::MESSAGES_SUBTYPE_VIDEO;
protected string $channel = 'rcs';
protected VideoObject $video;

public function __construct(
string $to,
string $from,
VideoObject $videoObject
) {
$this->to = $to;
$this->from = $from;
$this->video = $videoObject;
}

public function setTtl(?int $ttl): void
{
$range = [
'options' => [
'min_range' => self::RCS_TEXT_MIN_TTL,
'max_range' => self::RCS_TEXT_MAX_TTL
]
];

if (!filter_var($ttl, FILTER_VALIDATE_INT, $range)) {
throw new RcsInvalidTtlException('Timeout ' . $ttl . ' is not valid');
}

$this->ttl = $ttl;
}

public function getVideo(): VideoObject
{
return $this->video;
}

public function setVideo(VideoObject $videoObject): RcsVideo
{
$this->video = $videoObject;
return $this;
}

public function toArray(): array
{
$returnArray = $this->getBaseMessageUniversalOutputArray();

$returnArray['video'] = $this->getVideo()->toArray();

if ($this->getClientRef()) {
$returnArray['client_ref'] = $this->getClientRef();
}

if ($this->getWebhookUrl()) {
$returnArray['webhook_url'] = $this->getWebhookUrl();
}

if ($this->getTtl()) {
$returnArray['ttl'] = $this->getTtl();
}

return $returnArray;
}
}
Loading

0 comments on commit 0bb36b8

Please sign in to comment.