A PHP wrapper for Drip's REST API v2.0 for PHP 7.1+
Author: Gombos Lorand
$ composer require glorand/drip-php
{
"require": {
"glorand/drip-php": "^1.0"
}
}
use Glorand\Drip\Drip;
$drip = new Drip('your-account-id', 'your-api-token', 'user-agent-optional');
Methods
//http status code
public function getStatusCode(): int {}
public function isSuccess(): bool {}
public function getHttpMessage(): string {}
//drip response
public function getContents(): array {}
List all accounts
$accounts = $drip->accounts()->list();
if($accounts->isSuccess()) {
foreach($accounts->getContents() as $acount) {
//
}
}
Fetch an account
$account = $drip->accounts()->show('acount-id');
if($account->isSuccess()) {
// $account->getContents()
}
Event Model
$event = new Event();
$event->setEmail('test@email.com')
->setAction('Action')
->setOccurredAt(new \DateTime('2018-12-01'))
->setProperties(['prop_0' => 'val_prop_0'])
->addProperty('prop_1', 'val_prop_1')
->removeProperty('prop_1');
Record an event
/** Event Model */
$event = new Event();
/** boolean */
$drip->events()->store($event);
List all custom events actions used in an account
/** ApiResponse */
$events = $drip->events()->list();
Subscriber Model
$subscriber = new Subscriber();
$subscriber->setEmail('test@email.com')
->setNewEmail('new@email.com')
->addCustomField('custom_f_1', 'val_custom_f_1')
->removeCustomField('custom_f_0')
->addTag('tag_1', 'val_tag_1')
->removeTag('tag_2')
Create or update a subscriber
/** Subscriber Model */
$subscriber = new Subscriber();
/** boolean */
$drip->subscribers()->store($subscriber);
List all subscribers
/** ApiResponse */
$events = $drip->subscribers()->list();
Create or update a batch of subscribers
$testData = [
[
"email" => "john@acme.com",
"time_zone" => "America/Los_Angeles",
],
(new Subscriber())->setEmail('joe@acme.com')->setTimeZone('America/Los_Angeles'),
];
/** boolean */
$drip->subscribers()->batchStore($testData);
Unsubscribe a batch of subscribers
$testData = [
[
"email" => "john@acme.com",
],
(new Subscriber())->setEmail('joe@acme.com'),
];
/** boolean */
$drip->subscribers()->batchUnsubscribe($testData);
Record a batch of events
$testData = [
[
"email" => "john@acme.com",
"action" => "Opened a door",
],
(new Event())->setEmail('joe@acme.com')->setAction('Closed a door'),
];
/** boolean */
$drip->events()->batchStore($testData);
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see LICENSE for more information.