Skip to content
Open
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
34 changes: 34 additions & 0 deletions src/Brownie/ESputnik/ESputnik.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Brownie\ESputnik\HTTPClient\HTTPClient;
use Brownie\ESputnik\Model\Address;
use Brownie\ESputnik\Model\OrdersInfo;
use Brownie\ESputnik\Model\RecipientList;
use Brownie\ESputnik\Model\Version;
use Brownie\ESputnik\Model\Subscribe;
use Brownie\ESputnik\Model\Contact;
Expand Down Expand Up @@ -391,6 +392,39 @@ public function updateContacts(
return false;
}

/**
* SmartSend message.
*
* @param int $message_id ID message for send
* @param RecipientList $recipientList List users and params for send
*
* @return bool
*/
public function sendSmartMessage(
int $message_id,
RecipientList $recipientList
) {
$data = [
'recipients' => $recipientList->toArray(),
];

$response = $this
->getHttpClient()
->request(
HTTPClient::HTTP_CODE_200,
"message/{$message_id}/smartsend",
$data,
HTTPClient::HTTP_METHOD_POST

);

if (isset($response['response']['results']) && !empty($response['response']['results'])) {
return $response['response']['results'];
}

return false;
}

/**
* Creates a contact model for arguments.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Brownie/ESputnik/HTTPClient/HTTPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function request(
* Checking HTTP Code.
*/
if ($checkHTTPCode != $httpCode) {
throw new InvalidCodeException($httpCode);
throw new InvalidCodeException($responseBody);
}

if ($ignoreEmptyResponse && empty($response)) {
Expand Down
16 changes: 11 additions & 5 deletions src/Brownie/ESputnik/Model/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public function toArray()
{
$data = [];

if ($this->getId()) {
$data['id'] = $this->getId();
}

if ($this->getFirstName()) {
$data['firstName'] = $this->getFirstName();
}
Expand All @@ -83,11 +87,13 @@ public function toArray()
$data['lastName'] = $this->getLastName();
}

$data[$this->getChannelList()->getKeyName()] = array_map(
function (Channel $channel) {
return $channel->toArray();
}, $this->getChannelList()->toArray()
);
if ($this->getChannelList()) {
$data[$this->getChannelList()->getKeyName()] = array_map(
function (Channel $channel) {
return $channel->toArray();
}, $this->getChannelList()->toArray()
);
}

if ($this->getAddress()) {
$data['address'] = $this->getAddress()->toArray();
Expand Down
3 changes: 3 additions & 0 deletions src/Brownie/ESputnik/Model/ContactFieldsUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class ContactFieldsUpdate extends ArrayList

const POSTCODE = 'postcode';

const MOBILEPUSH = 'mobilepush';

const WEBPUSH = 'webpush';
protected $fields = [
'fieldNames' => [self::FIRST_NAME, self::LAST_NAME],
'customFieldIDS' => null,
Expand Down
19 changes: 19 additions & 0 deletions src/Brownie/ESputnik/Model/MobilePushChannel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* @category Brownie/ESputnik
* @author Brownie <oss.brownie@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html
*/

namespace Brownie\ESputnik\Model;

use Brownie\ESputnik\Model\Base\Channel;

/**
* Media channel "mobilepush".
*/
class MobilePushChannel extends Channel
{

protected $type = 'mobilepush';
}
36 changes: 36 additions & 0 deletions src/Brownie/ESputnik/Model/Recipient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* @category Brownie/ESputnik
* @author Brownie <oss.brownie@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html
*/

namespace Brownie\ESputnik\Model;

use Brownie\ESputnik\Model\Base\ArrayList;

/**
* Recipient.
*
* @method string setEmail($email) Set email client.
* @method int setContactId($id) Set id.
* @method string setLocator($email) Set email client.
* @method string setJsonParam($params) Set json params.
* @method bool setExternalRequestId($external_id) Set external id.
* @method string getEmail($email) Get email client.
* @method int getContactId() Get id.
* @method string getLocator($email) Get email client.
* @method string getJsonParam() Get json params.
* @method string getExternalRequestId() Get external id.
*/
class Recipient extends ArrayList
{

protected $fields = [
'email' => null,
'contactId' => null,
'locator' => null,
'jsonParam' => null,
'externalRequestId' => null,
];
}
47 changes: 47 additions & 0 deletions src/Brownie/ESputnik/Model/RecipientList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* @category Brownie/ESputnik
* @author Brownie <oss.brownie@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html
*/

namespace Brownie\ESputnik\Model;

use Brownie\ESputnik\Exception\ValidateException;
use Brownie\ESputnik\Model\Base\ArrayList;
use Brownie\ESputnik\Model\Base\Channel;
use Brownie\ESputnik\Model\Base\EntityList;

/**
* @method Contact setId($id) Set id.
* @method Contact setRecipients($recepients) Set recepients.
* @method int getId() Get id.
* @method Recepients getRecipients() Get recepients.
*/
class RecipientList extends EntityList
{
protected $keyName = 'recipients';

/**
* Add field to list.
* Returns the current object.
*
* @param Field $field Field contact.
*
* @return self
*/
public function add(Recipient $field)
{
parent::append($field);
return $this;
}

public function toArray()
{
return array_map(
function (Recipient $field) {
return $field->toArray();
}, parent::toArray()
);
}
}
19 changes: 19 additions & 0 deletions src/Brownie/ESputnik/Model/WebPushChannel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* @category Brownie/ESputnik
* @author Brownie <oss.brownie@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html
*/

namespace Brownie\ESputnik\Model;

use Brownie\ESputnik\Model\Base\Channel;

/**
* Media channel "webpush".
*/
class WebPushChannel extends Channel
{

protected $type = 'webpush';
}