rdoepner / cleverreach
CleverReach REST API v3 客户端
v1.7.0
2023-07-31 10:26 UTC
Requires
- ext-json: *
- guzzlehttp/guzzle: ^6.3 || ^7.0
- psr/log: ^1.1 || ^2.0 || ^3.0
Requires (Dev)
- monolog/monolog: ^1.24 || ^2.0 || ^3.0
- phpunit/phpunit: ^7.5
- symfony/dotenv: ^4.2
README
此库使与 CleverReach REST API v3 交互变得简单。
安装
composer require rdoepner/cleverreach
用法
获取访问令牌
use rdoepner\CleverReach\ApiManager; use rdoepner\CleverReach\Http\Guzzle as HttpAdapter; // Create an HTTP adapter $httpAdapter = new HttpAdapter(); // Authorize your app by credentials $response = $httpAdapter->authorize('<CLIENT_ID>', '<CLIENT_SECRET>'); if (isset($response['access_token'])) { // Persist the access token for later use... }
初始化 API 管理器
use rdoepner\CleverReach\ApiManager; use rdoepner\CleverReach\Http\Guzzle as HttpAdapter; // Create an HTTP adapter $httpAdapter = new HttpAdapter( [ 'access_token' => '<ACCESS_TOKEN>', ] ); // Create the API manager $apiManager = new ApiManager($httpAdapter);
创建一个非活跃订阅者
$response = $apiManager->createSubscriber( '<EMAIL>', '<GROUP_ID>', false, // not activated [ 'salutation' => 'Mr.', 'firstname' => 'John', 'lastname' => 'Doe', ], [], // global attributes 'Source', ['tagX'] // tags ); if (isset($response['id'])) { // ... }
更新订阅者
$response = $apiManager->updateSubscriber( '<EMAIL>', '<GROUP_ID>', [ 'salutation' => 'Mr.', 'firstname' => 'John', 'lastname' => 'Doe', ], [], // global attributes 'Source', ['tagX'] // tags ); if (isset($response['id'])) { // ... }
触发非活跃订阅者的双确认邮件
$response = $apiManager->triggerDoubleOptInEmail('<EMAIL>', '<FORM_ID>'); if (isset($response['success'])) { // ... }
触发活跃订阅者的双退出邮件
$response = $apiManager->triggerDoubleOptOutEmail('<EMAIL>', '<FORM_ID>'); if (isset($response['success'])) { // ... }
获取订阅者
$response = $apiManager->getSubscriber('<EMAIL>', '<GROUP_ID>'); if (isset($response['id'])) { // ... }
设置订阅者的活跃状态
$response = $apiManager->setSubscriberStatus('<EMAIL>', '<GROUP_ID>', '<TRUE_OR_FALSE>'); if (true === $response) { // ... }
删除订阅者
$response = $apiManager->deleteSubscriber('<EMAIL>', '<GROUP_ID>'); if (true === $response) { // ... }
获取属性
$response = $apiManager->getAttributes('<GROUP_ID>'); if (true === $response) { // ... }
更新订阅者的属性
$response = $apiManager->updateSubscriberAttributes('<POOL_ID>', '<ATTRIBUTE_ID>', '<VALUE>'); if (true === $response) { // ... }
替换订阅者的标签
$response = $apiManager->replaceSubscriberTags('<EMAIL>', '<GROUP_ID>', ['<TAG1>', '<TAG2>', ...]); if (true === $response) { // ... }
获取订阅者所在的组
$response = $apiManager->getSubscriberGroups('<EMAIL>'); if (true === $response) { // ... }