Skip to content

Add README.md #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
43 changes: 16 additions & 27 deletions src/OneSignal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}