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
});