Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
onesignal-node
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
CI / CD
CI / CD
Pipelines
Schedules
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Cedar Studios
onesignal-node
Commits
a56622a6
Commit
a56622a6
authored
Aug 02, 2017
by
=
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add csv export and track open
parent
fe422123
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
4 deletions
+56
-4
README.md
README.md
+25
-1
client.js
lib/client.js
+31
-3
No files found.
README.md
View file @
a56622a6
...
@@ -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 device
s
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
...
...
lib/client.js
View file @
a56622a6
...
@@ -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
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment