Comparing version 0.10.0 to 0.11.0
@@ -15,16 +15,2 @@ /*! | ||
'PARAM_REGISTRATION_ID' : 'registration_id', | ||
'PARAM_COLLAPSE_KEY' : 'collapse_key', | ||
'PARAM_DELAY_WHILE_IDLE' : 'delay_while_idle', | ||
'PARAM_PAYLOAD_KEY' : 'data', | ||
'PARAM_NOTIFICATION_KEY' : 'notification', | ||
'PARAM_TIME_TO_LIVE' : 'time_to_live', | ||
'PARAM_DRY_RUN' : 'dry_run', | ||
'ERROR_QUOTA_EXCEEDED' : 'QuotaExceeded', | ||
@@ -31,0 +17,0 @@ |
@@ -1,23 +0,21 @@ | ||
/*! | ||
* node-gcm | ||
* Copyright(c) 2013 Marcus Farkas <toothlessgear@finitebox.com> | ||
* MIT Licensed | ||
*/ | ||
var messageOptions = require("./message-options"); | ||
function Message(obj) { | ||
function Message(raw) { | ||
if (!(this instanceof Message)) { | ||
return new Message(obj); | ||
return new Message(raw); | ||
} | ||
if (!obj) { | ||
obj = {}; | ||
if (!raw) { | ||
raw = {}; | ||
} | ||
this.collapseKey = obj.collapseKey || undefined; | ||
this.delayWhileIdle = obj.delayWhileIdle || undefined; | ||
this.timeToLive = obj.timeToLive || undefined; | ||
this.dryRun = obj.dryRun || undefined; | ||
this.data = obj.data || {}; | ||
this.notification = obj.notification || {}; | ||
var params = {}; | ||
Object.keys(raw).forEach(function(param) { | ||
if(messageOptions[param]) { | ||
params[param] = raw[param]; | ||
} | ||
}); | ||
this.params = params; | ||
} | ||
@@ -29,3 +27,3 @@ | ||
if (typeof obj === 'object' && Object.keys(obj).length > 0) { | ||
this.notification = obj; | ||
this.params.notification = obj; | ||
} | ||
@@ -36,3 +34,6 @@ return; | ||
var key = arguments[0], value = arguments[1]; | ||
return this.notification[key] = value; | ||
if(!this.params.notification) { | ||
this.params.notification = {}; | ||
} | ||
return this.params.notification[key] = value; | ||
} | ||
@@ -46,3 +47,3 @@ throw new Error("Invalid number of arguments given to addNotification ("+arguments.length+")"); | ||
if (typeof obj === 'object' && Object.keys(obj).length > 0) { | ||
this.data = obj; | ||
this.params.data = obj; | ||
} | ||
@@ -53,3 +54,6 @@ return; | ||
var key = arguments[0], value = arguments[1]; | ||
return this.data[key] = value; | ||
if(!this.params.data) { | ||
this.params.data = {}; | ||
} | ||
return this.params.data[key] = value; | ||
} | ||
@@ -69,2 +73,22 @@ throw new Error("Invalid number of arguments given to addData ("+arguments.length+")"); | ||
Message.prototype.toJson = function() { | ||
var json = {}; | ||
Object.keys(this.params).forEach(function(param) { | ||
if(messageOptions[param]) { | ||
var key = param; | ||
var value = this.params[param]; | ||
var optionDescription = messageOptions[param]; | ||
if(optionDescription.__argName) { | ||
key = optionDescription.__argName; | ||
} | ||
json[key] = value; | ||
} | ||
}.bind(this)); | ||
return json; | ||
}; | ||
module.exports = Message; |
@@ -1,6 +0,1 @@ | ||
/*! | ||
* node-gcm | ||
* Copyright(c) 2013 Marcus Farkas <toothlessgear@finitebox.com> | ||
* MIT Licensed | ||
*/ | ||
var Constants = require('./constants'); | ||
@@ -10,3 +5,3 @@ var req = require('request'); | ||
function Sender(key , options) { | ||
function Sender(key, options) { | ||
if (!(this instanceof Sender)) { | ||
@@ -39,35 +34,14 @@ return new Sender(key, options); | ||
var body = message.toJson(); | ||
if(typeof registrationIds == "string") { | ||
registrationIds = [registrationIds]; | ||
body.to = registrationIds; | ||
} | ||
else { | ||
body.registration_ids = registrationIds; | ||
} | ||
var body = {}, | ||
requestBody, | ||
post_options, | ||
post_req, | ||
timeout; | ||
var requestBody = JSON.stringify(body); | ||
body[Constants.JSON_REGISTRATION_IDS] = registrationIds; | ||
if (message.delayWhileIdle !== undefined) { | ||
body[Constants.PARAM_DELAY_WHILE_IDLE] = message.delayWhileIdle; | ||
} | ||
if (message.collapseKey !== undefined) { | ||
body[Constants.PARAM_COLLAPSE_KEY] = message.collapseKey; | ||
} | ||
if (message.timeToLive !== undefined) { | ||
body[Constants.PARAM_TIME_TO_LIVE] = message.timeToLive; | ||
} | ||
if (message.dryRun !== undefined) { | ||
body[Constants.PARAM_DRY_RUN] = message.dryRun; | ||
} | ||
if (Object.keys(message.data)) { | ||
body[Constants.PARAM_PAYLOAD_KEY] = message.data; | ||
} | ||
if (message.notification && Object.keys(message.notification)) { | ||
body[Constants.PARAM_NOTIFICATION_KEY] = message.notification; | ||
} | ||
requestBody = JSON.stringify(body); | ||
post_options = { | ||
var post_options = { | ||
method: 'POST', | ||
@@ -91,3 +65,3 @@ headers: { | ||
timeout = Constants.SOCKET_TIMEOUT; | ||
var timeout = Constants.SOCKET_TIMEOUT; | ||
@@ -100,3 +74,3 @@ if (this.options && this.options.timeout) { | ||
post_req = req(post_options, function (err, res, resBody) { | ||
var post_req = req(post_options, function (err, res, resBody) { | ||
if (err) { | ||
@@ -103,0 +77,0 @@ return callback(err, null); |
{ | ||
"name": "node-gcm", | ||
"description": "a Node.JS wrapper library-port for Google Cloud Messaging for Android", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"author": "Marcus Farkas <toothlessgear@finitebox.com>", | ||
"contributors": [ | ||
"Marcus Farkas <toothlessgear@finitebox.com>", | ||
"monkbroc <jvanier@gmail.com>", | ||
"zlyinfinite", | ||
"Yann Biancheri <yann.biancheri@gmail.com>", | ||
"Hamid Palo <hamid@fogcreek.com>", | ||
"Dotan J. Nahum <jondotan@gmail.com>", | ||
"Max Rabin <rabin.max@gmail.com>", | ||
"Olivier Poitrey <rs@dailymotion.com>", | ||
"George Miroshnykov <george.miroshnykov@gmail.com>", | ||
"Alejandro Garcia Gil <alejandro@ideaknow.com>", | ||
"Ismael Gorissen <ismael.gorissen@gmail.com>", | ||
"Joris Verbogt <joris@notifica.re>", | ||
"goelvivek <goelvivek2011@gmail.com>", | ||
"Lars Jacob <lars@jaclar.net>", | ||
"Roman Iakovlev <roman.iakovlev@here.com>", | ||
"Roman Skvazh <roman.skvazh@gmail.com>", | ||
"Jeremy Goldstein <jg-dev@live.com>", | ||
"Adam Patacchiola <adam@2fours.com>", | ||
"Ivan Longin <ivan.longin@infobip.com>", | ||
"Paul Bininda <paul@bininda.com>", | ||
"monkbroc <jvanier@gmail.com> (https://github.com/monkbroc)", | ||
"zlyinfinite (https://github.com/zlyinfinite)", | ||
"Yann Biancheri <yann.biancheri@gmail.com> (https://github.com/yannooo)", | ||
"Hamid Palo <hamid@fogcreek.com> (https://github.com/hamidp)", | ||
"Dotan J. Nahum <jondotan@gmail.com> (https://github.com/jondot)", | ||
"Max Rabin <rabin.max@gmail.com> (https://github.com/maxrabin)", | ||
"Olivier Poitrey <rs@dailymotion.com> (https://github.com/rs)", | ||
"George Miroshnykov <george.miroshnykov@gmail.com> (https://github.com/laggyluke)", | ||
"Alejandro Garcia Gil <alejandro@ideaknow.com> (https://github.com/Alegege)", | ||
"Ismael Gorissen <ismael.gorissen@gmail.com> (https://github.com/igorissen)", | ||
"Joris Verbogt <joris@notifica.re> (https://github.com/silentjohnny)", | ||
"goelvivek <goelvivek2011@gmail.com> (https://github.com/goelvivek)", | ||
"Lars Jacob <lars@jaclar.net> (https://github.com/jaclar)", | ||
"Roman Iakovlev <roman.iakovlev@here.com> (https://github.com/RomanIakovlev) ", | ||
"Roman Skvazh <roman.skvazh@gmail.com> (https://github.com/rskvazh)", | ||
"Jeremy Goldstein <jg-dev@live.com> (https://github.com/jg10)", | ||
"Adam Patacchiola <adam@2fours.com> (https://github.com/surespot)", | ||
"Ivan Longin <ivan.longin@infobip.com> (https://github.com/ilongin)", | ||
"Paul Bininda <paul@bininda.com> (https://github.com/pbininda)", | ||
"Matt Merkes <matt.merkes@gmail.com>", | ||
"Niels Roesen Abildgaard <niels.abildgaard@gmail.com>", | ||
"Nonemoticoner <nonemoticoner@gmail.com>", | ||
"Simen Bekkhus <sbekkhus91@gmail.com>", | ||
"Alexander Johansson <alex@dice.fm>", | ||
"Ashwin R <ashrko619@gmail.com>", | ||
"Kaija Chang <kaija.chang@gmail.com>" | ||
"Niels Roesen Abildgaard <niels.abildgaard@gmail.com> (https://github.com/hypesystem)", | ||
"Nonemoticoner <nonemoticoner@gmail.com> (https://github.com/Nonemoticoner)", | ||
"Simen Bekkhus <sbekkhus91@gmail.com> (https://github.com/SimenB)", | ||
"Alexander Johansson <alex@dice.fm> (https://github.com/KATT)", | ||
"Ashwin R <ashrko619@gmail.com> (https://github.com/ashrko619)", | ||
"Kaija Chang <kaija.chang@gmail.com> (https://github.com/kaija)" | ||
], | ||
@@ -35,0 +35,0 @@ "repository": { |
# node-gcm | ||
node-gcm is a Node.JS library for [**Google Cloud Messaging for Android**](http://developer.android.com/guide/google/gcm/index.html), which replaces Cloud 2 Device Messaging (C2DM). | ||
node-gcm is a Node.JS library for [**Google Cloud Messaging for Android**](https://developers.google.com/cloud-messaging/), which replaces Cloud 2 Device Messaging (C2DM). | ||
## Installation | ||
```bash | ||
$ npm install node-gcm | ||
``` | ||
##Requirements | ||
An Android device running 2.2 or newer and an API key as per [GCM getting started guide](http://developer.android.com/guide/google/gcm/gs.html). | ||
## Requirements | ||
This library provides the server-side implementation of GCM. | ||
You need to generate an API key ([Sender ID](https://developers.google.com/cloud-messaging/gcm#senderid)). | ||
GCM notifications can be sent to both [Android](https://developers.google.com/cloud-messaging/android/start) and [iOS](https://developers.google.com/cloud-messaging/ios/start). | ||
If you are new to GCM you should probably look into the [documentation](https://developers.google.com/cloud-messaging/gcm). | ||
## Example application | ||
According to below **Usage** reference, we could create such application: | ||
@@ -52,7 +59,16 @@ | ||
collapseKey: 'demo', | ||
priority: 3, | ||
contentAvailable: true, | ||
delayWhileIdle: true, | ||
timeToLive: 3, | ||
restrictedPackageName: "somePackageName", | ||
dryRun: true, | ||
data: { | ||
key1: 'message1', | ||
key2: 'message2' | ||
}, | ||
notification: { | ||
title: "Hello, World", | ||
icon: "ic_launcher", | ||
body: "This is a notification that will be displayed ASAP." | ||
} | ||
@@ -72,8 +88,2 @@ }); | ||
// Change the message variables | ||
message.collapseKey = 'demo'; | ||
message.delayWhileIdle = true; | ||
message.timeToLive = 3; | ||
message.dryRun = true; | ||
// Set up the sender with you API key | ||
@@ -106,6 +116,6 @@ var sender = new gcm.Sender('insert Google Server API Key here'); | ||
``` | ||
Notice that [you can *at most* send notifications to 1000 registration ids at a time](https://github.com/ToothlessGear/node-gcm/issues/42). | ||
This is due to [a restriction](http://developer.android.com/training/cloudsync/gcm.html) on the side of the GCM API. | ||
## Notification usage | ||
@@ -135,3 +145,3 @@ | ||
|---|---|---|---| | ||
|title|Android, iOS (Watch)|equired (Android), Optional (iOS), string|Indicates notification title. This field is not visible on iOS phones and tablets.| | ||
|title|Android, iOS (Watch)|Required (Android), Optional (iOS), string|Indicates notification title. This field is not visible on iOS phones and tablets.| | ||
|body|Android, iOS|Optional, string|Indicates notification body text.| | ||
@@ -152,2 +162,3 @@ |icon|Android|Required, string|Indicates notification icon. On Android: sets value to myicon for drawable resource myicon.png.| | ||
## Debug | ||
To enable debug mode (print requests and responses to and from GCM), | ||
@@ -163,64 +174,1 @@ set the `DEBUG` environment flag when running your app (assuming you use `node app.js` to run your app): | ||
Bitcoin: [13iTQf7tDhrKgibw2Y3U5SyPJa7R8sQmHQ](https://blockchain.info/address/13iTQf7tDhrKgibw2Y3U5SyPJa7R8sQmHQ) | ||
## Contributing | ||
Do you see an issue in the code that is not represented by the [issues](https://github.com/ToothlessGear/node-gcm/issues), please do create it. | ||
If you want to help solve an issue, please [submit a Pull Request](https://github.com/ToothlessGear/node-gcm/compare) (PR). | ||
If the PR aims to solve a known issue, please refer this issue in your description. | ||
Make sure that your PR explains what problem it solves, and any key decisions made in regards to this. | ||
Make the PR *early* so maintainers and other contributors get a chance to give input on your code and how it fits in the bigger picture. | ||
Any help is much appreciated! | ||
## Contributors | ||
* [monkbroc](https://github.com/monkbroc) | ||
* [zlyinfinite](https://github.com/zlyinfinite) | ||
* [Yann Biancheri](https://github.com/yannooo) | ||
* [Hamid Palo](https://github.com/hamidp) | ||
* [Dotan J.Nahum](https://github.com/jondot) | ||
* [Olivier Poitrey](https://github.com/rs) | ||
* [Max Rabin](https://github.com/maxrabin) | ||
* [George Miroshnykov](https://github.com/laggyluke) | ||
* [Alejandro Garcia](https://github.com/Alegege) | ||
* [Ismael Gorissen](https://github.com/igorissen) | ||
* [Joris Verbogt](https://github.com/silentjohnny) | ||
* [goelvivek](https://github.com/goelvivek) | ||
* [Lars Jacob](https://github.com/jaclar) | ||
* [Roman Iakovlev](https://github.com/RomanIakovlev) | ||
* [Roman Skvazh](https://github.com/rskvazh) | ||
* [Jeremy Goldstein](https://github.com/jg10) | ||
* [Adam Patacchiola](https://github.com/surespot) | ||
* [Ivan Longin](https://github.com/ilongin) | ||
* [Paul Bininda](https://github.com/pbininda) | ||
* [Niels Roesen Abildgaard](https://github.com/hypesystem) | ||
* [Nonemoticoner](https://github.com/Nonemoticoner) | ||
* [Simen Bekkhus](https://github.com/SimenB) | ||
* [Alexander Johansson](https://github.com/KATT) | ||
* [Ashwin R](https://github.com/ashrko619) | ||
* [kaija](https://github.com/kaija) | ||
## License | ||
(The MIT License) | ||
Copyright (c) 2013 Marcus Farkas <toothlessgear@finitebox.com> | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10
371
0
22216
169