Deltas - PureClarity/php-sdk GitHub Wiki
Delta classes reside in the PureClarity\Api\Delta\Type namespace and each delta type has it's own class:
- PureClarity\Api\Delta\Type\Product
- PureClarity\Api\Delta\Type\User
Each feed class builds a json string of the data provided to it and sends it to PureClarity's feed endpoints in manageable chunks of data.
Usage
To use a feed class, you need to instantiate the class, passing the account details:
$feed = new \PureClarity\Api\Delta\Type\Product($accessKey, $secretKey, $region);
Param | Type | Description |
---|---|---|
$accessKey | string | PureClarity Account access key |
$secretKey | string | PureClarity Account secret key |
$region | integer | PureClarity Region |
See What account data should I use? for more information on what these parameters should be.
Then once you've instantiated the class, there are 3 functions you can call:
Function name | Purpose |
---|---|
addData | Adds a data update to the delta, for updating an item's data |
addDelete | Adds a delete to the delta, telling PureClarity to delete this item |
send | Sends the delta to PureClarity |
addData
Takes one parameter, $data, which is an array of data for an individual entity, the format of the data must match the format of the corresponding feed.
addDelete
Takes one parameter, $delete, which is an id of an individual entity to be deleted, the id must match the id sent in the corresponding feed.
Example:
$deltaData = <data pulled from your system>
$delta = new \PureClarity\Api\Delta\Type\Product($accessKey, $secretKey, $region);
foreach ($deltaData as $row) {
if (<is a deletion>) {
$delta->addDelete($row['id']);
} else {
$delta->addData($row);
}
}
$delta->send();