-
Notifications
You must be signed in to change notification settings - Fork 343
/
teams.js
156 lines (146 loc) · 3.71 KB
/
teams.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*!
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
*/
import {WebexPlugin, Page} from '@webex/webex-core';
/**
* @typedef {Object} TeamObject
* @property {string} id - (server generated) Unique identifier for the team
* @property {string} name - The name of the team
* @property {isoDate} created - (server generated) The date and time that the
* team was created
*/
/**
* @class
*/
const Teams = WebexPlugin.extend({
/**
* Create a new team.
* @instance
* @param {TeamObject} team
* @returns {Promise<TeamObject>}
* @memberof Teams
* @example
* webex.teams.create({name: 'Create Team Example'})
* .then(function(team) {
* var assert = require('assert');
* assert(team.id);
* assert(team.name);
* assert(team.created);
* return 'success';
* });
* // => success
*/
create(team) {
return this.request({
method: 'POST',
service: 'hydra',
resource: 'teams',
body: team
})
.then((res) => res.body);
},
/**
* Returns a single team
* @instance
* @param {TeamObject|string} team
* @param {Object} options
* @returns {Promise<TeamObject>}
* @memberof Teams
* @example
* var team;
* webex.teams.create({name: 'Get Team Example'})
* .then(function(r) {
* team = r;
* return webex.teams.get(team.id);
* })
* .then(function(team2) {
* var assert = require('assert');
* assert.equal(team2.id, team.id);
* return 'success';
* });
* // => success
*/
get(team, options) {
const id = team.id || team;
return this.request({
service: 'hydra',
resource: `teams/${id}`,
qs: options
})
.then((res) => res.body.items || res.body);
},
/**
* List teams.
* @instance
* @param {object} options
* @param {object} options.max Limit the maximum number of teams in the
* response.
* @returns {Promise<Page<TeamObject>>}
* @memberof Teams
* @example
* var createdRooms;
* Promise.all([
* webex.teams.create({name: 'List Teams Example 1'}),
* webex.teams.create({name: 'List Teams Example 2'}),
* webex.teams.create({name: 'List Teams Example 3'})
* ])
* .then(function(r) {
* createdRooms = r;
* return webex.teams.list({max: 3});
* })
* .then(function(teams) {
* var assert = require('assert');
* assert(teams.length === 3);
* for (var i = 0; i < teams.items.length; i+= 1) {
* assert(createdRooms.filter(function(room) {
* return room.id === teams.items[i].id;
* }).length === 1);
* }
* return 'success';
* });
* // => success
*/
list(options) {
return this.request({
service: 'hydra',
resource: 'teams/',
qs: options
})
.then((res) => new Page(res, this.webex));
},
/**
* Update a team.
* @instance
* @param {TeamObject} team
* @returns {Promise<TeamObject>}
* @memberof Teams
* @example
* var teams;
* webex.teams.create({name: 'Update Team Example'})
* .then(function(r) {
* teams = r;
* teams.name = 'Teams Example (Updated Title)';
* return webex.teams.update(teams);
* })
* .then(function() {
* return webex.teams.get(teams.id);
* })
* .then(function(teams) {
* var assert = require('assert');
* assert.equal(teams.name, 'Teams Example (Updated Title)');
* return 'success';
* });
* // => success
*/
update(team) {
const {id} = team;
return this.request({
method: 'PUT',
service: 'hydra',
resource: `teams/${id}`,
body: team
})
.then((res) => res.body);
}
});
export default Teams;