connect/connect-client

PHP Connect SDK for interacting with the Connect API

0.2.0 2015-08-24 00:13 UTC

README

Join the chat at https://gitter.im/getconnect/connect-php

Build Status Latest Stable Version

The Connect PHP SDK allows you to push events to Connect from PHP.

If you don’t already have a Connect account, sign up here - it’s free!

Installation

The easiest way to install the Connect SDK is to use Composer.

Add connect/connect-client as a dependency and run composer update.

"require": {
    …
    "connect/connect-client" : "0.*"
    …
}

Usage

Initializing a client

use Connect\Connect;

Connect::initialize('your-project-id', 'your-push-api-key');

Pushing events

Once you have initialized Connect, you can push events easily:

$purchase = [
	'customer' => [
	   'firstName' => 'Tom',
	   'lastName' => 'Smith'
	],
	'product' => '12 red roses',
	'purchasePrice' => 34.95
];

Connect::push('purchases', $purchase);

You can also push events in batches:

$batch = [
	'purchases' => [
		[
            'customer' => [
                'firstName' => 'Tom',
                'lastName' => 'Smith'
			],
			'product' => '12 red roses',
			'purchasePrice' => 34.95
		],
		[
            'customer' => [
                'firstName' => 'Fred',
				'lastName' => 'Jones'
			],
			'product' => '12 pink roses',
			'purchasePrice' => 38.95
		]
	]
];

Connect::push($batch);

Generating filtered keys

To generate a filtered key

$masterKey = 'YOUR_MASTER_KEY';
$keyDefinition = [
    'filters' => [
        'type' => 'cycling'
    ],
    'canQuery' => True,
    'canPush' => True
];
	
$filteredKey = Connect::generateFilteredKey($keyDefinition, $masterKey);
print $filteredKey;

Exception handling

When pushing events, exceptions could be thrown, so you should either ignore or handle those exceptions gracefully.

Currently, the following exception could be thrown when pushing events:

  • InvalidEventException - the event being pushed is invalid (e.g. invalid event properties)

License

The SDK is released under the MIT license.

Contributing

We love open source and welcome pull requests and issues from the community!