Commit 907fb355 authored by zeynel's avatar zeynel

Update README for new endpoints

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