getmo/smartpush-php-connector

Php library to connect with Smartpush API services

v0.3.0 2016-07-01 21:23 UTC

This package is not auto-updated.

Last update: 2024-04-22 10:41:42 UTC


README

Php library to connect with Smartpush API services.

Installation

composer require getmo/smartpush-php-connector

Platforms

Use one of the these platforms when you see $platform on the docs above.

$platforms = ['IOS', 'ANDROID', 'WINDOWS', 'CHROME', 'SAFARI', 'FIREFOX'];

Usage

Import the Push class into your project.

use Smartpush\Push;
use Smartpush\Notification; // optional, use only if you will consult data from server

Class: Push

Description: Create a new push instance.

Example:

$push = new Push(string $devid, string $when = 'now', string $alias = '');

The second and thirth parameters are optional. The second $when parameter can handle this entry models: 'now', '0000-00-00 00:00:00', '00/00/000 00:00:00', or a valida UNIX timestamp. The thirth $alias paramenter sets a custom name for this Push Notification, so you can track it later on control panel.

Method: setEnvironment()

Description: (Optional) Set the environment you want to use to sent this Push Notification.

Example:

$push->setEnvironment(string $envinronment = '1'); # This method return $this, so you can chain it.

Return:

$this; # so you can chain methods! 

This method is optional. If you dont set the environment, the lib will guess you choose production. If you want to use sandbox, use this method with $environment = '0'.

Method: addNotification()

Description: Add a notification to the Push payload.

Example:

$push->addNotification(string $appid, string $platform, array $params);
# or
$push->addNotification(string $appid, string $platform, object $params);

Return:

$this; # so you can chain methods! 

The thirth parameter, $params, must be an array or an object (If you pass in an array the lib will turn it into an object). The content schema variates according the platform. Consult the REST API docs to obtain the correct schema for the platform that you want to target.

Method: getNotifications()

Description: (Optional) Return an array of Notifications that you have previously configured to send.

Example:

$notifications = $push->getNotifications();
foreach ($notifications as $notification) {
    echo $notification->appid;
    echo $notification->platform;
    var_dump($notification->params);
}

Return:

array; # of objects 

This method can be used to inspect the Notifications data inside the Push object before sending.

Method: setFilterRange()

Description: (Optional) Set the range days of which the filter will operate when the job is processed. The $range value can be one of there: 7, 15, 30, 60, 90, all, otherwise it will fallback to default: all.

Example:

$push->setFilterRange(string $range);

Return:

$this; # so you can chain methods! 

Method: setFilterOperator()

Description: (Optional) Set the operator of which the filter will use to do comparisons. The $operator value can be one of there: AND, OR, otherwise it will fallback to default: AND.

Example:

$push->setFilterOperator(string $operator);

Return:

$this; # so you can chain methods! 

Method: addTag()

Description: Add a Tag to filter the Push Notification devices.

Example:

$push->addTag(string $key, string $value);
# or
$push->addTag(string $key, string $comparator, string $value);

Return:

$this; # so you can chain methods! 

The thirth parameter is optional. If you suppress the $comparator parameter the lib will guess you want to Equal (=) this entry. The complete list of comparators you find out in the REST API docs.

Method: getTags()

Description: (Optional) Return an array of Tags that you have previously configured to send.

Example:

$tags = $push->getTags();
foreach ($tags as $tag) {
    var_dump($tags);
}

Return:

array; # of tags 

This method can be used to inspect the Notifications data inside the Push object before sending.

Method: getPayload()

Description: (Optional) Return the complete payload that you have previously configured to send. If you pass true in the first parameter, the method will return a JSON string, otherwise an array.

Example:

var_dump($push->getPayload()); # array
# or
var_dump($push->getPayload(true)); # JSON string

Return:

'{...}' || array; # JSON string or array

This method can be used to inspect the data inside every notification before sending it.

Method: send()

Description: Send the Push Notification previously configured. If the inputs dont validate this methos will return false, otherwise true.

Example:

if ($push->send()) {
    # ...
} else {
    # ...
}

Return:

true || false;

If this method return false probably you forgot to config a notification or a tag.

Method: getResult()

Description: Grab the server response after send a Push Notification. One of the most important information that returns in the JSON string is the pushid.

Example:

$result = $push->getResult();
$data = json_decode($result);
echo $data->pushid;

Return:

'{...}'; # JSON string

Method: getInfo()

Description: Consult server for the status (and more information) about a Push Notification.

Example:

$info = $push->getInfo(string $pushid);
$data = json_decode($info);

var_dump($data->notifications); # array of information about all notifications of this push.
foreach ($data->notifications as $notification) {
    echo $notification->appid;
    echo $notification->status;
    # if push was sent the follow property will be available.
    echo $notification->sent_at;
}
...
# if push was configured to be sent at a future moment in time, this two properties will be available.
echo $data->{'time-left'};
echo $data->date;

Return:

'{...}'; # JSON string

Method: cancel().

Description: Cancel and Consult server for the status (and more information) about a Push Notification.

Example:

$push->cancel(string $pushid);
# or
$info = $push->cancel(string $pushid);
# Here, $info get the same result as getInfo() mention above.

Return:

'{...}'; # JSON string

You can only cancel Push Notifications which were not sent.

Method: hide().

Description: Cancel and Consult server for the status (and more information) about a Push Notification.

Example:

$push->hide(string $pushid);
# or
$info = $push->hide(string $pushid);
# Here, $info get the same result as getInfo() mention above.

Return:

'{...}'; # JSON string

Class: Notification

Description: Create a new notification instance.

Example:

$notification = new Notification(string $devid, string $appid, string $platform);

Method: getLastNotifications()

Description: Get the last ten (10) notifications of a specific hwid.

Example:

$result = $notification->getLastNotifications(string $hwid, array $options);

Return:

'{...}'; # JSON string

The second parameter, $options, is optional. It must be an array and can have the following keys: show, startingDate, dateFormat. Consult the REST API docs to get more information about there optional arguments.

Method: getLastUnreadNotifications()

Description: Get the last ten (10) unread notifications of a specific hwid (device).

Example:

$result = $notification->getLastUnreadNotifications(string $hwid, array $options);

Return:

'{...}'; # JSON string

The second parameter, $options, is optional. It must be an array and can have the following keys: show, startingDate, dateFormat. Consult the REST API docs to get more information about there optional arguments.

Method: getExtraPayload()

Description: Get the extra payload for a specific pushid.

Example:

$result = $notification->getExtraPayload(string $pushid);

Return:

'{...}'; # JSON string

Method: readOneNotification()

Description: Mark one Push Notification as READ for a specific hwid (device).

Example:

$notification->readOneNotification(string $hwid, string $pushid);

Method: readAllNotifications()

Description: Mark all Push Notifications as READ for a specific hwid (device).

Example:

$notification->readAllNotifications(string $hwid);

Method: hideHwidNotification()

Description: Hide one Push Notification for a specific hwid (device).

Example:

$notification->hideHwidNotification(string $hwid, string $pushid);

Support

Jonathan Martins, webmaster@getmo.com.br

Developed by Getmo