twilio 3.83.1 → 3.83.3

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.
@@ -0,0 +1,668 @@
1
+ 'use strict';
2
+
3
+ /* jshint ignore:start */
4
+ /**
5
+ * This code was generated by
6
+ * \ / _ _ _| _ _
7
+ * | (_)\/(_)(_|\/| |(/_ v1.0.0
8
+ * / /
9
+ */
10
+ /* jshint ignore:end */
11
+
12
+ var Q = require('q'); /* jshint ignore:line */
13
+ var _ = require('lodash'); /* jshint ignore:line */
14
+ var util = require('util'); /* jshint ignore:line */
15
+ var Page = require('../../../base/Page'); /* jshint ignore:line */
16
+ var deserialize = require(
17
+ '../../../base/deserialize'); /* jshint ignore:line */
18
+ var values = require('../../../base/values'); /* jshint ignore:line */
19
+
20
+ var ContentList;
21
+ var ContentPage;
22
+ var ContentInstance;
23
+ var ContentContext;
24
+
25
+ /* jshint ignore:start */
26
+ /**
27
+ * Initialize the ContentList
28
+ *
29
+ * PLEASE NOTE that this class contains preview products that are subject to
30
+ * change. Use them with caution. If you currently do not have developer preview
31
+ * access, please contact help@twilio.com.
32
+ *
33
+ * @constructor Twilio.Content.V1.ContentList
34
+ *
35
+ * @param {Twilio.Content.V1} version - Version of the resource
36
+ */
37
+ /* jshint ignore:end */
38
+ ContentList = function ContentList(version) {
39
+ /* jshint ignore:start */
40
+ /**
41
+ * @function contents
42
+ * @memberof Twilio.Content.V1#
43
+ *
44
+ * @param {string} sid - sid of instance
45
+ *
46
+ * @returns {Twilio.Content.V1.ContentContext}
47
+ */
48
+ /* jshint ignore:end */
49
+ function ContentListInstance(sid) {
50
+ return ContentListInstance.get(sid);
51
+ }
52
+
53
+ ContentListInstance._version = version;
54
+ // Path Solution
55
+ ContentListInstance._solution = {};
56
+ ContentListInstance._uri = `/Content`;
57
+ /* jshint ignore:start */
58
+ /**
59
+ * create a ContentInstance
60
+ *
61
+ * @function create
62
+ * @memberof Twilio.Content.V1.ContentList#
63
+ *
64
+ * @param {function} [callback] - Callback to handle processed record
65
+ *
66
+ * @returns {Promise} Resolves to processed ContentInstance
67
+ */
68
+ /* jshint ignore:end */
69
+ ContentListInstance.create = function create(callback) {
70
+ var deferred = Q.defer();
71
+ var promise = this._version.create({uri: this._uri, method: 'POST'});
72
+
73
+ promise = promise.then(function(payload) {
74
+ deferred.resolve(new ContentInstance(this._version, payload, this._solution.sid));
75
+ }.bind(this));
76
+
77
+ promise.catch(function(error) {
78
+ deferred.reject(error);
79
+ });
80
+
81
+ if (_.isFunction(callback)) {
82
+ deferred.promise.nodeify(callback);
83
+ }
84
+
85
+ return deferred.promise;
86
+ };
87
+
88
+ /* jshint ignore:start */
89
+ /**
90
+ * Streams ContentInstance records from the API.
91
+ *
92
+ * This operation lazily loads records as efficiently as possible until the limit
93
+ * is reached.
94
+ *
95
+ * The results are passed into the callback function, so this operation is memory
96
+ * efficient.
97
+ *
98
+ * If a function is passed as the first argument, it will be used as the callback
99
+ * function.
100
+ *
101
+ * @function each
102
+ * @memberof Twilio.Content.V1.ContentList#
103
+ *
104
+ * @param {object} [opts] - Options for request
105
+ * @param {number} [opts.limit] -
106
+ * Upper limit for the number of records to return.
107
+ * each() guarantees never to return more than limit.
108
+ * Default is no limit
109
+ * @param {number} [opts.pageSize] -
110
+ * Number of records to fetch per request,
111
+ * when not set will use the default value of 50 records.
112
+ * If no pageSize is defined but a limit is defined,
113
+ * each() will attempt to read the limit with the most efficient
114
+ * page size, i.e. min(limit, 1000)
115
+ * @param {Function} [opts.callback] -
116
+ * Function to process each record. If this and a positional
117
+ * callback are passed, this one will be used
118
+ * @param {Function} [opts.done] -
119
+ * Function to be called upon completion of streaming
120
+ * @param {Function} [callback] - Function to process each record
121
+ */
122
+ /* jshint ignore:end */
123
+ ContentListInstance.each = function each(opts, callback) {
124
+ if (_.isFunction(opts)) {
125
+ callback = opts;
126
+ opts = {};
127
+ }
128
+ opts = opts || {};
129
+ if (opts.callback) {
130
+ callback = opts.callback;
131
+ }
132
+ if (_.isUndefined(callback)) {
133
+ throw new Error('Callback function must be provided');
134
+ }
135
+
136
+ var done = false;
137
+ var currentPage = 1;
138
+ var currentResource = 0;
139
+ var limits = this._version.readLimits({
140
+ limit: opts.limit,
141
+ pageSize: opts.pageSize
142
+ });
143
+
144
+ function onComplete(error) {
145
+ done = true;
146
+ if (_.isFunction(opts.done)) {
147
+ opts.done(error);
148
+ }
149
+ }
150
+
151
+ function fetchNextPage(fn) {
152
+ var promise = fn();
153
+ if (_.isUndefined(promise)) {
154
+ onComplete();
155
+ return;
156
+ }
157
+
158
+ promise.then(function(page) {
159
+ _.each(page.instances, function(instance) {
160
+ if (done || (!_.isUndefined(opts.limit) && currentResource >= opts.limit)) {
161
+ done = true;
162
+ return false;
163
+ }
164
+
165
+ currentResource++;
166
+ callback(instance, onComplete);
167
+ });
168
+
169
+ if (!done) {
170
+ currentPage++;
171
+ fetchNextPage(_.bind(page.nextPage, page));
172
+ } else {
173
+ onComplete();
174
+ }
175
+ });
176
+
177
+ promise.catch(onComplete);
178
+ }
179
+
180
+ fetchNextPage(_.bind(this.page, this, _.merge(opts, limits)));
181
+ };
182
+
183
+ /* jshint ignore:start */
184
+ /**
185
+ * Lists ContentInstance records from the API as a list.
186
+ *
187
+ * If a function is passed as the first argument, it will be used as the callback
188
+ * function.
189
+ *
190
+ * @function list
191
+ * @memberof Twilio.Content.V1.ContentList#
192
+ *
193
+ * @param {object} [opts] - Options for request
194
+ * @param {number} [opts.limit] -
195
+ * Upper limit for the number of records to return.
196
+ * list() guarantees never to return more than limit.
197
+ * Default is no limit
198
+ * @param {number} [opts.pageSize] -
199
+ * Number of records to fetch per request,
200
+ * when not set will use the default value of 50 records.
201
+ * If no page_size is defined but a limit is defined,
202
+ * list() will attempt to read the limit with the most
203
+ * efficient page size, i.e. min(limit, 1000)
204
+ * @param {function} [callback] - Callback to handle list of records
205
+ *
206
+ * @returns {Promise} Resolves to a list of records
207
+ */
208
+ /* jshint ignore:end */
209
+ ContentListInstance.list = function list(opts, callback) {
210
+ if (_.isFunction(opts)) {
211
+ callback = opts;
212
+ opts = {};
213
+ }
214
+ opts = opts || {};
215
+ var deferred = Q.defer();
216
+ var allResources = [];
217
+ opts.callback = function(resource, done) {
218
+ allResources.push(resource);
219
+
220
+ if (!_.isUndefined(opts.limit) && allResources.length === opts.limit) {
221
+ done();
222
+ }
223
+ };
224
+
225
+ opts.done = function(error) {
226
+ if (_.isUndefined(error)) {
227
+ deferred.resolve(allResources);
228
+ } else {
229
+ deferred.reject(error);
230
+ }
231
+ };
232
+
233
+ if (_.isFunction(callback)) {
234
+ deferred.promise.nodeify(callback);
235
+ }
236
+
237
+ this.each(opts);
238
+ return deferred.promise;
239
+ };
240
+
241
+ /* jshint ignore:start */
242
+ /**
243
+ * Retrieve a single page of ContentInstance records from the API.
244
+ *
245
+ * The request is executed immediately.
246
+ *
247
+ * If a function is passed as the first argument, it will be used as the callback
248
+ * function.
249
+ *
250
+ * @function page
251
+ * @memberof Twilio.Content.V1.ContentList#
252
+ *
253
+ * @param {object} [opts] - Options for request
254
+ * @param {string} [opts.pageToken] - PageToken provided by the API
255
+ * @param {number} [opts.pageNumber] -
256
+ * Page Number, this value is simply for client state
257
+ * @param {number} [opts.pageSize] - Number of records to return, defaults to 50
258
+ * @param {function} [callback] - Callback to handle list of records
259
+ *
260
+ * @returns {Promise} Resolves to a list of records
261
+ */
262
+ /* jshint ignore:end */
263
+ ContentListInstance.page = function page(opts, callback) {
264
+ if (_.isFunction(opts)) {
265
+ callback = opts;
266
+ opts = {};
267
+ }
268
+ opts = opts || {};
269
+
270
+ var deferred = Q.defer();
271
+ var data = values.of({
272
+ 'PageToken': opts.pageToken,
273
+ 'Page': opts.pageNumber,
274
+ 'PageSize': opts.pageSize
275
+ });
276
+
277
+ var promise = this._version.page({uri: this._uri, method: 'GET', params: data});
278
+
279
+ promise = promise.then(function(payload) {
280
+ deferred.resolve(new ContentPage(this._version, payload, this._solution));
281
+ }.bind(this));
282
+
283
+ promise.catch(function(error) {
284
+ deferred.reject(error);
285
+ });
286
+
287
+ if (_.isFunction(callback)) {
288
+ deferred.promise.nodeify(callback);
289
+ }
290
+
291
+ return deferred.promise;
292
+ };
293
+
294
+ /* jshint ignore:start */
295
+ /**
296
+ * Retrieve a single target page of ContentInstance records from the API.
297
+ *
298
+ * The request is executed immediately.
299
+ *
300
+ * If a function is passed as the first argument, it will be used as the callback
301
+ * function.
302
+ *
303
+ * @function getPage
304
+ * @memberof Twilio.Content.V1.ContentList#
305
+ *
306
+ * @param {string} [targetUrl] - API-generated URL for the requested results page
307
+ * @param {function} [callback] - Callback to handle list of records
308
+ *
309
+ * @returns {Promise} Resolves to a list of records
310
+ */
311
+ /* jshint ignore:end */
312
+ ContentListInstance.getPage = function getPage(targetUrl, callback) {
313
+ var deferred = Q.defer();
314
+
315
+ var promise = this._version._domain.twilio.request({method: 'GET', uri: targetUrl});
316
+
317
+ promise = promise.then(function(payload) {
318
+ deferred.resolve(new ContentPage(this._version, payload, this._solution));
319
+ }.bind(this));
320
+
321
+ promise.catch(function(error) {
322
+ deferred.reject(error);
323
+ });
324
+
325
+ if (_.isFunction(callback)) {
326
+ deferred.promise.nodeify(callback);
327
+ }
328
+
329
+ return deferred.promise;
330
+ };
331
+
332
+ /* jshint ignore:start */
333
+ /**
334
+ * Constructs a content
335
+ *
336
+ * @function get
337
+ * @memberof Twilio.Content.V1.ContentList#
338
+ *
339
+ * @param {string} sid - The unique string that identifies the resource
340
+ *
341
+ * @returns {Twilio.Content.V1.ContentContext}
342
+ */
343
+ /* jshint ignore:end */
344
+ ContentListInstance.get = function get(sid) {
345
+ return new ContentContext(this._version, sid);
346
+ };
347
+
348
+ /* jshint ignore:start */
349
+ /**
350
+ * Provide a user-friendly representation
351
+ *
352
+ * @function toJSON
353
+ * @memberof Twilio.Content.V1.ContentList#
354
+ *
355
+ * @returns Object
356
+ */
357
+ /* jshint ignore:end */
358
+ ContentListInstance.toJSON = function toJSON() {
359
+ return this._solution;
360
+ };
361
+
362
+ ContentListInstance[util.inspect.custom] = function inspect(depth, options) {
363
+ return util.inspect(this.toJSON(), options);
364
+ };
365
+
366
+ return ContentListInstance;
367
+ };
368
+
369
+
370
+ /* jshint ignore:start */
371
+ /**
372
+ * Initialize the ContentPage
373
+ *
374
+ * PLEASE NOTE that this class contains preview products that are subject to
375
+ * change. Use them with caution. If you currently do not have developer preview
376
+ * access, please contact help@twilio.com.
377
+ *
378
+ * @constructor Twilio.Content.V1.ContentPage
379
+ *
380
+ * @param {V1} version - Version of the resource
381
+ * @param {Response<string>} response - Response from the API
382
+ * @param {ContentSolution} solution - Path solution
383
+ *
384
+ * @returns ContentPage
385
+ */
386
+ /* jshint ignore:end */
387
+ ContentPage = function ContentPage(version, response, solution) {
388
+ // Path Solution
389
+ this._solution = solution;
390
+
391
+ Page.prototype.constructor.call(this, version, response, this._solution);
392
+ };
393
+
394
+ _.extend(ContentPage.prototype, Page.prototype);
395
+ ContentPage.prototype.constructor = ContentPage;
396
+
397
+ /* jshint ignore:start */
398
+ /**
399
+ * Build an instance of ContentInstance
400
+ *
401
+ * @function getInstance
402
+ * @memberof Twilio.Content.V1.ContentPage#
403
+ *
404
+ * @param {ContentPayload} payload - Payload response from the API
405
+ *
406
+ * @returns ContentInstance
407
+ */
408
+ /* jshint ignore:end */
409
+ ContentPage.prototype.getInstance = function getInstance(payload) {
410
+ return new ContentInstance(this._version, payload);
411
+ };
412
+
413
+ /* jshint ignore:start */
414
+ /**
415
+ * Provide a user-friendly representation
416
+ *
417
+ * @function toJSON
418
+ * @memberof Twilio.Content.V1.ContentPage#
419
+ *
420
+ * @returns Object
421
+ */
422
+ /* jshint ignore:end */
423
+ ContentPage.prototype.toJSON = function toJSON() {
424
+ let clone = {};
425
+ _.forOwn(this, function(value, key) {
426
+ if (!_.startsWith(key, '_') && ! _.isFunction(value)) {
427
+ clone[key] = value;
428
+ }
429
+ });
430
+ return clone;
431
+ };
432
+
433
+ ContentPage.prototype[util.inspect.custom] = function inspect(depth, options) {
434
+ return util.inspect(this.toJSON(), options);
435
+ };
436
+
437
+
438
+ /* jshint ignore:start */
439
+ /**
440
+ * Initialize the ContentContext
441
+ *
442
+ * PLEASE NOTE that this class contains preview products that are subject to
443
+ * change. Use them with caution. If you currently do not have developer preview
444
+ * access, please contact help@twilio.com.
445
+ *
446
+ * @constructor Twilio.Content.V1.ContentInstance
447
+ *
448
+ * @property {Date} dateCreated -
449
+ * The RFC 2822 date and time in GMT that the resource was created
450
+ * @property {Date} dateUpdated -
451
+ * The RFC 2822 date and time in GMT that the resource was last updated
452
+ * @property {string} sid - The unique string that identifies the resource
453
+ * @property {string} accountSid - The SID of the Account that created the resource
454
+ * @property {string} friendlyName -
455
+ * A string name used to describe the Content resource
456
+ * @property {string} language -
457
+ * Two-letter language code identifying the language the Content resource is in.
458
+ * @property {object} variables -
459
+ * Defines the default placeholder values for variables included in the Content resource
460
+ * @property {object} types -
461
+ * The Content types (e.g. twilio/text) for this Content resource
462
+ * @property {string} url -
463
+ * The URL of the resource, relative to `https://content.twilio.com`
464
+ * @property {string} links - A list of links related to the Content resource
465
+ *
466
+ * @param {V1} version - Version of the resource
467
+ * @param {ContentPayload} payload - The instance payload
468
+ * @param {sid} sid - The unique string that identifies the resource
469
+ */
470
+ /* jshint ignore:end */
471
+ ContentInstance = function ContentInstance(version, payload, sid) {
472
+ this._version = version;
473
+
474
+ // Marshaled Properties
475
+ this.dateCreated = deserialize.iso8601DateTime(payload.date_created); // jshint ignore:line
476
+ this.dateUpdated = deserialize.iso8601DateTime(payload.date_updated); // jshint ignore:line
477
+ this.sid = payload.sid; // jshint ignore:line
478
+ this.accountSid = payload.account_sid; // jshint ignore:line
479
+ this.friendlyName = payload.friendly_name; // jshint ignore:line
480
+ this.language = payload.language; // jshint ignore:line
481
+ this.variables = payload.variables; // jshint ignore:line
482
+ this.types = payload.types; // jshint ignore:line
483
+ this.url = payload.url; // jshint ignore:line
484
+ this.links = payload.links; // jshint ignore:line
485
+
486
+ // Context
487
+ this._context = undefined;
488
+ this._solution = {sid: sid || this.sid, };
489
+ };
490
+
491
+ Object.defineProperty(ContentInstance.prototype,
492
+ '_proxy', {
493
+ get: function() {
494
+ if (!this._context) {
495
+ this._context = new ContentContext(this._version, this._solution.sid);
496
+ }
497
+
498
+ return this._context;
499
+ }
500
+ });
501
+
502
+ /* jshint ignore:start */
503
+ /**
504
+ * fetch a ContentInstance
505
+ *
506
+ * @function fetch
507
+ * @memberof Twilio.Content.V1.ContentInstance#
508
+ *
509
+ * @param {function} [callback] - Callback to handle processed record
510
+ *
511
+ * @returns {Promise} Resolves to processed ContentInstance
512
+ */
513
+ /* jshint ignore:end */
514
+ ContentInstance.prototype.fetch = function fetch(callback) {
515
+ return this._proxy.fetch(callback);
516
+ };
517
+
518
+ /* jshint ignore:start */
519
+ /**
520
+ * remove a ContentInstance
521
+ *
522
+ * @function remove
523
+ * @memberof Twilio.Content.V1.ContentInstance#
524
+ *
525
+ * @param {function} [callback] - Callback to handle processed record
526
+ *
527
+ * @returns {Promise} Resolves to processed ContentInstance
528
+ */
529
+ /* jshint ignore:end */
530
+ ContentInstance.prototype.remove = function remove(callback) {
531
+ return this._proxy.remove(callback);
532
+ };
533
+
534
+ /* jshint ignore:start */
535
+ /**
536
+ * Provide a user-friendly representation
537
+ *
538
+ * @function toJSON
539
+ * @memberof Twilio.Content.V1.ContentInstance#
540
+ *
541
+ * @returns Object
542
+ */
543
+ /* jshint ignore:end */
544
+ ContentInstance.prototype.toJSON = function toJSON() {
545
+ let clone = {};
546
+ _.forOwn(this, function(value, key) {
547
+ if (!_.startsWith(key, '_') && ! _.isFunction(value)) {
548
+ clone[key] = value;
549
+ }
550
+ });
551
+ return clone;
552
+ };
553
+
554
+ ContentInstance.prototype[util.inspect.custom] = function inspect(depth,
555
+ options) {
556
+ return util.inspect(this.toJSON(), options);
557
+ };
558
+
559
+
560
+ /* jshint ignore:start */
561
+ /**
562
+ * Initialize the ContentContext
563
+ *
564
+ * PLEASE NOTE that this class contains preview products that are subject to
565
+ * change. Use them with caution. If you currently do not have developer preview
566
+ * access, please contact help@twilio.com.
567
+ *
568
+ * @constructor Twilio.Content.V1.ContentContext
569
+ *
570
+ * @param {V1} version - Version of the resource
571
+ * @param {sid} sid - The unique string that identifies the resource
572
+ */
573
+ /* jshint ignore:end */
574
+ ContentContext = function ContentContext(version, sid) {
575
+ this._version = version;
576
+
577
+ // Path Solution
578
+ this._solution = {sid: sid, };
579
+ this._uri = `/Content/${sid}`;
580
+ };
581
+
582
+ /* jshint ignore:start */
583
+ /**
584
+ * fetch a ContentInstance
585
+ *
586
+ * @function fetch
587
+ * @memberof Twilio.Content.V1.ContentContext#
588
+ *
589
+ * @param {function} [callback] - Callback to handle processed record
590
+ *
591
+ * @returns {Promise} Resolves to processed ContentInstance
592
+ */
593
+ /* jshint ignore:end */
594
+ ContentContext.prototype.fetch = function fetch(callback) {
595
+ var deferred = Q.defer();
596
+ var promise = this._version.fetch({uri: this._uri, method: 'GET'});
597
+
598
+ promise = promise.then(function(payload) {
599
+ deferred.resolve(new ContentInstance(this._version, payload, this._solution.sid));
600
+ }.bind(this));
601
+
602
+ promise.catch(function(error) {
603
+ deferred.reject(error);
604
+ });
605
+
606
+ if (_.isFunction(callback)) {
607
+ deferred.promise.nodeify(callback);
608
+ }
609
+
610
+ return deferred.promise;
611
+ };
612
+
613
+ /* jshint ignore:start */
614
+ /**
615
+ * remove a ContentInstance
616
+ *
617
+ * @function remove
618
+ * @memberof Twilio.Content.V1.ContentContext#
619
+ *
620
+ * @param {function} [callback] - Callback to handle processed record
621
+ *
622
+ * @returns {Promise} Resolves to processed ContentInstance
623
+ */
624
+ /* jshint ignore:end */
625
+ ContentContext.prototype.remove = function remove(callback) {
626
+ var deferred = Q.defer();
627
+ var promise = this._version.remove({uri: this._uri, method: 'DELETE'});
628
+
629
+ promise = promise.then(function(payload) {
630
+ deferred.resolve(payload);
631
+ }.bind(this));
632
+
633
+ promise.catch(function(error) {
634
+ deferred.reject(error);
635
+ });
636
+
637
+ if (_.isFunction(callback)) {
638
+ deferred.promise.nodeify(callback);
639
+ }
640
+
641
+ return deferred.promise;
642
+ };
643
+
644
+ /* jshint ignore:start */
645
+ /**
646
+ * Provide a user-friendly representation
647
+ *
648
+ * @function toJSON
649
+ * @memberof Twilio.Content.V1.ContentContext#
650
+ *
651
+ * @returns Object
652
+ */
653
+ /* jshint ignore:end */
654
+ ContentContext.prototype.toJSON = function toJSON() {
655
+ return this._solution;
656
+ };
657
+
658
+ ContentContext.prototype[util.inspect.custom] = function inspect(depth, options)
659
+ {
660
+ return util.inspect(this.toJSON(), options);
661
+ };
662
+
663
+ module.exports = {
664
+ ContentList: ContentList,
665
+ ContentPage: ContentPage,
666
+ ContentInstance: ContentInstance,
667
+ ContentContext: ContentContext
668
+ };
@@ -13,8 +13,12 @@ import { ConfigurationList } from './v1/configuration';
13
13
  import { ConfigurationListInstance } from './v1/configuration';
14
14
  import { FlexFlowList } from './v1/flexFlow';
15
15
  import { FlexFlowListInstance } from './v1/flexFlow';
16
+ import { GoodDataList } from './v1/goodData';
17
+ import { GoodDataListInstance } from './v1/goodData';
16
18
  import { InteractionList } from './v1/interaction';
17
19
  import { InteractionListInstance } from './v1/interaction';
20
+ import { UserRolesList } from './v1/userRoles';
21
+ import { UserRolesListInstance } from './v1/userRoles';
18
22
  import { WebChannelList } from './v1/webChannel';
19
23
  import { WebChannelListInstance } from './v1/webChannel';
20
24
 
@@ -30,7 +34,9 @@ declare class V1 extends Version {
30
34
  readonly channel: ChannelListInstance;
31
35
  readonly configuration: ConfigurationListInstance;
32
36
  readonly flexFlow: FlexFlowListInstance;
37
+ readonly goodData: GoodDataListInstance;
33
38
  readonly interaction: InteractionListInstance;
39
+ readonly userRoles: UserRolesListInstance;
34
40
  readonly webChannel: WebChannelListInstance;
35
41
  }
36
42