├── .gitignore ├── .versions ├── LICENSE ├── README.md ├── lib └── one_signal.js └── package.js /.gitignore: -------------------------------------------------------------------------------- 1 | .meteor/local 2 | .meteor/meteorite 3 | -------------------------------------------------------------------------------- /.versions: -------------------------------------------------------------------------------- 1 | allow-deny@1.0.4 2 | astrocoders:one-signal@0.0.1 3 | babel-compiler@6.6.4 4 | babel-runtime@0.1.8 5 | base64@1.0.8 6 | binary-heap@1.0.8 7 | blaze@2.1.7 8 | blaze-tools@1.0.8 9 | boilerplate-generator@1.0.8 10 | callback-hook@1.0.8 11 | check@1.2.1 12 | ddp@1.2.5 13 | ddp-client@1.2.7 14 | ddp-common@1.2.5 15 | ddp-server@1.2.6 16 | deps@1.0.12 17 | diff-sequence@1.0.5 18 | ecmascript@0.4.3 19 | ecmascript-runtime@0.2.10 20 | ejson@1.0.11 21 | geojson-utils@1.0.8 22 | html-tools@1.0.9 23 | htmljs@1.0.9 24 | http@1.1.5 25 | id-map@1.0.7 26 | jquery@1.11.8 27 | local-test:astrocoders:one-signal@0.0.1 28 | logging@1.0.12 29 | meteor@1.1.14 30 | minimongo@1.0.16 31 | modules@0.6.1 32 | modules-runtime@0.6.3 33 | mongo@1.1.7 34 | mongo-id@1.0.4 35 | npm-mongo@1.4.43 36 | observe-sequence@1.0.11 37 | ordered-dict@1.0.7 38 | promise@0.6.7 39 | random@1.0.9 40 | reactive-var@1.0.9 41 | retry@1.0.7 42 | routepolicy@1.0.10 43 | spacebars@1.0.11 44 | spacebars-compiler@1.0.11 45 | tinytest@1.0.10 46 | tracker@1.0.13 47 | ui@1.0.11 48 | underscore@1.0.8 49 | url@1.0.9 50 | webapp@1.2.8 51 | webapp-hashing@1.0.9 52 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | meteor-onesignal 2 | ================ 3 | Easily send push notifications via OneSignal REST API. 4 | 5 | # Installing 6 | 7 | ``` 8 | $ meteor add astrocoders:one-signal 9 | ``` 10 | 11 | ## Getting started 12 | 13 | Ensure that you have a oneSignal entry in your settings.json: 14 | 15 | ```json 16 | { 17 | "oneSignal": { 18 | "apiKey": "YOUR_ONE_SIGNAL_API_KEY", 19 | "appId": "YOUR_APP_ID" 20 | }, 21 | } 22 | ``` 23 | 24 | ## Basic API 25 | 26 | ### OneSignal.Notifications.create 27 | Usage: 28 | 29 | ```js 30 | const data = { 31 | contents: { 32 | en: 'Hey! Wazup? We miss you.', 33 | }, 34 | }; 35 | 36 | OneSignal.Notifications.create([playersId], data); 37 | // => returns OneSignal response. 38 | ``` 39 | 40 | Every created notification is saved into SentNotifications collection. 41 | 42 | ### That's it for now, more coming. 43 | ### Sent us a PR if you'd like to complete this API! 44 | -------------------------------------------------------------------------------- /lib/one_signal.js: -------------------------------------------------------------------------------- 1 | SentNotifications = new Mongo.Collection('oneSignalNotifications'); 2 | 3 | OneSignal = { 4 | _base: 'https://onesignal.com/api/v1/', 5 | send(method, api, data){ 6 | const url = `${this._base}/${api}`; 7 | const { apiKey } = Meteor.settings.oneSignal; 8 | 9 | return HTTP.call(method, url, { 10 | data, 11 | headers: { 12 | Authorization: `Basic ${apiKey}`, 13 | }, 14 | }); 15 | }, 16 | }; 17 | 18 | OneSignal.Notifications = { 19 | _api: 'notifications', 20 | create(players, data){ 21 | const url = `${this._api}`; 22 | const { appId } = Meteor.settings.oneSignal; 23 | 24 | SentNotifications.insert({ 25 | ...data, 26 | createdAt: new Date(), 27 | }); 28 | 29 | return OneSignal.send('POST', url, { 30 | ...data, 31 | app_id: appId, 32 | include_player_ids: players, 33 | }); 34 | }, 35 | }; 36 | -------------------------------------------------------------------------------- /package.js: -------------------------------------------------------------------------------- 1 | Package.describe({ 2 | name: 'astrocoders:one-signal', 3 | version: '0.0.2', 4 | // Brief, one-line summary of the package. 5 | summary: 'Simple OneSignal integration for Meteor', 6 | // URL to the Git repository containing the source code for this package. 7 | git: 'https://github.com/Astrocoders/meteor-one-signal', 8 | // By default, Meteor will default to using README.md for documentation. 9 | // To avoid submitting documentation, set this field to null. 10 | documentation: 'README.md' 11 | }); 12 | 13 | Package.onUse(function(api) { 14 | api.versionsFrom('1.2'); 15 | api.use([ 16 | 'ecmascript', 17 | 'http', 18 | 'mongo', 19 | ]); 20 | 21 | api.addFiles([ 22 | 'lib/one_signal.js', 23 | ], 'server'); 24 | 25 | api.export(['OneSignal', 'SentNotifications'], 'server'); 26 | }); 27 | 28 | Package.onTest(function(api) { 29 | api.use('ecmascript'); 30 | api.use('tinytest'); 31 | api.use('astrocoders:one-signal'); 32 | }); 33 | --------------------------------------------------------------------------------