dicr/yii2-esputnik

ESputnik API for Yii2

Installs: 4

Dependents: 0

Suggesters: 0

Security: 0

Type:yii2-extension

2.0.0 2021-08-14 03:42 UTC

This package is auto-updated.

Last update: 2021-09-13 22:46:17 UTC


README

API: https://esputnik.com/api/

Конфигурация

$config = [
    'components' => [
        'esputnik' => [
            'class' => dicr\esputnik\ESputnikAPI::class,
            'user' => 'ваш_логин',
            'keyPass' => 'ваш_ключ_или_пароль'
        ]
    ]   
];

Использование


/** @var dicr\esputnik\ESputnikAPI $api */
$api = Yii::$app->get('esputnik');

/** @var dicr\esputnik\request\ContactsRequest $req */
$req = $api->contactsRequest([
    'contacts' => [
        [
            'firstName' => 'Иван',
            'channels' => [
                ['type' => dicr\esputnik\entity\Channel::TYPE_EMAIL, 'value' => 'ivan@mail.com']
            ]
        ],
        [
            'firstName' => 'Сергей',
            'channels' => [
                ['type' => dicr\esputnik\entity\Channel::TYPE_EMAIL, 'value' => 'sergey@mail.com']
            ]
        ]
    ],
    'dedupeOn' => dicr\esputnik\request\ContactsRequest::DEDUPE_ON_EMAIL,
    'groupNames' => ['Покупатели'],
    'eventKeyForNewContacts' => 'NewUsers'
]);

/** @var dicr\esputnik\request\ContactsResponse $res */
$res = $req->send();

if (! empty($res->errorMessage)) {
    throw new yii\base\Exception($res->errorMessage);
}

echo 'Передано: ' . count($req->contacts) . " контактов\n";
 
if (! empty($res->failedContacts)) {
    echo 'Пропущено: ' . count($res->failedContacts) . " контактов\n";
}