Skip to content
This repository has been archived by the owner on Jul 18, 2018. It is now read-only.

Commit

Permalink
More tentacles-like.
Browse files Browse the repository at this point in the history
  • Loading branch information
Le Roux Bodenstein committed Feb 8, 2016
1 parent 41babfa commit f8b0cc5
Show file tree
Hide file tree
Showing 15 changed files with 265 additions and 148 deletions.
19 changes: 19 additions & 0 deletions lib/resources/channels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

'use strict';

var Resource = require('tentacles/lib/Resource');
var method = Resource.method;

module.exports = Resource.extend({
listForRoom: method({
method: 'GET',
path: '/v1/rooms/:roomId/channels',
urlParams: ['roomId']
}),

listForUser: method({
method: 'GET',
path: '/v1/user/:userId/channels',
urlParams: ['userId']
})
});
12 changes: 12 additions & 0 deletions lib/resources/orgs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var Resource = require('tentacles/lib/Resource');
var method = Resource.method;

module.exports = Resource.extend({
listForUser: method({
method: 'GET',
path: '/v1/user/:userId/orgs',
urlParams: ['userId']
})
});
12 changes: 12 additions & 0 deletions lib/resources/repos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var Resource = require('tentacles/lib/Resource');
var method = Resource.method;

module.exports = Resource.extend({
listForUser: method({
method: 'GET',
path: '/v1/user/:userId/repos',
urlParams: ['userId']
})
});
12 changes: 3 additions & 9 deletions lib/resources/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@ module.exports = Resource.extend({
path: '/v1/rooms'
}),

