matchpint/batch

Package providing a PHP implementation of the different Batch APIs functionality.

dev-develop 2022-12-12 16:22 UTC

README

This library includes several classes and methods to implement the different Batch API calls. You will find the documentation of the different API here.

Installation

Composer installation

To install Google Analytics, you first need to install Composer, a Package Manager for PHP, following those few steps:

curl -s https://getcomposer.org/installer | php

You can run this command to easily access composer from anywhere on your system:

sudo mv composer.phar /usr/local/bin/composer

Batch Installation

You can install this package using composer by running the command below.

php /usr/local/bin/composer/composer.phar require matchpint/batch

You can also add matchpint\batch to your the require of your composer.json as below

{
    "name": "domain/your_project",
    "require": {
        "matchpint/batch": "~1"
    }
}

and run

php /usr/local/bin/composer/composer.phar update

Prerequisites

This library implements the APIs provide by batch.com. You must get your API Key and Rest Key before using this project.

Usage

Regular usage

  1. Initialisation
use Batch\BatchCustomData;

$batchCustomData = new BatchCustomData($yourApiKey, $yourRestKey);
  1. Write as an array the body that you want to send to Batch (if needed)
$body = [
  "u.field_name" => "newValue",
  "ut.tags" => [
    "$add" => ["newTag"]
  ]
];
  1. Send the request to Batch using the function corresponding to the endpoint you need.
$batchCustomData->send($customUserId, $body, FALSE);

When you have two projects (iOS and Android)

In case you have two Batch applications (iOS and Android), you probably want to make sure to send a call to each applications.

You will find for each client an version of this class implementing calls for two applications (iOS / Android).

Convention: The client {Client} will have a IosAndroid{Client} equivalent that is implementing this.

Functionality

Custom Data API

Class: Batch\CustomData

  • Update data: send(customUserId: string, values: array, override: boolean)

    • customUserId: Batch Custom Id described here for iOS and here for Android.
    • values: Array containing the values that should be sent to the API as described here.
    • override: Instead of merging the data we already have for a user, the existing data will be deleted and replaced by the incoming data (default to FALSE).
  • Update Bulk data: sendBulk(body: array)

    • body: Body of the request describe here
  • Delete member: TODO

Class Batch\IosAndroidCustomData

  • Update data:

    • only on iOS: sendIOS(customUserId: string, values: array, override: boolean);
    • only on Android: sendAndroid(customUserId: string, values: array, override: boolean);
    • on both projects: send(customUserId: string, values: array, override: boolean).
  • Update Bulk data:

    • only on iOS: sendBulkIOS(body: array);
    • only on Android: sendBulkAndroid(body: array);
    • on both projects: sendBulk(body: array).
  • Delete member: TODO

Transactional API

Class: Batch\TransactionalAPI

  • Send a push notification: sendPush(pushIdentifier, recipients, message, optionalFields)

    • pushIdentifier: (STRING) Name given to a given kind of push notification. ex: referral
    • recipients: (ARRAY[STRING[]]) Set of recipients ONLY ACCEPTED : ["tokens", "custom_ids", "install_ids"]. ex: ["custom_ids" => [162446]]
    • message: (STRING[]) Message to send to the user, must contain a title and a boy. ex: ["title" => "XXX", "body" => "XXXX"]
    • optionalFields: (ARRAY) Any kind of optional field that can precise push notification parameters. For more detailed information see here

Class Batch\IosAndroidTransactionalData

  • Send a push notification:

    • only on iOS: sendPushNotificationIOS(pushIdentifier, recipients, message, optionalFields);
    • only on Android: sendPushNotificationAndroid(pushIdentifier, recipients, message, optionalFields);
    • on both projects: sendPushNotification(pushIdentifier, recipients, message, optionalFields).

Campaigns API

TODO: