dicr / yii2-esputnik
ESputnik API for Yii2
3.0.2
2022-01-16 04:32 UTC
Requires
- php: ~8.0
- ext-curl: *
- dicr/yii2-helper: ~6.0
- dicr/yii2-json: ~3.0
- dicr/yii2-validate: ~3.0
- yiisoft/yii2: ~2.0
- yiisoft/yii2-httpclient: ~2.0
Requires (Dev)
- roave/security-advisories: dev-latest
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";
}