Commit 907fb355 authored by zeynel's avatar zeynel

Update README for new endpoints

parent 74f788e4
# onesignal-node
A Node.js client library for [OneSignal](https://onesignal.com/) API.
......@@ -7,19 +8,22 @@ A Node.js client library for [OneSignal](https://onesignal.com/) API.
* [Installation](#installation)
* [Usage](*usage)
* [Creating a service client](#creating-a-client)
* [Sending a push notification](#sending-push-notifications)
* [Cancelling a push notification](#cancelling-a-push-notification)
* [Viewing push notifications](#viewing-push-notifications)
* [Viewing a push notification](#viewing-a-push-notification)
* [Listing apps](#viewing-apps)
* [Creating an app](#creating-an-app)
* [Updating an app](#updating-an-app)
* [Listing devices](#viewing-devices)
* [Viewing a device](#viewing-a-device)
* [Adding a device](#adding-a-device)
* [Editing a device](#editing-a-device)
* [Send a push notification](#send-push-notifications)
* [Cancel a push notification](#cancel-a-push-notification)
* [View push notifications](#view-push-notifications)
* [View a push notification](#view-a-push-notification)
* [View apps](#view-apps)
* [Create an app](#create-an-app)
* [Update an app](#update-an-app)
* [View devices](#view-devices)
* [View a device](#view-a-device)
* [Add a device](#add-a-device)
* [Edit a device](#edit-a-device)
* [New session](#new-session)
* [New purchase](#new-purchase)
* [Increment Session Length](#increment-session-length)
* [CSV Export](#csv-export)
* [Opening track](#opening-track)
* [Open track](#open-track)
* [Tests](#tests)
## Installation
......@@ -36,7 +40,7 @@ var OneSignal = require('onesignal-node');
You can create a OneSignal Client as shown below. It takes a JSON object as parameter which
contains your OneSignal API credentials.
You can find your userAuthKey and REST API Key (appAuthKey) on OneSignal `Account & API Keys` page.
``` js
```js
// create a new Client for a single app
var myClient = new OneSignal.Client({
userAuthKey: 'XXXXXX',
......@@ -46,7 +50,7 @@ var myClient = new OneSignal.Client({
```
You can also create a Client for multiple Apps
``` js
```js
// create a Client for a multiple apps
var myClient = new OneSignal.Client({
userAuthKey: 'XXXXXX',
......@@ -54,7 +58,7 @@ var myClient = new OneSignal.Client({
});
```
You can always create a Client with no credential and set them later:
``` js
```js
// create a Client for a multiple apps
var myClient = new OneSignal.Client({});
myClient.userAuthKey = 'XXXXXX';
......@@ -107,7 +111,7 @@ firstNotification.postBody["data"] = {"abc": "123", "foo": "bar"};
firstNotification.postBody["headings"] = {"en": "English Title", "es": "Spanish Title"};
```
### Sending Push Notifications
### Send Push Notifications
Sending a notification using Segments:
```js
var OneSignal = require('onesignal-node');
......@@ -227,7 +231,7 @@ myClient.userAuthKey = 'XXXXXX';
myClient.apps = ['id1', 'id2'];
```
### Cancelling a push notification
### Cancel a push notification
You can cancel a notification simply by calling `.cancel(notificationId, callback)` method
```js
// this will cancel the notification for current app (myClient.app)
......@@ -238,7 +242,7 @@ myClient.cancelNotification('notificationId', function (err, httpResponse, data)
})
```
### Viewing push notifications
### View push notifications
To view all push notifications for an app:
```js
......@@ -254,7 +258,7 @@ myClient.viewNotifications('limit=30', function (err, httpResponse, data) {
});
```
### Viewing a push notification
### View a push notification
``` js
var myClient = new OneSignal.Client({
......@@ -269,7 +273,7 @@ myClient.viewNotification('notificationId', function (err, httpResponse, data) {
});
```
### Viewing apps
### View apps
``` js
myClient.viewApps(function (err, httpResponse, data) {
console.log(data[0].name); // print the name of the app
......@@ -282,7 +286,7 @@ myClient.viewApp('appId', function (err, httpResponse, data) {
});
```
### Creating an app
### Create an app
``` js
var OneSignal = require('onesignal-node');
......@@ -303,7 +307,7 @@ myClient.createApp(appBody, function (err, httpResponse, data) {
});
```
### Updating an app
### Update an app
``` js
var OneSignal = require('onesignal-node');
......@@ -322,7 +326,7 @@ myClient.updateApp(appBody, function (err, httpResponse, data) {
});
```
### Viewing devices
### View devices
You can view devices for an app:
``` js
var myClient = new OneSignal.Client({
......@@ -335,8 +339,8 @@ myClient.viewDevices('limit=100&offset=0', function (err, httpResponse, data) {
});
```
### Viewing a device
``` js
### View a device
```js
var myClient = new OneSignal.Client({
app: { appAuthKey: 'XXXXX', appId: 'XXXXX' }
});
......@@ -346,8 +350,8 @@ myClient.viewDevice('deviceId', function (err, httpResponse, data) {
});
```
### Adding a device
``` js
### Add a device
```js
var myClient = new OneSignal.Client({
userAuthKey: 'XXXXXX',
......@@ -365,8 +369,8 @@ myClient.addDevice(deviceBody, function (err, httpResponse, data) {
});
```
### Editing a device
``` js
### Edit a device
```js
var myClient = new OneSignal.Client({
userAuthKey: 'XXXXXX',
app: { appAuthKey: 'XXXXX', appId: 'XXXXX' }
......@@ -382,8 +386,64 @@ myClient.editDevice('deviceId', deviceBody, function (err, httpResponse, data) {
...
});
```
### New Session
```js
var myClient = new OneSignal.Client({
userAuthKey: 'XXXXXX',
app: { appAuthKey: 'XXXXX', appId: 'XXXXX' }
});
var postBody = {
language: 'es',
game_version: '1.0',
timezone: -28800
};
myClient.newSession('playerId', postBody, function (err, httpResponse, data) {
...
});
```
### New Purchase
```js
var myClient = new OneSignal.Client({
userAuthKey: 'XXXXXX',
app: { appAuthKey: 'XXXXX', appId: 'XXXXX' }
});
var postBody = {
purchases: [{
sku: 'SKU123',
iso: 'USD',
amount: 0.99
}]
};
myClient.newPurchase('playerId', postBody, function (err, httpResponse, data) {
...
});
```
### Increment Session Length
```js
var myClient = new OneSignal.Client({
userAuthKey: 'XXXXXX',
app: { appAuthKey: 'XXXXX', appId: 'XXXXX' }
});
var postBody = {
state: 'ping',
active_time: 60
};
myClient.incrementSessionLength('playerId', postBody, function (err, httpResponse, data) {
...
});
```
### CSV Export
``` js
```js
var myClient = new OneSignal.Client({
userAuthKey: 'XXXXXX',
app: { appAuthKey: 'XXXXX', appId: 'XXXXX' }
......@@ -394,7 +454,7 @@ myClient.csvExport({ extra_fields: ['location'] }, function (err, httpResponse,
});
```
### Opening track
### Open track
``` js
var myClient = new OneSignal.Client({
userAuthKey: 'XXXXXX',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment