drip
v0.9
用于针对drip发出基于令牌的 API 请求的 PHP 库。
下载并包含,或通过 Composer 安装:
composer require drewm/ drip
创建一个新的drip对象
use DrewM drip drip ;
use DrewM drip Dataset ;
$ drip = new drip ( ' abc123 ' , ' 1234567 ' )
创建一个新订阅者:
$ data = new Dataset ( ' subscribers ' , [
' email ' => ' [email protected] ' ,
]);
$ Response = $ drip -> post ( ' subscribers ' , $ data );
列出所有订阅者:
$ Response = $ drip -> get ( ' subscribers ' );
要请求 URL 中没有帐户 ID 的方法(例如列出帐户):
$ drip = new drip ( ' abc123 ' );
$ Response = $ drip -> getGlobal ( ' accounts ' );
随后设置帐户 ID:
$ drip -> setAccountID ( ' 1234567 ' );
方法返回一个 Response 对象
if ( $ Response -> status == 200 ) {
// all is ok!
$ subscribers = $ Response -> subscribers ;
} else {
echo $ Response -> error ;
echo $ Response -> message ;
}
获取原始响应:
$ raw = $ Response -> get ();
您可以通过多种方式监听网络钩子。最基本的是:
use DrewM drip drip ;
$ data = drip :: receiveWebhook ();
如果您更喜欢 pub/sub 模型,您可以注册侦听器可调用对象:
use DrewM drip drip ;
drip :: subscribeToWebhook ( ' subscriber.created ' , function ( $ data ){
// A subscriber was created
});
drip :: subscribeToWebhook ( ' subscriber.subscribed_to_campaign ' , function ( $ data ){
// A subscriber was added to a campaign
});