Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix request url when still no notificationId received
Browse files Browse the repository at this point in the history
  • Loading branch information
isocolsky committed Oct 20, 2015
1 parent cbd5589 commit b1d4636
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,15 @@ API.prototype._fetchLatestNotifications = function(interval, cb) {

cb = cb || function() {};

var url = '/v1/notifications/';
if (self.lastNotificationId) {
url += '?notificationId=' + self.lastNotificationId;
} else {
url += '?timeSpan=' + (interval + 2); // Give a couple of seconds for network latency
var opts = {
lastNotificationId: self.lastNotificationId,
};

if (!self.lastNotificationId) {
opts.timeSpan = interval + 2; // Give a couple of seconds for network latency
}

self.getNotifications({
lastNotificationId: self.lastNotificationId
}, function(err, notifications) {
self.getNotifications(opts, function(err, notifications) {
if (err) {
log.warn('Error receiving notifications.');
log.debug(err);
Expand Down Expand Up @@ -1060,14 +1059,21 @@ API.prototype._processCustomData = function(result) {
*
* @param {object} opts
* @param {String} lastNotificationId (optional) - The ID of the last received notification
* @param {String} timeSpan (optional) - A time window on which to look for notifications (in seconds)
* @returns {Callback} cb - Returns error or an array of notifications
*/
API.prototype.getNotifications = function(opts, cb) {
$.checkState(this.credentials);

var self = this;
opts = opts || {};

var url = '/v1/notifications/';
if (opts.lastNotificationId) url += '?notificationId=' + opts.lastNotificationId;
if (opts.lastNotificationId) {
url += '?notificationId=' + opts.lastNotificationId;
} else if (opts.timeSpan) {
url += '?timeSpan=' + opts.timeSpan;
}

self._doGetRequest(url, function(err, result) {
if (err) return cb(err);
Expand Down

0 comments on commit b1d4636

Please sign in to comment.