PHP code example of glorand / drip-php

1. Go to this page and download the library: Download glorand/drip-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

glorand / drip-php example snippets


use Glorand\Drip\Drip;

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

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

public function isSuccess(): bool {}

public function getHttpMessage(): string {}

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

$accounts = $drip->accounts()->list();

if($accounts->isSuccess()) {
    foreach($accounts->getContents() as $acount) {
        //
    }
}
 
$account = $drip->accounts()->show('acount-id');

if($account->isSuccess()) {
    // $account->getContents()
}

$event = new Event();
$event->setEmail('[email protected]')
    ->setAction('Action')
    ->setOccurredAt(new \DateTime('2018-12-01'))
    ->setProperties(['prop_0' => 'val_prop_0'])
    ->addProperty('prop_1', 'val_prop_1')
    ->removeProperty('prop_1');

/** Event Model */
$event = new Event();

/** boolean */
$drip->events()->store($event);

/** ApiResponse */
$events = $drip->events()->list();

$subscriber = new Subscriber();
$subscriber->setEmail('[email protected]')
    ->setNewEmail('[email protected]')
    ->addCustomField('custom_f_1', 'val_custom_f_1')
    ->removeCustomField('custom_f_0')
    ->addTag('tag_1', 'val_tag_1')
    ->removeTag('tag_2')

/** Subscriber Model */
$subscriber = new Subscriber(); 

/** boolean */
$drip->subscribers()->store($subscriber);

/** ApiResponse */
$events = $drip->subscribers()->list();

$testData = [
    [
        "email"     => "[email protected]",
        "time_zone" => "America/Los_Angeles",
    ],
    (new Subscriber())->setEmail('[email protected]')->setTimeZone('America/Los_Angeles'),
];

/** boolean */
$drip->subscribers()->batchStore($testData);

$testData = [
    [
        "email"     => "[email protected]",
    ],
    (new Subscriber())->setEmail('[email protected]'),
];

/** boolean */
$drip->subscribers()->batchUnsubscribe($testData);

$testData = [
    [
        "email"  => "[email protected]",
        "action" => "Opened a door",
    ],
    (new Event())->setEmail('[email protected]')->setAction('Closed a door'),
];

/** boolean */
$drip->events()->batchStore($testData);

$ composer