Commit a56622a6 authored by ='s avatar =

add csv export and track open

parent fe422123
...@@ -17,6 +17,8 @@ A Node.js client library for [OneSignal](https://onesignal.com/) API. ...@@ -17,6 +17,8 @@ A Node.js client library for [OneSignal](https://onesignal.com/) API.
* [Vieving a device](#viewing-a-device) * [Vieving a device](#viewing-a-device)
* [Adding a device](#adding-a-device) * [Adding a device](#adding-a-device)
* [Editing a device](#editing-a-device) * [Editing a device](#editing-a-device)
* [CSV Export](#csv-export)
* [Opening track](#opening-track)
## Installation ## Installation
...@@ -164,7 +166,7 @@ myClient.sendNotification(firstNotification, function (err, httpResponse,data) { ...@@ -164,7 +166,7 @@ myClient.sendNotification(firstNotification, function (err, httpResponse,data) {
} }
}); });
``` ```
To target one or more devices use `.setTargetDevices(include_player_ids)` method: To target one or more device, use `.setTargetDevices(include_player_ids)` method:
``` js ``` js
var OneSignal = require('onesignal-node'); var OneSignal = require('onesignal-node');
...@@ -357,7 +359,29 @@ myClient.editDevice('deviceId', deviceBody, function (err, httpResponse, data) { ...@@ -357,7 +359,29 @@ myClient.editDevice('deviceId', deviceBody, function (err, httpResponse, data) {
... ...
}); });
``` ```
### CSV Export
``` js
var myClient = new OneSignal.Client({
userAuthKey: 'XXXXXX',
app: { appAuthKey: 'XXXXX', appId: 'XXXXX' }
});
myClient.csvExport({ extra_fields: ['location'] }, function (err, httpResponse, data) {
...
});
```
## Opening track
``` js
var myClient = new OneSignal.Client({
userAuthKey: 'XXXXXX',
app: { appAuthKey: 'XXXXX', appId: 'XXXXX' }
});
myClient.trackOpen('notificationId', { opened: true }, function (err, httpResponse, data) {
...
});
```
## License ## License
......
...@@ -237,7 +237,7 @@ Client.prototype.viewDevice = function (deviceId, callback) { ...@@ -237,7 +237,7 @@ Client.prototype.viewDevice = function (deviceId, callback) {
throw 'You must define an "app" object.' throw 'You must define an "app" object.'
} }
var viewUri = this.API_URI + constants.DEVICES_PATH + '/' + deviceId + '?app_id=' + this.app.appId; var viewUri = this.API_URI + constants.DEVICES_PATH + '/' + deviceId + '?app_id=' + this.app.appId;
basicRequest(viewUri, null, 'GET', null, callback); basicRequest(viewUri, this.app.appAuthKey, 'GET', null, callback);
}; };
...@@ -253,7 +253,7 @@ Client.prototype.addDevice = function (body, callback) { ...@@ -253,7 +253,7 @@ Client.prototype.addDevice = function (body, callback) {
if (!('app_id' in body)) { if (!('app_id' in body)) {
body.app_id = this.app.appId; body.app_id = this.app.appId;
} }
basicRequest(this.API_URI + constants.DEVICES_PATH, null, 'POST', body, callback); basicRequest(this.API_URI + constants.DEVICES_PATH, this.app.appAuthKey, 'POST', body, callback);
}; };
/** /**
...@@ -266,9 +266,37 @@ Client.prototype.editDevice = function (deviceId, body, callback) { ...@@ -266,9 +266,37 @@ Client.prototype.editDevice = function (deviceId, body, callback) {
if (!this.app) { if (!this.app) {
throw 'You must define an "app" object.' throw 'You must define an "app" object.'
} }
basicRequest(this.API_URI + constants.DEVICES_PATH + '/' + deviceId, null, 'PUT', body, callback); basicRequest(this.API_URI + constants.DEVICES_PATH + '/' + deviceId, this.app.appAuthKey, 'PUT', body, callback);
}; };
/**
*
* @param notificationId { String }
* @param body { JSON }
* @param callback
*/
Client.prototype.trackOpen = function (notificationId, body, callback) {
if (!this.app) {
throw 'You must define an "app" object.'
}
if (!('app_id' in body)) {
body.app_id = this.app.appId;
}
basicRequest(this.API_URI + constants.NOTIFICATIONS_PATH + '/' + notificationId, this.app.appAuthKey, 'PUT', body, callback);
};
/**
*
* @param body
* @param callback
*/
Client.prototype.csvExport = function (body, callback) {
if (!this.app) {
throw 'You must define an "app" object.'
}
var csvUri = this.API_URI + constants.DEVICES_PATH + '/csv_export' + '?app_id=' + this.app.appId;
basicRequest(csvUri, this.app.appAuthKey, 'POST', body, callback);
};
module.exports = Client; module.exports = Client;
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