/drip

A PHP wrapper for Drip's REST API v2.0

Primary LanguagePHPMIT LicenseMIT

A PHP wrapper for Drip's REST API

Latest Stable Version Build Status Software License CodeFactor StyleCI Scrutinizer Code Quality Code Coverage

Drip PHP

A PHP wrapper for Drip's REST API v2.0 for PHP 7.1+

Author: Gombos Lorand

Table of contents

Installation

$ composer require glorand/drip-php
{
    "require": {
        "glorand/drip-php": "^1.0"
    }
}

Current Features

Instantiation

use Glorand\Drip\Drip;

$drip = new Drip('your-account-id', 'your-api-token', 'user-agent-optional');

ApiResponse

Methods

//http status code
public function getStatusCode(): int {}

public function isSuccess(): bool {}

public function getHttpMessage(): string {}

//drip response
public function getContents(): array {}

Accounts

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

Events

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

Subscribers

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

Batch Operations

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

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see LICENSE for more information.