Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ $ meteor add astrocoders:one-signal

## Getting started

Ensure that you have a oneSignal entry in your settings.json:
Make sure to enter the following information from settings.json by default.
You can also give `apiId` and `apiKey` values as options.

```json
{
Expand All @@ -33,7 +34,15 @@ Usage:
},
};

OneSignal.Notifications.create([playersId], data);
const options = {
apiKey:'',
appId:'',
}

const oneSignal = new OneSignal() // By default it looks at Meteor.settings.oneSignal.
const oneSignal = new OneSignal(options)

oneSignal.notifications.create([playersId], data);
// => returns OneSignal response.
```

Expand Down
67 changes: 38 additions & 29 deletions lib/one_signal.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
SentNotifications = new Mongo.Collection('oneSignalNotifications');
SentNotifications = new Mongo.Collection('oneSignalNotifications')

OneSignal = {
_base: 'https://onesignal.com/api/v1/',
send(method, api, data){
const url = `${this._base}/${api}`;
const { apiKey } = Meteor.settings.oneSignal;
OneSignal = class OneSignal {
_baseUrl = 'https://onesignal.com/api/v1/'

constructor(options = {}) {
const { apiKey, appId } = Meteor.settings.oneSignal
this.apiKey = options.apiKey || apiKey
this.appId = options.appId || appId
}

send(method, api, data) {
const url = `${this._baseUrl}${api}`

return HTTP.call(method, url, {
data,
headers: {
Authorization: `Basic ${apiKey}`,
Authorization: `Basic ${this.apiKey}`,
},
});
},
};

OneSignal.Notifications = {
_api: 'notifications',
create(players, data){
const url = `${this._api}`;
const { appId } = Meteor.settings.oneSignal;

SentNotifications.insert({
...data,
createdAt: new Date(),
});

return OneSignal.send('POST', url, {
...data,
app_id: appId,
include_player_ids: players,
});
},
};
})
}

notifications = {
self: this,
_api: 'notifications',

create(players, data) {
const url = `${this._api}`
const appId = this.self.appId

SentNotifications.insert({
...data,
appId,
createdAt: new Date(),
})

return this.self.send('POST', url, {
...data,
app_id: appId,
include_player_ids: players,
})
},
}
}
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'astrocoders:one-signal',
version: '0.0.2',
version: '0.0.3',
// Brief, one-line summary of the package.
summary: 'Simple OneSignal integration for Meteor',
// URL to the Git repository containing the source code for this package.
Expand Down