Package Data | |
---|---|
Maintainer Username: | kodjunkie |
Maintainer Contact: | paplow01@gmail.com (Lawrence Onah) |
Package Create Date: | 2021-08-04 |
Package Last Update: | 2024-11-11 |
Home Page: | https://packagist.org/packages/kodjunkie/onesignal-php-sdk |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-11 15:18:38 |
Package Statistics | |
---|---|
Total Downloads: | 1,580 |
Monthly Downloads: | 17 |
Daily Downloads: | 2 |
Total Stars: | 3 |
Total Watchers: | 2 |
Total Forks: | 3 |
Total Open Issues: | 0 |
OneSignal SDK for PHP developers with fluent API and supports Laravel / Lumen out of the box.
composer require kodjunkie/onesignal-php-sdk
NOTE: For Laravel
users, this package registers itself automatically.
use Kodjunkie\OnesignalPhpSdk\OneSignal;
use Kodjunkie\OnesignalPhpSdk\Exceptions\OneSignalException;
try {
$config = [
// Onesignal API key
'api_key' => '',
// Onesignal Auth key
'auth_key' => '',
// Onesignal App ID (optional)
// Providing your app_id is beneficial if you're working with a single OneSignal app
// and don't want to provide it all the time for endpoints that requires it
'app_id' => '',
];
// Initialize the SDK
$oneSignal = new OneSignal($config);
// Using the API
// Get all apps
$response = $oneSignal->app()->getAll();
// You can use json_decode to get the response as an stdClass Object
var_dump($response);
} catch (OneSignalException $exception) {
var_dump($exception->getMessage());
}
Set these values in your .env
file
ONESIGNAL_API_KEY=
ONESIGNAL_AUTH_KEY=
ONESIGNAL_APP_ID=
Add this line to your bootstrap/app.php
file
$app->register(\Kodjunkie\OnesignalPhpSdk\OneSignalServiceProvider::class);
Lastly, use in your controller
or wherever it's needed
use Kodjunkie\OnesignalPhpSdk\OneSignal;
use Kodjunkie\OnesignalPhpSdk\Exceptions\OneSignalException;
try {
// Initialize the SDK
// Resolve from the IoC container
$oneSignal = app()->make('onesignal');
// Using the API
// Get all devices
$response = $oneSignal->device()->getAll($appId, $limit, $offset);
// Using Facade, the code above will look like this
// With app_id provided in the config
$response = OneSignal::device()->getAll(null, $limit, $offset);
dd($response);
} catch (OneSignalException $exception) {
dd($exception->getMessage());
}
composer test
This project is opened under the MIT 2.0 License which allows very broad use for both academic and commercial purposes.