-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
410 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/Conversation/ConversationObjects/ConversationCallback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vonage\Conversation\ConversationObjects; | ||
|
||
use Vonage\Entity\Hydrator\ArrayHydrateInterface; | ||
|
||
class ConversationCallback implements ArrayHydrateInterface | ||
{ | ||
protected string $method = 'POST'; | ||
protected ?array $params; | ||
|
||
public function __construct( | ||
protected ?string $url = null, | ||
protected ?string $eventMask = null | ||
) { | ||
} | ||
|
||
public function getMethod(): string | ||
{ | ||
return $this->method; | ||
} | ||
|
||
public function setMethod(string $method): ConversationCallback | ||
{ | ||
$this->method = $method; | ||
|
||
return $this; | ||
} | ||
|
||
public function getParams(): ?array | ||
{ | ||
return $this->params; | ||
} | ||
|
||
public function setParams(?array $params): ConversationCallback | ||
{ | ||
$this->params = $params; | ||
|
||
return $this; | ||
} | ||
|
||
public function getUrl(): ?string | ||
{ | ||
return $this->url; | ||
} | ||
|
||
public function setUrl(?string $url): ConversationCallback | ||
{ | ||
$this->url = $url; | ||
|
||
return $this; | ||
} | ||
|
||
public function getEventMask(): ?string | ||
{ | ||
return $this->eventMask; | ||
} | ||
|
||
public function setEventMask(?string $eventMask): ConversationCallback | ||
{ | ||
$this->eventMask = $eventMask; | ||
|
||
return $this; | ||
} | ||
|
||
public function setApplicationId(string $applicationId): static | ||
{ | ||
$this->params['applicationId'] = $applicationId; | ||
|
||
return $this; | ||
} | ||
|
||
public function setNccoUrl(string $nccoUrl): static | ||
{ | ||
$this->params['ncco_url'] = $nccoUrl; | ||
|
||
return $this; | ||
} | ||
|
||
public function fromArray(array $data): static | ||
{ | ||
if (isset($data['url'])) { | ||
$this->setUrl($data['url']); | ||
} | ||
|
||
if (isset($data['event_mask'])) { | ||
$this->setEventMask($data['event_mask']); | ||
} | ||
|
||
if (isset($data['params'])) { | ||
$this->setParams($data['params']); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$returnPayload = []; | ||
|
||
if ($this->getUrl()) { | ||
$returnPayload['url'] = $this->getUrl(); | ||
} | ||
|
||
if ($this->getEventMask()) { | ||
$returnPayload['event_mask'] = $this->getEventMask(); | ||
} | ||
|
||
if ($this->getParams()) { | ||
$returnPayload['params'] = $this->getParams(); | ||
} | ||
|
||
$returnPayload['method'] = $this->getMethod(); | ||
|
||
return $returnPayload; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/Conversation/ConversationObjects/ConversationNumber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vonage\Conversation\ConversationObjects; | ||
|
||
use Vonage\Entity\Hydrator\ArrayHydrateInterface; | ||
|
||
class ConversationNumber implements ArrayHydrateInterface | ||
{ | ||
public const PHONE_TYPE = 'phone'; | ||
|
||
protected string $type = self::PHONE_TYPE; | ||
|
||
public function __construct( | ||
protected ?string $number, | ||
) { | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function getNumber(): ?string | ||
{ | ||
return $this->number; | ||
} | ||
|
||
public function setNumber(?string $number): ConversationNumber | ||
{ | ||
$this->number = $number; | ||
|
||
return $this; | ||
} | ||
|
||
public function fromArray(array $data): static | ||
{ | ||
if (isset($data['number'])) { | ||
$this->number = $data['number']; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'type' => $this->getType(), | ||
'number' => $this->getNumber() | ||
]; | ||
} | ||
} |
177 changes: 177 additions & 0 deletions
177
src/Conversation/ConversationObjects/NewConversationRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vonage\Conversation\ConversationObjects; | ||
|
||
use Vonage\Entity\Hydrator\ArrayHydrateInterface; | ||
|
||
class NewConversationRequest implements ArrayHydrateInterface | ||
{ | ||
protected ?int $ttl = null; | ||
protected ?array $customData = null; | ||
|
||
protected ?ConversationNumber $number = null; | ||
protected ?ConversationCallback $conversationCallback = null; | ||
|
||
public function __construct( | ||
protected ?string $name, | ||
protected ?string $displayName, | ||
protected ?string $imageUrl | ||
) { | ||
} | ||
|
||
public function getTtl(): ?int | ||
{ | ||
return $this->ttl; | ||
} | ||
|
||
public function setTtl(?int $ttl): NewConversationRequest | ||
{ | ||
$this->ttl = $ttl; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCustomData(): ?array | ||
{ | ||
return $this->customData; | ||
} | ||
|
||
public function setCustomData(?array $customData): NewConversationRequest | ||
{ | ||
$this->customData = $customData; | ||
|
||
return $this; | ||
} | ||
|
||
public function getNumber(): ?ConversationNumber | ||
{ | ||
return $this->number; | ||
} | ||
|
||
public function setNumber(ConversationNumber $number): NewConversationRequest | ||
{ | ||
$this->number = $number; | ||
|
||
return $this; | ||
} | ||
|
||
public function getConversationCallback(): ?ConversationCallback | ||
{ | ||
return $this->conversationCallback; | ||
} | ||
|
||
public function setConversationCallback(?ConversationCallback $conversationCallback): NewConversationRequest | ||
{ | ||
$this->conversationCallback = $conversationCallback; | ||
|
||
return $this; | ||
} | ||
|
||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(?string $name): NewConversationRequest | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function getDisplayName(): ?string | ||
{ | ||
return $this->displayName; | ||
} | ||
|
||
public function setDisplayName(?string $displayName): NewConversationRequest | ||
{ | ||
$this->displayName = $displayName; | ||
|
||
return $this; | ||
} | ||
|
||
public function getImageUrl(): ?string | ||
{ | ||
return $this->imageUrl; | ||
} | ||
|
||
public function setImageUrl(?string $imageUrl): NewConversationRequest | ||
{ | ||
$this->imageUrl = $imageUrl; | ||
|
||
return $this; | ||
} | ||
|
||
public function fromArray(array $data) | ||
{ | ||
if (isset($data['name'])) { | ||
$this->setName($data['name']); | ||
} | ||
|
||
if (isset($data['display_name'])) { | ||
$this->setDisplayName($data['display_name']); | ||
} | ||
|
||
if (isset($data['image_url'])) { | ||
$this->setImageUrl($data['image_url']); | ||
} | ||
|
||
if (isset($data['properties']['ttl'])) { | ||
$this->setTtl($data['properties']['ttl']); | ||
} | ||
|
||
if (isset($data['properties']['custom_data'])) { | ||
$this->setCustomData($data['properties']['custom_data']); | ||
} | ||
|
||
if (isset($data['numbers'])) { | ||
$numbers = new ConversationNumber(null); | ||
$numbers->fromArray($data['numbers']); | ||
$this->setNumbers($numbers); | ||
Check failure on line 133 in src/Conversation/ConversationObjects/NewConversationRequest.php
|
||
} | ||
|
||
if (isset($data['callback'])) { | ||
$callback = new Callback(); | ||
Check failure on line 137 in src/Conversation/ConversationObjects/NewConversationRequest.php
|
||
$callback->fromArray($data['callback']); | ||
$this->setConversationCallback($callback); | ||
} | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$returnPayload = []; | ||
|
||
if ($this->getName()) { | ||
$returnPayload['name'] = $this->getName(); | ||
} | ||
|
||
if ($this->getDisplayName()) { | ||
$returnPayload['display_name'] = $this->getDisplayName(); | ||
} | ||
|
||
if ($this->getImageUrl()) { | ||
$returnPayload['image_url'] = $this->getImageUrl(); | ||
} | ||
|
||
if ($this->getTtl()) { | ||
$returnPayload['properties']['ttl'] = $this->getTtl(); | ||
} | ||
|
||
if ($this->getCustomData()) { | ||
$returnPayload['properties']['custom_data'] = $this->getCustomData(); | ||
} | ||
|
||
if ($this->getNumber()) { | ||
$returnPayload['numbers'] = $this->getNumber()->toArray(); | ||
} | ||
|
||
if ($this->getConversationCallback()) { | ||
$returnPayload['callback'] = $this->getConversationCallback()->toArray(); | ||
} | ||
|
||
return $returnPayload; | ||
} | ||
} |
Oops, something went wrong.