Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.0 (aka 1.0.0) #238

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
5e74be1
Removed for-sure deprecated constants
hypesystem May 29, 2016
bde2696
Removed deprecated Result from project
hypesystem May 29, 2016
3e4b168
Removed deprecated MulticastResult from project
hypesystem May 29, 2016
b1bbff0
Removed comment from node-gcm.js
hypesystem May 29, 2016
7d34f01
Removed deprecated methods Message#addDataWith{KeyValue,Object} from …
hypesystem May 29, 2016
c85f66a
Removed tests for now-removed funcitonality
hypesystem May 29, 2016
022f6f3
Version bump and CHANGELOG for -alpha.0
hypesystem May 29, 2016
dce3ae7
Make it clear that this is v1 readme
hypesystem May 29, 2016
6d50454
Make Sender#send{,NoRetry} expect a raw JSON object
hypesystem May 29, 2016
4e2446c
Remove Message from lib, no longer used
hypesystem May 29, 2016
a92d737
Simply export the sender
hypesystem May 29, 2016
ee1ce8a
No mapping of argument names: simply use the names that the FCM servi…
hypesystem May 29, 2016
b87b3ad
cleaned up comment in message-options
hypesystem May 29, 2016
141e998
Adjusted README to show this new reality -- much simpler!
hypesystem May 29, 2016
3a5fe3f
Updated the usage section to fit the real code
hypesystem May 29, 2016
a3dcac0
More adjustments to the README
hypesystem May 29, 2016
8f93ad8
Updated example to new reality
hypesystem May 29, 2016
9a4b643
Adjust sender specs to new reality
hypesystem May 29, 2016
93aa28d
Add a test that invalid or wrong properties are ignored
hypesystem May 29, 2016
f3208cf
Remove message specs, no longer needed
hypesystem May 29, 2016
3784ce4
Depend only on lodash.defaultsdeep (instead of all lodash)
hypesystem May 29, 2016
201f37b
Merge pull request #239 from ToothlessGear/v1-remove-message
eladnava May 30, 2016
b4eae56
Merge pull request #240 from ToothlessGear/v1-smaller-lodash-dep
eladnava May 30, 2016
022ce33
Add entries to .gitignore (vscode & test.js)
eladnava May 30, 2016
8160865
Only allow arrays or strings as recipients -- move closer to the API …
hypesystem May 30, 2016
976a02c
Still check if the array is empty, though
hypesystem May 30, 2016
ea0a850
Return error objects instead of strings
hypesystem May 30, 2016
9ab4d23
Remove all the specs that had to do with the special recipient format…
hypesystem May 30, 2016
e62aaae
Update README to match new interface
hypesystem May 30, 2016
f3d0c9f
Fixed typo in README (og -> or)
hypesystem May 31, 2016
2048582
Merge pull request #242 from ToothlessGear/v1-simpler-recipient-arg
hypesystem Jun 1, 2016
22a07f3
Remove sendNoRetry from being exposed
hypesystem Jun 1, 2016
3d8b4f6
Rename sendNoRetry -> sendMessage
hypesystem Jun 1, 2016
81c27c3
Remove unnecessary support for no callback (always called with callba…
hypesystem Jun 1, 2016
3d18769
Rewrite sendNoRetry tests to use send with retries: 0
hypesystem Jun 2, 2016
0e6d133
Extract sendMessageWithRetries function
hypesystem Jun 2, 2016
008e2fd
Modify retry to use sendMessageWithRetries
hypesystem Jun 2, 2016
cf7b494
Added a note about a case that seems odd
hypesystem Jun 2, 2016
0236fbf
Remove self argument from retry and sendMessageWithRetries
hypesystem Jun 2, 2016
d125924
Get request body early on, simply pass it through
hypesystem Jun 2, 2016
d4eec16
fix indentation
hypesystem Jun 2, 2016
d174ce7
Build requestOptions early and pass around (instead of building for e…
hypesystem Jun 2, 2016
e177346
Reorder functions
hypesystem Jun 2, 2016
c558a7c
Remove an irrelevant return
hypesystem Jun 2, 2016
7a0e08e
Removed redundant tests (now covered by send with retries: 0)
hypesystem Jun 2, 2016
e0a6969
Dont try to mock sendNoRetry
hypesystem Jun 2, 2016
e8dd0ff
Removed some more redundant tests
hypesystem Jun 2, 2016
9c32fb2
Make all send specs async
hypesystem Jun 2, 2016
79873f8
Break out of retry if there are no retries left!
hypesystem Jun 8, 2016
20fad62
Remove this one weird case that is good for naught
hypesystem Jun 8, 2016
41b2d94
Make send() tests work.
hypesystem Jun 8, 2016
a1343eb
merge two tests, so the same on now tests sender options and auth key
hypesystem Jun 8, 2016
7e55699
Remove two tests that no longer pass (and shouldnt!)
hypesystem Jun 8, 2016
7286a4b
Merge pull request #248 from ToothlessGear/v1-no-send-no-retry
hypesystem Jun 9, 2016
c89d01a
Update README for no sendNoRetry
hypesystem Jun 9, 2016
3476392
vbump 1.0.0-alpha.1 and CHANGELOG
hypesystem Jun 9, 2016
5fd55d7
Upgrade debug
ratson Jul 17, 2016
7876a2d
Update contributors
ratson Aug 3, 2016
3901643
Merge pull request #260 from ratson/debug-v2
hypesystem Aug 5, 2016
fb8cbb8
Return a Promise from Sender.send() if it is called without a callback.
Jul 20, 2016
c829e37
Merge pull request #264 from dan-perron/v1-promises
hypesystem Aug 8, 2016
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pids
logs
results

test.js

node_modules
npm-debug.log
.idea
.vscode
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changelog
=========

**1.0.0-alpha.1**
* Removed the Message abstraction, now expect plain objects.
* Smaller lodash dependency (only depending on the part that is used).
* Simplified the recipient argument so it is now closer to the actual API interface.
* Removed `sendNoRetry` method on sender --- use `send` with the option `retries: 0` instead.

**1.0.0-alpha.0**
* Removed deprecated things: constants, Result, MulticastResult, Message#addDataWith...

**0.14.2**
* Updated README, added note on v1 development

Expand Down
106 changes: 35 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ If you are developing an open-source project with a broader scope (like a full F

See the [official FCM documentation](https://firebase.google.com/docs/cloud-messaging/) for more information.

We are currently working on version 1.0.0 of the project, and it is available in an early alpha version.
This is the README for the `v1` branch, and it is currently work in progress.
Version 1.0.0 is only available in an alpha version.
Follow [PR #238](https://github.com/ToothlessGear/node-gcm/pull/238) to see current status.
We currently recommend you use the mainline version of node-gcm (found on the master branch) for production.

## Installation

Expand All @@ -31,17 +33,14 @@ If you are new to GCM you should probably look into the [documentation](https://
According to below **Usage** reference, we could create such application:

```js
var gcm = require('node-gcm');
var gcm = require('node-gcm')('YOUR_API_KEY_HERE');

var message = new gcm.Message({
var message = {
data: { key1: 'msg1' }
});

// Set up the sender with you API key, prepare your recipients' registration tokens.
var sender = new gcm.Sender('YOUR_API_KEY_HERE');
var regTokens = ['YOUR_REG_TOKEN_HERE'];
};
var recipient = 'YOUR_REG_TOKEN_HERE';

sender.send(message, { registrationTokens: regTokens }, function (err, response) {
gcm.send(message, recipient, function (err, response) {
if(err) console.error(err);
else console.log(response);
});
Expand All @@ -50,21 +49,17 @@ sender.send(message, { registrationTokens: regTokens }, function (err, response)
## Usage

```js
var gcm = require('node-gcm');
var gcm = require('node-gcm')('insert Google Server API Key here');

// Create a message
// ... with default values
var message = new gcm.Message();

// ... or some given values
var message = new gcm.Message({
collapseKey: 'demo',
// Create a message (all possible values shown)
var message = {
collapse_key: 'demo',
priority: 'high',
contentAvailable: true,
delayWhileIdle: true,
timeToLive: 3,
restrictedPackageName: "somePackageName",
dryRun: true,
content_available: true,
delay_while_idle: true,
time_to_live: 3,
restricted_package_name: "somePackageName",
dry_run: true,
data: {
key1: 'message1',
key2: 'message2'
Expand All @@ -74,21 +69,7 @@ var message = new gcm.Message({
icon: "ic_launcher",
body: "This is a notification that will be displayed ASAP."
}
});

// Change the message data
// ... as key-value
message.addData('key1','message1');
message.addData('key2','message2');

// ... or as a data object (overwrites previous data object)
message.addData({
key1: 'message1',
key2: 'message2'
});

// Set up the sender with you API key
var sender = new gcm.Sender('insert Google Server API Key here');
};

// Add the registration tokens of the devices you want to send to
var registrationTokens = [];
Expand All @@ -97,59 +78,42 @@ registrationTokens.push('regToken2');

// Send the message
// ... trying only once
sender.sendNoRetry(message, { registrationTokens: registrationTokens }, function(err, response) {
gcm.send(message, registrationTokens, { retries: 0 }, function(err, response) {
if(err) console.error(err);
else console.log(response);
});

// ... or retrying
sender.send(message, { registrationTokens: registrationTokens }, function (err, response) {
gcm.send(message, registrationTokens, function (err, response) {
if(err) console.error(err);
else console.log(response);
});

// ... or retrying a specific number of times (10)
sender.send(message, { registrationTokens: registrationTokens }, 10, function (err, response) {
gcm.send(message, registrationTokens, 10, function (err, response) {
if(err) console.error(err);
else console.log(response);
});
```
## Recipients

You can send push notifications to various recipient types by providing one of the following recipient keys:


|Key|Type|Description|
|---|---|---|
|to|String|A single [registration token](https://developers.google.com/cloud-messaging/android/client#sample-register), [notification key](https://developers.google.com/cloud-messaging/notifications), or [topic](https://developers.google.com/cloud-messaging/topic-messaging).
|topic|String|A single publish/subscribe topic.
|notificationKey|String|Deprecated. A key that groups multiple registration tokens linked to the same user.
|registrationIds|String[]|Deprecated. Use registrationTokens instead.|
|registrationTokens|String[]|A list of registration tokens. Must contain at least 1 and at most 1000 registration tokens.|
## Recipients

If you provide an incorrect recipient key or object type, an `Error` object will be returned to your callback.
You can send a push notification to various recipient or topic, by providing a notification key, registration token or topic as a string.
Alternatively, you can send it to several recipients at once, by providing an array of registration tokens.

Notice that [you can *at most* send notifications to 1000 registration tokens 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

```js

var message = new gcm.Message();

// Add notification payload as key value
message.addNotification('title', 'Alert!!!');
message.addNotification('body', 'Abnormal data access');
message.addNotification('icon', 'ic_launcher');

// as object
message.addNotification({
title: 'Alert!!!',
body: 'Abnormal data access',
icon: 'ic_launcher'
});

var message = {
notification: {
title: 'Alert!!!',
body: 'Abnormal data access',
icon: 'ic_launcher'
}
};
```

### Notification payload option table
Expand Down Expand Up @@ -182,15 +146,15 @@ var requestOptions = {
timeout: 5000
};

// Set up the sender with your API key and request options
var sender = new gcm.Sender('YOUR_API_KEY_HERE', requestOptions);
// Set up gcm with your API key and request options
var gcm = require("node-gcm")('YOUR_API_KEY_HERE', requestOptions);

// Prepare a GCM message...

// Send it to GCM endpoint with modified request options
sender.send(message, { registrationTokens: regTokens }, function (err, response) {
gcm.send(message, regTokens, function (err, response) {
if(err) console.error(err);
else console.log(response);
else console.log(response);
});
```

Expand Down
24 changes: 13 additions & 11 deletions examples/notification.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
var gcm = require('../lib/node-gcm');

var message = new gcm.Message();

message.addData('hello', 'world');
message.addNotification('title', 'Hello');
message.addNotification('icon', 'ic_launcher');
message.addNotification('body', 'World');
//Replace your developer API key with GCM enabled here
var gcm = require('../index')('AIza*******************5O6FM');

var message = {
data: {
hello: 'world'
},
notification: {
title: 'Hello',
icon: 'ic_launcher',
body: 'World'
}
};

//Add your mobile device registration tokens here
var regTokens = ['ecG3ps_bNBk:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXl7TDJkW'];
//Replace your developer API key with GCM enabled here
var sender = new gcm.Sender('AIza*******************5O6FM');

sender.send(message, regTokens, function (err, response) {
gcm.send(message, regTokens, function (err, response) {
if(err) {
console.error(err);
} else {
Expand Down
15 changes: 0 additions & 15 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@ var Constants = {

/** DEPRECATED **/

'TOKEN_MESSAGE_ID' : 'id',
'TOKEN_CANONICAL_REG_ID' : 'registration_id',
'TOKEN_ERROR' : 'Error',
'JSON_REGISTRATION_IDS' : 'registration_ids',
'JSON_PAYLOAD' : 'data',
'JSON_NOTIFICATION' : 'notification',
'JSON_SUCCESS' : 'success',
'JSON_FAILURE' : 'failure',
'JSON_CANONICAL_IDS' : 'canonical_ids',
'JSON_MULTICAST_ID' : 'multicast_id',
'JSON_RESULTS' : 'results',
'JSON_ERROR' : 'error',
'JSON_MESSAGE_ID' : 'message_id',
'UTF8' : 'UTF-8',

//These errors could probably be structured more nicely, and could be used in the code.
// -- maybe just as an Error abstraction?
'ERROR_QUOTA_EXCEEDED' : 'QuotaExceeded',
Expand Down
28 changes: 8 additions & 20 deletions lib/message-options.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,31 @@
/**
* This module defines all the arguments that may be passed to a message.
*
* Each argument may contain a field `__argName`, if the name of the field
* should be different when sent to the server.
*
* The argument may also contain a field `__argType`, if the given
*
* Each argument may contain a field `__argType`, in which case the given
* argument must be of that type. The types are the strings resulting from
* calling `typeof <arg>` where `<arg>` is the argument.
*
* Other than that, the arguments are expected to follow the indicated
* structure.
*/

module.exports = {
collapseKey: {
__argName: "collapse_key",
collapse_key: {
__argType: "string"
},
priority: {
__argType: "string"
},
contentAvailable: {
__argName: "content_available",
content_available: {
__argType: "boolean"
},
delayWhileIdle: {
__argName: "delay_while_idle",
delay_while_idle: {
__argType: "boolean"
},
timeToLive: {
__argName: "time_to_live",
time_to_live: {
__argType: "number"
},
restrictedPackageName: {
__argName: "restricted_package_name",
restricted_package_name: {
__argType: "string"
},
dryRun: {
__argName: "dry_run",
dry_run: {
__argType: "boolean"
},
data: {
Expand Down
80 changes: 0 additions & 80 deletions lib/message.js

This file was deleted.

Loading