Git Product home page Git Product logo

php-onesignal-sdk's Introduction

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.

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"

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.

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:

Application body parameters: Create and Update

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) body parameters: Create, Update, New session, New purchase, Increment session length and CSV export

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 body parameters: Create

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>");

php-onesignal-sdk's People

Contributors

namnv609 avatar sanderjongsma avatar thewildhorse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

php-onesignal-sdk's Issues

The min requirement should be set to php 5.5.*

Neither guzzlehttp nor symphony-resolver work on php 5.4 and therefore the library can't be used in php 5.4.

The first issue occurring is that ::class used in OptionsResolver.php is not available until php 5.5

HP Parse error: syntax error, unexpected 'finally' (T_STRING), expecting catch (T_CATCH) in ..../vendor/symfony/options-resolver/OptionsResolver.php on line 786

Error When Trying To Create App

I keep getting this error when I try to create an app:

stdClass Object
(
    [status] => 
    [code] => 400
    [response] => stdClass Object
        (
            [errors] => Array
                (
                    [0] => Your subdomain must only contain lowercase letters, numbers, and dashes (not as a starting or ending character) and must be between 4 and 14 characters long.
                )

        )

)

This is the code I'm using to create an app:

use NNV\OneSignal\OneSignal;
use NNV\OneSignal\API\App;
  
$oneSignal = new OneSignal("<Auth Key Here>");
$app = new App($oneSignal);

$appData = [
    'name' => 'My App',
    'chrome_web_origin' => "http://my-domain.com",
    'chrome_web_sub_domain' => "https://subdomain.os.tc",
    'apns_env' => 'production'
];

$response = $app->create($appData);

echo "<pre>", print_r($response), "</pre>";

Any help in fixing this issue is greatly appreciated. :)

Doesnt allow for spesific player_id

I want to send notif to a spesific user which is done with include_player_ids parameter. onesignal api says you cannot use include_player_ids with included_segments , you should choose one. But this sdk doesnt allow to remove included_segments from parameters when creating notification.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.