Skip to content

Created Recipients object rather than it being a stdClass #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/MessageBird/Objects/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ class Message extends Base
/**
* An array of recipients
*
* @var array
* @var Recipients
*/
public $recipients = array ();
public $recipients;

/**
* The URL to send status delivery reports for the message to
Expand Down Expand Up @@ -225,14 +225,8 @@ public function loadFromArray ($object)
{
parent::loadFromArray($object);

if (!empty($this->recipients->items)) {
foreach($this->recipients->items AS &$item) {
$Recipient = new Recipient();
$Recipient->loadFromArray($item);

$item = $Recipient;
}
}
$recipients = new Recipients();
$this->recipients = $recipients->loadFromArray($this->recipients);

return $this;
}
Expand Down
24 changes: 24 additions & 0 deletions src/MessageBird/Objects/Recipient.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,28 @@ class Recipient extends Base
* @var string
*/
public $statusDatetime;

/**
* @return int
*/
public function getRecipient()
{
return $this->recipient;
}

/**
* @return string
*/
public function getStatus()
{
return $this->status;
}

/**
* @return string
*/
public function getStatusDatetime()
{
return $this->statusDatetime;
}
}
97 changes: 97 additions & 0 deletions src/MessageBird/Objects/Recipients.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

namespace MessageBird\Objects;

/**
* Class Recipients
*
* @package MessageBird\Objects
*/
class Recipients extends Base
{
/**
* @var int
*/
public $totalCount;

/**
* @var int
*/
public $totalSentCount;

/**
* @var int
*/
public $totalDeliveredCount;

/**
* @var int
*/
public $totalDeliveryFailedCount;

/**
* @var Recipient[]
*/
public $items;

/**
* @return int
*/
public function getTotalCount()
{
return $this->totalCount;
}

/**
* @return int
*/
public function getTotalSentCount()
{
return $this->totalSentCount;
}

/**
* @return int
*/
public function getTotalDeliveredCount()
{
return $this->totalDeliveredCount;
}

/**
* @return int
*/
public function getTotalDeliveryFailedCount()
{
return $this->totalDeliveryFailedCount;
}

/**
* @return Recipient[]
*/
public function getItems()
{
return $this->items;
}

/**
* @param $object
*
* @return $this|void
*/
public function loadFromArray($object)
{
parent::loadFromArray($object);

if (!empty($this->items)) {
foreach ($this->items as &$item) {
$recipient = new Recipient();
$recipient->loadFromArray($item);

$item = $recipient;
}
}

return $this;
}
}