diff --git a/README.md b/README.md new file mode 100644 index 0000000..81b798f --- /dev/null +++ b/README.md @@ -0,0 +1,73 @@ +# OneSignal Leaf PHP Extension + +This repository provides an extension for the Leaf PHP framework that integrates OneSignal, a powerful and reliable push notification service. This extension simplifies the process of sending push notifications through OneSignal by wrapping the OneSignal API with a convenient PHP class. + +> [!IMPORTANT] +> This extension has been created as part of a livestream series, is not actively maintained, and should not be used in production. Please check out the series on [YouTube](#) for more information. + +## Features + +- Easy integration with OneSignal using Leaf PHP framework. +- Simple setup with minimal configuration. +- Provides a ready-to-use OneSignal client for your Leaf PHP applications. + +## Installation + +To install this extension, you can use Composer. Run the following command in your project directory: + +```bash +composer require your-namespace/onesignal-leaf-extension +``` + +## Usage + +### Configuration + +First, ensure you have your OneSignal REST API key and User Auth key. You can obtain these from the OneSignal dashboard. + +### Example + +Here is an example of how to use this extension in your Leaf PHP application: + +```php +require 'vendor/autoload.php'; + +use OneSignal\OneSignal; + +// Initialize the OneSignal client with your REST API key and User Auth key +$rest_api_key = 'YOUR_REST_API_KEY'; +$user_auth_key = 'YOUR_USER_AUTH_KEY'; +$oneSignal = new OneSignal($rest_api_key, $user_auth_key); + +// Get the OneSignal client +$client = $oneSignal->getClient(); + +// Now you can use the $client to send notifications, manage devices, etc. +``` + +## API + +### `OneSignal` + +The main class of this extension. It initializes the OneSignal client. + +#### `__construct($rest_api_key, $user_auth_key)` + +- `$rest_api_key`: Your OneSignal REST API key. +- `$user_auth_key`: Your OneSignal User Auth key. + +Initializes the OneSignal client with the provided keys. + +#### `getOneSignalClient()` + +Returns the initialized OneSignal client instance. + +## License + +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. + +## Acknowledgements + +- [OneSignal](https://onesignal.com/) for providing a robust push notification service. +- [Leaf PHP Framework](https://leafphp.dev/) for providing a simple and powerful PHP framework. +- [GuzzleHttp](http://docs.guzzlephp.org/en/stable/) for providing a reliable HTTP client. diff --git a/src/OneSignal.php b/src/OneSignal.php index 34ff3a8..7e5c6c9 100644 --- a/src/OneSignal.php +++ b/src/OneSignal.php @@ -8,33 +8,22 @@ class OneSignal { - public $onesignalClient; - - function __construct($rest_api_key, $user_auth_key) - { - $config = Configuration::getDefaultConfiguration() - ->setAppKeyToken($rest_api_key) - ->setUserKeyToken($user_auth_key); - - $this->onesignalClient = new DefaultApi( - new GuzzleHttp\Client(), - $config - ); - } - - function viewApps() - { - $appArray = []; - - foreach ($this->onesignalClient->getApps() as &$app) { - array_push($appArray, [$app['name'], $app['id']]); + public $onesignalClient; + + function __construct($rest_api_key, $user_auth_key) + { + $config = Configuration::getDefaultConfiguration() + ->setAppKeyToken($rest_api_key) + ->setUserKeyToken($user_auth_key); + + $this->onesignalClient = new DefaultApi( + new GuzzleHttp\Client(), + $config + ); } - return $appArray; - } - - function getClient() - { - return $this->onesignalClient; - } + function getOneSignalClient() + { + return $this->onesignalClient; + } }