picr/php-autopilothq

用于与AutopilotHQ API交互的PHP包装器。

v0.1.5 2018-05-31 13:16 UTC

This package is auto-updated.

Last update: 2024-09-12 03:31:35 UTC


README

一个用于与AutopilotHQ API交互的PHP库 http://docs.autopilot.apiary.io/#.

安装

$ composer require picr/php-autopilothq

用法

所有交互都在 AutopilotManager 类中发生。

初始化管理器

$manager = new AutopilotManager($apiKey);

获取联系人

$manager->getContact($id|$email);

保存联系人

$manager->saveContact(AutopilotContact $contact);

保存联系人列表

$manager->saveContacts(array $contacts);

删除联系人

$manager->deleteContact($id|$email);

取消订阅联系人

$manager->unsubscribeContact($id|$email);

订阅联系人

$manager->subscribeContact($id|$email);

更新联系人邮箱

$manager->updateContactEmail($oldEmail, $newEmail);

获取所有列表

$manager->getAllLists();

创建列表

$manager->createList($list);

按名称获取列表

$manager->getListByName($list);

删除列表

//TODO: AutopilotHQ hasn't implemented this yet
$manager->deleteList($list);

获取列表中的所有联系人

$manager->getAllContactsInList($list);

将联系人添加到列表

$manager->addContactToList($list, $id|$email);

从列表中删除联系人

$manager->removeContactFromList($list, $id|$email);

检查联系人是否在列表中

$manager->checkContactInList($list, $id|$email);

所有触发器

$manager->allTriggers();

将联系人添加到旅程

$manager->addContactToJourney($journey, $id|$email);

所有REST钩子

$manager->allRestHooks();

删除所有REST钩子

$manager->deleteAllRestHooks();

添加REST钩子

$manager->addRestHook($event, $targetUrl);

删除REST钩子

$manager->deleteRestHook($hookId);

AutopilotContact

获取值

// magic method
$value = $contact->$name;
// getter
$value = $contact->getFieldValue($name);

设置值

// magic method
$contact->$name = $value;
// setter
$contact->setFieldValue($name, $value);

取消设置值

// magic method
unset($contact->$name);
// method
$contact->unsetFieldValue($name);

检查值是否存在

// magic method
isset($contact->$name);
// method
$contact->issetFieldValue($name);

获取所有联系人列表

//NOTE: this only reads cached "lists" array returned for a "contact info" request
$contact->getAllContactLists();

检查是否有列表

//NOTE: this only reads cached "lists" array returned for a "contact info" request
$contact->hasList($list);

填充

// read array of values and populate properties
// NOTE: automatically formats attributes according to AutopilotHQ's "naming convention" (doesn't really exist)
$contact->fill([
    'firstName' => 'John',
    'lastName'  => 'Smith',
    'age'       => 42,
]);

转换为请求

// return array ready to be pushed to the API
$user = $contact->toRequest();

转换为数组

// return array of [ property => value ] no matter if custom or defined field
$user = $contact->toArray();
/* [
 *    'firstName' => 'John',
 *    'lastName'  => 'Smith',
 *    'age'       => 42,
 * ]
 */

json序列化

// json representation of "toArray()"
$user = $contact->jsonSerialze();
$user = json_encode($contact);

许可证

MIT