From a0d362dfa2f8837cf0b7c239b27100569bf7dd9b Mon Sep 17 00:00:00 2001 From: Dicoders Date: Tue, 29 Jan 2019 14:22:42 +0700 Subject: [PATCH 1/6] +add send smart message --- src/Brownie/ESputnik/ESputnik.php | 34 ++++++++++++++ src/Brownie/ESputnik/Model/Recipient.php | 36 +++++++++++++++ src/Brownie/ESputnik/Model/RecipientList.php | 47 ++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 src/Brownie/ESputnik/Model/Recipient.php create mode 100644 src/Brownie/ESputnik/Model/RecipientList.php diff --git a/src/Brownie/ESputnik/ESputnik.php b/src/Brownie/ESputnik/ESputnik.php index 58ff41a..a91cb9c 100644 --- a/src/Brownie/ESputnik/ESputnik.php +++ b/src/Brownie/ESputnik/ESputnik.php @@ -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; @@ -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']['id']) && (0 == $response['response']['id'])) { + return $response['response']['asyncSessionId']; + } + + return false; + } + /** * Creates a contact model for arguments. * diff --git a/src/Brownie/ESputnik/Model/Recipient.php b/src/Brownie/ESputnik/Model/Recipient.php new file mode 100644 index 0000000..04a87c4 --- /dev/null +++ b/src/Brownie/ESputnik/Model/Recipient.php @@ -0,0 +1,36 @@ + + * @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, + ]; +} diff --git a/src/Brownie/ESputnik/Model/RecipientList.php b/src/Brownie/ESputnik/Model/RecipientList.php new file mode 100644 index 0000000..9a513bc --- /dev/null +++ b/src/Brownie/ESputnik/Model/RecipientList.php @@ -0,0 +1,47 @@ + + * @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() + ); + } +} From 3d94b60c780736b8275eea632361b8d13e6b89f3 Mon Sep 17 00:00:00 2001 From: Dicoders Date: Tue, 29 Jan 2019 14:33:08 +0700 Subject: [PATCH 2/6] *fix return result send message --- src/Brownie/ESputnik/ESputnik.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Brownie/ESputnik/ESputnik.php b/src/Brownie/ESputnik/ESputnik.php index a91cb9c..52117b8 100644 --- a/src/Brownie/ESputnik/ESputnik.php +++ b/src/Brownie/ESputnik/ESputnik.php @@ -418,8 +418,8 @@ public function sendSmartMessage( ); - if (isset($response['response']['id']) && (0 == $response['response']['id'])) { - return $response['response']['asyncSessionId']; + if (isset($response['response']['results']) && !empty($response['response']['results'])) { + return $response['response']['results']; } return false; From 9339d91b5f9c30063740ff930349f7bd26187246 Mon Sep 17 00:00:00 2001 From: Dicoders Date: Tue, 29 Jan 2019 17:10:03 +0700 Subject: [PATCH 3/6] *change response error --- src/Brownie/ESputnik/HTTPClient/HTTPClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Brownie/ESputnik/HTTPClient/HTTPClient.php b/src/Brownie/ESputnik/HTTPClient/HTTPClient.php index 9a271d5..b814787 100644 --- a/src/Brownie/ESputnik/HTTPClient/HTTPClient.php +++ b/src/Brownie/ESputnik/HTTPClient/HTTPClient.php @@ -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)) { From 799f1ffdaec6f3f9b187127fdf2324e709687b97 Mon Sep 17 00:00:00 2001 From: Dicoders Date: Fri, 1 Feb 2019 14:31:10 +0700 Subject: [PATCH 4/6] +add webpush and mobilepush channels --- .../ESputnik/Model/ContactFieldsUpdate.php | 3 +++ .../ESputnik/Model/MobilePushChannel.php | 19 +++++++++++++++++++ src/Brownie/ESputnik/Model/WebPushChannel.php | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 src/Brownie/ESputnik/Model/MobilePushChannel.php create mode 100644 src/Brownie/ESputnik/Model/WebPushChannel.php diff --git a/src/Brownie/ESputnik/Model/ContactFieldsUpdate.php b/src/Brownie/ESputnik/Model/ContactFieldsUpdate.php index f63670b..d7456e2 100644 --- a/src/Brownie/ESputnik/Model/ContactFieldsUpdate.php +++ b/src/Brownie/ESputnik/Model/ContactFieldsUpdate.php @@ -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, diff --git a/src/Brownie/ESputnik/Model/MobilePushChannel.php b/src/Brownie/ESputnik/Model/MobilePushChannel.php new file mode 100644 index 0000000..9d3ac7d --- /dev/null +++ b/src/Brownie/ESputnik/Model/MobilePushChannel.php @@ -0,0 +1,19 @@ + + * @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'; +} diff --git a/src/Brownie/ESputnik/Model/WebPushChannel.php b/src/Brownie/ESputnik/Model/WebPushChannel.php new file mode 100644 index 0000000..63a799b --- /dev/null +++ b/src/Brownie/ESputnik/Model/WebPushChannel.php @@ -0,0 +1,19 @@ + + * @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'; +} From 14d7009a538d94c9b8fd45d1d201e863ab714760 Mon Sep 17 00:00:00 2001 From: Dicoders Date: Tue, 30 Apr 2019 17:06:19 +0700 Subject: [PATCH 5/6] * fix update user email by user id --- src/Brownie/ESputnik/Model/Contact.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Brownie/ESputnik/Model/Contact.php b/src/Brownie/ESputnik/Model/Contact.php index 2e06029..9d9f1ca 100644 --- a/src/Brownie/ESputnik/Model/Contact.php +++ b/src/Brownie/ESputnik/Model/Contact.php @@ -75,6 +75,10 @@ public function toArray() { $data = []; + if ($this->getId()) { + $data['id'] = $this->getId(); + } + if ($this->getFirstName()) { $data['firstName'] = $this->getFirstName(); } From 5fa8e3af2b75f4b03c442ea235a545c060188571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Fri, 11 Dec 2020 20:01:32 +0700 Subject: [PATCH 6/6] Update Contact.php fix fatal error by null attribute --- src/Brownie/ESputnik/Model/Contact.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Brownie/ESputnik/Model/Contact.php b/src/Brownie/ESputnik/Model/Contact.php index 9d9f1ca..3c4c021 100644 --- a/src/Brownie/ESputnik/Model/Contact.php +++ b/src/Brownie/ESputnik/Model/Contact.php @@ -87,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();