2017 © Pedro Peláez
 

library php-onesignal-sdk

PHP SDK for OneSignal RESTful API

image

namnv609/php-onesignal-sdk

PHP SDK for OneSignal RESTful API

  • Monday, May 7, 2018
  • by namnv609
  • Repository
  • 3 Watchers
  • 16 Stars
  • 1,331 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 5 Forks
  • 3 Open issues
  • 3 Versions
  • 92 % Grown

The README.md

PHP SDK for OneSignal RESTful API

OneSignal is a high volume and reliable push notification service for websites and mobile applications. We support all major native and mobile platforms by providing dedicated SDKs for each platform, a RESTful server API, and an online dashboard for marketers to design and send push notifications., (*1)

System requirements

  • PHP >= 5.5

Installation

Using Composer composer require namnv609/php-onesignal-sdk or you can include the following in your composer.json "namnv609/php-onesignal-sdk": "1.0", (*2)

Response format

{"status":true,"code":200,"response":<OneSignal result>}
$players = $player->all();

foreach ($players->response->players as $player) {
    echo $player->id . PHP_EOL;
}

Usage Instructions

First, create a new OneSignal instance to make configuring the library for usage., (*3)

use NNV\OneSignal\OneSignal;

$oneSignal = new OneSignal(<User Auth key> [, <App ID>, <App REST key>, <Extra options for GuzzleHttp Client>])

Once the OneSignal instance has been registered. You may use it like so:, (*4)

Application

Application body parameters: Create and Update, (*5)

use NNV\OneSignal\API\App;

$app = new App($oneSignal);
  • View apps
$app->all();
  • View an app
$app->get("<App ID>");
  • Create an app
$appData = [
    'name' => '<App name>',
    'apns_env' => 'sandbox',
];

$app->create($appData);
  • Update an app
$appData = [
    'apns_env' => 'production',
];

$app->update("<App ID>", $appData);

Player (Device)

Player (Device) body parameters: Create, Update, New session, New purchase, Increment session length and CSV export, (*6)

use NNV\OneSignal\API\Player;

$player = new Player($oneSignal [, <App ID>, <App REST key>]);
  • View devices
$player->all([<Limit>, <Offset>]);
  • View device
$player->get("<Player ID>");
  • Add a device
use NNV\OneSignal\Constants\DeviceTypes;

$playerData = [
    'language' => 'en',
    'tags' => [
        'for' => 'bar',
        'this' => 'that'
    ]
];

$player->create(DeviceTypes::CHROME_WEBSITE, $playerData);
  • Edit device
use NNV\OneSignal\Constants\NotificationTypes;
use NNV\OneSignal\Constants\TestTypes;

$playerData = [
    'test_type' => TestTypes::DEVELOPMENT,
    'notification_types' => NotificationTypes::UNSUBSCRIBED
];

$player->update("<Player ID>", $playerData);
  • New session
$sessionData = [
    'tags' => [
        'new' => 'session',
    ],
];
$player->onSession("<Player ID>", $sessionData);
  • New purchase (Currently, i've support one item per request)
$purchaseData = [
    'sku' => 'SKU123',
    'iso' => 'USD',
    'amount' => '0.99',
];

$player->onPurchase("<Player ID>", $purchaseData, [<Is existing>]);
  • Increment session length
$focusData = [
    'state' => 'ping',
    'active_time' => 1,
];

$player->onFocus("<App ID>", $focusData);
  • CSV export
$extraFields = ['rooted'];

$player->csvExport($extraFields);

Notification

Notification body parameters: Create, (*7)

use NNV\OneSignal\API\Notification;

$notification = new Notification($oneSignal[, <App ID>, <App REST key>]);
  • Create notification
$notificationData = [
    'included_segments' => ['All'],
    'contents' => [
        'en' => 'Hello, world',
    ],
    'headings' => [
        'en' => 'Hello',
    ],
    'buttons' => [
        [
            'id' => 'button_id',
            'text' => 'Button text',
            'icon' => 'button_icon',
        ],
    ],
    'filters' => [
        [
            'field' => 'tag',
            'key' => 'level',
            'relation' => '>',
            'value' => '10',
        ],
    ],
    'send_after' => 'Sep 24 2017 14:00:00 GMT-0700',
    'isChromeWeb' => true,
];

$notification->create($notificationData);
  • Cancel notification
$notification->cancel("<Notification ID>");
  • View notification
$notification->get("<Notification ID>");
  • View notifications
$notification->all([<Limit>, <Offset>]);
  • Track open
$notification->trackOpen("<Notification ID>");

The Versions

07/05 2018

dev-master

9999999-dev

PHP SDK for OneSignal RESTful API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar namnv609

03/07 2017

v1.0.1

1.0.1.0

PHP SDK for OneSignal RESTful API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar namnv609

25/01 2017

v1.0

1.0.0.0

PHP SDK for OneSignal RESTful API

  Sources   Download

MIT

The Requires

 

by Avatar namnv609

notification onesignal restful api web push notification