contactlab/contacthub-sdk-php

This package is abandoned and no longer maintained. No replacement package was suggested.

Php SDK for ContactHub

v1.1.0 2017-08-31 15:02 UTC

This package is auto-updated.

Last update: 2020-08-25 12:12:21 UTC


README

Build Status Latest Stable Version Total Downloads License

PHP SDK for the ContactHub API.

Installation

composer require contactlab/contacthub-sdk-php

Documentation

Documentation can be found in the the docs directory.

Quick start

Create customer

use ContactHub\ContactHub;

$contactHub = new ContactHub('TOKEN', 'WORKSPACE_ID', 'NODE_ID');

$customer = [
    'externalId' => 'externalId',
    'base' => [
        'firstName' => 'First Name',
        'lastName' => 'Lastddd Name',
        'contacts' => [
            'email' => 'email@example.com'
        ]
    ],
    'extra' => 'extra string',
    'tags' => [
        'auto' => ['autotag'],
        'manual' => ['manualtag']
    ],
    'enabled' => true
];
$contactHub->addCustomer($customer);

Retrieve Customers

use ContactHub\ContactHub;
use ContactHub\GetCustomersOptions;

$contactHub = new ContactHub('TOKEN', 'WORKSPACE_ID', 'NODE_ID');

$options = GetCustomersOptions::create()
    ->withExternalId('58ede74e05d14')
    ->withFields(['base.firstName']);
$customers = $contactHub->getCustomers($options);

Create Event

use ContactHub\ContactHub;

$contactHub = new ContactHub('TOKEN', 'WORKSPACE_ID', 'NODE_ID');

$event = [
    'type' => EventType::VIEWED_PAGE,
    'context' => EventContext::MOBILE,
    'properties' => [
        'url' => 'http://ecommerce.event.url'
    ],
    'date' => date('c')
];

$contactHub->addEventByCustomerId('a_customer_id', $event);

Query Builder

use ContactHub\ContactHub;
use ContactHub\GetCustomersOptions;
use ContactHub\QueryBuilder;
use ContactHub\QueryBuilder\CombinedQuery;
use ContactHub\QueryBuilder\Condition\AtomicCondition;
use ContactHub\QueryBuilder\Condition\CompositeCondition;
use ContactHub\QueryBuilder\SimpleQuery;

$simpleWithAtomicCondition = SimpleQuery::with(AtomicCondition::where('firstName' , 'IS_NOT_NULL'));
$simpleWithCompositeCondition = SimpleQuery::with(
    CompositeCondition::where(
        'OR',
        AtomicCondition::where('base.lastName', 'IS', 'Giovanni'),
        AtomicCondition::where('base.lastName', 'IS', 'Giacomo')
    )
);
$combined = CombinedQuery::with('OR', $simpleWithCompositeCondition, $simpleWithAtomicCondition);
$query = QueryBuilder::createQuery($combined, 'named_query');

$contactHub = new ContactHub('TOKEN', 'WORKSPACE_ID', 'NODE_ID');

$options = GetCustomersOptions::create()->withQuery($query->build());
$customers = $contactHub->getCustomers($options);