This packages requires an http adapter to work. You can choose any from php-http/client-implementation
Example with Guzzle v6 adapter, install it with Composer:
composer require php-http/guzzle6-adapter:^1.1 norkunas/onesignal-php-api:^1.0
And now configure the service:
<?php
require __DIR__ . '/vendor/autoload.php';
use GuzzleHttp\Client as GuzzleClient;
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
use Http\Client\Common\HttpMethodsClient as HttpClient;
use Http\Message\MessageFactory\GuzzleMessageFactory;
use OneSignal\Config;
use OneSignal\OneSignal;
$config = new Config();
$config->setApplicationId('your_application_id');
$config->setApplicationAuthKey('your_application_auth_key');
$config->setUserAuthKey('your_auth_key');
$guzzle = new GuzzleClient([ // http://docs.guzzlephp.org/en/stable/quickstart.html
// ..config
]);
$client = new HttpClient(new GuzzleAdapter($guzzle), new GuzzleMessageFactory());
$api = new OneSignal($config, $client);
View the details of all of your current OneSignal applications (official documentation):
$myApps = $api->apps->getAll();
View the details of a single OneSignal application (official documentation):
$myApp = $api->apps->getOne('application_id');
Create a new OneSignal app (official documentation):
$newApp = $api->apps->add([
'name' => 'app name',
'gcm_key' => 'key'
]);
Update the name or configuration settings of OneSignal application (official documentation):
$api->apps->update('application_id', [
'name' => 'new app name'
]);
View the details of multiple devices in one of your OneSignal apps (official documentation):
$devices = $api->devices->getAll();
View the details of an existing device in your configured OneSignal application (official documentation):
$device = $api->devices->getOne('device_id');
Register a new device to your configured OneSignal application (official documentation):
$newDevice = $api->devices->add([
'device_type' => Devices::ANDROID,
'identifier' => 'abcdefghijklmn',
]);
Update an existing device in your configured OneSignal application (official documentation):
$api->devices->update('device_id', [
'session_count' => 2,
]);
View the details of multiple notifications (official documentation):
$notifications = $api->notifications->getAll();
Get the details of a single notification (official documentation):
$notification = $api->notifications->getOne('notification_id');
Create and send notifications or emails to a segment or individual users. You may target users in one of three ways using this method: by Segment, by Filter, or by Device (at least one targeting parameter must be specified) (official documentation):
$api->notifications->add([
'contents' => [
'en' => 'Notification message'
],
'included_segments' => ['All'],
'data' => ['foo' => 'bar'],
'isChrome' => true,
'send_after' => new \DateTime('1 hour'),
'filters' => [
[
'field' => 'tag',
'key' => 'is_vip',
'relation' => '!=',
'value' => 'true',
],
[
'operator' => 'OR',
],
[
'field' => 'tag',
'key' => 'is_admin',
'relation' => '=',
'value' => 'true',
],
],
// ..other options
]));
Mark notification as opened (official documentation):
$api->notifications->open('notification_id');
Stop a scheduled or currently outgoing notification (official documentation):
$api->notifications->cancel('notification_id');
If you have any questions please open an issue.
This library is released under the MIT License. See the bundled LICENSE file for details.