listUsers: method({
listForUser: method({
method: 'GET',
path: '/v1/rooms/:roomId/users',
urlParams: ['roomId']
}),

listChannels: method({
method: 'GET',
path: '/v1/rooms/:roomId/channels',
urlParams: ['roomId']
path: '/v1/user/:userId/rooms',
urlParams: ['userId']
}),

join: method({
Expand Down
18 changes: 18 additions & 0 deletions lib/resources/unreads.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

var Resource = require('tentacles/lib/Resource');
var method = Resource.method;

module.exports = Resource.extend({
listForUserAndRoom: method({
method: 'GET',
path: '/v1/user/:userId/rooms/:roomId/unreadItems',
urlParams: ['userId', 'roomId']
}),

markForUserAndRoom: method({

This comment has been minimized.

Copy link
@suprememoocow

suprememoocow Feb 10, 2016

Member

markItemsRead?

method: 'POST',
path: '/v1/user/:userId/rooms/:roomId/unreadItems',
urlParams: ['userId', 'roomId']
})
});
36 changes: 3 additions & 33 deletions lib/resources/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,9 @@ module.exports = Resource.extend({
path: '/v1/user/me'
}),

listRooms: method({
listForRoom: method({
method: 'GET',
path: '/v1/user/:userId/rooms',
urlParams: ['userId']
}),

listOrgs: method({
method: 'GET',
path: '/v1/user/:userId/orgs',
urlParams: ['userId']
}),

listRepos: method({
method: 'GET',
path: '/v1/user/:userId/repos',
urlParams: ['userId']
}),

listChannels: method({
method: 'GET',
path: '/v1/user/:userId/channels',
urlParams: ['userId']
}),

listUnreadsForRoom: method({
method: 'GET',
path: '/v1/user/:userId/rooms/:roomId/unreadItems',
urlParams: ['userId', 'roomId']
}),

markUnreadsForRoom: method({
method: 'POST',
path: '/v1/user/:userId/rooms/:roomId/unreadItems',
urlParams: ['userId', 'roomId']
path: '/v1/rooms/:roomId/users',
urlParams: ['roomId']
})
});
35 changes: 35 additions & 0 deletions test/resources/channels-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

var assert = require('assert');
var testUtils = require('../utils');

describe('channels', function() {
var client;
var userId;
var roomId;

before(function() {
assert(process.env.GITTER_ACCESS_TOKEN, 'Please set GITTER_ACCESS_TOKEN');
return testUtils.setup()
.spread(function(_client, _userId, _roomId) {
client = _client
userId = _userId;
roomId = _roomId;
});
});

it("it lists a user's channels", function() {
return client.channels.listForUser(userId)
.then(function(channels) {
assert(Array.isArray(channels));
});
});

it('it lists the channels in a room', function() {
return client.channels.listForRoom(roomId)
.then(function(channels) {
assert(Array.isArray(channels));
});
});

});
22 changes: 8 additions & 14 deletions test/resources/messages.js → test/resources/messages-test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
var Client = require('../..');
'use strict';

var assert = require('assert');
var testUtils = require('../utils');

describe('messages', function() {
var client;
var userId;
var username;
var roomId;

before(function() {
assert(process.env.GITTER_ACCESS_TOKEN, 'Please set GITTER_ACCESS_TOKEN');

client = new Client({ accessToken: process.env.GITTER_ACCESS_TOKEN });

return client.users.getAuthUser()
.then(function(user) {
userId = user.id;
username = user.username;
uri = username+'/test';
return client.rooms.join({uri: uri})
})
.then(function(room) {
roomId = room.id;
return testUtils.setup()
.spread(function(_client, _userId, _roomId) {
client = _client;
userId = _userId;
roomId = _roomId;
});
});

Expand Down
28 changes: 28 additions & 0 deletions test/resources/orgs-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

var assert = require('assert');
var testUtils = require('../utils');

describe('orgs', function() {
var client;
var userId;
var roomId;

before(function() {
assert(process.env.GITTER_ACCESS_TOKEN, 'Please set GITTER_ACCESS_TOKEN');
return testUtils.setup()
.spread(function(_client, _userId, _roomId) {
client = _client;
userId = _userId;
roomId = _roomId;
});
});

it("should list a user's orgs", function() {
return client.orgs.listForUser(userId)
.then(function(orgs) {
assert(Array.isArray(orgs));
});
});

});
27 changes: 27 additions & 0 deletions test/resources/repos-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

var assert = require('assert');
var testUtils = require('../utils');

describe('repos', function() {
var client;
var userId;
var roomId;

before(function() {
assert(process.env.GITTER_ACCESS_TOKEN, 'Please set GITTER_ACCESS_TOKEN');
return testUtils.setup()
.spread(function(_client, _userId, _roomId) {
client = _client;
userId = _userId;
roomId = _roomId;
});
});

it("should list a user's repos", function() {
return client.repos.listForUser(userId)
.then(function(repos) {
assert(Array.isArray(repos));
});
});
});
35 changes: 15 additions & 20 deletions test/resources/rooms.js → test/resources/rooms-test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
var Client = require('../..');
'use strict';

var assert = require('assert');
var testUtils = require('../utils');

describe('rooms', function() {
var client;
var userId;
var roomId;

before(function() {
assert(process.env.GITTER_ACCESS_TOKEN, 'Please set GITTER_ACCESS_TOKEN');

client = new Client({ accessToken: process.env.GITTER_ACCESS_TOKEN });
return client.rooms.listForAuthUser()
.then(function(rooms) {
roomId = rooms[0].id;
return testUtils.setup()
.spread(function(_client, _userId, _roomId) {
client = _client;
userId = _userId;
roomId = _roomId;
});
});

Expand All @@ -22,20 +25,6 @@ describe('rooms', function() {
})
});

it('should list the users in a room', function() {
return client.rooms.listUsers(roomId)
.then(function(users) {
assert(Array.isArray(users));
})
});

it('should list the channels in a room', function() {
return client.rooms.listChannels(roomId)
.then(function(channels) {
assert(Array.isArray(channels));
})
});

it('should allow a user to join a room', function() {
var uri = 'gitterHQ/gitter';
return client.rooms.join({uri: uri})
Expand All @@ -44,4 +33,10 @@ describe('rooms', function() {
});
});

it("should list a user's rooms", function() {
return client.rooms.listForUser(userId)
.then(function(rooms) {
assert(Array.isArray(rooms));
});
});
});
35 changes: 35 additions & 0 deletions test/resources/unreads-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

var assert = require('assert');
var testUtils = require('../utils');

describe('unreads', function() {
var client;
var userId;
var roomId;

before(function() {
assert(process.env.GITTER_ACCESS_TOKEN, 'Please set GITTER_ACCESS_TOKEN');
return testUtils.setup()
.spread(function(_client, _userId, _roomId) {
client = _client;
userId = _userId;
roomId = _roomId;
});
});

it("should list a user's unreads for a room", function() {
return client.unreads.listForUserAndRoom(userId, roomId)
.then(function(result) {
assert(Array.isArray(result.chat));
assert(Array.isArray(result.mention));
});
});

it("should mark a user's unreads for a room", function() {
return client.unreads.markForUserAndRoom(userId, roomId, {chat: ['foo']})
.then(function(result) {
assert.equal(result.success, true);
});
});
});
34 changes: 34 additions & 0 deletions test/resources/users-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

var assert = require('assert');
var testUtils = require('../utils');

describe('users', function() {
var client;
var userId;
var roomId;

before(function() {
assert(process.env.GITTER_ACCESS_TOKEN, 'Please set GITTER_ACCESS_TOKEN');
return testUtils.setup()
.spread(function(_client, _userId, _roomId) {
client = _client;
userId = _userId;
roomId = _roomId;
});
});

it('should get the authenticated user', function() {
return client.users.getAuthUser()
.then(function(user) {
assert(user.username);
})
});

it('should list the users in a room', function() {
return client.users.listForRoom(roomId)
.then(function(users) {
assert(Array.isArray(users));
})
});
});
Loading

0 comments on commit f8b0cc5

Please sign in to comment.