Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ user.gists(function(err, gists) {});
List unread notifications for the authenticated user.

```js
user.notifications(function(err, notifications) {});
user.notifications(options, function(err, notifications) {});
```

Show user information for a particular username. Also works for organizations.
Expand Down
37 changes: 35 additions & 2 deletions github.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,41 @@
// List authenticated user's unread notifications
// -------

this.notifications = function(cb) {
_request("GET", '/notifications', null, function(err, res) {
this.notifications = function(options, cb) {
if (arguments.length === 1 && typeof arguments[0] === 'function') {
cb = options;
options = {};
}
options = options || {};
var url = '/notifications';
var params = [];
if (options.all) {
params.push('all=true');
}
if (options.participating) {
params.push('participating=true');
}
if (options.since) {
var since = options.since;
if (since.constructor === Date) {
since = since.toISOString();
}
params.push('since=' + encodeURIComponent(since));
}
if (options.before) {
var before = options.before;
if (before.constructor === Date) {
before = before.toISOString();
}
params.push('before=' + encodeURIComponent(before));
}
if (options.page) {
params.push('page=' + encodeURIComponent(options.page));
}
if (params.length > 0) {
url += '?' + params.join('&');
}
_request("GET", url, null, function(err, res) {
cb(err,res);
});
};
Expand Down
13 changes: 13 additions & 0 deletions test/test.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ test("User API", function(t) {
});
});

t.test('user.notifications with options', function(q) {
var options = {
all: true,
participating: true,
since: '2015-01-01T00:00:00Z',
before: '2015-02-01T00:00:00Z'
};
user.notifications(options, function(err) {
q.error(err, 'user notifications');
q.end();
});
});

t.test('user.show', function(q) {
user.show('ingalls', function(err) {
q.error(err, 'user show');
Expand Down