Php SDK for ContactHub https://hub.contactlab.it
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs
src
tests
.gitignore
.travis.yml
Dockerfile
LICENSE
Makefile
README.md
composer.json
phpdoc.xml
phpunit.xml.dist

README.md

ContactHub PHP SDK

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