@webex/plugin-webhooks 2.59.3-next.1 → 2.59.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.js CHANGED
@@ -1,11 +1,11 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {registerPlugin} from '@webex/webex-core';
6
-
7
- import Webhooks from './webhooks';
8
-
9
- registerPlugin('webhooks', Webhooks);
10
-
11
- export default Webhooks;
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {registerPlugin} from '@webex/webex-core';
6
+
7
+ import Webhooks from './webhooks';
8
+
9
+ registerPlugin('webhooks', Webhooks);
10
+
11
+ export default Webhooks;
package/src/webhooks.js CHANGED
@@ -1,240 +1,240 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {WebexPlugin, Page} from '@webex/webex-core';
6
-
7
- /**
8
- * @typedef {Object} WebhookObject
9
- * @property {string} id - (server generated) Unique identifier for the webhook
10
- * @property {string} resource - The resource type for the webhook
11
- * @property {string} event - The event type for the webhook
12
- * @property {string} filter - The filter that defines the webhook scope
13
- * @property {string} targetUrl - The URL that receives POST requests for each event
14
- * @property {string} name - A user-friendly name for this webhook
15
- * @property {string} created - (server generated) The date and time that the webhook was created
16
- */
17
-
18
- /**
19
- * Webhooks allow your app to be notified via HTTP when a specific event
20
- * occurs on Webex. For example, your app can register a webhook to be
21
- * notified when a new message is posted into a specific room.
22
- * @class
23
- */
24
- const Webhooks = WebexPlugin.extend({
25
- /**
26
- * Posts a webhook.
27
- * @instance
28
- * @memberof Webhooks
29
- * @param {WebhookObject} webhook
30
- * @returns {Promise<Webhook>}
31
- * @example
32
- * webex.rooms.create({title: 'Create Webhook Example'})
33
- * .then(function(room) {
34
- * return webex.webhooks.create({
35
- * resource: 'messages',
36
- * event: 'created',
37
- * filter: 'roomId=' + room.id,
38
- * targetUrl: 'https://example.com/webhook',
39
- * name: 'Test Webhook'
40
- * });
41
- * })
42
- * .then(function(webhook) {
43
- * var assert = require('assert');
44
- * assert(webhook.id);
45
- * assert(webhook.resource);
46
- * assert(webhook.event);
47
- * assert(webhook.filter);
48
- * assert(webhook.targetUrl);
49
- * assert(webhook.name);
50
- * return 'success';
51
- * });
52
- * // => success
53
- */
54
- create(webhook) {
55
- return this.request({
56
- method: 'POST',
57
- service: 'hydra',
58
- resource: 'webhooks',
59
- body: webhook,
60
- }).then((res) => res.body);
61
- },
62
-
63
- /**
64
- * Shows details for a webhook.
65
- * @instance
66
- * @memberof Webhooks
67
- * @param {Webhook|string} webhook
68
- * @returns {Promise<Webhook>}
69
- * @example
70
- * var webhook;
71
- * webex.rooms.create({title: 'Get Webhook Example'})
72
- * .then(function(room) {
73
- * return webex.webhooks.create({
74
- * resource: 'messages',
75
- * event: 'created',
76
- * filter: 'roomId=' + room.id,
77
- * targetUrl: 'https://example.com/webhook',
78
- * name: 'Test Webhook'
79
- * });
80
- * })
81
- * .then(function(w) {
82
- * webhook = w;
83
- * return webex.webhooks.get(webhook.id);
84
- * })
85
- * .then(function(webhook2) {
86
- * var assert = require('assert');
87
- * assert.deepEqual(webhook2, webhook);
88
- * return 'success';
89
- * });
90
- * // => success
91
- */
92
- get(webhook) {
93
- const id = webhook.id || webhook;
94
-
95
- return this.request({
96
- service: 'hydra',
97
- resource: `webhooks/${id}`,
98
- }).then((res) => res.body.items || res.body);
99
- },
100
-
101
- /**
102
- * Lists all webhooks.
103
- * @instance
104
- * @memberof Webhooks
105
- * @param {Object} options
106
- * @param {integer} options.max Limit the maximum number of webhooks in the response.
107
- * @returns {Promise<Array<Webhook>>}
108
- * @example
109
- * var room, webhook;
110
- * webex.rooms.create({title: 'List Webhooks Example'})
111
- * .then(function(r) {
112
- * room = r;
113
- * return webex.webhooks.create({
114
- * resource: 'messages',
115
- * event: 'created',
116
- * filter: 'roomId=' + room.id,
117
- * targetUrl: 'https://example.com/webhook',
118
- * name: 'Test Webhook'
119
- * });
120
- * })
121
- * .then(function(w) {
122
- * webhook = w;
123
- * return webex.webhooks.list();
124
- * })
125
- * .then(function(webhooks) {
126
- * var assert = require('assert');
127
- * assert.equal(webhooks.items.filter(function(w) {
128
- * return w.id === webhook.id;
129
- * }).length, 1);
130
- * return 'success';
131
- * });
132
- * // => success
133
- */
134
- list(options) {
135
- return this.request({
136
- service: 'hydra',
137
- resource: 'webhooks/',
138
- qs: options,
139
- }).then((res) => new Page(res, this.webex));
140
- },
141
-
142
- /**
143
- * Delete a webhook.
144
- * @instance
145
- * @memberof Webhooks
146
- * @param {Webhook|string} webhook
147
- * @returns {Promise}
148
- * @example
149
- * var room, webhook;
150
- * webex.rooms.create({title: 'Remove Webhook Example'})
151
- * .then(function(r) {
152
- * room = r;
153
- * return webex.webhooks.create({
154
- * resource: 'messages',
155
- * event: 'created',
156
- * filter: 'roomId=' + room.id,
157
- * targetUrl: 'https://example.com/webhook',
158
- * name: 'Test Webhook'
159
- * });
160
- * })
161
- * .then(function(w) {
162
- * webhook = w;
163
- * return webex.webhooks.remove(webhook);
164
- * })
165
- * .then(function() {
166
- * return webex.webhooks.list();
167
- * })
168
- * .then(function(webhooks) {
169
- * var assert = require('assert');
170
- * assert.equal(webhooks.items.filter(function(w) {
171
- * return w.id === webhook.id;
172
- * }).length, 0);
173
- * return 'success';
174
- * });
175
- * // => success
176
- */
177
- remove(webhook) {
178
- const id = webhook.id || webhook;
179
-
180
- return this.request({
181
- method: 'DELETE',
182
- service: 'hydra',
183
- resource: `webhooks/${id}`,
184
- }).then((res) => {
185
- // Firefox has some issues with 204s and/or DELETE. This should move to
186
- // http-core
187
- if (res.statusCode === 204) {
188
- return undefined;
189
- }
190
-
191
- return res.body;
192
- });
193
- },
194
-
195
- /**
196
- * Update a webhook.
197
- * @instance
198
- * @memberof Webhooks
199
- * @param {Webhook} webhook
200
- * @returns {Promise<Webhook>}
201
- * @example
202
- * var webhook;
203
- * webex.rooms.create({title: 'Webhook Example'})
204
- * .then(function(room) {
205
- * return webex.webhooks.create({
206
- * resource: 'messages',
207
- * event: 'created',
208
- * filter: 'roomId=' + room.id,
209
- * targetUrl: 'https://example.com/webhook',
210
- * name: 'Test Webhook'
211
- * });
212
- * })
213
- * .then(function(w) {
214
- * webhook = w;
215
- * webhook.targetUrl = 'https://example.com/webhook/newtarget';
216
- * return webex.webhooks.update(webhook);
217
- * })
218
- * .then(function() {
219
- * return webex.webhooks.get(webhook);
220
- * })
221
- * .then(function(webhook) {
222
- * var assert = require('assert');
223
- * assert.equal(webhook.targetUrl, 'https://example.com/webhook/newtarget');
224
- * return 'success';
225
- * });
226
- * // => success
227
- */
228
- update(webhook) {
229
- const {id} = webhook;
230
-
231
- return this.request({
232
- method: 'PUT',
233
- service: 'hydra',
234
- resource: `webhooks/${id}`,
235
- body: webhook,
236
- }).then((res) => res.body);
237
- },
238
- });
239
-
240
- export default Webhooks;
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {WebexPlugin, Page} from '@webex/webex-core';
6
+
7
+ /**
8
+ * @typedef {Object} WebhookObject
9
+ * @property {string} id - (server generated) Unique identifier for the webhook
10
+ * @property {string} resource - The resource type for the webhook
11
+ * @property {string} event - The event type for the webhook
12
+ * @property {string} filter - The filter that defines the webhook scope
13
+ * @property {string} targetUrl - The URL that receives POST requests for each event
14
+ * @property {string} name - A user-friendly name for this webhook
15
+ * @property {string} created - (server generated) The date and time that the webhook was created
16
+ */
17
+
18
+ /**
19
+ * Webhooks allow your app to be notified via HTTP when a specific event
20
+ * occurs on Webex. For example, your app can register a webhook to be
21
+ * notified when a new message is posted into a specific room.
22
+ * @class
23
+ */
24
+ const Webhooks = WebexPlugin.extend({
25
+ /**
26
+ * Posts a webhook.
27
+ * @instance
28
+ * @memberof Webhooks
29
+ * @param {WebhookObject} webhook
30
+ * @returns {Promise<Webhook>}
31
+ * @example
32
+ * webex.rooms.create({title: 'Create Webhook Example'})
33
+ * .then(function(room) {
34
+ * return webex.webhooks.create({
35
+ * resource: 'messages',
36
+ * event: 'created',
37
+ * filter: 'roomId=' + room.id,
38
+ * targetUrl: 'https://example.com/webhook',
39
+ * name: 'Test Webhook'
40
+ * });
41
+ * })
42
+ * .then(function(webhook) {
43
+ * var assert = require('assert');
44
+ * assert(webhook.id);
45
+ * assert(webhook.resource);
46
+ * assert(webhook.event);
47
+ * assert(webhook.filter);
48
+ * assert(webhook.targetUrl);
49
+ * assert(webhook.name);
50
+ * return 'success';
51
+ * });
52
+ * // => success
53
+ */
54
+ create(webhook) {
55
+ return this.request({
56
+ method: 'POST',
57
+ service: 'hydra',
58
+ resource: 'webhooks',
59
+ body: webhook,
60
+ }).then((res) => res.body);
61
+ },
62
+
63
+ /**
64
+ * Shows details for a webhook.
65
+ * @instance
66
+ * @memberof Webhooks
67
+ * @param {Webhook|string} webhook
68
+ * @returns {Promise<Webhook>}
69
+ * @example
70
+ * var webhook;
71
+ * webex.rooms.create({title: 'Get Webhook Example'})
72
+ * .then(function(room) {
73
+ * return webex.webhooks.create({
74
+ * resource: 'messages',
75
+ * event: 'created',
76
+ * filter: 'roomId=' + room.id,
77
+ * targetUrl: 'https://example.com/webhook',
78
+ * name: 'Test Webhook'
79
+ * });
80
+ * })
81
+ * .then(function(w) {
82
+ * webhook = w;
83
+ * return webex.webhooks.get(webhook.id);
84
+ * })
85
+ * .then(function(webhook2) {
86
+ * var assert = require('assert');
87
+ * assert.deepEqual(webhook2, webhook);
88
+ * return 'success';
89
+ * });
90
+ * // => success
91
+ */
92
+ get(webhook) {
93
+ const id = webhook.id || webhook;
94
+
95
+ return this.request({
96
+ service: 'hydra',
97
+ resource: `webhooks/${id}`,
98
+ }).then((res) => res.body.items || res.body);
99
+ },
100
+
101
+ /**
102
+ * Lists all webhooks.
103
+ * @instance
104
+ * @memberof Webhooks
105
+ * @param {Object} options
106
+ * @param {integer} options.max Limit the maximum number of webhooks in the response.
107
+ * @returns {Promise<Array<Webhook>>}
108
+ * @example
109
+ * var room, webhook;
110
+ * webex.rooms.create({title: 'List Webhooks Example'})
111
+ * .then(function(r) {
112
+ * room = r;
113
+ * return webex.webhooks.create({
114
+ * resource: 'messages',
115
+ * event: 'created',
116
+ * filter: 'roomId=' + room.id,
117
+ * targetUrl: 'https://example.com/webhook',
118
+ * name: 'Test Webhook'
119
+ * });
120
+ * })
121
+ * .then(function(w) {
122
+ * webhook = w;
123
+ * return webex.webhooks.list();
124
+ * })
125
+ * .then(function(webhooks) {
126
+ * var assert = require('assert');
127
+ * assert.equal(webhooks.items.filter(function(w) {
128
+ * return w.id === webhook.id;
129
+ * }).length, 1);
130
+ * return 'success';
131
+ * });
132
+ * // => success
133
+ */
134
+ list(options) {
135
+ return this.request({
136
+ service: 'hydra',
137
+ resource: 'webhooks/',
138
+ qs: options,
139
+ }).then((res) => new Page(res, this.webex));
140
+ },
141
+
142
+ /**
143
+ * Delete a webhook.
144
+ * @instance
145
+ * @memberof Webhooks
146
+ * @param {Webhook|string} webhook
147
+ * @returns {Promise}
148
+ * @example
149
+ * var room, webhook;
150
+ * webex.rooms.create({title: 'Remove Webhook Example'})
151
+ * .then(function(r) {
152
+ * room = r;
153
+ * return webex.webhooks.create({
154
+ * resource: 'messages',
155
+ * event: 'created',
156
+ * filter: 'roomId=' + room.id,
157
+ * targetUrl: 'https://example.com/webhook',
158
+ * name: 'Test Webhook'
159
+ * });
160
+ * })
161
+ * .then(function(w) {
162
+ * webhook = w;
163
+ * return webex.webhooks.remove(webhook);
164
+ * })
165
+ * .then(function() {
166
+ * return webex.webhooks.list();
167
+ * })
168
+ * .then(function(webhooks) {
169
+ * var assert = require('assert');
170
+ * assert.equal(webhooks.items.filter(function(w) {
171
+ * return w.id === webhook.id;
172
+ * }).length, 0);
173
+ * return 'success';
174
+ * });
175
+ * // => success
176
+ */
177
+ remove(webhook) {
178
+ const id = webhook.id || webhook;
179
+
180
+ return this.request({
181
+ method: 'DELETE',
182
+ service: 'hydra',
183
+ resource: `webhooks/${id}`,
184
+ }).then((res) => {
185
+ // Firefox has some issues with 204s and/or DELETE. This should move to
186
+ // http-core
187
+ if (res.statusCode === 204) {
188
+ return undefined;
189
+ }
190
+
191
+ return res.body;
192
+ });
193
+ },
194
+
195
+ /**
196
+ * Update a webhook.
197
+ * @instance
198
+ * @memberof Webhooks
199
+ * @param {Webhook} webhook
200
+ * @returns {Promise<Webhook>}
201
+ * @example
202
+ * var webhook;
203
+ * webex.rooms.create({title: 'Webhook Example'})
204
+ * .then(function(room) {
205
+ * return webex.webhooks.create({
206
+ * resource: 'messages',
207
+ * event: 'created',
208
+ * filter: 'roomId=' + room.id,
209
+ * targetUrl: 'https://example.com/webhook',
210
+ * name: 'Test Webhook'
211
+ * });
212
+ * })
213
+ * .then(function(w) {
214
+ * webhook = w;
215
+ * webhook.targetUrl = 'https://example.com/webhook/newtarget';
216
+ * return webex.webhooks.update(webhook);
217
+ * })
218
+ * .then(function() {
219
+ * return webex.webhooks.get(webhook);
220
+ * })
221
+ * .then(function(webhook) {
222
+ * var assert = require('assert');
223
+ * assert.equal(webhook.targetUrl, 'https://example.com/webhook/newtarget');
224
+ * return 'success';
225
+ * });
226
+ * // => success
227
+ */
228
+ update(webhook) {
229
+ const {id} = webhook;
230
+
231
+ return this.request({
232
+ method: 'PUT',
233
+ service: 'hydra',
234
+ resource: `webhooks/${id}`,
235
+ body: webhook,
236
+ }).then((res) => res.body);
237
+ },
238
+ });
239
+
240
+ export default Webhooks;