markuszeller / cleverreach
CleverReach REST API v3 客户端
v0.0.1
2019-04-15 13:59 UTC
Requires
- ext-json: *
- guzzlehttp/guzzle: ^6.3
- psr/log: ^1.1
Requires (Dev)
- monolog/monolog: ^1.24
- symfony/dotenv: ^4.2
This package is auto-updated.
Last update: 2024-09-16 01:57:06 UTC
README
这个库使得与 CleverReach REST API v3 交互变得容易。
从 https://github.com/rdoepner/cleverreach 分支而来。由于作者没有合并拉取请求或做出任何其他反应,已转移到自己的命名空间。
安装
composer require markuszeller/cleverreach
使用方法
获取访问令牌
use markuszeller\CleverReach\ApiManager; use markuszeller\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 markuszeller\CleverReach\ApiManager; use markuszeller\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', ] ); 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->getSubscriber('<EMAIL>', '<GROUP_ID>', '<TRUE_OR_FALSE>'); if (true === $response) { // ... }
删除订阅者
$response = $apiManager->deleteSubscriber('<EMAIL>', '<GROUP_ID>'); if (true === $response) { // ... }
阅读邮件示例
// Get a list of all Mailings // You can provide a state, i.e. draft $mailings = $apiManager->getMailings(0, ApiManager::MAILING_STATE_DRAFT); // Get a specific Mailing // returns a Mailing Object $mailing = $apiManager->getMailing(MAILING_ID); // Get Specific Mailing details $mailingLinks = $apiManager->getMailingLinks(MAILING_ID); $mailingOrders = $apiManager->getMailingOrders(MAILING_ID); $mailingChannels = $apiManager->getMailingChannels(); $mailingChannel = $apiManager->getMailingChannel(CHANNEL_ID);
更新邮件
// Read one for updating $mailing = $apiManager->getMailing(MAILING_ID); // Create a fresh Mailing and Content instance with no data $updatedMailing = new Mailing(MAILING_ID); $content = new MailingContent(); // Get HTML content from "old" $html = $mailingData->getContent()->getHtml(); // Inject a update message after body tag $date = date(DATE_W3C); $html = preg_replace("/(<body.*?>)/", "\$1\n<div>Automated update at {$date}</div>", $html); // Place into Content entity and update Mailings content $content->setHtml($html); $updatedMailing->setContent($content); // Update request (PUT) $apiManager->updateMailing($updatedMailing);