OneSignal PHP SDK

Overview
OneSignal

OneSignal PHP SDK

OneSignal SDK for PHP developers with fluent API and supports Laravel / Lumen out of the box.

Latest Stable Version Total Downloads PHP Version Require tests license: MIT

Why use this package?

This is the only package out there that is unambiguous to set up, and has a fluent / straightforward API.

Installation

NOTE: For Laravel users, this package registers itself automatically.

composer require kodjunkie/onesignal-php-sdk

Usage in plain PHP

'', ]; try { // Initialize the SDK $oneSignal = new OneSignal($config); // Using the API // Get all apps $response = $oneSignal->app()->getAll(); // Use json_decode() to get the response as an stdClass object var_dump($response); } catch (OneSignalException $exception) { var_dump($exception->getMessage()); }">
use Kodjunkie\OnesignalPhpSdk\OneSignal;
use Kodjunkie\OnesignalPhpSdk\Exceptions\OneSignalException;

$config = [
    // Onesignal API key
    'api_key' => '',
    // Onesignal Auth key
    'auth_key' => '',
    // Onesignal App ID (optional)
    // this is beneficial if you're working with a single OneSignal app
    // so, you could pass "null" to methods that requires it.
    'app_id' => '',
];

try {
    // Initialize the SDK
    $oneSignal = new OneSignal($config);
    
    // Using the API
    // Get all apps
    $response = $oneSignal->app()->getAll();
    
    // Use json_decode() to get the response as an stdClass object
    var_dump($response);
} catch (OneSignalException $exception) {
    var_dump($exception->getMessage());
}

Usage in Laravel / Lumen

Set these values in your .env file

ONESIGNAL_API_KEY=
ONESIGNAL_AUTH_KEY=
ONESIGNAL_APP_ID=

Register the service provider (lumen only)

Add this line to your bootstrap/app.php file

$app->register(Kodjunkie\OnesignalPhpSdk\OneSignalServiceProvider::class);

// Register the facade (optional)
// To use, must have $app->withFacades() enabled
if (!class_exists('OneSignal')) {
    class_alias(Kodjunkie\OnesignalPhpSdk\Facade::class, 'OneSignal');
}

Code samples

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());
}

Tests

composer test

License

This project is opened under the MIT 2.0 License which allows very broad use for both academic and commercial purposes.

You might also like...
Laravel wrapper for the Facebook Graph PHP 8 SDK

Laravel Facebook Graph SDK Installation Getting started with Laravel Facebook Graph is easy - first, install the package via composer composer require

2c2p payment gateway Redirect PHP-SDK
2c2p payment gateway Redirect PHP-SDK

2c2p payment gateway Redirect PHP-SDK

可能是基于 hyperf 的最优雅的支付宝、微信支付 SDK 了
可能是基于 hyperf 的最优雅的支付宝、微信支付 SDK 了

当前组件整体处于 beta 阶段 运行环境 php = 7.3 composer hyperf = 2.1 安装 composer require yansongda/hyperf-pay:~1.0.0 说明 发布配置文件 php bin/hyperf.php vendor:publish ya

SDK for latest version of Telegram bots API

SDK for latest version of Telegram bots API (from April 24, 2020) Using Examples Installing composer require "DiyorbekUz/Telelib: dev-master" Init bot

API SDK for OpenTrade Commerce API: Taobao, Alibaba, JD, 1688, Aliexpress, Ebay.

OtapiPhpClient Create Client $client = new OtClient($key, $secret, $lang); key (Access Key) secret (Secret for access key) language (2 symbol lang id

Laravel SDK for Sentry
Laravel SDK for Sentry

Sentry for Laravel Laravel integration for Sentry. Laravel Version Compatibility Laravel = 4.2.x is supported until 0.8.x Laravel = 5.7.x on PHP =

Universal payments API SDK (UNOFFICIAL QIWI CLIENT)

Qiwi Php Client Especially for 🦊 Zorra Telecom and 👥 Everyone else Привет Attention: At the moment the number of methods is very limited, they will

⚡️ Web3 PHP is a supercharged PHP API client that allows you to interact with a generic Ethereum RPC.
⚡️ Web3 PHP is a supercharged PHP API client that allows you to interact with a generic Ethereum RPC.

Web3 PHP is a supercharged PHP API client that allows you to interact with a generic Ethereum RPC. This project is a work-in-progress. Code and docume

Lightweight PHP library for WhatsApp API to send the whatsapp messages in PHP provided by ultramsg.com

Ultramsg.com WhatsApp API PHP SDK Lightweight PHP library for WhatsApp API to send the whatsappp messages in PHP provided by Ultramsg.com Installation

Releases(v1.1.3)
Owner
Lawrence Onah
Full-stack Engineer • Web3 Freak • Blockchain Developer • Cyber Security Enthusiast 🎓 • Performance & Clean Code Monger
Lawrence Onah
Official repository of the AWS SDK for PHP (@awsforphp)

AWS SDK for PHP - Version 3 The AWS SDK for PHP makes it easy for developers to access Amazon Web Services in their PHP code, and build robust applica

Amazon Web Services 5.7k Jan 1, 2023
Mailgun's Official SDK for PHP

Mailgun PHP client This is the Mailgun PHP SDK. This SDK contains methods for easily interacting with the Mailgun API. Below are examples to get you s

Mailgun Team 1k Dec 23, 2022
A Laravel package to help integrate Shopware PHP SDK much more easier

Shopware 6 Laravel SDK A Laravel package to help integrate Shopware PHP SDK much more easier Installation Install with Composer composer require sas/s

Shape & Shift 16 Nov 3, 2022
Minter Blockchain PHP SDK

About This is a pure PHP SDK for working with Minter blockchain Installation Minter Api Methods: getBalance getNonce send getAddresses getStatus getVa

Minter 24 Nov 21, 2022
The official PHP SDK for Webmarketer (app.webmarketer.io)

PHP SDK for Webmarketer The official PHP SDK for Webmarketer (app.webmarketer.io). Install To add this package, your project must meet several require

Webmarketer 5 Dec 13, 2021
A PHP SDK for the GlobalSmartOTP API.

GlobalSmartOTP PHP SDK A PHP SDK for the GlobalSmartOTP API. Requirements PHP 7.4 or higher cURL Installation $ git clone [email protected]:GlobalSmartOT

GlobalSmartOTP 4 Oct 2, 2022
Fatture in Cloud SDK (Software Development Kit) for PHP

FattureInCloud PHP SDK Request informations In every request description you will be able to find some additional informations about context, permissi

Fatture in Cloud 25 Dec 5, 2022
🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.

Telegram Bot API - PHP SDK Telegram Bot PHP SDK lets you develop Telegram Bots in PHP easily! Supports Laravel out of the box. Telegram Bot API is an

Irfaq Syed 2.5k Jan 6, 2023
Explicador e2Payments PHP SDK

This package seeks to help php developers implement the e2Payments APIs without much hustle. It is based on the REST API whose documentation

Explicador 5 Oct 26, 2022
Official PHP SDK for interacting with the Knock API.

Knock PHP library Documentation See the documentation for PHP usage examples

Knock 4 Dec 16, 2022