Skip to content

Commit

Permalink
Updated readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
berkayk committed May 2, 2016
1 parent 1664ab8 commit 568fa32
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Introduction

This is a simple OneSignal wrapper library for Laravel. It simplifies the basic notification flow with the defined methods. You can send a message to all users or you can notify a single user.
Before you start installing this service, please complete your OneSignal setup at https://onesignal.com and finish all the steps that is necessary to obtain an application id and REST API Keys.


Expand Down Expand Up @@ -46,7 +47,44 @@ You need to fill in `onesignal.php` file that is found in your applications `con

## Usage

...
### Sending a Notification To All Users

You can easily send a message to all registered users with the command

OneSignal::sendNotificationToAll("Some Message");
OneSignal::sendNotificationToAll("Some Message", $url);
OneSignal::sendNotificationToAll("Some Message", $url, $data);

`$url` and `$data` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url.


### Sending a Notification To A Specific User

After storing a user's tokens in a table, you can simply send a message with

OneSignal::sendNotificationToUser("Some Message", $userId);
OneSignal::sendNotificationToUser("Some Message", $userId, $url);
OneSignal::sendNotificationToUser("Some Message", $userId, $url, $data);

`$userId` is the user's unique id where he/she is registered for notifications. Read https://documentation.onesignal.com/docs/website-sdk-api#getUserId for additional details.
`$url` and `$data` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url.


### Sending a Notification To Segment

You can simply send a notification to a specific segment with

OneSignal::sendNotificationToSegment("Some Message", $segment);
OneSignal::sendNotificationToSegment("Some Message", $segment, $url);
OneSignal::sendNotificationToSegment("Some Message", $segment, $url, $data);

`$url` and `$data` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url.

### Sending a Custom Notification

You can send a custom message with

OneSignal::sendNotificationCustom($parameters);

Please refer to https://documentation.onesignal.com/docs/notifications-create-notification for all customizable parameters.

14 changes: 11 additions & 3 deletions src/OneSignalClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function sendNotificationToUser($message, $userId, $url = null, $data = n
$this->sendNotificationCustom($params);
}

public function sendNotificationToAll($message, $data = null) {
public function sendNotificationToAll($message, $url = null, $data = null) {
$contents = array(
"en" => $message
);
Expand All @@ -68,24 +68,32 @@ public function sendNotificationToAll($message, $data = null) {
'included_segments' => array('All')
);

if (isset($url)) {
$params['url'] = $url;
}

if (isset($data)) {
$params['data'] = $data;
}

$this->sendNotificationCustom($params);
}

public function sendNotificationToSegment($message, $segments, $data = null) {
public function sendNotificationToSegment($message, $segment, $url = null, $data = null) {
$contents = array(
"en" => $message
);

$params = array(
'app_id' => $this->appId,
'contents' => $contents,
'included_segments' => array('All')
'included_segments' => [$segment]
);

if (isset($url)) {
$params['url'] = $url;
}

if (isset($data)) {
$params['data'] = $data;
}
Expand Down

0 comments on commit 568fa32

Please sign in to comment.