From f8f368c5f8e83f1d181f2bd7543dc09518a202c4 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 19 Feb 2020 20:03:38 +0000 Subject: [PATCH] [Librarian] Regenerated @ 59055a0e4517ecbe8ab584e0f9b38f2a70cd94a8 --- CHANGES.md | 35 + lib/rest/Messaging.d.ts | 4 - lib/rest/Messaging.js | 16 - lib/rest/api/v2010/account/call.d.ts | 10 + lib/rest/api/v2010/account/call.js | 14 + .../v2010/account/conference/participant.d.ts | 2 + .../v2010/account/conference/participant.js | 4 +- .../v1/service/entity/factor/challenge.d.ts | 2 +- lib/rest/flexApi/v1/configuration.d.ts | 2 + lib/rest/flexApi/v1/configuration.js | 3 + lib/rest/messaging/V1.d.ts | 6 - lib/rest/messaging/V1.js | 22 - lib/rest/messaging/v1/session.d.ts | 351 ------- lib/rest/messaging/v1/session.js | 864 ------------------ lib/rest/messaging/v1/session/message.d.ts | 334 ------- .../messaging/v1/session/participant.d.ts | 336 ------- lib/rest/messaging/v1/session/participant.js | 798 ---------------- lib/rest/messaging/v1/session/webhook.d.ts | 350 ------- lib/rest/messaging/v1/session/webhook.js | 817 ----------------- lib/rest/messaging/v1/webhook.d.ts | 185 ---- lib/rest/messaging/v1/webhook.js | 429 --------- lib/rest/numbers/v2/regulatoryCompliance.d.ts | 1 + lib/rest/numbers/v2/regulatoryCompliance.js | 13 + .../v2/regulatoryCompliance/regulation.d.ts | 256 ++++++ .../v2/regulatoryCompliance/regulation.js | 584 ++++++++++++ lib/rest/studio/v2/flow.d.ts | 16 + lib/rest/studio/v2/flow.js | 58 ++ lib/rest/studio/v2/flow/execution.d.ts | 319 +++++++ .../v2/flow/execution.js} | 542 ++++++----- .../v2/flow/execution/executionContext.d.ts | 141 +++ .../v2/flow/execution/executionContext.js | 348 +++++++ .../v2/flow/execution/executionStep.d.ts | 273 ++++++ .../studio/v2/flow/execution/executionStep.js | 652 +++++++++++++ .../executionStep/executionStepContext.d.ts | 147 +++ .../executionStep/executionStepContext.js | 361 ++++++++ lib/rest/studio/v2/flow/testUser.d.ts | 157 ++++ lib/rest/studio/v2/flow/testUser.js | 382 ++++++++ lib/rest/taskrouter/v1/workspace/task.d.ts | 2 + lib/rest/taskrouter/v1/workspace/task.js | 9 +- .../taskQueueCumulativeStatistics.d.ts | 2 + .../taskQueueCumulativeStatistics.js | 3 + .../taskQueueRealTimeStatistics.d.ts | 4 + .../taskQueue/taskQueueRealTimeStatistics.js | 6 + lib/rest/verify/v2/service.d.ts | 2 +- lib/rest/verify/v2/service.js | 4 +- lib/rest/verify/v2/service/verification.d.ts | 2 +- lib/rest/verify/v2/service/verification.js | 3 +- package-lock.json | 70 +- package.json | 2 +- .../rest/api/v2010/account.spec.js | 47 + .../rest/api/v2010/account/call.spec.js | 64 +- .../account/conference/participant.spec.js | 32 + .../api/v2010/account/notification.spec.js | 2 +- .../rest/flexApi/v1/configuration.spec.js | 3 + .../rest/messaging/v1/session.spec.js | 404 -------- .../rest/messaging/v1/session/message.spec.js | 453 --------- .../messaging/v1/session/participant.spec.js | 434 --------- .../rest/messaging/v1/session/webhook.spec.js | 595 ------------ .../rest/messaging/v1/webhook.spec.js | 129 --- .../regulatoryCompliance/regulation.spec.js | 400 ++++++++ spec/integration/rest/studio/v2/flow.spec.js | 35 +- .../rest/studio/v2/flow/execution.spec.js | 229 +++++ .../flow/execution/executionContext.spec.js | 81 ++ .../v2/flow/execution/executionStep.spec.js | 141 +++ .../executionStepContext.spec.js | 85 ++ .../rest/studio/v2/flow/testUser.spec.js | 128 +++ .../rest/taskrouter/v1/workspace/task.spec.js | 7 + .../taskQueueCumulativeStatistics.spec.js | 6 + .../taskQueueRealTimeStatistics.spec.js | 2 + 69 files changed, 5338 insertions(+), 6882 deletions(-) delete mode 100644 lib/rest/messaging/v1/session.d.ts delete mode 100644 lib/rest/messaging/v1/session.js delete mode 100644 lib/rest/messaging/v1/session/message.d.ts delete mode 100644 lib/rest/messaging/v1/session/participant.d.ts delete mode 100644 lib/rest/messaging/v1/session/participant.js delete mode 100644 lib/rest/messaging/v1/session/webhook.d.ts delete mode 100644 lib/rest/messaging/v1/session/webhook.js delete mode 100644 lib/rest/messaging/v1/webhook.d.ts delete mode 100644 lib/rest/messaging/v1/webhook.js create mode 100644 lib/rest/numbers/v2/regulatoryCompliance/regulation.d.ts create mode 100644 lib/rest/numbers/v2/regulatoryCompliance/regulation.js create mode 100644 lib/rest/studio/v2/flow/execution.d.ts rename lib/rest/{messaging/v1/session/message.js => studio/v2/flow/execution.js} (50%) create mode 100644 lib/rest/studio/v2/flow/execution/executionContext.d.ts create mode 100644 lib/rest/studio/v2/flow/execution/executionContext.js create mode 100644 lib/rest/studio/v2/flow/execution/executionStep.d.ts create mode 100644 lib/rest/studio/v2/flow/execution/executionStep.js create mode 100644 lib/rest/studio/v2/flow/execution/executionStep/executionStepContext.d.ts create mode 100644 lib/rest/studio/v2/flow/execution/executionStep/executionStepContext.js create mode 100644 lib/rest/studio/v2/flow/testUser.d.ts create mode 100644 lib/rest/studio/v2/flow/testUser.js delete mode 100644 spec/integration/rest/messaging/v1/session.spec.js delete mode 100644 spec/integration/rest/messaging/v1/session/message.spec.js delete mode 100644 spec/integration/rest/messaging/v1/session/participant.spec.js delete mode 100644 spec/integration/rest/messaging/v1/session/webhook.spec.js delete mode 100644 spec/integration/rest/messaging/v1/webhook.spec.js create mode 100644 spec/integration/rest/numbers/v2/regulatoryCompliance/regulation.spec.js create mode 100644 spec/integration/rest/studio/v2/flow/execution.spec.js create mode 100644 spec/integration/rest/studio/v2/flow/execution/executionContext.spec.js create mode 100644 spec/integration/rest/studio/v2/flow/execution/executionStep.spec.js create mode 100644 spec/integration/rest/studio/v2/flow/execution/executionStep/executionStepContext.spec.js create mode 100644 spec/integration/rest/studio/v2/flow/testUser.spec.js diff --git a/CHANGES.md b/CHANGES.md index 3418c84833..244a87bf1b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,41 @@ twilio-node changelog ===================== +[2020-02-19] Version 3.39.5 +--------------------------- +**Api** +- Make call create parameters `async_amd`, `async_amd_status_callback`, and `async_amd_status_callback_method` public +- Add `trunk_sid` as an optional field to Call resource fetch/read responses +- Add property `queue_time` to successful response of create, fetch, and update requests for Call +- Add optional parameter `byoc` to conference participant create. + +**Authy** +- Added support for challenges associated to push factors + +**Flex** +- Adding `ui_dependencies` to Flex Configuration + +**Messaging** +- Deprecate Session API **(breaking change)** + +**Numbers** +- Add Regulations API + +**Studio** +- Add Execution and Step endpoints to v2 API +- Add webhook_url to Flow response and add new /TestUsers endpoint to v2 API + +**Taskrouter** +- Adding `longest_relative_task_age_in_queue` and `longest_relative_task_sid_in_queue` to TaskQueue Real Time Statistics API. +- Add `wait_duration_in_queue_until_accepted` aggregations to TaskQueues Cumulative Statistics endpoint +- Add TaskQueueEnteredDate property to Tasks. + +**Video** +- [Composer] Clarification for the composition hooks creation documentation: one source is mandatory, either the `audio_sources` or the `video_layout`, but one of them has to be provided +- [Composer] `audio_sources` type on the composer HTTP POST command, changed from `sid[]` to `string[]` **(breaking change)** +- [Composer] Clarification for the composition creation documentation: one source is mandatory, either the `audio_sources` or the `video_layout`, but one of them has to be provided + + [2020-02-05] Version 3.39.4 --------------------------- **Api** diff --git a/lib/rest/Messaging.d.ts b/lib/rest/Messaging.d.ts index bd8bb18c1c..60b86e12a8 100644 --- a/lib/rest/Messaging.d.ts +++ b/lib/rest/Messaging.d.ts @@ -9,8 +9,6 @@ import Domain = require('../base/Domain'); import Twilio = require('./Twilio'); import V1 = require('./messaging/V1'); import { ServiceListInstance } from './messaging/v1/service'; -import { SessionListInstance } from './messaging/v1/session'; -import { WebhookListInstance } from './messaging/v1/webhook'; declare class Messaging extends Domain { @@ -22,9 +20,7 @@ declare class Messaging extends Domain { constructor(twilio: Twilio); readonly services: ServiceListInstance; - readonly sessions: SessionListInstance; readonly v1: V1; - readonly webhooks: WebhookListInstance; } export = Messaging; diff --git a/lib/rest/Messaging.js b/lib/rest/Messaging.js index b32b5ade83..132ea0c1c8 100644 --- a/lib/rest/Messaging.js +++ b/lib/rest/Messaging.js @@ -22,8 +22,6 @@ var V1 = require('./messaging/V1'); /* jshint ignore:line */ * * @property {Twilio.Messaging.V1} v1 - v1 version * @property {Twilio.Messaging.V1.ServiceList} services - services resource - * @property {Twilio.Messaging.V1.SessionList} sessions - sessions resource - * @property {Twilio.Messaging.V1.WebhookList} webhooks - webhooks resource * * @param {Twilio} twilio - The twilio client */ @@ -53,18 +51,4 @@ Object.defineProperty(Messaging.prototype, } }); -Object.defineProperty(Messaging.prototype, - 'sessions', { - get: function() { - return this.v1.sessions; - } -}); - -Object.defineProperty(Messaging.prototype, - 'webhooks', { - get: function() { - return this.v1.webhooks; - } -}); - module.exports = Messaging; diff --git a/lib/rest/api/v2010/account/call.d.ts b/lib/rest/api/v2010/account/call.d.ts index 052757d269..6d69a9818b 100644 --- a/lib/rest/api/v2010/account/call.d.ts +++ b/lib/rest/api/v2010/account/call.d.ts @@ -135,6 +135,9 @@ interface CallListInstance { * Options to pass to create * * @property applicationSid - The SID of the Application resource that will handle the call + * @property asyncAmd - Enable asynchronous AMD + * @property asyncAmdStatusCallback - The URL we should call to send amd status information to your application + * @property asyncAmdStatusCallbackMethod - HTTP Method to use with async_amd_status_callback * @property byoc - BYOC trunk SID (Beta) * @property callerId - The phone number, SIP address, or Client identifier that made this call. Phone numbers are in E.164 format (e.g., +16175551212). SIP addresses are formatted as `name@company.com`. * @property fallbackMethod - HTTP Method to use with fallback_url @@ -165,6 +168,9 @@ interface CallListInstance { */ interface CallListInstanceCreateOptions { applicationSid?: string; + asyncAmd?: string; + asyncAmdStatusCallback?: string; + asyncAmdStatusCallbackMethod?: string; byoc?: string; callerId?: string; fallbackMethod?: string; @@ -333,12 +339,14 @@ interface CallResource { phone_number_sid: string; price: string; price_unit: string; + queue_time: string; sid: string; start_time: Date; status: CallStatus; subresource_uris: string; to: string; to_formatted: string; + trunk_sid: string; uri: string; } @@ -435,6 +443,7 @@ declare class CallInstance extends SerializableClass { phoneNumberSid: string; price: string; priceUnit: string; + queueTime: string; /** * Access the recordings */ @@ -455,6 +464,7 @@ declare class CallInstance extends SerializableClass { * Provide a user-friendly representation */ toJSON(): any; + trunkSid: string; /** * update a CallInstance * diff --git a/lib/rest/api/v2010/account/call.js b/lib/rest/api/v2010/account/call.js index adb332400c..84618a33d8 100644 --- a/lib/rest/api/v2010/account/call.js +++ b/lib/rest/api/v2010/account/call.js @@ -111,6 +111,11 @@ CallList = function CallList(version, accountSid) { * Number of milliseconds of silence after speech activity * @param {number} [opts.machineDetectionSilenceTimeout] - * Number of milliseconds of initial silence + * @param {string} [opts.asyncAmd] - Enable asynchronous AMD + * @param {string} [opts.asyncAmdStatusCallback] - + * The URL we should call to send amd status information to your application + * @param {string} [opts.asyncAmdStatusCallbackMethod] - + * HTTP Method to use with async_amd_status_callback * @param {string} [opts.byoc] - BYOC trunk SID (Beta) * @param {string} [opts.url] - The absolute URL that returns TwiML for this call * @param {string} [opts.twiml] - TwiML instructions for the call @@ -161,6 +166,9 @@ CallList = function CallList(version, accountSid) { 'MachineDetectionSpeechThreshold': _.get(opts, 'machineDetectionSpeechThreshold'), 'MachineDetectionSpeechEndThreshold': _.get(opts, 'machineDetectionSpeechEndThreshold'), 'MachineDetectionSilenceTimeout': _.get(opts, 'machineDetectionSilenceTimeout'), + 'AsyncAmd': _.get(opts, 'asyncAmd'), + 'AsyncAmdStatusCallback': _.get(opts, 'asyncAmdStatusCallback'), + 'AsyncAmdStatusCallbackMethod': _.get(opts, 'asyncAmdStatusCallbackMethod'), 'Byoc': _.get(opts, 'byoc') }); @@ -643,8 +651,12 @@ CallPage.prototype[util.inspect.custom] = function inspect(depth, options) { * The phone number, SIP address or Client identifier that received this call. Phone numbers are in E.164 format (e.g., +16175551212). SIP addresses are formatted as `name@company.com`. Client identifiers are formatted `client:name`. * @property {string} toFormatted - * The phone number, SIP address or Client identifier that received this call. Formatted for display. + * @property {string} trunkSid - + * The (optional) unique identifier of the trunk resource that was used for this call. * @property {string} uri - * The URI of this resource, relative to `https://api.twilio.com` + * @property {string} queueTime - + * The wait time in milliseconds before the call is placed. * * @param {V2010} version - Version of the resource * @param {CallPayload} payload - The instance payload @@ -680,7 +692,9 @@ CallInstance = function CallInstance(version, payload, accountSid, sid) { this.subresourceUris = payload.subresource_uris; // jshint ignore:line this.to = payload.to; // jshint ignore:line this.toFormatted = payload.to_formatted; // jshint ignore:line + this.trunkSid = payload.trunk_sid; // jshint ignore:line this.uri = payload.uri; // jshint ignore:line + this.queueTime = payload.queue_time; // jshint ignore:line // Context this._context = undefined; diff --git a/lib/rest/api/v2010/account/conference/participant.d.ts b/lib/rest/api/v2010/account/conference/participant.d.ts index 4da496e2df..c3aeb58a1f 100644 --- a/lib/rest/api/v2010/account/conference/participant.d.ts +++ b/lib/rest/api/v2010/account/conference/participant.d.ts @@ -131,6 +131,7 @@ interface ParticipantListInstance { * Options to pass to create * * @property beep - Whether to play a notification beep to the conference when the participant joins + * @property byoc - BYOC trunk SID (Beta) * @property callSidToCoach - The SID of the participant who is being `coached` * @property coaching - Indicates if the participant changed to coach * @property conferenceRecord - Whether to record the conference the participant is joining @@ -165,6 +166,7 @@ interface ParticipantListInstance { */ interface ParticipantListInstanceCreateOptions { beep?: string; + byoc?: string; callSidToCoach?: string; coaching?: boolean; conferenceRecord?: string; diff --git a/lib/rest/api/v2010/account/conference/participant.js b/lib/rest/api/v2010/account/conference/participant.js index c9e22a12c7..b003a89f97 100644 --- a/lib/rest/api/v2010/account/conference/participant.js +++ b/lib/rest/api/v2010/account/conference/participant.js @@ -121,6 +121,7 @@ ParticipantList = function ParticipantList(version, accountSid, conferenceSid) { * @param {boolean} [opts.coaching] - Indicates if the participant changed to coach * @param {string} [opts.callSidToCoach] - * The SID of the participant who is being `coached` + * @param {string} [opts.byoc] - BYOC trunk SID (Beta) * @param {function} [callback] - Callback to handle processed record * * @returns {Promise} Resolves to processed ParticipantInstance @@ -170,7 +171,8 @@ ParticipantList = function ParticipantList(version, accountSid, conferenceSid) { 'RecordingStatusCallbackEvent': serialize.map(_.get(opts, 'recordingStatusCallbackEvent'), function(e) { return e; }), 'ConferenceRecordingStatusCallbackEvent': serialize.map(_.get(opts, 'conferenceRecordingStatusCallbackEvent'), function(e) { return e; }), 'Coaching': serialize.bool(_.get(opts, 'coaching')), - 'CallSidToCoach': _.get(opts, 'callSidToCoach') + 'CallSidToCoach': _.get(opts, 'callSidToCoach'), + 'Byoc': _.get(opts, 'byoc') }); var promise = this._version.create({uri: this._uri, method: 'POST', data: data}); diff --git a/lib/rest/authy/v1/service/entity/factor/challenge.d.ts b/lib/rest/authy/v1/service/entity/factor/challenge.d.ts index e84893ff8d..7134ac5643 100644 --- a/lib/rest/authy/v1/service/entity/factor/challenge.d.ts +++ b/lib/rest/authy/v1/service/entity/factor/challenge.d.ts @@ -17,7 +17,7 @@ type ChallengeChallengeStatuses = 'pending'|'expired'|'approved'|'denied'; type ChallengeFactorStrengths = 'unknown'|'very_low'|'low'|'medium'|'high'|'very_high'; -type ChallengeFactorTypes = 'app-push'|'sms'|'totp'; +type ChallengeFactorTypes = 'app-push'|'sms'|'totp'|'push'; /** * Initialize the ChallengeList diff --git a/lib/rest/flexApi/v1/configuration.d.ts b/lib/rest/flexApi/v1/configuration.d.ts index 28f6b821f1..07f65449e6 100644 --- a/lib/rest/flexApi/v1/configuration.d.ts +++ b/lib/rest/flexApi/v1/configuration.d.ts @@ -78,6 +78,7 @@ interface ConfigurationResource { taskrouter_worker_channels: object; taskrouter_workspace_sid: string; ui_attributes: object; + ui_dependencies: object; ui_language: string; ui_version: string; url: string; @@ -179,6 +180,7 @@ declare class ConfigurationInstance extends SerializableClass { */ toJSON(): any; uiAttributes: object; + uiDependencies: object; uiLanguage: string; uiVersion: string; /** diff --git a/lib/rest/flexApi/v1/configuration.js b/lib/rest/flexApi/v1/configuration.js index 08505c0b0e..1a21c8d2ea 100644 --- a/lib/rest/flexApi/v1/configuration.js +++ b/lib/rest/flexApi/v1/configuration.js @@ -186,6 +186,8 @@ ConfigurationPage.prototype[util.inspect.custom] = function inspect(depth, * @property {string} uiLanguage - The primary language of the Flex UI * @property {object} uiAttributes - * The object that describes Flex UI characteristics and settings + * @property {object} uiDependencies - + * The object that defines the NPM packages and versions to be used in Hosted Flex * @property {string} uiVersion - The Pinned UI version * @property {string} serviceVersion - The Flex Service version * @property {boolean} callRecordingEnabled - Whether call recording is enabled @@ -230,6 +232,7 @@ ConfigurationInstance = function ConfigurationInstance(version, payload) { this.chatServiceInstanceSid = payload.chat_service_instance_sid; // jshint ignore:line this.uiLanguage = payload.ui_language; // jshint ignore:line this.uiAttributes = payload.ui_attributes; // jshint ignore:line + this.uiDependencies = payload.ui_dependencies; // jshint ignore:line this.uiVersion = payload.ui_version; // jshint ignore:line this.serviceVersion = payload.service_version; // jshint ignore:line this.callRecordingEnabled = payload.call_recording_enabled; // jshint ignore:line diff --git a/lib/rest/messaging/V1.d.ts b/lib/rest/messaging/V1.d.ts index f416c7ed0a..4babfa6d0b 100644 --- a/lib/rest/messaging/V1.d.ts +++ b/lib/rest/messaging/V1.d.ts @@ -9,10 +9,6 @@ import Messaging = require('../Messaging'); import Version = require('../../base/Version'); import { ServiceList } from './v1/service'; import { ServiceListInstance } from './v1/service'; -import { SessionList } from './v1/session'; -import { SessionListInstance } from './v1/session'; -import { WebhookList } from './v1/webhook'; -import { WebhookListInstance } from './v1/webhook'; declare class V1 extends Version { @@ -24,8 +20,6 @@ declare class V1 extends Version { constructor(domain: Messaging); readonly services: ServiceListInstance; - readonly sessions: SessionListInstance; - readonly webhooks: WebhookListInstance; } export = V1; diff --git a/lib/rest/messaging/V1.js b/lib/rest/messaging/V1.js index e1c75f0b88..40b75d23cc 100644 --- a/lib/rest/messaging/V1.js +++ b/lib/rest/messaging/V1.js @@ -11,9 +11,7 @@ var _ = require('lodash'); /* jshint ignore:line */ var ServiceList = require('./v1/service').ServiceList; -var SessionList = require('./v1/session').SessionList; var Version = require('../../base/Version'); /* jshint ignore:line */ -var WebhookList = require('./v1/webhook').WebhookList; /* jshint ignore:start */ @@ -23,8 +21,6 @@ var WebhookList = require('./v1/webhook').WebhookList; * @constructor Twilio.Messaging.V1 * * @property {Twilio.Messaging.V1.ServiceList} services - services resource - * @property {Twilio.Messaging.V1.SessionList} sessions - sessions resource - * @property {Twilio.Messaging.V1.WebhookList} webhooks - webhooks resource * * @param {Twilio.Messaging} domain - The twilio domain */ @@ -34,8 +30,6 @@ function V1(domain) { // Resources this._services = undefined; - this._sessions = undefined; - this._webhooks = undefined; } _.extend(V1.prototype, Version.prototype); @@ -49,20 +43,4 @@ Object.defineProperty(V1.prototype, } }); -Object.defineProperty(V1.prototype, - 'sessions', { - get: function() { - this._sessions = this._sessions || new SessionList(this); - return this._sessions; - } -}); - -Object.defineProperty(V1.prototype, - 'webhooks', { - get: function() { - this._webhooks = this._webhooks || new WebhookList(this); - return this._webhooks; - } -}); - module.exports = V1; diff --git a/lib/rest/messaging/v1/session.d.ts b/lib/rest/messaging/v1/session.d.ts deleted file mode 100644 index 1f68f9d23a..0000000000 --- a/lib/rest/messaging/v1/session.d.ts +++ /dev/null @@ -1,351 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -import Page = require('../../../base/Page'); -import Response = require('../../../http/response'); -import V1 = require('../V1'); -import serialize = require('../../../base/serialize'); -import { MessageList } from './session/message'; -import { MessageListInstance } from './session/message'; -import { ParticipantList } from './session/participant'; -import { ParticipantListInstance } from './session/participant'; -import { SerializableClass } from '../../../interfaces'; -import { WebhookList } from './session/webhook'; -import { WebhookListInstance } from './session/webhook'; - -/** - * Initialize the SessionList - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - */ -declare function SessionList(version: V1): SessionListInstance; - -/** - * Options to pass to update - * - * @property attributes - A JSON string that stores application-specific data - * @property createdBy - The Identity of the session's creator - * @property dateCreated - The ISO 8601 date and time in GMT when the resource was created - * @property dateUpdated - The ISO 8601 date and time in GMT when the resource was updated - * @property friendlyName - A string to describe the resource - */ -interface SessionInstanceUpdateOptions { - attributes?: string; - createdBy?: string; - dateCreated?: Date; - dateUpdated?: Date; - friendlyName?: string; -} - -interface SessionListInstance { - /** - * @param sid - sid of instance - */ - (sid: string): SessionContext; - /** - * create a SessionInstance - * - * @param opts - Options for request - * @param callback - Callback to handle processed record - */ - create(opts: SessionListInstanceCreateOptions, callback?: (error: Error | null, item: SessionInstance) => any): Promise; - /** - * Streams SessionInstance records from the API. - * - * This operation lazily loads records as efficiently as possible until the limit - * is reached. - * - * The results are passed into the callback function, so this operation is memory - * efficient. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param opts - Options for request - * @param callback - Function to process each record - */ - each(opts?: SessionListInstanceEachOptions, callback?: (item: SessionInstance, done: (err?: Error) => void) => void): void; - /** - * Constructs a session - * - * @param sid - The SID that identifies the resource to fetch - */ - get(sid: string): SessionContext; - /** - * Retrieve a single target page of SessionInstance records from the API. - * - * The request is executed immediately. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param targetUrl - API-generated URL for the requested results page - * @param callback - Callback to handle list of records - */ - getPage(targetUrl?: string, callback?: (error: Error | null, items: SessionPage) => any): Promise; - /** - * Lists SessionInstance records from the API as a list. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param opts - Options for request - * @param callback - Callback to handle list of records - */ - list(opts?: SessionListInstanceOptions, callback?: (error: Error | null, items: SessionInstance[]) => any): Promise; - /** - * Retrieve a single page of SessionInstance records from the API. - * - * The request is executed immediately. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param opts - Options for request - * @param callback - Callback to handle list of records - */ - page(opts?: SessionListInstancePageOptions, callback?: (error: Error | null, items: SessionPage) => any): Promise; - /** - * Provide a user-friendly representation - */ - toJSON(): any; -} - -/** - * Options to pass to create - * - * @property attributes - A JSON string that stores application-specific data - * @property createdBy - The Identity of the session's creator - * @property dateCreated - The ISO 8601 date and time in GMT when the resource was created - * @property dateUpdated - The ISO 8601 date and time in GMT when the resource was updated - * @property friendlyName - A string to describe the resource - * @property messagingServiceSid - The SID of the SMS Service the session belongs to - */ -interface SessionListInstanceCreateOptions { - attributes?: string; - createdBy?: string; - dateCreated?: Date; - dateUpdated?: Date; - friendlyName?: string; - messagingServiceSid: string; -} - -/** - * Options to pass to each - * - * @property callback - - * Function to process each record. If this and a positional - * callback are passed, this one will be used - * @property done - Function to be called upon completion of streaming - * @property limit - - * Upper limit for the number of records to return. - * each() guarantees never to return more than limit. - * Default is no limit - * @property pageSize - - * Number of records to fetch per request, - * when not set will use the default value of 50 records. - * If no pageSize is defined but a limit is defined, - * each() will attempt to read the limit with the most efficient - * page size, i.e. min(limit, 1000) - */ -interface SessionListInstanceEachOptions { - callback?: (item: SessionInstance, done: (err?: Error) => void) => void; - done?: Function; - limit?: number; - pageSize?: number; -} - -/** - * Options to pass to list - * - * @property limit - - * Upper limit for the number of records to return. - * list() guarantees never to return more than limit. - * Default is no limit - * @property pageSize - - * Number of records to fetch per request, - * when not set will use the default value of 50 records. - * If no page_size is defined but a limit is defined, - * list() will attempt to read the limit with the most - * efficient page size, i.e. min(limit, 1000) - */ -interface SessionListInstanceOptions { - limit?: number; - pageSize?: number; -} - -/** - * Options to pass to page - * - * @property pageNumber - Page Number, this value is simply for client state - * @property pageSize - Number of records to return, defaults to 50 - * @property pageToken - PageToken provided by the API - */ -interface SessionListInstancePageOptions { - pageNumber?: number; - pageSize?: number; - pageToken?: string; -} - -interface SessionPayload extends SessionResource, Page.TwilioResponsePayload { -} - -interface SessionResource { - account_sid: string; - attributes: string; - created_by: string; - date_created: Date; - date_updated: Date; - friendly_name: string; - links: string; - messaging_service_sid: string; - service_sid: string; - sid: string; - url: string; -} - -interface SessionSolution { -} - - -declare class SessionContext { - /** - * Initialize the SessionContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param sid - The SID that identifies the resource to fetch - */ - constructor(version: V1, sid: string); - - /** - * fetch a SessionInstance - * - * @param callback - Callback to handle processed record - */ - fetch(callback?: (error: Error | null, items: SessionInstance) => any): Promise; - messages: MessageListInstance; - participants: ParticipantListInstance; - /** - * remove a SessionInstance - * - * @param callback - Callback to handle processed record - */ - remove(callback?: (error: Error | null, items: SessionInstance) => any): Promise; - /** - * Provide a user-friendly representation - */ - toJSON(): any; - /** - * update a SessionInstance - * - * @param opts - Options for request - * @param callback - Callback to handle processed record - */ - update(opts?: SessionInstanceUpdateOptions, callback?: (error: Error | null, items: SessionInstance) => any): Promise; - webhooks: WebhookListInstance; -} - - -declare class SessionInstance extends SerializableClass { - /** - * Initialize the SessionContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param payload - The instance payload - * @param sid - The SID that identifies the resource to fetch - */ - constructor(version: V1, payload: SessionPayload, sid: string); - - private _proxy: SessionContext; - accountSid: string; - attributes: string; - createdBy: string; - dateCreated: Date; - dateUpdated: Date; - /** - * fetch a SessionInstance - * - * @param callback - Callback to handle processed record - */ - fetch(callback?: (error: Error | null, items: SessionInstance) => any): Promise; - friendlyName: string; - links: string; - /** - * Access the messages - */ - messages(): MessageListInstance; - messagingServiceSid: string; - /** - * Access the participants - */ - participants(): ParticipantListInstance; - /** - * remove a SessionInstance - * - * @param callback - Callback to handle processed record - */ - remove(callback?: (error: Error | null, items: SessionInstance) => any): Promise; - serviceSid: string; - sid: string; - /** - * Provide a user-friendly representation - */ - toJSON(): any; - /** - * update a SessionInstance - * - * @param opts - Options for request - * @param callback - Callback to handle processed record - */ - update(opts?: SessionInstanceUpdateOptions, callback?: (error: Error | null, items: SessionInstance) => any): Promise; - url: string; - /** - * Access the webhooks - */ - webhooks(): WebhookListInstance; -} - - -declare class SessionPage extends Page { - /** - * Initialize the SessionPage - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param response - Response from the API - * @param solution - Path solution - */ - constructor(version: V1, response: Response, solution: SessionSolution); - - /** - * Build an instance of SessionInstance - * - * @param payload - Payload response from the API - */ - getInstance(payload: SessionPayload): SessionInstance; - /** - * Provide a user-friendly representation - */ - toJSON(): any; -} - -export { SessionContext, SessionInstance, SessionInstanceUpdateOptions, SessionList, SessionListInstance, SessionListInstanceCreateOptions, SessionListInstanceEachOptions, SessionListInstanceOptions, SessionListInstancePageOptions, SessionPage, SessionPayload, SessionResource, SessionSolution } diff --git a/lib/rest/messaging/v1/session.js b/lib/rest/messaging/v1/session.js deleted file mode 100644 index f2412332c3..0000000000 --- a/lib/rest/messaging/v1/session.js +++ /dev/null @@ -1,864 +0,0 @@ -'use strict'; - -/* jshint ignore:start */ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ -/* jshint ignore:end */ - -var Q = require('q'); /* jshint ignore:line */ -var _ = require('lodash'); /* jshint ignore:line */ -var util = require('util'); /* jshint ignore:line */ -var MessageList = require('./session/message').MessageList; -var Page = require('../../../base/Page'); /* jshint ignore:line */ -var ParticipantList = require('./session/participant').ParticipantList; -var WebhookList = require('./session/webhook').WebhookList; -var deserialize = require( - '../../../base/deserialize'); /* jshint ignore:line */ -var serialize = require('../../../base/serialize'); /* jshint ignore:line */ -var values = require('../../../base/values'); /* jshint ignore:line */ - -var SessionList; -var SessionPage; -var SessionInstance; -var SessionContext; - -/* jshint ignore:start */ -/** - * Initialize the SessionList - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.SessionList - * - * @param {Twilio.Messaging.V1} version - Version of the resource - */ -/* jshint ignore:end */ -SessionList = function SessionList(version) { - /* jshint ignore:start */ - /** - * @function sessions - * @memberof Twilio.Messaging.V1# - * - * @param {string} sid - sid of instance - * - * @returns {Twilio.Messaging.V1.SessionContext} - */ - /* jshint ignore:end */ - function SessionListInstance(sid) { - return SessionListInstance.get(sid); - } - - SessionListInstance._version = version; - // Path Solution - SessionListInstance._solution = {}; - SessionListInstance._uri = `/Sessions`; - /* jshint ignore:start */ - /** - * create a SessionInstance - * - * @function create - * @memberof Twilio.Messaging.V1.SessionList# - * - * @param {object} opts - Options for request - * @param {string} opts.messagingServiceSid - - * The SID of the SMS Service the session belongs to - * @param {string} [opts.friendlyName] - A string to describe the resource - * @param {string} [opts.attributes] - - * A JSON string that stores application-specific data - * @param {Date} [opts.dateCreated] - - * The ISO 8601 date and time in GMT when the resource was created - * @param {Date} [opts.dateUpdated] - - * The ISO 8601 date and time in GMT when the resource was updated - * @param {string} [opts.createdBy] - The Identity of the session's creator - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed SessionInstance - */ - /* jshint ignore:end */ - SessionListInstance.create = function create(opts, callback) { - if (_.isUndefined(opts)) { - throw new Error('Required parameter "opts" missing.'); - } - if (_.isUndefined(opts.messagingServiceSid)) { - throw new Error('Required parameter "opts.messagingServiceSid" missing.'); - } - - var deferred = Q.defer(); - var data = values.of({ - 'MessagingServiceSid': _.get(opts, 'messagingServiceSid'), - 'FriendlyName': _.get(opts, 'friendlyName'), - 'Attributes': _.get(opts, 'attributes'), - 'DateCreated': serialize.iso8601DateTime(_.get(opts, 'dateCreated')), - 'DateUpdated': serialize.iso8601DateTime(_.get(opts, 'dateUpdated')), - 'CreatedBy': _.get(opts, 'createdBy') - }); - - var promise = this._version.create({uri: this._uri, method: 'POST', data: data}); - - promise = promise.then(function(payload) { - deferred.resolve(new SessionInstance(this._version, payload, this._solution.sid)); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; - }; - - /* jshint ignore:start */ - /** - * Streams SessionInstance records from the API. - * - * This operation lazily loads records as efficiently as possible until the limit - * is reached. - * - * The results are passed into the callback function, so this operation is memory - * efficient. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @function each - * @memberof Twilio.Messaging.V1.SessionList# - * - * @param {object} [opts] - Options for request - * @param {number} [opts.limit] - - * Upper limit for the number of records to return. - * each() guarantees never to return more than limit. - * Default is no limit - * @param {number} [opts.pageSize] - - * Number of records to fetch per request, - * when not set will use the default value of 50 records. - * If no pageSize is defined but a limit is defined, - * each() will attempt to read the limit with the most efficient - * page size, i.e. min(limit, 1000) - * @param {Function} [opts.callback] - - * Function to process each record. If this and a positional - * callback are passed, this one will be used - * @param {Function} [opts.done] - - * Function to be called upon completion of streaming - * @param {Function} [callback] - Function to process each record - */ - /* jshint ignore:end */ - SessionListInstance.each = function each(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - if (opts.callback) { - callback = opts.callback; - } - if (_.isUndefined(callback)) { - throw new Error('Callback function must be provided'); - } - - var done = false; - var currentPage = 1; - var currentResource = 0; - var limits = this._version.readLimits({ - limit: opts.limit, - pageSize: opts.pageSize - }); - - function onComplete(error) { - done = true; - if (_.isFunction(opts.done)) { - opts.done(error); - } - } - - function fetchNextPage(fn) { - var promise = fn(); - if (_.isUndefined(promise)) { - onComplete(); - return; - } - - promise.then(function(page) { - _.each(page.instances, function(instance) { - if (done || (!_.isUndefined(opts.limit) && currentResource >= opts.limit)) { - done = true; - return false; - } - - currentResource++; - callback(instance, onComplete); - }); - - if ((limits.pageLimit && limits.pageLimit <= currentPage)) { - onComplete(); - } else if (!done) { - currentPage++; - fetchNextPage(_.bind(page.nextPage, page)); - } - }); - - promise.catch(onComplete); - } - - fetchNextPage(_.bind(this.page, this, _.merge(opts, limits))); - }; - - /* jshint ignore:start */ - /** - * Lists SessionInstance records from the API as a list. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @function list - * @memberof Twilio.Messaging.V1.SessionList# - * - * @param {object} [opts] - Options for request - * @param {number} [opts.limit] - - * Upper limit for the number of records to return. - * list() guarantees never to return more than limit. - * Default is no limit - * @param {number} [opts.pageSize] - - * Number of records to fetch per request, - * when not set will use the default value of 50 records. - * If no page_size is defined but a limit is defined, - * list() will attempt to read the limit with the most - * efficient page size, i.e. min(limit, 1000) - * @param {function} [callback] - Callback to handle list of records - * - * @returns {Promise} Resolves to a list of records - */ - /* jshint ignore:end */ - SessionListInstance.list = function list(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - var deferred = Q.defer(); - var allResources = []; - opts.callback = function(resource, done) { - allResources.push(resource); - - if (!_.isUndefined(opts.limit) && allResources.length === opts.limit) { - done(); - } - }; - - opts.done = function(error) { - if (_.isUndefined(error)) { - deferred.resolve(allResources); - } else { - deferred.reject(error); - } - }; - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - this.each(opts); - return deferred.promise; - }; - - /* jshint ignore:start */ - /** - * Retrieve a single page of SessionInstance records from the API. - * - * The request is executed immediately. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @function page - * @memberof Twilio.Messaging.V1.SessionList# - * - * @param {object} [opts] - Options for request - * @param {string} [opts.pageToken] - PageToken provided by the API - * @param {number} [opts.pageNumber] - - * Page Number, this value is simply for client state - * @param {number} [opts.pageSize] - Number of records to return, defaults to 50 - * @param {function} [callback] - Callback to handle list of records - * - * @returns {Promise} Resolves to a list of records - */ - /* jshint ignore:end */ - SessionListInstance.page = function page(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - - var deferred = Q.defer(); - var data = values.of({ - 'PageToken': opts.pageToken, - 'Page': opts.pageNumber, - 'PageSize': opts.pageSize - }); - - var promise = this._version.page({uri: this._uri, method: 'GET', params: data}); - - promise = promise.then(function(payload) { - deferred.resolve(new SessionPage(this._version, payload, this._solution)); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; - }; - - /* jshint ignore:start */ - /** - * Retrieve a single target page of SessionInstance records from the API. - * - * The request is executed immediately. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @function getPage - * @memberof Twilio.Messaging.V1.SessionList# - * - * @param {string} [targetUrl] - API-generated URL for the requested results page - * @param {function} [callback] - Callback to handle list of records - * - * @returns {Promise} Resolves to a list of records - */ - /* jshint ignore:end */ - SessionListInstance.getPage = function getPage(targetUrl, callback) { - var deferred = Q.defer(); - - var promise = this._version._domain.twilio.request({method: 'GET', uri: targetUrl}); - - promise = promise.then(function(payload) { - deferred.resolve(new SessionPage(this._version, payload, this._solution)); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; - }; - - /* jshint ignore:start */ - /** - * Constructs a session - * - * @function get - * @memberof Twilio.Messaging.V1.SessionList# - * - * @param {string} sid - The SID that identifies the resource to fetch - * - * @returns {Twilio.Messaging.V1.SessionContext} - */ - /* jshint ignore:end */ - SessionListInstance.get = function get(sid) { - return new SessionContext(this._version, sid); - }; - - /* jshint ignore:start */ - /** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.SessionList# - * - * @returns Object - */ - /* jshint ignore:end */ - SessionListInstance.toJSON = function toJSON() { - return this._solution; - }; - - SessionListInstance[util.inspect.custom] = function inspect(depth, options) { - return util.inspect(this.toJSON(), options); - }; - - return SessionListInstance; -}; - - -/* jshint ignore:start */ -/** - * Initialize the SessionPage - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.SessionPage - * - * @param {V1} version - Version of the resource - * @param {Response} response - Response from the API - * @param {SessionSolution} solution - Path solution - * - * @returns SessionPage - */ -/* jshint ignore:end */ -SessionPage = function SessionPage(version, response, solution) { - // Path Solution - this._solution = solution; - - Page.prototype.constructor.call(this, version, response, this._solution); -}; - -_.extend(SessionPage.prototype, Page.prototype); -SessionPage.prototype.constructor = SessionPage; - -/* jshint ignore:start */ -/** - * Build an instance of SessionInstance - * - * @function getInstance - * @memberof Twilio.Messaging.V1.SessionPage# - * - * @param {SessionPayload} payload - Payload response from the API - * - * @returns SessionInstance - */ -/* jshint ignore:end */ -SessionPage.prototype.getInstance = function getInstance(payload) { - return new SessionInstance(this._version, payload); -}; - -/* jshint ignore:start */ -/** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.SessionPage# - * - * @returns Object - */ -/* jshint ignore:end */ -SessionPage.prototype.toJSON = function toJSON() { - let clone = {}; - _.forOwn(this, function(value, key) { - if (!_.startsWith(key, '_') && ! _.isFunction(value)) { - clone[key] = value; - } - }); - return clone; -}; - -SessionPage.prototype[util.inspect.custom] = function inspect(depth, options) { - return util.inspect(this.toJSON(), options); -}; - - -/* jshint ignore:start */ -/** - * Initialize the SessionContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.SessionInstance - * - * @property {string} sid - The unique string that identifies the resource - * @property {string} accountSid - The SID of the Account that created the resource - * @property {string} serviceSid - - * The SID of the Service that the resource is associated with - * @property {string} messagingServiceSid - - * The SID of the SMS Service the session belongs to - * @property {string} friendlyName - - * The string that you assigned to describe the resource - * @property {string} attributes - - * The JSON string that stores application-specific data - * @property {string} createdBy - The Identity of the session's creator - * @property {Date} dateCreated - - * The ISO 8601 date and time in GMT when the resource was created - * @property {Date} dateUpdated - - * The ISO 8601 date and time in GMT when the resource was last updated - * @property {string} url - The absolute URL of the session - * @property {string} links - - * The absolute URLs of the Participants, Interactions, and Messages for the Session - * - * @param {V1} version - Version of the resource - * @param {SessionPayload} payload - The instance payload - * @param {sid} sid - The SID that identifies the resource to fetch - */ -/* jshint ignore:end */ -SessionInstance = function SessionInstance(version, payload, sid) { - this._version = version; - - // Marshaled Properties - this.sid = payload.sid; // jshint ignore:line - this.accountSid = payload.account_sid; // jshint ignore:line - this.serviceSid = payload.service_sid; // jshint ignore:line - this.messagingServiceSid = payload.messaging_service_sid; // jshint ignore:line - this.friendlyName = payload.friendly_name; // jshint ignore:line - this.attributes = payload.attributes; // jshint ignore:line - this.createdBy = payload.created_by; // jshint ignore:line - this.dateCreated = deserialize.iso8601DateTime(payload.date_created); // jshint ignore:line - this.dateUpdated = deserialize.iso8601DateTime(payload.date_updated); // jshint ignore:line - this.url = payload.url; // jshint ignore:line - this.links = payload.links; // jshint ignore:line - - // Context - this._context = undefined; - this._solution = {sid: sid || this.sid, }; -}; - -Object.defineProperty(SessionInstance.prototype, - '_proxy', { - get: function() { - if (!this._context) { - this._context = new SessionContext(this._version, this._solution.sid); - } - - return this._context; - } -}); - -/* jshint ignore:start */ -/** - * fetch a SessionInstance - * - * @function fetch - * @memberof Twilio.Messaging.V1.SessionInstance# - * - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed SessionInstance - */ -/* jshint ignore:end */ -SessionInstance.prototype.fetch = function fetch(callback) { - return this._proxy.fetch(callback); -}; - -/* jshint ignore:start */ -/** - * remove a SessionInstance - * - * @function remove - * @memberof Twilio.Messaging.V1.SessionInstance# - * - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed SessionInstance - */ -/* jshint ignore:end */ -SessionInstance.prototype.remove = function remove(callback) { - return this._proxy.remove(callback); -}; - -/* jshint ignore:start */ -/** - * update a SessionInstance - * - * @function update - * @memberof Twilio.Messaging.V1.SessionInstance# - * - * @param {object} [opts] - Options for request - * @param {string} [opts.friendlyName] - A string to describe the resource - * @param {string} [opts.attributes] - - * A JSON string that stores application-specific data - * @param {Date} [opts.dateCreated] - - * The ISO 8601 date and time in GMT when the resource was created - * @param {Date} [opts.dateUpdated] - - * The ISO 8601 date and time in GMT when the resource was updated - * @param {string} [opts.createdBy] - The Identity of the session's creator - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed SessionInstance - */ -/* jshint ignore:end */ -SessionInstance.prototype.update = function update(opts, callback) { - return this._proxy.update(opts, callback); -}; - -/* jshint ignore:start */ -/** - * Access the participants - * - * @function participants - * @memberof Twilio.Messaging.V1.SessionInstance# - * - * @returns {Twilio.Messaging.V1.SessionContext.ParticipantList} - */ -/* jshint ignore:end */ -SessionInstance.prototype.participants = function participants() { - return this._proxy.participants; -}; - -/* jshint ignore:start */ -/** - * Access the messages - * - * @function messages - * @memberof Twilio.Messaging.V1.SessionInstance# - * - * @returns {Twilio.Messaging.V1.SessionContext.MessageList} - */ -/* jshint ignore:end */ -SessionInstance.prototype.messages = function messages() { - return this._proxy.messages; -}; - -/* jshint ignore:start */ -/** - * Access the webhooks - * - * @function webhooks - * @memberof Twilio.Messaging.V1.SessionInstance# - * - * @returns {Twilio.Messaging.V1.SessionContext.WebhookList} - */ -/* jshint ignore:end */ -SessionInstance.prototype.webhooks = function webhooks() { - return this._proxy.webhooks; -}; - -/* jshint ignore:start */ -/** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.SessionInstance# - * - * @returns Object - */ -/* jshint ignore:end */ -SessionInstance.prototype.toJSON = function toJSON() { - let clone = {}; - _.forOwn(this, function(value, key) { - if (!_.startsWith(key, '_') && ! _.isFunction(value)) { - clone[key] = value; - } - }); - return clone; -}; - -SessionInstance.prototype[util.inspect.custom] = function inspect(depth, - options) { - return util.inspect(this.toJSON(), options); -}; - - -/* jshint ignore:start */ -/** - * Initialize the SessionContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.SessionContext - * - * @property {Twilio.Messaging.V1.SessionContext.ParticipantList} participants - - * participants resource - * @property {Twilio.Messaging.V1.SessionContext.MessageList} messages - - * messages resource - * @property {Twilio.Messaging.V1.SessionContext.WebhookList} webhooks - - * webhooks resource - * - * @param {V1} version - Version of the resource - * @param {sid} sid - The SID that identifies the resource to fetch - */ -/* jshint ignore:end */ -SessionContext = function SessionContext(version, sid) { - this._version = version; - - // Path Solution - this._solution = {sid: sid, }; - this._uri = `/Sessions/${sid}`; - - // Dependents - this._participants = undefined; - this._messages = undefined; - this._webhooks = undefined; -}; - -/* jshint ignore:start */ -/** - * fetch a SessionInstance - * - * @function fetch - * @memberof Twilio.Messaging.V1.SessionContext# - * - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed SessionInstance - */ -/* jshint ignore:end */ -SessionContext.prototype.fetch = function fetch(callback) { - var deferred = Q.defer(); - var promise = this._version.fetch({uri: this._uri, method: 'GET'}); - - promise = promise.then(function(payload) { - deferred.resolve(new SessionInstance(this._version, payload, this._solution.sid)); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; -}; - -/* jshint ignore:start */ -/** - * remove a SessionInstance - * - * @function remove - * @memberof Twilio.Messaging.V1.SessionContext# - * - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed SessionInstance - */ -/* jshint ignore:end */ -SessionContext.prototype.remove = function remove(callback) { - var deferred = Q.defer(); - var promise = this._version.remove({uri: this._uri, method: 'DELETE'}); - - promise = promise.then(function(payload) { - deferred.resolve(payload); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; -}; - -/* jshint ignore:start */ -/** - * update a SessionInstance - * - * @function update - * @memberof Twilio.Messaging.V1.SessionContext# - * - * @param {object} [opts] - Options for request - * @param {string} [opts.friendlyName] - A string to describe the resource - * @param {string} [opts.attributes] - - * A JSON string that stores application-specific data - * @param {Date} [opts.dateCreated] - - * The ISO 8601 date and time in GMT when the resource was created - * @param {Date} [opts.dateUpdated] - - * The ISO 8601 date and time in GMT when the resource was updated - * @param {string} [opts.createdBy] - The Identity of the session's creator - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed SessionInstance - */ -/* jshint ignore:end */ -SessionContext.prototype.update = function update(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - - var deferred = Q.defer(); - var data = values.of({ - 'FriendlyName': _.get(opts, 'friendlyName'), - 'Attributes': _.get(opts, 'attributes'), - 'DateCreated': serialize.iso8601DateTime(_.get(opts, 'dateCreated')), - 'DateUpdated': serialize.iso8601DateTime(_.get(opts, 'dateUpdated')), - 'CreatedBy': _.get(opts, 'createdBy') - }); - - var promise = this._version.update({uri: this._uri, method: 'POST', data: data}); - - promise = promise.then(function(payload) { - deferred.resolve(new SessionInstance(this._version, payload, this._solution.sid)); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; -}; - -Object.defineProperty(SessionContext.prototype, - 'participants', { - get: function() { - if (!this._participants) { - this._participants = new ParticipantList(this._version, this._solution.sid); - } - return this._participants; - } -}); - -Object.defineProperty(SessionContext.prototype, - 'messages', { - get: function() { - if (!this._messages) { - this._messages = new MessageList(this._version, this._solution.sid); - } - return this._messages; - } -}); - -Object.defineProperty(SessionContext.prototype, - 'webhooks', { - get: function() { - if (!this._webhooks) { - this._webhooks = new WebhookList(this._version, this._solution.sid); - } - return this._webhooks; - } -}); - -/* jshint ignore:start */ -/** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.SessionContext# - * - * @returns Object - */ -/* jshint ignore:end */ -SessionContext.prototype.toJSON = function toJSON() { - return this._solution; -}; - -SessionContext.prototype[util.inspect.custom] = function inspect(depth, options) - { - return util.inspect(this.toJSON(), options); -}; - -module.exports = { - SessionList: SessionList, - SessionPage: SessionPage, - SessionInstance: SessionInstance, - SessionContext: SessionContext -}; diff --git a/lib/rest/messaging/v1/session/message.d.ts b/lib/rest/messaging/v1/session/message.d.ts deleted file mode 100644 index 8aeb27854c..0000000000 --- a/lib/rest/messaging/v1/session/message.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -import Page = require('../../../../base/Page'); -import Response = require('../../../../http/response'); -import V1 = require('../../V1'); -import serialize = require('../../../../base/serialize'); -import { SerializableClass } from '../../../../interfaces'; - -/** - * Initialize the MessageList - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param sessionSid - The SID of the Session for the message - */ -declare function MessageList(version: V1, sessionSid: string): MessageListInstance; - -/** - * Options to pass to update - * - * @property attributes - A JSON string that stores application-specific data - * @property author - The identity of the message's author - * @property body - The message body - * @property dateCreated - The ISO 8601 date and time in GMT when the resource was created - * @property dateUpdated - The ISO 8601 date and time in GMT when the resource was updated - */ -interface MessageInstanceUpdateOptions { - attributes?: string; - author?: string; - body?: string; - dateCreated?: Date; - dateUpdated?: Date; -} - -interface MessageListInstance { - /** - * @param sid - sid of instance - */ - (sid: string): MessageContext; - /** - * create a MessageInstance - * - * @param opts - Options for request - * @param callback - Callback to handle processed record - */ - create(opts?: MessageListInstanceCreateOptions, callback?: (error: Error | null, item: MessageInstance) => any): Promise; - /** - * Streams MessageInstance records from the API. - * - * This operation lazily loads records as efficiently as possible until the limit - * is reached. - * - * The results are passed into the callback function, so this operation is memory - * efficient. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param opts - Options for request - * @param callback - Function to process each record - */ - each(opts?: MessageListInstanceEachOptions, callback?: (item: MessageInstance, done: (err?: Error) => void) => void): void; - /** - * Constructs a message - * - * @param sid - The SID that identifies the resource to fetch - */ - get(sid: string): MessageContext; - /** - * Retrieve a single target page of MessageInstance records from the API. - * - * The request is executed immediately. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param targetUrl - API-generated URL for the requested results page - * @param callback - Callback to handle list of records - */ - getPage(targetUrl?: string, callback?: (error: Error | null, items: MessagePage) => any): Promise; - /** - * Lists MessageInstance records from the API as a list. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param opts - Options for request - * @param callback - Callback to handle list of records - */ - list(opts?: MessageListInstanceOptions, callback?: (error: Error | null, items: MessageInstance[]) => any): Promise; - /** - * Retrieve a single page of MessageInstance records from the API. - * - * The request is executed immediately. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param opts - Options for request - * @param callback - Callback to handle list of records - */ - page(opts?: MessageListInstancePageOptions, callback?: (error: Error | null, items: MessagePage) => any): Promise; - /** - * Provide a user-friendly representation - */ - toJSON(): any; -} - -/** - * Options to pass to create - * - * @property attributes - A JSON string that stores application-specific data - * @property author - The identity of the message's author - * @property body - The message body - * @property dateCreated - The ISO 8601 date and time in GMT when the resource was created - * @property dateUpdated - The ISO 8601 date and time in GMT when the resource was updated - */ -interface MessageListInstanceCreateOptions { - attributes?: string; - author?: string; - body?: string; - dateCreated?: Date; - dateUpdated?: Date; -} - -/** - * Options to pass to each - * - * @property callback - - * Function to process each record. If this and a positional - * callback are passed, this one will be used - * @property done - Function to be called upon completion of streaming - * @property limit - - * Upper limit for the number of records to return. - * each() guarantees never to return more than limit. - * Default is no limit - * @property pageSize - - * Number of records to fetch per request, - * when not set will use the default value of 50 records. - * If no pageSize is defined but a limit is defined, - * each() will attempt to read the limit with the most efficient - * page size, i.e. min(limit, 1000) - */ -interface MessageListInstanceEachOptions { - callback?: (item: MessageInstance, done: (err?: Error) => void) => void; - done?: Function; - limit?: number; - pageSize?: number; -} - -/** - * Options to pass to list - * - * @property limit - - * Upper limit for the number of records to return. - * list() guarantees never to return more than limit. - * Default is no limit - * @property pageSize - - * Number of records to fetch per request, - * when not set will use the default value of 50 records. - * If no page_size is defined but a limit is defined, - * list() will attempt to read the limit with the most - * efficient page size, i.e. min(limit, 1000) - */ -interface MessageListInstanceOptions { - limit?: number; - pageSize?: number; -} - -/** - * Options to pass to page - * - * @property pageNumber - Page Number, this value is simply for client state - * @property pageSize - Number of records to return, defaults to 50 - * @property pageToken - PageToken provided by the API - */ -interface MessageListInstancePageOptions { - pageNumber?: number; - pageSize?: number; - pageToken?: string; -} - -interface MessagePayload extends MessageResource, Page.TwilioResponsePayload { -} - -interface MessageResource { - account_sid: string; - attributes: string; - author: string; - body: string; - date_created: Date; - date_updated: Date; - index: number; - messaging_service_sid: string; - service_sid: string; - session_sid: string; - sid: string; - url: string; -} - -interface MessageSolution { - sessionSid?: string; -} - - -declare class MessageContext { - /** - * Initialize the MessageContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param sessionSid - The SID of the Session with the message to fetch - * @param sid - The SID that identifies the resource to fetch - */ - constructor(version: V1, sessionSid: string, sid: string); - - /** - * fetch a MessageInstance - * - * @param callback - Callback to handle processed record - */ - fetch(callback?: (error: Error | null, items: MessageInstance) => any): Promise; - /** - * remove a MessageInstance - * - * @param callback - Callback to handle processed record - */ - remove(callback?: (error: Error | null, items: MessageInstance) => any): Promise; - /** - * Provide a user-friendly representation - */ - toJSON(): any; - /** - * update a MessageInstance - * - * @param opts - Options for request - * @param callback - Callback to handle processed record - */ - update(opts?: MessageInstanceUpdateOptions, callback?: (error: Error | null, items: MessageInstance) => any): Promise; -} - - -declare class MessageInstance extends SerializableClass { - /** - * Initialize the MessageContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param payload - The instance payload - * @param sessionSid - The SID of the Session for the message - * @param sid - The SID that identifies the resource to fetch - */ - constructor(version: V1, payload: MessagePayload, sessionSid: string, sid: string); - - private _proxy: MessageContext; - accountSid: string; - attributes: string; - author: string; - body: string; - dateCreated: Date; - dateUpdated: Date; - /** - * fetch a MessageInstance - * - * @param callback - Callback to handle processed record - */ - fetch(callback?: (error: Error | null, items: MessageInstance) => any): Promise; - index: number; - messagingServiceSid: string; - /** - * remove a MessageInstance - * - * @param callback - Callback to handle processed record - */ - remove(callback?: (error: Error | null, items: MessageInstance) => any): Promise; - serviceSid: string; - sessionSid: string; - sid: string; - /** - * Provide a user-friendly representation - */ - toJSON(): any; - /** - * update a MessageInstance - * - * @param opts - Options for request - * @param callback - Callback to handle processed record - */ - update(opts?: MessageInstanceUpdateOptions, callback?: (error: Error | null, items: MessageInstance) => any): Promise; - url: string; -} - - -declare class MessagePage extends Page { - /** - * Initialize the MessagePage - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param response - Response from the API - * @param solution - Path solution - */ - constructor(version: V1, response: Response, solution: MessageSolution); - - /** - * Build an instance of MessageInstance - * - * @param payload - Payload response from the API - */ - getInstance(payload: MessagePayload): MessageInstance; - /** - * Provide a user-friendly representation - */ - toJSON(): any; -} - -export { MessageContext, MessageInstance, MessageInstanceUpdateOptions, MessageList, MessageListInstance, MessageListInstanceCreateOptions, MessageListInstanceEachOptions, MessageListInstanceOptions, MessageListInstancePageOptions, MessagePage, MessagePayload, MessageResource, MessageSolution } diff --git a/lib/rest/messaging/v1/session/participant.d.ts b/lib/rest/messaging/v1/session/participant.d.ts deleted file mode 100644 index b7d3665341..0000000000 --- a/lib/rest/messaging/v1/session/participant.d.ts +++ /dev/null @@ -1,336 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -import Page = require('../../../../base/Page'); -import Response = require('../../../../http/response'); -import V1 = require('../../V1'); -import serialize = require('../../../../base/serialize'); -import { SerializableClass } from '../../../../interfaces'; - -type ParticipantParticipantType = 'chat'|'sms'; - -/** - * Initialize the ParticipantList - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param sessionSid - The SID of the Session for the participant - */ -declare function ParticipantList(version: V1, sessionSid: string): ParticipantListInstance; - -/** - * Options to pass to update - * - * @property attributes - A JSON string that stores application-specific data - * @property dateCreated - The ISO 8601 date and time in GMT when the resource was created - * @property dateUpdated - The ISO 8601 date and time in GMT when the resource was updated - */ -interface ParticipantInstanceUpdateOptions { - attributes?: string; - dateCreated?: Date; - dateUpdated?: Date; -} - -interface ParticipantListInstance { - /** - * @param sid - sid of instance - */ - (sid: string): ParticipantContext; - /** - * create a ParticipantInstance - * - * @param opts - Options for request - * @param callback - Callback to handle processed record - */ - create(opts?: ParticipantListInstanceCreateOptions, callback?: (error: Error | null, item: ParticipantInstance) => any): Promise; - /** - * Streams ParticipantInstance records from the API. - * - * This operation lazily loads records as efficiently as possible until the limit - * is reached. - * - * The results are passed into the callback function, so this operation is memory - * efficient. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param opts - Options for request - * @param callback - Function to process each record - */ - each(opts?: ParticipantListInstanceEachOptions, callback?: (item: ParticipantInstance, done: (err?: Error) => void) => void): void; - /** - * Constructs a participant - * - * @param sid - The SID that identifies the resource to fetch - */ - get(sid: string): ParticipantContext; - /** - * Retrieve a single target page of ParticipantInstance records from the API. - * - * The request is executed immediately. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param targetUrl - API-generated URL for the requested results page - * @param callback - Callback to handle list of records - */ - getPage(targetUrl?: string, callback?: (error: Error | null, items: ParticipantPage) => any): Promise; - /** - * Lists ParticipantInstance records from the API as a list. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param opts - Options for request - * @param callback - Callback to handle list of records - */ - list(opts?: ParticipantListInstanceOptions, callback?: (error: Error | null, items: ParticipantInstance[]) => any): Promise; - /** - * Retrieve a single page of ParticipantInstance records from the API. - * - * The request is executed immediately. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param opts - Options for request - * @param callback - Callback to handle list of records - */ - page(opts?: ParticipantListInstancePageOptions, callback?: (error: Error | null, items: ParticipantPage) => any): Promise; - /** - * Provide a user-friendly representation - */ - toJSON(): any; -} - -/** - * Options to pass to create - * - * @property attributes - A JSON string that stores application-specific data - * @property dateCreated - The ISO 8601 date and time in GMT when the resource was created - * @property dateUpdated - The ISO 8601 date and time in GMT when the resource was updated - * @property identity - The string that identifies the resource's User - * @property twilioAddress - The address of the Twilio phone number that the participant is in contact with - * @property userAddress - The address of the participant's device - */ -interface ParticipantListInstanceCreateOptions { - attributes?: string; - dateCreated?: Date; - dateUpdated?: Date; - identity?: string; - twilioAddress?: string; - userAddress?: string; -} - -/** - * Options to pass to each - * - * @property callback - - * Function to process each record. If this and a positional - * callback are passed, this one will be used - * @property done - Function to be called upon completion of streaming - * @property limit - - * Upper limit for the number of records to return. - * each() guarantees never to return more than limit. - * Default is no limit - * @property pageSize - - * Number of records to fetch per request, - * when not set will use the default value of 50 records. - * If no pageSize is defined but a limit is defined, - * each() will attempt to read the limit with the most efficient - * page size, i.e. min(limit, 1000) - */ -interface ParticipantListInstanceEachOptions { - callback?: (item: ParticipantInstance, done: (err?: Error) => void) => void; - done?: Function; - limit?: number; - pageSize?: number; -} - -/** - * Options to pass to list - * - * @property limit - - * Upper limit for the number of records to return. - * list() guarantees never to return more than limit. - * Default is no limit - * @property pageSize - - * Number of records to fetch per request, - * when not set will use the default value of 50 records. - * If no page_size is defined but a limit is defined, - * list() will attempt to read the limit with the most - * efficient page size, i.e. min(limit, 1000) - */ -interface ParticipantListInstanceOptions { - limit?: number; - pageSize?: number; -} - -/** - * Options to pass to page - * - * @property pageNumber - Page Number, this value is simply for client state - * @property pageSize - Number of records to return, defaults to 50 - * @property pageToken - PageToken provided by the API - */ -interface ParticipantListInstancePageOptions { - pageNumber?: number; - pageSize?: number; - pageToken?: string; -} - -interface ParticipantPayload extends ParticipantResource, Page.TwilioResponsePayload { -} - -interface ParticipantResource { - account_sid: string; - attributes: string; - date_created: Date; - date_updated: Date; - identity: string; - messaging_service_sid: string; - service_sid: string; - session_sid: string; - sid: string; - twilio_address: string; - type: ParticipantParticipantType; - url: string; - user_address: string; -} - -interface ParticipantSolution { - sessionSid?: string; -} - - -declare class ParticipantContext { - /** - * Initialize the ParticipantContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param sessionSid - The SID of the Session with the participant to fetch - * @param sid - The SID that identifies the resource to fetch - */ - constructor(version: V1, sessionSid: string, sid: string); - - /** - * fetch a ParticipantInstance - * - * @param callback - Callback to handle processed record - */ - fetch(callback?: (error: Error | null, items: ParticipantInstance) => any): Promise; - /** - * remove a ParticipantInstance - * - * @param callback - Callback to handle processed record - */ - remove(callback?: (error: Error | null, items: ParticipantInstance) => any): Promise; - /** - * Provide a user-friendly representation - */ - toJSON(): any; - /** - * update a ParticipantInstance - * - * @param opts - Options for request - * @param callback - Callback to handle processed record - */ - update(opts?: ParticipantInstanceUpdateOptions, callback?: (error: Error | null, items: ParticipantInstance) => any): Promise; -} - - -declare class ParticipantInstance extends SerializableClass { - /** - * Initialize the ParticipantContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param payload - The instance payload - * @param sessionSid - The SID of the Session for the participant - * @param sid - The SID that identifies the resource to fetch - */ - constructor(version: V1, payload: ParticipantPayload, sessionSid: string, sid: string); - - private _proxy: ParticipantContext; - accountSid: string; - attributes: string; - dateCreated: Date; - dateUpdated: Date; - /** - * fetch a ParticipantInstance - * - * @param callback - Callback to handle processed record - */ - fetch(callback?: (error: Error | null, items: ParticipantInstance) => any): Promise; - identity: string; - messagingServiceSid: string; - /** - * remove a ParticipantInstance - * - * @param callback - Callback to handle processed record - */ - remove(callback?: (error: Error | null, items: ParticipantInstance) => any): Promise; - serviceSid: string; - sessionSid: string; - sid: string; - /** - * Provide a user-friendly representation - */ - toJSON(): any; - twilioAddress: string; - type: ParticipantParticipantType; - /** - * update a ParticipantInstance - * - * @param opts - Options for request - * @param callback - Callback to handle processed record - */ - update(opts?: ParticipantInstanceUpdateOptions, callback?: (error: Error | null, items: ParticipantInstance) => any): Promise; - url: string; - userAddress: string; -} - - -declare class ParticipantPage extends Page { - /** - * Initialize the ParticipantPage - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param response - Response from the API - * @param solution - Path solution - */ - constructor(version: V1, response: Response, solution: ParticipantSolution); - - /** - * Build an instance of ParticipantInstance - * - * @param payload - Payload response from the API - */ - getInstance(payload: ParticipantPayload): ParticipantInstance; - /** - * Provide a user-friendly representation - */ - toJSON(): any; -} - -export { ParticipantContext, ParticipantInstance, ParticipantInstanceUpdateOptions, ParticipantList, ParticipantListInstance, ParticipantListInstanceCreateOptions, ParticipantListInstanceEachOptions, ParticipantListInstanceOptions, ParticipantListInstancePageOptions, ParticipantPage, ParticipantParticipantType, ParticipantPayload, ParticipantResource, ParticipantSolution } diff --git a/lib/rest/messaging/v1/session/participant.js b/lib/rest/messaging/v1/session/participant.js deleted file mode 100644 index 4ba78a6df4..0000000000 --- a/lib/rest/messaging/v1/session/participant.js +++ /dev/null @@ -1,798 +0,0 @@ -'use strict'; - -/* jshint ignore:start */ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ -/* jshint ignore:end */ - -var Q = require('q'); /* jshint ignore:line */ -var _ = require('lodash'); /* jshint ignore:line */ -var util = require('util'); /* jshint ignore:line */ -var Page = require('../../../../base/Page'); /* jshint ignore:line */ -var deserialize = require( - '../../../../base/deserialize'); /* jshint ignore:line */ -var serialize = require('../../../../base/serialize'); /* jshint ignore:line */ -var values = require('../../../../base/values'); /* jshint ignore:line */ - -var ParticipantList; -var ParticipantPage; -var ParticipantInstance; -var ParticipantContext; - -/* jshint ignore:start */ -/** - * Initialize the ParticipantList - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.SessionContext.ParticipantList - * - * @param {Twilio.Messaging.V1} version - Version of the resource - * @param {string} sessionSid - The SID of the Session for the participant - */ -/* jshint ignore:end */ -ParticipantList = function ParticipantList(version, sessionSid) { - /* jshint ignore:start */ - /** - * @function participants - * @memberof Twilio.Messaging.V1.SessionContext# - * - * @param {string} sid - sid of instance - * - * @returns {Twilio.Messaging.V1.SessionContext.ParticipantContext} - */ - /* jshint ignore:end */ - function ParticipantListInstance(sid) { - return ParticipantListInstance.get(sid); - } - - ParticipantListInstance._version = version; - // Path Solution - ParticipantListInstance._solution = {sessionSid: sessionSid}; - ParticipantListInstance._uri = `/Sessions/${sessionSid}/Participants`; - /* jshint ignore:start */ - /** - * create a ParticipantInstance - * - * @function create - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantList# - * - * @param {object} [opts] - Options for request - * @param {string} [opts.attributes] - - * A JSON string that stores application-specific data - * @param {string} [opts.twilioAddress] - - * The address of the Twilio phone number that the participant is in contact with - * @param {Date} [opts.dateCreated] - - * The ISO 8601 date and time in GMT when the resource was created - * @param {Date} [opts.dateUpdated] - - * The ISO 8601 date and time in GMT when the resource was updated - * @param {string} [opts.identity] - The string that identifies the resource's User - * @param {string} [opts.userAddress] - The address of the participant's device - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed ParticipantInstance - */ - /* jshint ignore:end */ - ParticipantListInstance.create = function create(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - - var deferred = Q.defer(); - var data = values.of({ - 'Identity': _.get(opts, 'identity'), - 'UserAddress': _.get(opts, 'userAddress'), - 'Attributes': _.get(opts, 'attributes'), - 'TwilioAddress': _.get(opts, 'twilioAddress'), - 'DateCreated': serialize.iso8601DateTime(_.get(opts, 'dateCreated')), - 'DateUpdated': serialize.iso8601DateTime(_.get(opts, 'dateUpdated')) - }); - - var promise = this._version.create({uri: this._uri, method: 'POST', data: data}); - - promise = promise.then(function(payload) { - deferred.resolve(new ParticipantInstance( - this._version, - payload, - this._solution.sessionSid, - this._solution.sid - )); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; - }; - - /* jshint ignore:start */ - /** - * Streams ParticipantInstance records from the API. - * - * This operation lazily loads records as efficiently as possible until the limit - * is reached. - * - * The results are passed into the callback function, so this operation is memory - * efficient. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @function each - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantList# - * - * @param {object} [opts] - Options for request - * @param {number} [opts.limit] - - * Upper limit for the number of records to return. - * each() guarantees never to return more than limit. - * Default is no limit - * @param {number} [opts.pageSize] - - * Number of records to fetch per request, - * when not set will use the default value of 50 records. - * If no pageSize is defined but a limit is defined, - * each() will attempt to read the limit with the most efficient - * page size, i.e. min(limit, 1000) - * @param {Function} [opts.callback] - - * Function to process each record. If this and a positional - * callback are passed, this one will be used - * @param {Function} [opts.done] - - * Function to be called upon completion of streaming - * @param {Function} [callback] - Function to process each record - */ - /* jshint ignore:end */ - ParticipantListInstance.each = function each(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - if (opts.callback) { - callback = opts.callback; - } - if (_.isUndefined(callback)) { - throw new Error('Callback function must be provided'); - } - - var done = false; - var currentPage = 1; - var currentResource = 0; - var limits = this._version.readLimits({ - limit: opts.limit, - pageSize: opts.pageSize - }); - - function onComplete(error) { - done = true; - if (_.isFunction(opts.done)) { - opts.done(error); - } - } - - function fetchNextPage(fn) { - var promise = fn(); - if (_.isUndefined(promise)) { - onComplete(); - return; - } - - promise.then(function(page) { - _.each(page.instances, function(instance) { - if (done || (!_.isUndefined(opts.limit) && currentResource >= opts.limit)) { - done = true; - return false; - } - - currentResource++; - callback(instance, onComplete); - }); - - if ((limits.pageLimit && limits.pageLimit <= currentPage)) { - onComplete(); - } else if (!done) { - currentPage++; - fetchNextPage(_.bind(page.nextPage, page)); - } - }); - - promise.catch(onComplete); - } - - fetchNextPage(_.bind(this.page, this, _.merge(opts, limits))); - }; - - /* jshint ignore:start */ - /** - * Lists ParticipantInstance records from the API as a list. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @function list - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantList# - * - * @param {object} [opts] - Options for request - * @param {number} [opts.limit] - - * Upper limit for the number of records to return. - * list() guarantees never to return more than limit. - * Default is no limit - * @param {number} [opts.pageSize] - - * Number of records to fetch per request, - * when not set will use the default value of 50 records. - * If no page_size is defined but a limit is defined, - * list() will attempt to read the limit with the most - * efficient page size, i.e. min(limit, 1000) - * @param {function} [callback] - Callback to handle list of records - * - * @returns {Promise} Resolves to a list of records - */ - /* jshint ignore:end */ - ParticipantListInstance.list = function list(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - var deferred = Q.defer(); - var allResources = []; - opts.callback = function(resource, done) { - allResources.push(resource); - - if (!_.isUndefined(opts.limit) && allResources.length === opts.limit) { - done(); - } - }; - - opts.done = function(error) { - if (_.isUndefined(error)) { - deferred.resolve(allResources); - } else { - deferred.reject(error); - } - }; - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - this.each(opts); - return deferred.promise; - }; - - /* jshint ignore:start */ - /** - * Retrieve a single page of ParticipantInstance records from the API. - * - * The request is executed immediately. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @function page - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantList# - * - * @param {object} [opts] - Options for request - * @param {string} [opts.pageToken] - PageToken provided by the API - * @param {number} [opts.pageNumber] - - * Page Number, this value is simply for client state - * @param {number} [opts.pageSize] - Number of records to return, defaults to 50 - * @param {function} [callback] - Callback to handle list of records - * - * @returns {Promise} Resolves to a list of records - */ - /* jshint ignore:end */ - ParticipantListInstance.page = function page(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - - var deferred = Q.defer(); - var data = values.of({ - 'PageToken': opts.pageToken, - 'Page': opts.pageNumber, - 'PageSize': opts.pageSize - }); - - var promise = this._version.page({uri: this._uri, method: 'GET', params: data}); - - promise = promise.then(function(payload) { - deferred.resolve(new ParticipantPage(this._version, payload, this._solution)); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; - }; - - /* jshint ignore:start */ - /** - * Retrieve a single target page of ParticipantInstance records from the API. - * - * The request is executed immediately. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @function getPage - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantList# - * - * @param {string} [targetUrl] - API-generated URL for the requested results page - * @param {function} [callback] - Callback to handle list of records - * - * @returns {Promise} Resolves to a list of records - */ - /* jshint ignore:end */ - ParticipantListInstance.getPage = function getPage(targetUrl, callback) { - var deferred = Q.defer(); - - var promise = this._version._domain.twilio.request({method: 'GET', uri: targetUrl}); - - promise = promise.then(function(payload) { - deferred.resolve(new ParticipantPage(this._version, payload, this._solution)); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; - }; - - /* jshint ignore:start */ - /** - * Constructs a participant - * - * @function get - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantList# - * - * @param {string} sid - The SID that identifies the resource to fetch - * - * @returns {Twilio.Messaging.V1.SessionContext.ParticipantContext} - */ - /* jshint ignore:end */ - ParticipantListInstance.get = function get(sid) { - return new ParticipantContext(this._version, this._solution.sessionSid, sid); - }; - - /* jshint ignore:start */ - /** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantList# - * - * @returns Object - */ - /* jshint ignore:end */ - ParticipantListInstance.toJSON = function toJSON() { - return this._solution; - }; - - ParticipantListInstance[util.inspect.custom] = function inspect(depth, options) - { - return util.inspect(this.toJSON(), options); - }; - - return ParticipantListInstance; -}; - - -/* jshint ignore:start */ -/** - * Initialize the ParticipantPage - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.SessionContext.ParticipantPage - * - * @param {V1} version - Version of the resource - * @param {Response} response - Response from the API - * @param {ParticipantSolution} solution - Path solution - * - * @returns ParticipantPage - */ -/* jshint ignore:end */ -ParticipantPage = function ParticipantPage(version, response, solution) { - // Path Solution - this._solution = solution; - - Page.prototype.constructor.call(this, version, response, this._solution); -}; - -_.extend(ParticipantPage.prototype, Page.prototype); -ParticipantPage.prototype.constructor = ParticipantPage; - -/* jshint ignore:start */ -/** - * Build an instance of ParticipantInstance - * - * @function getInstance - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantPage# - * - * @param {ParticipantPayload} payload - Payload response from the API - * - * @returns ParticipantInstance - */ -/* jshint ignore:end */ -ParticipantPage.prototype.getInstance = function getInstance(payload) { - return new ParticipantInstance(this._version, payload, this._solution.sessionSid); -}; - -/* jshint ignore:start */ -/** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantPage# - * - * @returns Object - */ -/* jshint ignore:end */ -ParticipantPage.prototype.toJSON = function toJSON() { - let clone = {}; - _.forOwn(this, function(value, key) { - if (!_.startsWith(key, '_') && ! _.isFunction(value)) { - clone[key] = value; - } - }); - return clone; -}; - -ParticipantPage.prototype[util.inspect.custom] = function inspect(depth, - options) { - return util.inspect(this.toJSON(), options); -}; - - -/* jshint ignore:start */ -/** - * Initialize the ParticipantContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.SessionContext.ParticipantInstance - * - * @property {string} accountSid - The SID of the Account that created the resource - * @property {string} serviceSid - The SID of the Service the session belongs to - * @property {string} messagingServiceSid - - * The SID of the SMS Service the session belongs to - * @property {string} sessionSid - The SID of the Session for the participant - * @property {string} sid - The unique string that identifies the resource - * @property {string} identity - The string that identifies the resource's User - * @property {string} twilioAddress - - * The address of the Twilio phone number that the participant is in contact with - * @property {string} userAddress - The address of the participant's device - * @property {string} attributes - - * The JSON string that stores application-specific data - * @property {participant.participant_type} type - - * The type of messaging used by the participant - * @property {Date} dateCreated - - * The ISO 8601 date and time in GMT when the resource was created - * @property {Date} dateUpdated - - * The ISO 8601 date and time in GMT when the resource was last updated - * @property {string} url - The absolute URL of the participant - * - * @param {V1} version - Version of the resource - * @param {ParticipantPayload} payload - The instance payload - * @param {sid} sessionSid - The SID of the Session for the participant - * @param {sid_like} sid - The SID that identifies the resource to fetch - */ -/* jshint ignore:end */ -ParticipantInstance = function ParticipantInstance(version, payload, sessionSid, - sid) { - this._version = version; - - // Marshaled Properties - this.accountSid = payload.account_sid; // jshint ignore:line - this.serviceSid = payload.service_sid; // jshint ignore:line - this.messagingServiceSid = payload.messaging_service_sid; // jshint ignore:line - this.sessionSid = payload.session_sid; // jshint ignore:line - this.sid = payload.sid; // jshint ignore:line - this.identity = payload.identity; // jshint ignore:line - this.twilioAddress = payload.twilio_address; // jshint ignore:line - this.userAddress = payload.user_address; // jshint ignore:line - this.attributes = payload.attributes; // jshint ignore:line - this.type = payload.type; // jshint ignore:line - this.dateCreated = deserialize.iso8601DateTime(payload.date_created); // jshint ignore:line - this.dateUpdated = deserialize.iso8601DateTime(payload.date_updated); // jshint ignore:line - this.url = payload.url; // jshint ignore:line - - // Context - this._context = undefined; - this._solution = {sessionSid: sessionSid, sid: sid || this.sid, }; -}; - -Object.defineProperty(ParticipantInstance.prototype, - '_proxy', { - get: function() { - if (!this._context) { - this._context = new ParticipantContext( - this._version, - this._solution.sessionSid, - this._solution.sid - ); - } - - return this._context; - } -}); - -/* jshint ignore:start */ -/** - * update a ParticipantInstance - * - * @function update - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantInstance# - * - * @param {object} [opts] - Options for request - * @param {string} [opts.attributes] - - * A JSON string that stores application-specific data - * @param {Date} [opts.dateCreated] - - * The ISO 8601 date and time in GMT when the resource was created - * @param {Date} [opts.dateUpdated] - - * The ISO 8601 date and time in GMT when the resource was updated - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed ParticipantInstance - */ -/* jshint ignore:end */ -ParticipantInstance.prototype.update = function update(opts, callback) { - return this._proxy.update(opts, callback); -}; - -/* jshint ignore:start */ -/** - * fetch a ParticipantInstance - * - * @function fetch - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantInstance# - * - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed ParticipantInstance - */ -/* jshint ignore:end */ -ParticipantInstance.prototype.fetch = function fetch(callback) { - return this._proxy.fetch(callback); -}; - -/* jshint ignore:start */ -/** - * remove a ParticipantInstance - * - * @function remove - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantInstance# - * - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed ParticipantInstance - */ -/* jshint ignore:end */ -ParticipantInstance.prototype.remove = function remove(callback) { - return this._proxy.remove(callback); -}; - -/* jshint ignore:start */ -/** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantInstance# - * - * @returns Object - */ -/* jshint ignore:end */ -ParticipantInstance.prototype.toJSON = function toJSON() { - let clone = {}; - _.forOwn(this, function(value, key) { - if (!_.startsWith(key, '_') && ! _.isFunction(value)) { - clone[key] = value; - } - }); - return clone; -}; - -ParticipantInstance.prototype[util.inspect.custom] = function inspect(depth, - options) { - return util.inspect(this.toJSON(), options); -}; - - -/* jshint ignore:start */ -/** - * Initialize the ParticipantContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.SessionContext.ParticipantContext - * - * @param {V1} version - Version of the resource - * @param {sid} sessionSid - The SID of the Session with the participant to fetch - * @param {sid_like} sid - The SID that identifies the resource to fetch - */ -/* jshint ignore:end */ -ParticipantContext = function ParticipantContext(version, sessionSid, sid) { - this._version = version; - - // Path Solution - this._solution = {sessionSid: sessionSid, sid: sid, }; - this._uri = `/Sessions/${sessionSid}/Participants/${sid}`; -}; - -/* jshint ignore:start */ -/** - * update a ParticipantInstance - * - * @function update - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantContext# - * - * @param {object} [opts] - Options for request - * @param {string} [opts.attributes] - - * A JSON string that stores application-specific data - * @param {Date} [opts.dateCreated] - - * The ISO 8601 date and time in GMT when the resource was created - * @param {Date} [opts.dateUpdated] - - * The ISO 8601 date and time in GMT when the resource was updated - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed ParticipantInstance - */ -/* jshint ignore:end */ -ParticipantContext.prototype.update = function update(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - - var deferred = Q.defer(); - var data = values.of({ - 'Attributes': _.get(opts, 'attributes'), - 'DateCreated': serialize.iso8601DateTime(_.get(opts, 'dateCreated')), - 'DateUpdated': serialize.iso8601DateTime(_.get(opts, 'dateUpdated')) - }); - - var promise = this._version.update({uri: this._uri, method: 'POST', data: data}); - - promise = promise.then(function(payload) { - deferred.resolve(new ParticipantInstance( - this._version, - payload, - this._solution.sessionSid, - this._solution.sid - )); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; -}; - -/* jshint ignore:start */ -/** - * fetch a ParticipantInstance - * - * @function fetch - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantContext# - * - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed ParticipantInstance - */ -/* jshint ignore:end */ -ParticipantContext.prototype.fetch = function fetch(callback) { - var deferred = Q.defer(); - var promise = this._version.fetch({uri: this._uri, method: 'GET'}); - - promise = promise.then(function(payload) { - deferred.resolve(new ParticipantInstance( - this._version, - payload, - this._solution.sessionSid, - this._solution.sid - )); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; -}; - -/* jshint ignore:start */ -/** - * remove a ParticipantInstance - * - * @function remove - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantContext# - * - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed ParticipantInstance - */ -/* jshint ignore:end */ -ParticipantContext.prototype.remove = function remove(callback) { - var deferred = Q.defer(); - var promise = this._version.remove({uri: this._uri, method: 'DELETE'}); - - promise = promise.then(function(payload) { - deferred.resolve(payload); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; -}; - -/* jshint ignore:start */ -/** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.SessionContext.ParticipantContext# - * - * @returns Object - */ -/* jshint ignore:end */ -ParticipantContext.prototype.toJSON = function toJSON() { - return this._solution; -}; - -ParticipantContext.prototype[util.inspect.custom] = function inspect(depth, - options) { - return util.inspect(this.toJSON(), options); -}; - -module.exports = { - ParticipantList: ParticipantList, - ParticipantPage: ParticipantPage, - ParticipantInstance: ParticipantInstance, - ParticipantContext: ParticipantContext -}; diff --git a/lib/rest/messaging/v1/session/webhook.d.ts b/lib/rest/messaging/v1/session/webhook.d.ts deleted file mode 100644 index 72bda3249e..0000000000 --- a/lib/rest/messaging/v1/session/webhook.d.ts +++ /dev/null @@ -1,350 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -import Page = require('../../../../base/Page'); -import Response = require('../../../../http/response'); -import V1 = require('../../V1'); -import serialize = require('../../../../base/serialize'); -import { SerializableClass } from '../../../../interfaces'; - -type WebhookMethod = 'GET'|'POST'; - -type WebhookTarget = 'webhook'|'trigger'|'studio'; - -/** - * Initialize the WebhookList - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param sessionSid - The SID of the Session for the webhook - */ -declare function WebhookList(version: V1, sessionSid: string): WebhookListInstance; - -/** - * Options to pass to update - * - * @property configuration.bufferMessages - Whether buffering should be applied to messages - * @property configuration.bufferWindow - The period to buffer messages - * @property configuration.filters - The list of events that trigger a webhook event for the Session - * @property configuration.flowSid - The SID of the studio flow where the webhook should be sent to - * @property configuration.method - The HTTP method we should use when sending a webhook request to url - * @property configuration.retryCount - The number of times to try the webhook request if the first attempt fails - * @property configuration.triggers - The list of keywords, that trigger a webhook event for the Session - * @property configuration.url - The absolute URL the webhook request should be sent to - */ -interface WebhookInstanceUpdateOptions { - configuration?: { - url?: string; - method?: WebhookMethod; - filters?: string | string[]; - triggers?: string | string[]; - flowSid?: string; - retryCount?: number; - bufferMessages?: boolean; - bufferWindow?: number; - }; -} - -interface WebhookListInstance { - /** - * @param sid - sid of instance - */ - (sid: string): WebhookContext; - /** - * create a WebhookInstance - * - * @param opts - Options for request - * @param callback - Callback to handle processed record - */ - create(opts: WebhookListInstanceCreateOptions, callback?: (error: Error | null, item: WebhookInstance) => any): Promise; - /** - * Streams WebhookInstance records from the API. - * - * This operation lazily loads records as efficiently as possible until the limit - * is reached. - * - * The results are passed into the callback function, so this operation is memory - * efficient. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param opts - Options for request - * @param callback - Function to process each record - */ - each(opts?: WebhookListInstanceEachOptions, callback?: (item: WebhookInstance, done: (err?: Error) => void) => void): void; - /** - * Constructs a webhook - * - * @param sid - The SID of the resource to fetch - */ - get(sid: string): WebhookContext; - /** - * Retrieve a single target page of WebhookInstance records from the API. - * - * The request is executed immediately. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param targetUrl - API-generated URL for the requested results page - * @param callback - Callback to handle list of records - */ - getPage(targetUrl?: string, callback?: (error: Error | null, items: WebhookPage) => any): Promise; - /** - * Lists WebhookInstance records from the API as a list. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param opts - Options for request - * @param callback - Callback to handle list of records - */ - list(opts?: WebhookListInstanceOptions, callback?: (error: Error | null, items: WebhookInstance[]) => any): Promise; - /** - * Retrieve a single page of WebhookInstance records from the API. - * - * The request is executed immediately. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @param opts - Options for request - * @param callback - Callback to handle list of records - */ - page(opts?: WebhookListInstancePageOptions, callback?: (error: Error | null, items: WebhookPage) => any): Promise; - /** - * Provide a user-friendly representation - */ - toJSON(): any; -} - -/** - * Options to pass to create - * - * @property configuration.bufferMessages - Whether buffering should be applied to messages - * @property configuration.bufferWindow - The period to buffer messages - * @property configuration.filters - The list of events that trigger a webhook event for the Session - * @property configuration.flowSid - The SID of the studio flow where the webhook should be sent to - * @property configuration.method - The HTTP method we should use when sending a webhook request to url - * @property configuration.replayAfter - The message index for which and its successors the webhook will be replayed - * @property configuration.retryCount - The number of times to call the webhook request if the first attempt fails - * @property configuration.triggers - The list of keywords, firing webhook event for the Session - * @property configuration.url - The absolute URL the webhook request should be sent to - * @property target - The target of the webhook - */ -interface WebhookListInstanceCreateOptions { - configuration?: { - url?: string; - method?: WebhookMethod; - filters?: string | string[]; - triggers?: string | string[]; - flowSid?: string; - retryCount?: number; - replayAfter?: number; - bufferMessages?: boolean; - bufferWindow?: number; - }; - target: WebhookTarget; -} - -/** - * Options to pass to each - * - * @property callback - - * Function to process each record. If this and a positional - * callback are passed, this one will be used - * @property done - Function to be called upon completion of streaming - * @property limit - - * Upper limit for the number of records to return. - * each() guarantees never to return more than limit. - * Default is no limit - * @property pageSize - - * Number of records to fetch per request, - * when not set will use the default value of 50 records. - * If no pageSize is defined but a limit is defined, - * each() will attempt to read the limit with the most efficient - * page size, i.e. min(limit, 1000) - */ -interface WebhookListInstanceEachOptions { - callback?: (item: WebhookInstance, done: (err?: Error) => void) => void; - done?: Function; - limit?: number; - pageSize?: number; -} - -/** - * Options to pass to list - * - * @property limit - - * Upper limit for the number of records to return. - * list() guarantees never to return more than limit. - * Default is no limit - * @property pageSize - - * Number of records to fetch per request, - * when not set will use the default value of 50 records. - * If no page_size is defined but a limit is defined, - * list() will attempt to read the limit with the most - * efficient page size, i.e. min(limit, 1000) - */ -interface WebhookListInstanceOptions { - limit?: number; - pageSize?: number; -} - -/** - * Options to pass to page - * - * @property pageNumber - Page Number, this value is simply for client state - * @property pageSize - Number of records to return, defaults to 50 - * @property pageToken - PageToken provided by the API - */ -interface WebhookListInstancePageOptions { - pageNumber?: number; - pageSize?: number; - pageToken?: string; -} - -interface WebhookPayload extends WebhookResource, Page.TwilioResponsePayload { -} - -interface WebhookResource { - account_sid: string; - configuration: object; - date_created: Date; - date_updated: Date; - session_sid: string; - sid: string; - target: string; - url: string; -} - -interface WebhookSolution { - sessionSid?: string; -} - - -declare class WebhookContext { - /** - * Initialize the WebhookContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param sessionSid - The SID of the Session with the Webhook resource to fetch - * @param sid - The SID of the resource to fetch - */ - constructor(version: V1, sessionSid: string, sid: string); - - /** - * fetch a WebhookInstance - * - * @param callback - Callback to handle processed record - */ - fetch(callback?: (error: Error | null, items: WebhookInstance) => any): Promise; - /** - * remove a WebhookInstance - * - * @param callback - Callback to handle processed record - */ - remove(callback?: (error: Error | null, items: WebhookInstance) => any): Promise; - /** - * Provide a user-friendly representation - */ - toJSON(): any; - /** - * update a WebhookInstance - * - * @param opts - Options for request - * @param callback - Callback to handle processed record - */ - update(opts?: WebhookInstanceUpdateOptions, callback?: (error: Error | null, items: WebhookInstance) => any): Promise; -} - - -declare class WebhookInstance extends SerializableClass { - /** - * Initialize the WebhookContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param payload - The instance payload - * @param sessionSid - The SID of the Session for the webhook - * @param sid - The SID of the resource to fetch - */ - constructor(version: V1, payload: WebhookPayload, sessionSid: string, sid: string); - - private _proxy: WebhookContext; - accountSid: string; - configuration: object; - dateCreated: Date; - dateUpdated: Date; - /** - * fetch a WebhookInstance - * - * @param callback - Callback to handle processed record - */ - fetch(callback?: (error: Error | null, items: WebhookInstance) => any): Promise; - /** - * remove a WebhookInstance - * - * @param callback - Callback to handle processed record - */ - remove(callback?: (error: Error | null, items: WebhookInstance) => any): Promise; - sessionSid: string; - sid: string; - target: string; - /** - * Provide a user-friendly representation - */ - toJSON(): any; - /** - * update a WebhookInstance - * - * @param opts - Options for request - * @param callback - Callback to handle processed record - */ - update(opts?: WebhookInstanceUpdateOptions, callback?: (error: Error | null, items: WebhookInstance) => any): Promise; - url: string; -} - - -declare class WebhookPage extends Page { - /** - * Initialize the WebhookPage - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param response - Response from the API - * @param solution - Path solution - */ - constructor(version: V1, response: Response, solution: WebhookSolution); - - /** - * Build an instance of WebhookInstance - * - * @param payload - Payload response from the API - */ - getInstance(payload: WebhookPayload): WebhookInstance; - /** - * Provide a user-friendly representation - */ - toJSON(): any; -} - -export { WebhookContext, WebhookInstance, WebhookInstanceUpdateOptions, WebhookList, WebhookListInstance, WebhookListInstanceCreateOptions, WebhookListInstanceEachOptions, WebhookListInstanceOptions, WebhookListInstancePageOptions, WebhookMethod, WebhookPage, WebhookPayload, WebhookResource, WebhookSolution, WebhookTarget } diff --git a/lib/rest/messaging/v1/session/webhook.js b/lib/rest/messaging/v1/session/webhook.js deleted file mode 100644 index a8e1836fdd..0000000000 --- a/lib/rest/messaging/v1/session/webhook.js +++ /dev/null @@ -1,817 +0,0 @@ -'use strict'; - -/* jshint ignore:start */ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ -/* jshint ignore:end */ - -var Q = require('q'); /* jshint ignore:line */ -var _ = require('lodash'); /* jshint ignore:line */ -var util = require('util'); /* jshint ignore:line */ -var Page = require('../../../../base/Page'); /* jshint ignore:line */ -var deserialize = require( - '../../../../base/deserialize'); /* jshint ignore:line */ -var serialize = require('../../../../base/serialize'); /* jshint ignore:line */ -var values = require('../../../../base/values'); /* jshint ignore:line */ - -var WebhookList; -var WebhookPage; -var WebhookInstance; -var WebhookContext; - -/* jshint ignore:start */ -/** - * Initialize the WebhookList - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.SessionContext.WebhookList - * - * @param {Twilio.Messaging.V1} version - Version of the resource - * @param {string} sessionSid - The SID of the Session for the webhook - */ -/* jshint ignore:end */ -WebhookList = function WebhookList(version, sessionSid) { - /* jshint ignore:start */ - /** - * @function webhooks - * @memberof Twilio.Messaging.V1.SessionContext# - * - * @param {string} sid - sid of instance - * - * @returns {Twilio.Messaging.V1.SessionContext.WebhookContext} - */ - /* jshint ignore:end */ - function WebhookListInstance(sid) { - return WebhookListInstance.get(sid); - } - - WebhookListInstance._version = version; - // Path Solution - WebhookListInstance._solution = {sessionSid: sessionSid}; - WebhookListInstance._uri = `/Sessions/${sessionSid}/Webhooks`; - /* jshint ignore:start */ - /** - * Streams WebhookInstance records from the API. - * - * This operation lazily loads records as efficiently as possible until the limit - * is reached. - * - * The results are passed into the callback function, so this operation is memory - * efficient. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @function each - * @memberof Twilio.Messaging.V1.SessionContext.WebhookList# - * - * @param {object} [opts] - Options for request - * @param {number} [opts.limit] - - * Upper limit for the number of records to return. - * each() guarantees never to return more than limit. - * Default is no limit - * @param {number} [opts.pageSize] - - * Number of records to fetch per request, - * when not set will use the default value of 50 records. - * If no pageSize is defined but a limit is defined, - * each() will attempt to read the limit with the most efficient - * page size, i.e. min(limit, 1000) - * @param {Function} [opts.callback] - - * Function to process each record. If this and a positional - * callback are passed, this one will be used - * @param {Function} [opts.done] - - * Function to be called upon completion of streaming - * @param {Function} [callback] - Function to process each record - */ - /* jshint ignore:end */ - WebhookListInstance.each = function each(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - if (opts.callback) { - callback = opts.callback; - } - if (_.isUndefined(callback)) { - throw new Error('Callback function must be provided'); - } - - var done = false; - var currentPage = 1; - var currentResource = 0; - var limits = this._version.readLimits({ - limit: opts.limit, - pageSize: opts.pageSize - }); - - function onComplete(error) { - done = true; - if (_.isFunction(opts.done)) { - opts.done(error); - } - } - - function fetchNextPage(fn) { - var promise = fn(); - if (_.isUndefined(promise)) { - onComplete(); - return; - } - - promise.then(function(page) { - _.each(page.instances, function(instance) { - if (done || (!_.isUndefined(opts.limit) && currentResource >= opts.limit)) { - done = true; - return false; - } - - currentResource++; - callback(instance, onComplete); - }); - - if ((limits.pageLimit && limits.pageLimit <= currentPage)) { - onComplete(); - } else if (!done) { - currentPage++; - fetchNextPage(_.bind(page.nextPage, page)); - } - }); - - promise.catch(onComplete); - } - - fetchNextPage(_.bind(this.page, this, _.merge(opts, limits))); - }; - - /* jshint ignore:start */ - /** - * Lists WebhookInstance records from the API as a list. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @function list - * @memberof Twilio.Messaging.V1.SessionContext.WebhookList# - * - * @param {object} [opts] - Options for request - * @param {number} [opts.limit] - - * Upper limit for the number of records to return. - * list() guarantees never to return more than limit. - * Default is no limit - * @param {number} [opts.pageSize] - - * Number of records to fetch per request, - * when not set will use the default value of 50 records. - * If no page_size is defined but a limit is defined, - * list() will attempt to read the limit with the most - * efficient page size, i.e. min(limit, 1000) - * @param {function} [callback] - Callback to handle list of records - * - * @returns {Promise} Resolves to a list of records - */ - /* jshint ignore:end */ - WebhookListInstance.list = function list(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - var deferred = Q.defer(); - var allResources = []; - opts.callback = function(resource, done) { - allResources.push(resource); - - if (!_.isUndefined(opts.limit) && allResources.length === opts.limit) { - done(); - } - }; - - opts.done = function(error) { - if (_.isUndefined(error)) { - deferred.resolve(allResources); - } else { - deferred.reject(error); - } - }; - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - this.each(opts); - return deferred.promise; - }; - - /* jshint ignore:start */ - /** - * Retrieve a single page of WebhookInstance records from the API. - * - * The request is executed immediately. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @function page - * @memberof Twilio.Messaging.V1.SessionContext.WebhookList# - * - * @param {object} [opts] - Options for request - * @param {string} [opts.pageToken] - PageToken provided by the API - * @param {number} [opts.pageNumber] - - * Page Number, this value is simply for client state - * @param {number} [opts.pageSize] - Number of records to return, defaults to 50 - * @param {function} [callback] - Callback to handle list of records - * - * @returns {Promise} Resolves to a list of records - */ - /* jshint ignore:end */ - WebhookListInstance.page = function page(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - - var deferred = Q.defer(); - var data = values.of({ - 'PageToken': opts.pageToken, - 'Page': opts.pageNumber, - 'PageSize': opts.pageSize - }); - - var promise = this._version.page({uri: this._uri, method: 'GET', params: data}); - - promise = promise.then(function(payload) { - deferred.resolve(new WebhookPage(this._version, payload, this._solution)); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; - }; - - /* jshint ignore:start */ - /** - * Retrieve a single target page of WebhookInstance records from the API. - * - * The request is executed immediately. - * - * If a function is passed as the first argument, it will be used as the callback - * function. - * - * @function getPage - * @memberof Twilio.Messaging.V1.SessionContext.WebhookList# - * - * @param {string} [targetUrl] - API-generated URL for the requested results page - * @param {function} [callback] - Callback to handle list of records - * - * @returns {Promise} Resolves to a list of records - */ - /* jshint ignore:end */ - WebhookListInstance.getPage = function getPage(targetUrl, callback) { - var deferred = Q.defer(); - - var promise = this._version._domain.twilio.request({method: 'GET', uri: targetUrl}); - - promise = promise.then(function(payload) { - deferred.resolve(new WebhookPage(this._version, payload, this._solution)); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; - }; - - /* jshint ignore:start */ - /** - * create a WebhookInstance - * - * @function create - * @memberof Twilio.Messaging.V1.SessionContext.WebhookList# - * - * @param {object} opts - Options for request - * @param {webhook.target} opts.target - The target of the webhook - * @param {string} [opts.configuration.url] - - * The absolute URL the webhook request should be sent to - * @param {webhook.method} [opts.configuration.method] - - * The HTTP method we should use when sending a webhook request to url - * @param {string|list} [opts.configuration.filters] - - * The list of events that trigger a webhook event for the Session - * @param {string|list} [opts.configuration.triggers] - - * The list of keywords, firing webhook event for the Session - * @param {string} [opts.configuration.flowSid] - - * The SID of the studio flow where the webhook should be sent to - * @param {number} [opts.configuration.retryCount] - - * The number of times to call the webhook request if the first attempt fails - * @param {number} [opts.configuration.replayAfter] - - * The message index for which and its successors the webhook will be replayed - * @param {boolean} [opts.configuration.bufferMessages] - - * Whether buffering should be applied to messages - * @param {number} [opts.configuration.bufferWindow] - - * The period to buffer messages - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed WebhookInstance - */ - /* jshint ignore:end */ - WebhookListInstance.create = function create(opts, callback) { - if (_.isUndefined(opts)) { - throw new Error('Required parameter "opts" missing.'); - } - if (_.isUndefined(opts.target)) { - throw new Error('Required parameter "opts.target" missing.'); - } - - var deferred = Q.defer(); - var data = values.of({ - 'Target': _.get(opts, 'target'), - 'Configuration.Url': _.get(opts, 'configuration.url'), - 'Configuration.Method': _.get(opts, 'configuration.method'), - 'Configuration.Filters': serialize.map(_.get(opts, 'configuration.filters'), function(e) { return e; }), - 'Configuration.Triggers': serialize.map(_.get(opts, 'configuration.triggers'), function(e) { return e; }), - 'Configuration.FlowSid': _.get(opts, 'configuration.flowSid'), - 'Configuration.RetryCount': _.get(opts, 'configuration.retryCount'), - 'Configuration.ReplayAfter': _.get(opts, 'configuration.replayAfter'), - 'Configuration.BufferMessages': serialize.bool(_.get(opts, 'configuration.bufferMessages')), - 'Configuration.BufferWindow': _.get(opts, 'configuration.bufferWindow') - }); - - var promise = this._version.create({uri: this._uri, method: 'POST', data: data}); - - promise = promise.then(function(payload) { - deferred.resolve(new WebhookInstance( - this._version, - payload, - this._solution.sessionSid, - this._solution.sid - )); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; - }; - - /* jshint ignore:start */ - /** - * Constructs a webhook - * - * @function get - * @memberof Twilio.Messaging.V1.SessionContext.WebhookList# - * - * @param {string} sid - The SID of the resource to fetch - * - * @returns {Twilio.Messaging.V1.SessionContext.WebhookContext} - */ - /* jshint ignore:end */ - WebhookListInstance.get = function get(sid) { - return new WebhookContext(this._version, this._solution.sessionSid, sid); - }; - - /* jshint ignore:start */ - /** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.SessionContext.WebhookList# - * - * @returns Object - */ - /* jshint ignore:end */ - WebhookListInstance.toJSON = function toJSON() { - return this._solution; - }; - - WebhookListInstance[util.inspect.custom] = function inspect(depth, options) { - return util.inspect(this.toJSON(), options); - }; - - return WebhookListInstance; -}; - - -/* jshint ignore:start */ -/** - * Initialize the WebhookPage - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.SessionContext.WebhookPage - * - * @param {V1} version - Version of the resource - * @param {Response} response - Response from the API - * @param {WebhookSolution} solution - Path solution - * - * @returns WebhookPage - */ -/* jshint ignore:end */ -WebhookPage = function WebhookPage(version, response, solution) { - // Path Solution - this._solution = solution; - - Page.prototype.constructor.call(this, version, response, this._solution); -}; - -_.extend(WebhookPage.prototype, Page.prototype); -WebhookPage.prototype.constructor = WebhookPage; - -/* jshint ignore:start */ -/** - * Build an instance of WebhookInstance - * - * @function getInstance - * @memberof Twilio.Messaging.V1.SessionContext.WebhookPage# - * - * @param {WebhookPayload} payload - Payload response from the API - * - * @returns WebhookInstance - */ -/* jshint ignore:end */ -WebhookPage.prototype.getInstance = function getInstance(payload) { - return new WebhookInstance(this._version, payload, this._solution.sessionSid); -}; - -/* jshint ignore:start */ -/** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.SessionContext.WebhookPage# - * - * @returns Object - */ -/* jshint ignore:end */ -WebhookPage.prototype.toJSON = function toJSON() { - let clone = {}; - _.forOwn(this, function(value, key) { - if (!_.startsWith(key, '_') && ! _.isFunction(value)) { - clone[key] = value; - } - }); - return clone; -}; - -WebhookPage.prototype[util.inspect.custom] = function inspect(depth, options) { - return util.inspect(this.toJSON(), options); -}; - - -/* jshint ignore:start */ -/** - * Initialize the WebhookContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.SessionContext.WebhookInstance - * - * @property {string} sid - The unique string that identifies the resource - * @property {string} accountSid - The SID of the Account that created the resource - * @property {string} sessionSid - The SID of the Session for the webhook - * @property {string} target - The target of the webhook - * @property {string} url - The absolute URL of the webhook - * @property {object} configuration - The configuration of the webhook - * @property {Date} dateCreated - - * The ISO 8601 date and time in GMT when the resource was created - * @property {Date} dateUpdated - - * The ISO 8601 date and time in GMT when the resource was last updated - * - * @param {V1} version - Version of the resource - * @param {WebhookPayload} payload - The instance payload - * @param {sid} sessionSid - The SID of the Session for the webhook - * @param {sid} sid - The SID of the resource to fetch - */ -/* jshint ignore:end */ -WebhookInstance = function WebhookInstance(version, payload, sessionSid, sid) { - this._version = version; - - // Marshaled Properties - this.sid = payload.sid; // jshint ignore:line - this.accountSid = payload.account_sid; // jshint ignore:line - this.sessionSid = payload.session_sid; // jshint ignore:line - this.target = payload.target; // jshint ignore:line - this.url = payload.url; // jshint ignore:line - this.configuration = payload.configuration; // jshint ignore:line - this.dateCreated = deserialize.iso8601DateTime(payload.date_created); // jshint ignore:line - this.dateUpdated = deserialize.iso8601DateTime(payload.date_updated); // jshint ignore:line - - // Context - this._context = undefined; - this._solution = {sessionSid: sessionSid, sid: sid || this.sid, }; -}; - -Object.defineProperty(WebhookInstance.prototype, - '_proxy', { - get: function() { - if (!this._context) { - this._context = new WebhookContext(this._version, this._solution.sessionSid, this._solution.sid); - } - - return this._context; - } -}); - -/* jshint ignore:start */ -/** - * fetch a WebhookInstance - * - * @function fetch - * @memberof Twilio.Messaging.V1.SessionContext.WebhookInstance# - * - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed WebhookInstance - */ -/* jshint ignore:end */ -WebhookInstance.prototype.fetch = function fetch(callback) { - return this._proxy.fetch(callback); -}; - -/* jshint ignore:start */ -/** - * update a WebhookInstance - * - * @function update - * @memberof Twilio.Messaging.V1.SessionContext.WebhookInstance# - * - * @param {object} [opts] - Options for request - * @param {string} [opts.configuration.url] - - * The absolute URL the webhook request should be sent to - * @param {webhook.method} [opts.configuration.method] - - * The HTTP method we should use when sending a webhook request to url - * @param {string|list} [opts.configuration.filters] - - * The list of events that trigger a webhook event for the Session - * @param {string|list} [opts.configuration.triggers] - - * The list of keywords, that trigger a webhook event for the Session - * @param {string} [opts.configuration.flowSid] - - * The SID of the studio flow where the webhook should be sent to - * @param {number} [opts.configuration.retryCount] - - * The number of times to try the webhook request if the first attempt fails - * @param {boolean} [opts.configuration.bufferMessages] - - * Whether buffering should be applied to messages - * @param {number} [opts.configuration.bufferWindow] - - * The period to buffer messages - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed WebhookInstance - */ -/* jshint ignore:end */ -WebhookInstance.prototype.update = function update(opts, callback) { - return this._proxy.update(opts, callback); -}; - -/* jshint ignore:start */ -/** - * remove a WebhookInstance - * - * @function remove - * @memberof Twilio.Messaging.V1.SessionContext.WebhookInstance# - * - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed WebhookInstance - */ -/* jshint ignore:end */ -WebhookInstance.prototype.remove = function remove(callback) { - return this._proxy.remove(callback); -}; - -/* jshint ignore:start */ -/** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.SessionContext.WebhookInstance# - * - * @returns Object - */ -/* jshint ignore:end */ -WebhookInstance.prototype.toJSON = function toJSON() { - let clone = {}; - _.forOwn(this, function(value, key) { - if (!_.startsWith(key, '_') && ! _.isFunction(value)) { - clone[key] = value; - } - }); - return clone; -}; - -WebhookInstance.prototype[util.inspect.custom] = function inspect(depth, - options) { - return util.inspect(this.toJSON(), options); -}; - - -/* jshint ignore:start */ -/** - * Initialize the WebhookContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.SessionContext.WebhookContext - * - * @param {V1} version - Version of the resource - * @param {sid} sessionSid - - * The SID of the Session with the Webhook resource to fetch - * @param {sid} sid - The SID of the resource to fetch - */ -/* jshint ignore:end */ -WebhookContext = function WebhookContext(version, sessionSid, sid) { - this._version = version; - - // Path Solution - this._solution = {sessionSid: sessionSid, sid: sid, }; - this._uri = `/Sessions/${sessionSid}/Webhooks/${sid}`; -}; - -/* jshint ignore:start */ -/** - * fetch a WebhookInstance - * - * @function fetch - * @memberof Twilio.Messaging.V1.SessionContext.WebhookContext# - * - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed WebhookInstance - */ -/* jshint ignore:end */ -WebhookContext.prototype.fetch = function fetch(callback) { - var deferred = Q.defer(); - var promise = this._version.fetch({uri: this._uri, method: 'GET'}); - - promise = promise.then(function(payload) { - deferred.resolve(new WebhookInstance( - this._version, - payload, - this._solution.sessionSid, - this._solution.sid - )); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; -}; - -/* jshint ignore:start */ -/** - * update a WebhookInstance - * - * @function update - * @memberof Twilio.Messaging.V1.SessionContext.WebhookContext# - * - * @param {object} [opts] - Options for request - * @param {string} [opts.configuration.url] - - * The absolute URL the webhook request should be sent to - * @param {webhook.method} [opts.configuration.method] - - * The HTTP method we should use when sending a webhook request to url - * @param {string|list} [opts.configuration.filters] - - * The list of events that trigger a webhook event for the Session - * @param {string|list} [opts.configuration.triggers] - - * The list of keywords, that trigger a webhook event for the Session - * @param {string} [opts.configuration.flowSid] - - * The SID of the studio flow where the webhook should be sent to - * @param {number} [opts.configuration.retryCount] - - * The number of times to try the webhook request if the first attempt fails - * @param {boolean} [opts.configuration.bufferMessages] - - * Whether buffering should be applied to messages - * @param {number} [opts.configuration.bufferWindow] - - * The period to buffer messages - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed WebhookInstance - */ -/* jshint ignore:end */ -WebhookContext.prototype.update = function update(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - - var deferred = Q.defer(); - var data = values.of({ - 'Configuration.Url': _.get(opts, 'configuration.url'), - 'Configuration.Method': _.get(opts, 'configuration.method'), - 'Configuration.Filters': serialize.map(_.get(opts, 'configuration.filters'), function(e) { return e; }), - 'Configuration.Triggers': serialize.map(_.get(opts, 'configuration.triggers'), function(e) { return e; }), - 'Configuration.FlowSid': _.get(opts, 'configuration.flowSid'), - 'Configuration.RetryCount': _.get(opts, 'configuration.retryCount'), - 'Configuration.BufferMessages': serialize.bool(_.get(opts, 'configuration.bufferMessages')), - 'Configuration.BufferWindow': _.get(opts, 'configuration.bufferWindow') - }); - - var promise = this._version.update({uri: this._uri, method: 'POST', data: data}); - - promise = promise.then(function(payload) { - deferred.resolve(new WebhookInstance( - this._version, - payload, - this._solution.sessionSid, - this._solution.sid - )); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; -}; - -/* jshint ignore:start */ -/** - * remove a WebhookInstance - * - * @function remove - * @memberof Twilio.Messaging.V1.SessionContext.WebhookContext# - * - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed WebhookInstance - */ -/* jshint ignore:end */ -WebhookContext.prototype.remove = function remove(callback) { - var deferred = Q.defer(); - var promise = this._version.remove({uri: this._uri, method: 'DELETE'}); - - promise = promise.then(function(payload) { - deferred.resolve(payload); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; -}; - -/* jshint ignore:start */ -/** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.SessionContext.WebhookContext# - * - * @returns Object - */ -/* jshint ignore:end */ -WebhookContext.prototype.toJSON = function toJSON() { - return this._solution; -}; - -WebhookContext.prototype[util.inspect.custom] = function inspect(depth, options) - { - return util.inspect(this.toJSON(), options); -}; - -module.exports = { - WebhookList: WebhookList, - WebhookPage: WebhookPage, - WebhookInstance: WebhookInstance, - WebhookContext: WebhookContext -}; diff --git a/lib/rest/messaging/v1/webhook.d.ts b/lib/rest/messaging/v1/webhook.d.ts deleted file mode 100644 index a10d79e86e..0000000000 --- a/lib/rest/messaging/v1/webhook.d.ts +++ /dev/null @@ -1,185 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -import Page = require('../../../base/Page'); -import Response = require('../../../http/response'); -import V1 = require('../V1'); -import serialize = require('../../../base/serialize'); -import { SerializableClass } from '../../../interfaces'; - -type WebhookTarget = 'webhook'|'flex'; - -/** - * Initialize the WebhookList - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - */ -declare function WebhookList(version: V1): WebhookListInstance; - -/** - * Options to pass to update - * - * @property postWebhookRetryCount - The number of times to try the post-event webhook request if the first attempt fails - * @property postWebhookUrl - The absolute URL of the post-event webhook - * @property preWebhookRetryCount - The number of times to try the pre-event webhook request if the first attempt fails - * @property preWebhookUrl - The absolute URL of the pre-event webhook - * @property target - The routing target of the webhook - * @property webhookFilters - The list of webhook event triggers that are enabled for the Service - * @property webhookMethod - The HTTP method to use when sending a webhook request - */ -interface WebhookInstanceUpdateOptions { - postWebhookRetryCount?: number; - postWebhookUrl?: string; - preWebhookRetryCount?: number; - preWebhookUrl?: string; - target?: WebhookTarget; - webhookFilters?: string | string[]; - webhookMethod?: string; -} - -interface WebhookListInstance { - /** - * @param sid - sid of instance - */ - (sid: string): WebhookContext; - /** - * Constructs a webhook - */ - get(): WebhookContext; - /** - * Provide a user-friendly representation - */ - toJSON(): any; -} - -interface WebhookPayload extends WebhookResource, Page.TwilioResponsePayload { -} - -interface WebhookResource { - account_sid: string; - post_webhook_retry_count: number; - post_webhook_url: string; - pre_webhook_retry_count: number; - pre_webhook_url: string; - service_sid: string; - target: WebhookTarget; - url: string; - webhook_filters: string[]; - webhook_method: string; -} - -interface WebhookSolution { -} - - -declare class WebhookContext { - /** - * Initialize the WebhookContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - */ - constructor(version: V1); - - /** - * fetch a WebhookInstance - * - * @param callback - Callback to handle processed record - */ - fetch(callback?: (error: Error | null, items: WebhookInstance) => any): Promise; - /** - * Provide a user-friendly representation - */ - toJSON(): any; - /** - * update a WebhookInstance - * - * @param opts - Options for request - * @param callback - Callback to handle processed record - */ - update(opts?: WebhookInstanceUpdateOptions, callback?: (error: Error | null, items: WebhookInstance) => any): Promise; -} - - -declare class WebhookInstance extends SerializableClass { - /** - * Initialize the WebhookContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param payload - The instance payload - */ - constructor(version: V1, payload: WebhookPayload); - - private _proxy: WebhookContext; - accountSid: string; - /** - * fetch a WebhookInstance - * - * @param callback - Callback to handle processed record - */ - fetch(callback?: (error: Error | null, items: WebhookInstance) => any): Promise; - postWebhookRetryCount: number; - postWebhookUrl: string; - preWebhookRetryCount: number; - preWebhookUrl: string; - serviceSid: string; - target: WebhookTarget; - /** - * Provide a user-friendly representation - */ - toJSON(): any; - /** - * update a WebhookInstance - * - * @param opts - Options for request - * @param callback - Callback to handle processed record - */ - update(opts?: WebhookInstanceUpdateOptions, callback?: (error: Error | null, items: WebhookInstance) => any): Promise; - url: string; - webhookFilters: string[]; - webhookMethod: string; -} - - -declare class WebhookPage extends Page { - /** - * Initialize the WebhookPage - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @param version - Version of the resource - * @param response - Response from the API - * @param solution - Path solution - */ - constructor(version: V1, response: Response, solution: WebhookSolution); - - /** - * Build an instance of WebhookInstance - * - * @param payload - Payload response from the API - */ - getInstance(payload: WebhookPayload): WebhookInstance; - /** - * Provide a user-friendly representation - */ - toJSON(): any; -} - -export { WebhookContext, WebhookInstance, WebhookInstanceUpdateOptions, WebhookList, WebhookListInstance, WebhookPage, WebhookPayload, WebhookResource, WebhookSolution, WebhookTarget } diff --git a/lib/rest/messaging/v1/webhook.js b/lib/rest/messaging/v1/webhook.js deleted file mode 100644 index ce7ecc5300..0000000000 --- a/lib/rest/messaging/v1/webhook.js +++ /dev/null @@ -1,429 +0,0 @@ -'use strict'; - -/* jshint ignore:start */ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ -/* jshint ignore:end */ - -var Q = require('q'); /* jshint ignore:line */ -var _ = require('lodash'); /* jshint ignore:line */ -var util = require('util'); /* jshint ignore:line */ -var Page = require('../../../base/Page'); /* jshint ignore:line */ -var deserialize = require( - '../../../base/deserialize'); /* jshint ignore:line */ -var serialize = require('../../../base/serialize'); /* jshint ignore:line */ -var values = require('../../../base/values'); /* jshint ignore:line */ - -var WebhookList; -var WebhookPage; -var WebhookInstance; -var WebhookContext; - -/* jshint ignore:start */ -/** - * Initialize the WebhookList - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.WebhookList - * - * @param {Twilio.Messaging.V1} version - Version of the resource - */ -/* jshint ignore:end */ -WebhookList = function WebhookList(version) { - /* jshint ignore:start */ - /** - * @function webhooks - * @memberof Twilio.Messaging.V1# - * - * @param {string} sid - sid of instance - * - * @returns {Twilio.Messaging.V1.WebhookContext} - */ - /* jshint ignore:end */ - function WebhookListInstance(sid) { - return WebhookListInstance.get(sid); - } - - WebhookListInstance._version = version; - // Path Solution - WebhookListInstance._solution = {}; - /* jshint ignore:start */ - /** - * Constructs a webhook - * - * @function get - * @memberof Twilio.Messaging.V1.WebhookList# - * - * @returns {Twilio.Messaging.V1.WebhookContext} - */ - /* jshint ignore:end */ - WebhookListInstance.get = function get() { - return new WebhookContext(this._version); - }; - - /* jshint ignore:start */ - /** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.WebhookList# - * - * @returns Object - */ - /* jshint ignore:end */ - WebhookListInstance.toJSON = function toJSON() { - return this._solution; - }; - - WebhookListInstance[util.inspect.custom] = function inspect(depth, options) { - return util.inspect(this.toJSON(), options); - }; - - return WebhookListInstance; -}; - - -/* jshint ignore:start */ -/** - * Initialize the WebhookPage - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.WebhookPage - * - * @param {V1} version - Version of the resource - * @param {Response} response - Response from the API - * @param {WebhookSolution} solution - Path solution - * - * @returns WebhookPage - */ -/* jshint ignore:end */ -WebhookPage = function WebhookPage(version, response, solution) { - // Path Solution - this._solution = solution; - - Page.prototype.constructor.call(this, version, response, this._solution); -}; - -_.extend(WebhookPage.prototype, Page.prototype); -WebhookPage.prototype.constructor = WebhookPage; - -/* jshint ignore:start */ -/** - * Build an instance of WebhookInstance - * - * @function getInstance - * @memberof Twilio.Messaging.V1.WebhookPage# - * - * @param {WebhookPayload} payload - Payload response from the API - * - * @returns WebhookInstance - */ -/* jshint ignore:end */ -WebhookPage.prototype.getInstance = function getInstance(payload) { - return new WebhookInstance(this._version, payload); -}; - -/* jshint ignore:start */ -/** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.WebhookPage# - * - * @returns Object - */ -/* jshint ignore:end */ -WebhookPage.prototype.toJSON = function toJSON() { - let clone = {}; - _.forOwn(this, function(value, key) { - if (!_.startsWith(key, '_') && ! _.isFunction(value)) { - clone[key] = value; - } - }); - return clone; -}; - -WebhookPage.prototype[util.inspect.custom] = function inspect(depth, options) { - return util.inspect(this.toJSON(), options); -}; - - -/* jshint ignore:start */ -/** - * Initialize the WebhookContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.WebhookInstance - * - * @property {string} accountSid - The SID of the Account that created the resource - * @property {string} serviceSid - - * The SID of the Chat Service that the resource is associated with - * @property {string} webhookMethod - - * The HTTP method to use when sending a webhook request - * @property {string} webhookFilters - - * The list of webhook event triggers that are enabled for the Service - * @property {string} preWebhookUrl - The absolute URL of the pre-event webhook - * @property {string} postWebhookUrl - The absolute URL of the post-event webhook - * @property {number} preWebhookRetryCount - - * The number of times to try the pre-event webhook request if the first attempt fails - * @property {number} postWebhookRetryCount - - * The number of times to try the post-event webhook request if the first attempt fails - * @property {webhook.target} target - The routing target of the webhook - * @property {string} url - The absolute URL of the webhook - * - * @param {V1} version - Version of the resource - * @param {WebhookPayload} payload - The instance payload - */ -/* jshint ignore:end */ -WebhookInstance = function WebhookInstance(version, payload) { - this._version = version; - - // Marshaled Properties - this.accountSid = payload.account_sid; // jshint ignore:line - this.serviceSid = payload.service_sid; // jshint ignore:line - this.webhookMethod = payload.webhook_method; // jshint ignore:line - this.webhookFilters = payload.webhook_filters; // jshint ignore:line - this.preWebhookUrl = payload.pre_webhook_url; // jshint ignore:line - this.postWebhookUrl = payload.post_webhook_url; // jshint ignore:line - this.preWebhookRetryCount = deserialize.integer(payload.pre_webhook_retry_count); // jshint ignore:line - this.postWebhookRetryCount = deserialize.integer(payload.post_webhook_retry_count); // jshint ignore:line - this.target = payload.target; // jshint ignore:line - this.url = payload.url; // jshint ignore:line - - // Context - this._context = undefined; - this._solution = {}; -}; - -Object.defineProperty(WebhookInstance.prototype, - '_proxy', { - get: function() { - if (!this._context) { - this._context = new WebhookContext(this._version); - } - - return this._context; - } -}); - -/* jshint ignore:start */ -/** - * fetch a WebhookInstance - * - * @function fetch - * @memberof Twilio.Messaging.V1.WebhookInstance# - * - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed WebhookInstance - */ -/* jshint ignore:end */ -WebhookInstance.prototype.fetch = function fetch(callback) { - return this._proxy.fetch(callback); -}; - -/* jshint ignore:start */ -/** - * update a WebhookInstance - * - * @function update - * @memberof Twilio.Messaging.V1.WebhookInstance# - * - * @param {object} [opts] - Options for request - * @param {string} [opts.webhookMethod] - - * The HTTP method to use when sending a webhook request - * @param {string|list} [opts.webhookFilters] - - * The list of webhook event triggers that are enabled for the Service - * @param {string} [opts.preWebhookUrl] - The absolute URL of the pre-event webhook - * @param {string} [opts.postWebhookUrl] - - * The absolute URL of the post-event webhook - * @param {number} [opts.preWebhookRetryCount] - - * The number of times to try the pre-event webhook request if the first attempt fails - * @param {number} [opts.postWebhookRetryCount] - - * The number of times to try the post-event webhook request if the first attempt fails - * @param {webhook.target} [opts.target] - The routing target of the webhook - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed WebhookInstance - */ -/* jshint ignore:end */ -WebhookInstance.prototype.update = function update(opts, callback) { - return this._proxy.update(opts, callback); -}; - -/* jshint ignore:start */ -/** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.WebhookInstance# - * - * @returns Object - */ -/* jshint ignore:end */ -WebhookInstance.prototype.toJSON = function toJSON() { - let clone = {}; - _.forOwn(this, function(value, key) { - if (!_.startsWith(key, '_') && ! _.isFunction(value)) { - clone[key] = value; - } - }); - return clone; -}; - -WebhookInstance.prototype[util.inspect.custom] = function inspect(depth, - options) { - return util.inspect(this.toJSON(), options); -}; - - -/* jshint ignore:start */ -/** - * Initialize the WebhookContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.WebhookContext - * - * @param {V1} version - Version of the resource - */ -/* jshint ignore:end */ -WebhookContext = function WebhookContext(version) { - this._version = version; - - // Path Solution - this._solution = {}; - this._uri = `/Sessions/Webhooks`; -}; - -/* jshint ignore:start */ -/** - * fetch a WebhookInstance - * - * @function fetch - * @memberof Twilio.Messaging.V1.WebhookContext# - * - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed WebhookInstance - */ -/* jshint ignore:end */ -WebhookContext.prototype.fetch = function fetch(callback) { - var deferred = Q.defer(); - var promise = this._version.fetch({uri: this._uri, method: 'GET'}); - - promise = promise.then(function(payload) { - deferred.resolve(new WebhookInstance(this._version, payload)); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; -}; - -/* jshint ignore:start */ -/** - * update a WebhookInstance - * - * @function update - * @memberof Twilio.Messaging.V1.WebhookContext# - * - * @param {object} [opts] - Options for request - * @param {string} [opts.webhookMethod] - - * The HTTP method to use when sending a webhook request - * @param {string|list} [opts.webhookFilters] - - * The list of webhook event triggers that are enabled for the Service - * @param {string} [opts.preWebhookUrl] - The absolute URL of the pre-event webhook - * @param {string} [opts.postWebhookUrl] - - * The absolute URL of the post-event webhook - * @param {number} [opts.preWebhookRetryCount] - - * The number of times to try the pre-event webhook request if the first attempt fails - * @param {number} [opts.postWebhookRetryCount] - - * The number of times to try the post-event webhook request if the first attempt fails - * @param {webhook.target} [opts.target] - The routing target of the webhook - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed WebhookInstance - */ -/* jshint ignore:end */ -WebhookContext.prototype.update = function update(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - - var deferred = Q.defer(); - var data = values.of({ - 'WebhookMethod': _.get(opts, 'webhookMethod'), - 'WebhookFilters': serialize.map(_.get(opts, 'webhookFilters'), function(e) { return e; }), - 'PreWebhookUrl': _.get(opts, 'preWebhookUrl'), - 'PostWebhookUrl': _.get(opts, 'postWebhookUrl'), - 'PreWebhookRetryCount': _.get(opts, 'preWebhookRetryCount'), - 'PostWebhookRetryCount': _.get(opts, 'postWebhookRetryCount'), - 'Target': _.get(opts, 'target') - }); - - var promise = this._version.update({uri: this._uri, method: 'POST', data: data}); - - promise = promise.then(function(payload) { - deferred.resolve(new WebhookInstance(this._version, payload)); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; -}; - -/* jshint ignore:start */ -/** - * Provide a user-friendly representation - * - * @function toJSON - * @memberof Twilio.Messaging.V1.WebhookContext# - * - * @returns Object - */ -/* jshint ignore:end */ -WebhookContext.prototype.toJSON = function toJSON() { - return this._solution; -}; - -WebhookContext.prototype[util.inspect.custom] = function inspect(depth, options) - { - return util.inspect(this.toJSON(), options); -}; - -module.exports = { - WebhookList: WebhookList, - WebhookPage: WebhookPage, - WebhookInstance: WebhookInstance, - WebhookContext: WebhookContext -}; diff --git a/lib/rest/numbers/v2/regulatoryCompliance.d.ts b/lib/rest/numbers/v2/regulatoryCompliance.d.ts index da529c21af..db4951cfe1 100644 --- a/lib/rest/numbers/v2/regulatoryCompliance.d.ts +++ b/lib/rest/numbers/v2/regulatoryCompliance.d.ts @@ -19,6 +19,7 @@ interface RegulatoryComplianceListInstance { bundles?: object; endUserTypes?: object; endUsers?: object; + regulations?: object; supportingDocumentTypes?: object; supportingDocuments?: object; /** diff --git a/lib/rest/numbers/v2/regulatoryCompliance.js b/lib/rest/numbers/v2/regulatoryCompliance.js index 8ffbda920d..f85263c0bf 100644 --- a/lib/rest/numbers/v2/regulatoryCompliance.js +++ b/lib/rest/numbers/v2/regulatoryCompliance.js @@ -15,6 +15,8 @@ var BundleList = require('./regulatoryCompliance/bundle').BundleList; var EndUserList = require('./regulatoryCompliance/endUser').EndUserList; var EndUserTypeList = require( './regulatoryCompliance/endUserType').EndUserTypeList; +var RegulationList = require( + './regulatoryCompliance/regulation').RegulationList; var SupportingDocumentList = require( './regulatoryCompliance/supportingDocument').SupportingDocumentList; var SupportingDocumentTypeList = require( @@ -91,6 +93,17 @@ RegulatoryComplianceList = function RegulatoryComplianceList(version) { } }); + Object.defineProperty(RegulatoryComplianceListInstance, + 'regulations', { + get: function regulations() { + if (!this._regulations) { + this._regulations = new RegulationList(this._version); + } + + return this._regulations; + } + }); + Object.defineProperty(RegulatoryComplianceListInstance, 'supportingDocuments', { get: function supportingDocuments() { diff --git a/lib/rest/numbers/v2/regulatoryCompliance/regulation.d.ts b/lib/rest/numbers/v2/regulatoryCompliance/regulation.d.ts new file mode 100644 index 0000000000..015045ef7e --- /dev/null +++ b/lib/rest/numbers/v2/regulatoryCompliance/regulation.d.ts @@ -0,0 +1,256 @@ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ + +import Page = require('../../../../base/Page'); +import Response = require('../../../../http/response'); +import V2 = require('../../V2'); +import { SerializableClass } from '../../../../interfaces'; + +type RegulationEndUserType = 'individual'|'business'; + +/** + * Initialize the RegulationList + * + * @param version - Version of the resource + */ +declare function RegulationList(version: V2): RegulationListInstance; + +interface RegulationListInstance { + /** + * @param sid - sid of instance + */ + (sid: string): RegulationContext; + /** + * Streams RegulationInstance records from the API. + * + * This operation lazily loads records as efficiently as possible until the limit + * is reached. + * + * The results are passed into the callback function, so this operation is memory + * efficient. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @param opts - Options for request + * @param callback - Function to process each record + */ + each(opts?: RegulationListInstanceEachOptions, callback?: (item: RegulationInstance, done: (err?: Error) => void) => void): void; + /** + * Constructs a regulation + * + * @param sid - The unique string that identifies the Regulation resource + */ + get(sid: string): RegulationContext; + /** + * Retrieve a single target page of RegulationInstance records from the API. + * + * The request is executed immediately. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @param targetUrl - API-generated URL for the requested results page + * @param callback - Callback to handle list of records + */ + getPage(targetUrl?: string, callback?: (error: Error | null, items: RegulationPage) => any): Promise; + /** + * Lists RegulationInstance records from the API as a list. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @param opts - Options for request + * @param callback - Callback to handle list of records + */ + list(opts?: RegulationListInstanceOptions, callback?: (error: Error | null, items: RegulationInstance[]) => any): Promise; + /** + * Retrieve a single page of RegulationInstance records from the API. + * + * The request is executed immediately. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @param opts - Options for request + * @param callback - Callback to handle list of records + */ + page(opts?: RegulationListInstancePageOptions, callback?: (error: Error | null, items: RegulationPage) => any): Promise; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + +/** + * Options to pass to each + * + * @property callback - + * Function to process each record. If this and a positional + * callback are passed, this one will be used + * @property done - Function to be called upon completion of streaming + * @property endUserType - The type of End User of the Regulation resource + * @property isoCountry - The ISO country code of the phone number's country + * @property limit - + * Upper limit for the number of records to return. + * each() guarantees never to return more than limit. + * Default is no limit + * @property numberType - The type of phone number being regulated + * @property pageSize - + * Number of records to fetch per request, + * when not set will use the default value of 50 records. + * If no pageSize is defined but a limit is defined, + * each() will attempt to read the limit with the most efficient + * page size, i.e. min(limit, 1000) + */ +interface RegulationListInstanceEachOptions { + callback?: (item: RegulationInstance, done: (err?: Error) => void) => void; + done?: Function; + endUserType?: RegulationEndUserType; + isoCountry?: string; + limit?: number; + numberType?: string; + pageSize?: number; +} + +/** + * Options to pass to list + * + * @property endUserType - The type of End User of the Regulation resource + * @property isoCountry - The ISO country code of the phone number's country + * @property limit - + * Upper limit for the number of records to return. + * list() guarantees never to return more than limit. + * Default is no limit + * @property numberType - The type of phone number being regulated + * @property pageSize - + * Number of records to fetch per request, + * when not set will use the default value of 50 records. + * If no page_size is defined but a limit is defined, + * list() will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + */ +interface RegulationListInstanceOptions { + endUserType?: RegulationEndUserType; + isoCountry?: string; + limit?: number; + numberType?: string; + pageSize?: number; +} + +/** + * Options to pass to page + * + * @property endUserType - The type of End User of the Regulation resource + * @property isoCountry - The ISO country code of the phone number's country + * @property numberType - The type of phone number being regulated + * @property pageNumber - Page Number, this value is simply for client state + * @property pageSize - Number of records to return, defaults to 50 + * @property pageToken - PageToken provided by the API + */ +interface RegulationListInstancePageOptions { + endUserType?: RegulationEndUserType; + isoCountry?: string; + numberType?: string; + pageNumber?: number; + pageSize?: number; + pageToken?: string; +} + +interface RegulationPayload extends RegulationResource, Page.TwilioResponsePayload { +} + +interface RegulationResource { + end_user_type: RegulationEndUserType; + friendly_name: string; + iso_country: string; + number_type: string; + requirements: object; + sid: string; + url: string; +} + +interface RegulationSolution { +} + + +declare class RegulationContext { + /** + * Initialize the RegulationContext + * + * @param version - Version of the resource + * @param sid - The unique string that identifies the Regulation resource + */ + constructor(version: V2, sid: string); + + /** + * fetch a RegulationInstance + * + * @param callback - Callback to handle processed record + */ + fetch(callback?: (error: Error | null, items: RegulationInstance) => any): Promise; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + + +declare class RegulationInstance extends SerializableClass { + /** + * Initialize the RegulationContext + * + * @param version - Version of the resource + * @param payload - The instance payload + * @param sid - The unique string that identifies the Regulation resource + */ + constructor(version: V2, payload: RegulationPayload, sid: string); + + private _proxy: RegulationContext; + endUserType: RegulationEndUserType; + /** + * fetch a RegulationInstance + * + * @param callback - Callback to handle processed record + */ + fetch(callback?: (error: Error | null, items: RegulationInstance) => any): Promise; + friendlyName: string; + isoCountry: string; + numberType: string; + requirements: object; + sid: string; + /** + * Provide a user-friendly representation + */ + toJSON(): any; + url: string; +} + + +declare class RegulationPage extends Page { + /** + * Initialize the RegulationPage + * + * @param version - Version of the resource + * @param response - Response from the API + * @param solution - Path solution + */ + constructor(version: V2, response: Response, solution: RegulationSolution); + + /** + * Build an instance of RegulationInstance + * + * @param payload - Payload response from the API + */ + getInstance(payload: RegulationPayload): RegulationInstance; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + +export { RegulationContext, RegulationEndUserType, RegulationInstance, RegulationList, RegulationListInstance, RegulationListInstanceEachOptions, RegulationListInstanceOptions, RegulationListInstancePageOptions, RegulationPage, RegulationPayload, RegulationResource, RegulationSolution } diff --git a/lib/rest/numbers/v2/regulatoryCompliance/regulation.js b/lib/rest/numbers/v2/regulatoryCompliance/regulation.js new file mode 100644 index 0000000000..d74c65a89e --- /dev/null +++ b/lib/rest/numbers/v2/regulatoryCompliance/regulation.js @@ -0,0 +1,584 @@ +'use strict'; + +/* jshint ignore:start */ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ +/* jshint ignore:end */ + +var Q = require('q'); /* jshint ignore:line */ +var _ = require('lodash'); /* jshint ignore:line */ +var util = require('util'); /* jshint ignore:line */ +var Page = require('../../../../base/Page'); /* jshint ignore:line */ +var values = require('../../../../base/values'); /* jshint ignore:line */ + +var RegulationList; +var RegulationPage; +var RegulationInstance; +var RegulationContext; + +/* jshint ignore:start */ +/** + * Initialize the RegulationList + * + * @constructor Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationList + * + * @param {Twilio.Numbers.V2} version - Version of the resource + */ +/* jshint ignore:end */ +RegulationList = function RegulationList(version) { + /* jshint ignore:start */ + /** + * @function regulations + * @memberof Twilio.Numbers.V2.RegulatoryComplianceContext# + * + * @param {string} sid - sid of instance + * + * @returns {Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationContext} + */ + /* jshint ignore:end */ + function RegulationListInstance(sid) { + return RegulationListInstance.get(sid); + } + + RegulationListInstance._version = version; + // Path Solution + RegulationListInstance._solution = {}; + RegulationListInstance._uri = `/RegulatoryCompliance/Regulations`; + /* jshint ignore:start */ + /** + * Streams RegulationInstance records from the API. + * + * This operation lazily loads records as efficiently as possible until the limit + * is reached. + * + * The results are passed into the callback function, so this operation is memory + * efficient. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @function each + * @memberof Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationList# + * + * @param {object} [opts] - Options for request + * @param {regulation.end_user_type} [opts.endUserType] - + * The type of End User of the Regulation resource + * @param {string} [opts.isoCountry] - + * The ISO country code of the phone number's country + * @param {string} [opts.numberType] - The type of phone number being regulated + * @param {number} [opts.limit] - + * Upper limit for the number of records to return. + * each() guarantees never to return more than limit. + * Default is no limit + * @param {number} [opts.pageSize] - + * Number of records to fetch per request, + * when not set will use the default value of 50 records. + * If no pageSize is defined but a limit is defined, + * each() will attempt to read the limit with the most efficient + * page size, i.e. min(limit, 1000) + * @param {Function} [opts.callback] - + * Function to process each record. If this and a positional + * callback are passed, this one will be used + * @param {Function} [opts.done] - + * Function to be called upon completion of streaming + * @param {Function} [callback] - Function to process each record + */ + /* jshint ignore:end */ + RegulationListInstance.each = function each(opts, callback) { + if (_.isFunction(opts)) { + callback = opts; + opts = {}; + } + opts = opts || {}; + if (opts.callback) { + callback = opts.callback; + } + if (_.isUndefined(callback)) { + throw new Error('Callback function must be provided'); + } + + var done = false; + var currentPage = 1; + var currentResource = 0; + var limits = this._version.readLimits({ + limit: opts.limit, + pageSize: opts.pageSize + }); + + function onComplete(error) { + done = true; + if (_.isFunction(opts.done)) { + opts.done(error); + } + } + + function fetchNextPage(fn) { + var promise = fn(); + if (_.isUndefined(promise)) { + onComplete(); + return; + } + + promise.then(function(page) { + _.each(page.instances, function(instance) { + if (done || (!_.isUndefined(opts.limit) && currentResource >= opts.limit)) { + done = true; + return false; + } + + currentResource++; + callback(instance, onComplete); + }); + + if ((limits.pageLimit && limits.pageLimit <= currentPage)) { + onComplete(); + } else if (!done) { + currentPage++; + fetchNextPage(_.bind(page.nextPage, page)); + } + }); + + promise.catch(onComplete); + } + + fetchNextPage(_.bind(this.page, this, _.merge(opts, limits))); + }; + + /* jshint ignore:start */ + /** + * Lists RegulationInstance records from the API as a list. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @function list + * @memberof Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationList# + * + * @param {object} [opts] - Options for request + * @param {regulation.end_user_type} [opts.endUserType] - + * The type of End User of the Regulation resource + * @param {string} [opts.isoCountry] - + * The ISO country code of the phone number's country + * @param {string} [opts.numberType] - The type of phone number being regulated + * @param {number} [opts.limit] - + * Upper limit for the number of records to return. + * list() guarantees never to return more than limit. + * Default is no limit + * @param {number} [opts.pageSize] - + * Number of records to fetch per request, + * when not set will use the default value of 50 records. + * If no page_size is defined but a limit is defined, + * list() will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @param {function} [callback] - Callback to handle list of records + * + * @returns {Promise} Resolves to a list of records + */ + /* jshint ignore:end */ + RegulationListInstance.list = function list(opts, callback) { + if (_.isFunction(opts)) { + callback = opts; + opts = {}; + } + opts = opts || {}; + var deferred = Q.defer(); + var allResources = []; + opts.callback = function(resource, done) { + allResources.push(resource); + + if (!_.isUndefined(opts.limit) && allResources.length === opts.limit) { + done(); + } + }; + + opts.done = function(error) { + if (_.isUndefined(error)) { + deferred.resolve(allResources); + } else { + deferred.reject(error); + } + }; + + if (_.isFunction(callback)) { + deferred.promise.nodeify(callback); + } + + this.each(opts); + return deferred.promise; + }; + + /* jshint ignore:start */ + /** + * Retrieve a single page of RegulationInstance records from the API. + * + * The request is executed immediately. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @function page + * @memberof Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationList# + * + * @param {object} [opts] - Options for request + * @param {regulation.end_user_type} [opts.endUserType] - + * The type of End User of the Regulation resource + * @param {string} [opts.isoCountry] - + * The ISO country code of the phone number's country + * @param {string} [opts.numberType] - The type of phone number being regulated + * @param {string} [opts.pageToken] - PageToken provided by the API + * @param {number} [opts.pageNumber] - + * Page Number, this value is simply for client state + * @param {number} [opts.pageSize] - Number of records to return, defaults to 50 + * @param {function} [callback] - Callback to handle list of records + * + * @returns {Promise} Resolves to a list of records + */ + /* jshint ignore:end */ + RegulationListInstance.page = function page(opts, callback) { + if (_.isFunction(opts)) { + callback = opts; + opts = {}; + } + opts = opts || {}; + + var deferred = Q.defer(); + var data = values.of({ + 'EndUserType': _.get(opts, 'endUserType'), + 'IsoCountry': _.get(opts, 'isoCountry'), + 'NumberType': _.get(opts, 'numberType'), + 'PageToken': opts.pageToken, + 'Page': opts.pageNumber, + 'PageSize': opts.pageSize + }); + + var promise = this._version.page({uri: this._uri, method: 'GET', params: data}); + + promise = promise.then(function(payload) { + deferred.resolve(new RegulationPage(this._version, payload, this._solution)); + }.bind(this)); + + promise.catch(function(error) { + deferred.reject(error); + }); + + if (_.isFunction(callback)) { + deferred.promise.nodeify(callback); + } + + return deferred.promise; + }; + + /* jshint ignore:start */ + /** + * Retrieve a single target page of RegulationInstance records from the API. + * + * The request is executed immediately. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @function getPage + * @memberof Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationList# + * + * @param {string} [targetUrl] - API-generated URL for the requested results page + * @param {function} [callback] - Callback to handle list of records + * + * @returns {Promise} Resolves to a list of records + */ + /* jshint ignore:end */ + RegulationListInstance.getPage = function getPage(targetUrl, callback) { + var deferred = Q.defer(); + + var promise = this._version._domain.twilio.request({method: 'GET', uri: targetUrl}); + + promise = promise.then(function(payload) { + deferred.resolve(new RegulationPage(this._version, payload, this._solution)); + }.bind(this)); + + promise.catch(function(error) { + deferred.reject(error); + }); + + if (_.isFunction(callback)) { + deferred.promise.nodeify(callback); + } + + return deferred.promise; + }; + + /* jshint ignore:start */ + /** + * Constructs a regulation + * + * @function get + * @memberof Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationList# + * + * @param {string} sid - The unique string that identifies the Regulation resource + * + * @returns {Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationContext} + */ + /* jshint ignore:end */ + RegulationListInstance.get = function get(sid) { + return new RegulationContext(this._version, sid); + }; + + /* jshint ignore:start */ + /** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationList# + * + * @returns Object + */ + /* jshint ignore:end */ + RegulationListInstance.toJSON = function toJSON() { + return this._solution; + }; + + RegulationListInstance[util.inspect.custom] = function inspect(depth, options) { + return util.inspect(this.toJSON(), options); + }; + + return RegulationListInstance; +}; + + +/* jshint ignore:start */ +/** + * Initialize the RegulationPage + * + * @constructor Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationPage + * + * @param {V2} version - Version of the resource + * @param {Response} response - Response from the API + * @param {RegulationSolution} solution - Path solution + * + * @returns RegulationPage + */ +/* jshint ignore:end */ +RegulationPage = function RegulationPage(version, response, solution) { + // Path Solution + this._solution = solution; + + Page.prototype.constructor.call(this, version, response, this._solution); +}; + +_.extend(RegulationPage.prototype, Page.prototype); +RegulationPage.prototype.constructor = RegulationPage; + +/* jshint ignore:start */ +/** + * Build an instance of RegulationInstance + * + * @function getInstance + * @memberof Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationPage# + * + * @param {RegulationPayload} payload - Payload response from the API + * + * @returns RegulationInstance + */ +/* jshint ignore:end */ +RegulationPage.prototype.getInstance = function getInstance(payload) { + return new RegulationInstance(this._version, payload); +}; + +/* jshint ignore:start */ +/** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationPage# + * + * @returns Object + */ +/* jshint ignore:end */ +RegulationPage.prototype.toJSON = function toJSON() { + let clone = {}; + _.forOwn(this, function(value, key) { + if (!_.startsWith(key, '_') && ! _.isFunction(value)) { + clone[key] = value; + } + }); + return clone; +}; + +RegulationPage.prototype[util.inspect.custom] = function inspect(depth, options) + { + return util.inspect(this.toJSON(), options); +}; + + +/* jshint ignore:start */ +/** + * Initialize the RegulationContext + * + * @constructor Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationInstance + * + * @property {string} sid - + * The unique string that identifies the Regulation resource + * @property {string} friendlyName - + * A human-readable description of the Regulation resource + * @property {string} isoCountry - + * The ISO country code of the phone number's country + * @property {string} numberType - + * The type of phone number restricted by the regulatory requirement + * @property {regulation.end_user_type} endUserType - + * The type of End User of the Regulation resource + * @property {object} requirements - + * The sid of a regulation object that dictates requirements + * @property {string} url - The absolute URL of the Regulation resource + * + * @param {V2} version - Version of the resource + * @param {RegulationPayload} payload - The instance payload + * @param {sid} sid - The unique string that identifies the Regulation resource + */ +/* jshint ignore:end */ +RegulationInstance = function RegulationInstance(version, payload, sid) { + this._version = version; + + // Marshaled Properties + this.sid = payload.sid; // jshint ignore:line + this.friendlyName = payload.friendly_name; // jshint ignore:line + this.isoCountry = payload.iso_country; // jshint ignore:line + this.numberType = payload.number_type; // jshint ignore:line + this.endUserType = payload.end_user_type; // jshint ignore:line + this.requirements = payload.requirements; // jshint ignore:line + this.url = payload.url; // jshint ignore:line + + // Context + this._context = undefined; + this._solution = {sid: sid || this.sid, }; +}; + +Object.defineProperty(RegulationInstance.prototype, + '_proxy', { + get: function() { + if (!this._context) { + this._context = new RegulationContext(this._version, this._solution.sid); + } + + return this._context; + } +}); + +/* jshint ignore:start */ +/** + * fetch a RegulationInstance + * + * @function fetch + * @memberof Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationInstance# + * + * @param {function} [callback] - Callback to handle processed record + * + * @returns {Promise} Resolves to processed RegulationInstance + */ +/* jshint ignore:end */ +RegulationInstance.prototype.fetch = function fetch(callback) { + return this._proxy.fetch(callback); +}; + +/* jshint ignore:start */ +/** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationInstance# + * + * @returns Object + */ +/* jshint ignore:end */ +RegulationInstance.prototype.toJSON = function toJSON() { + let clone = {}; + _.forOwn(this, function(value, key) { + if (!_.startsWith(key, '_') && ! _.isFunction(value)) { + clone[key] = value; + } + }); + return clone; +}; + +RegulationInstance.prototype[util.inspect.custom] = function inspect(depth, + options) { + return util.inspect(this.toJSON(), options); +}; + + +/* jshint ignore:start */ +/** + * Initialize the RegulationContext + * + * @constructor Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationContext + * + * @param {V2} version - Version of the resource + * @param {sid} sid - The unique string that identifies the Regulation resource + */ +/* jshint ignore:end */ +RegulationContext = function RegulationContext(version, sid) { + this._version = version; + + // Path Solution + this._solution = {sid: sid, }; + this._uri = `/RegulatoryCompliance/Regulations/${sid}`; +}; + +/* jshint ignore:start */ +/** + * fetch a RegulationInstance + * + * @function fetch + * @memberof Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationContext# + * + * @param {function} [callback] - Callback to handle processed record + * + * @returns {Promise} Resolves to processed RegulationInstance + */ +/* jshint ignore:end */ +RegulationContext.prototype.fetch = function fetch(callback) { + var deferred = Q.defer(); + var promise = this._version.fetch({uri: this._uri, method: 'GET'}); + + promise = promise.then(function(payload) { + deferred.resolve(new RegulationInstance(this._version, payload, this._solution.sid)); + }.bind(this)); + + promise.catch(function(error) { + deferred.reject(error); + }); + + if (_.isFunction(callback)) { + deferred.promise.nodeify(callback); + } + + return deferred.promise; +}; + +/* jshint ignore:start */ +/** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Numbers.V2.RegulatoryComplianceContext.RegulationContext# + * + * @returns Object + */ +/* jshint ignore:end */ +RegulationContext.prototype.toJSON = function toJSON() { + return this._solution; +}; + +RegulationContext.prototype[util.inspect.custom] = function inspect(depth, + options) { + return util.inspect(this.toJSON(), options); +}; + +module.exports = { + RegulationList: RegulationList, + RegulationPage: RegulationPage, + RegulationInstance: RegulationInstance, + RegulationContext: RegulationContext +}; diff --git a/lib/rest/studio/v2/flow.d.ts b/lib/rest/studio/v2/flow.d.ts index ebb8a7eb53..d12aa5b4c5 100644 --- a/lib/rest/studio/v2/flow.d.ts +++ b/lib/rest/studio/v2/flow.d.ts @@ -9,8 +9,12 @@ import Page = require('../../../base/Page'); import Response = require('../../../http/response'); import V2 = require('../V2'); import serialize = require('../../../base/serialize'); +import { ExecutionList } from './flow/execution'; +import { ExecutionListInstance } from './flow/execution'; import { FlowRevisionList } from './flow/flowRevision'; import { FlowRevisionListInstance } from './flow/flowRevision'; +import { FlowTestUserList } from './flow/testUser'; +import { FlowTestUserListInstance } from './flow/testUser'; import { SerializableClass } from '../../../interfaces'; type FlowStatus = 'draft'|'published'; @@ -203,6 +207,7 @@ interface FlowResource { status: FlowStatus; url: string; valid: boolean; + webhook_url: string; } interface FlowSolution { @@ -221,6 +226,7 @@ declare class FlowContext { */ constructor(version: V2, sid: string); + executions: ExecutionListInstance; /** * fetch a FlowInstance * @@ -234,6 +240,7 @@ declare class FlowContext { */ remove(callback?: (error: Error | null, items: FlowInstance) => any): Promise; revisions: FlowRevisionListInstance; + testUsers: FlowTestUserListInstance; /** * Provide a user-friendly representation */ @@ -268,6 +275,10 @@ declare class FlowInstance extends SerializableClass { dateUpdated: Date; definition: object; errors: object[]; + /** + * Access the executions + */ + executions(): ExecutionListInstance; /** * fetch a FlowInstance * @@ -289,6 +300,10 @@ declare class FlowInstance extends SerializableClass { revisions(): FlowRevisionListInstance; sid: string; status: FlowStatus; + /** + * Access the testUsers + */ + testUsers(): FlowTestUserListInstance; /** * Provide a user-friendly representation */ @@ -302,6 +317,7 @@ declare class FlowInstance extends SerializableClass { update(opts: FlowInstanceUpdateOptions, callback?: (error: Error | null, items: FlowInstance) => any): Promise; url: string; valid: boolean; + webhookUrl: string; } diff --git a/lib/rest/studio/v2/flow.js b/lib/rest/studio/v2/flow.js index 67e49a8802..ac985d897c 100644 --- a/lib/rest/studio/v2/flow.js +++ b/lib/rest/studio/v2/flow.js @@ -12,7 +12,9 @@ var Q = require('q'); /* jshint ignore:line */ var _ = require('lodash'); /* jshint ignore:line */ var util = require('util'); /* jshint ignore:line */ +var ExecutionList = require('./flow/execution').ExecutionList; var FlowRevisionList = require('./flow/flowRevision').FlowRevisionList; +var FlowTestUserList = require('./flow/testUser').FlowTestUserList; var Page = require('../../../base/Page'); /* jshint ignore:line */ var deserialize = require( '../../../base/deserialize'); /* jshint ignore:line */ @@ -486,6 +488,7 @@ FlowPage.prototype[util.inspect.custom] = function inspect(depth, options) { * The ISO 8601 date and time in GMT when the resource was created * @property {Date} dateUpdated - * The ISO 8601 date and time in GMT when the resource was last updated + * @property {string} webhookUrl - The webhook_url * @property {string} url - The absolute URL of the resource * @property {string} links - Nested resource URLs * @@ -509,6 +512,7 @@ FlowInstance = function FlowInstance(version, payload, sid) { this.errors = payload.errors; // jshint ignore:line this.dateCreated = deserialize.iso8601DateTime(payload.date_created); // jshint ignore:line this.dateUpdated = deserialize.iso8601DateTime(payload.date_updated); // jshint ignore:line + this.webhookUrl = payload.webhook_url; // jshint ignore:line this.url = payload.url; // jshint ignore:line this.links = payload.links; // jshint ignore:line @@ -597,6 +601,34 @@ FlowInstance.prototype.revisions = function revisions() { return this._proxy.revisions; }; +/* jshint ignore:start */ +/** + * Access the testUsers + * + * @function testUsers + * @memberof Twilio.Studio.V2.FlowInstance# + * + * @returns {Twilio.Studio.V2.FlowContext.FlowTestUserList} + */ +/* jshint ignore:end */ +FlowInstance.prototype.testUsers = function testUsers() { + return this._proxy.testUsers; +}; + +/* jshint ignore:start */ +/** + * Access the executions + * + * @function executions + * @memberof Twilio.Studio.V2.FlowInstance# + * + * @returns {Twilio.Studio.V2.FlowContext.ExecutionList} + */ +/* jshint ignore:end */ +FlowInstance.prototype.executions = function executions() { + return this._proxy.executions; +}; + /* jshint ignore:start */ /** * Provide a user-friendly representation @@ -633,6 +665,10 @@ FlowInstance.prototype[util.inspect.custom] = function inspect(depth, options) { * * @property {Twilio.Studio.V2.FlowContext.FlowRevisionList} revisions - * revisions resource + * @property {Twilio.Studio.V2.FlowContext.FlowTestUserList} testUsers - + * testUsers resource + * @property {Twilio.Studio.V2.FlowContext.ExecutionList} executions - + * executions resource * * @param {V2} version - Version of the resource * @param {sid} sid - The SID that identifies the resource to fetch @@ -647,6 +683,8 @@ FlowContext = function FlowContext(version, sid) { // Dependents this._revisions = undefined; + this._testUsers = undefined; + this._executions = undefined; }; /* jshint ignore:start */ @@ -773,6 +811,26 @@ Object.defineProperty(FlowContext.prototype, } }); +Object.defineProperty(FlowContext.prototype, + 'testUsers', { + get: function() { + if (!this._testUsers) { + this._testUsers = new FlowTestUserList(this._version, this._solution.sid); + } + return this._testUsers; + } +}); + +Object.defineProperty(FlowContext.prototype, + 'executions', { + get: function() { + if (!this._executions) { + this._executions = new ExecutionList(this._version, this._solution.sid); + } + return this._executions; + } +}); + /* jshint ignore:start */ /** * Provide a user-friendly representation diff --git a/lib/rest/studio/v2/flow/execution.d.ts b/lib/rest/studio/v2/flow/execution.d.ts new file mode 100644 index 0000000000..18d5272bbf --- /dev/null +++ b/lib/rest/studio/v2/flow/execution.d.ts @@ -0,0 +1,319 @@ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ + +import Page = require('../../../../base/Page'); +import Response = require('../../../../http/response'); +import V2 = require('../../V2'); +import serialize = require('../../../../base/serialize'); +import { ExecutionContextList } from './execution/executionContext'; +import { ExecutionContextListInstance } from './execution/executionContext'; +import { ExecutionStepList } from './execution/executionStep'; +import { ExecutionStepListInstance } from './execution/executionStep'; +import { SerializableClass } from '../../../../interfaces'; + +type ExecutionStatus = 'active'|'ended'; + +/** + * Initialize the ExecutionList + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param flowSid - The flow_sid + */ +declare function ExecutionList(version: V2, flowSid: string): ExecutionListInstance; + +interface ExecutionListInstance { + /** + * @param sid - sid of instance + */ + (sid: string): ExecutionContext; + /** + * create a ExecutionInstance + * + * @param opts - Options for request + * @param callback - Callback to handle processed record + */ + create(opts: ExecutionListInstanceCreateOptions, callback?: (error: Error | null, item: ExecutionInstance) => any): Promise; + /** + * Streams ExecutionInstance records from the API. + * + * This operation lazily loads records as efficiently as possible until the limit + * is reached. + * + * The results are passed into the callback function, so this operation is memory + * efficient. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @param opts - Options for request + * @param callback - Function to process each record + */ + each(opts?: ExecutionListInstanceEachOptions, callback?: (item: ExecutionInstance, done: (err?: Error) => void) => void): void; + /** + * Constructs a execution + * + * @param sid - The sid + */ + get(sid: string): ExecutionContext; + /** + * Retrieve a single target page of ExecutionInstance records from the API. + * + * The request is executed immediately. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @param targetUrl - API-generated URL for the requested results page + * @param callback - Callback to handle list of records + */ + getPage(targetUrl?: string, callback?: (error: Error | null, items: ExecutionPage) => any): Promise; + /** + * Lists ExecutionInstance records from the API as a list. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @param opts - Options for request + * @param callback - Callback to handle list of records + */ + list(opts?: ExecutionListInstanceOptions, callback?: (error: Error | null, items: ExecutionInstance[]) => any): Promise; + /** + * Retrieve a single page of ExecutionInstance records from the API. + * + * The request is executed immediately. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @param opts - Options for request + * @param callback - Callback to handle list of records + */ + page(opts?: ExecutionListInstancePageOptions, callback?: (error: Error | null, items: ExecutionPage) => any): Promise; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + +/** + * Options to pass to create + * + * @property from - The from + * @property parameters - The parameters + * @property to - The to + */ +interface ExecutionListInstanceCreateOptions { + from: string; + parameters?: object; + to: string; +} + +/** + * Options to pass to each + * + * @property callback - + * Function to process each record. If this and a positional + * callback are passed, this one will be used + * @property dateCreatedFrom - The date_created_from + * @property dateCreatedTo - The date_created_to + * @property done - Function to be called upon completion of streaming + * @property limit - + * Upper limit for the number of records to return. + * each() guarantees never to return more than limit. + * Default is no limit + * @property pageSize - + * Number of records to fetch per request, + * when not set will use the default value of 50 records. + * If no pageSize is defined but a limit is defined, + * each() will attempt to read the limit with the most efficient + * page size, i.e. min(limit, 1000) + */ +interface ExecutionListInstanceEachOptions { + callback?: (item: ExecutionInstance, done: (err?: Error) => void) => void; + dateCreatedFrom?: Date; + dateCreatedTo?: Date; + done?: Function; + limit?: number; + pageSize?: number; +} + +/** + * Options to pass to list + * + * @property dateCreatedFrom - The date_created_from + * @property dateCreatedTo - The date_created_to + * @property limit - + * Upper limit for the number of records to return. + * list() guarantees never to return more than limit. + * Default is no limit + * @property pageSize - + * Number of records to fetch per request, + * when not set will use the default value of 50 records. + * If no page_size is defined but a limit is defined, + * list() will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + */ +interface ExecutionListInstanceOptions { + dateCreatedFrom?: Date; + dateCreatedTo?: Date; + limit?: number; + pageSize?: number; +} + +/** + * Options to pass to page + * + * @property dateCreatedFrom - The date_created_from + * @property dateCreatedTo - The date_created_to + * @property pageNumber - Page Number, this value is simply for client state + * @property pageSize - Number of records to return, defaults to 50 + * @property pageToken - PageToken provided by the API + */ +interface ExecutionListInstancePageOptions { + dateCreatedFrom?: Date; + dateCreatedTo?: Date; + pageNumber?: number; + pageSize?: number; + pageToken?: string; +} + +interface ExecutionPayload extends ExecutionResource, Page.TwilioResponsePayload { +} + +interface ExecutionResource { + account_sid: string; + contact_channel_address: string; + context: object; + date_created: Date; + date_updated: Date; + flow_sid: string; + links: string; + sid: string; + status: ExecutionStatus; + url: string; +} + +interface ExecutionSolution { + flowSid?: string; +} + + +declare class ExecutionContext { + /** + * Initialize the ExecutionContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param flowSid - The flow_sid + * @param sid - The sid + */ + constructor(version: V2, flowSid: string, sid: string); + + executionContext: ExecutionContextListInstance; + /** + * fetch a ExecutionInstance + * + * @param callback - Callback to handle processed record + */ + fetch(callback?: (error: Error | null, items: ExecutionInstance) => any): Promise; + /** + * remove a ExecutionInstance + * + * @param callback - Callback to handle processed record + */ + remove(callback?: (error: Error | null, items: ExecutionInstance) => any): Promise; + steps: ExecutionStepListInstance; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + + +declare class ExecutionInstance extends SerializableClass { + /** + * Initialize the ExecutionContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param payload - The instance payload + * @param flowSid - The flow_sid + * @param sid - The sid + */ + constructor(version: V2, payload: ExecutionPayload, flowSid: string, sid: string); + + private _proxy: ExecutionContext; + accountSid: string; + contactChannelAddress: string; + context: object; + dateCreated: Date; + dateUpdated: Date; + /** + * Access the executionContext + */ + executionContext(): ExecutionContextListInstance; + /** + * fetch a ExecutionInstance + * + * @param callback - Callback to handle processed record + */ + fetch(callback?: (error: Error | null, items: ExecutionInstance) => any): Promise; + flowSid: string; + links: string; + /** + * remove a ExecutionInstance + * + * @param callback - Callback to handle processed record + */ + remove(callback?: (error: Error | null, items: ExecutionInstance) => any): Promise; + sid: string; + status: ExecutionStatus; + /** + * Access the steps + */ + steps(): ExecutionStepListInstance; + /** + * Provide a user-friendly representation + */ + toJSON(): any; + url: string; +} + + +declare class ExecutionPage extends Page { + /** + * Initialize the ExecutionPage + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param response - Response from the API + * @param solution - Path solution + */ + constructor(version: V2, response: Response, solution: ExecutionSolution); + + /** + * Build an instance of ExecutionInstance + * + * @param payload - Payload response from the API + */ + getInstance(payload: ExecutionPayload): ExecutionInstance; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + +export { ExecutionContext, ExecutionInstance, ExecutionList, ExecutionListInstance, ExecutionListInstanceCreateOptions, ExecutionListInstanceEachOptions, ExecutionListInstanceOptions, ExecutionListInstancePageOptions, ExecutionPage, ExecutionPayload, ExecutionResource, ExecutionSolution, ExecutionStatus } diff --git a/lib/rest/messaging/v1/session/message.js b/lib/rest/studio/v2/flow/execution.js similarity index 50% rename from lib/rest/messaging/v1/session/message.js rename to lib/rest/studio/v2/flow/execution.js index be806ce347..f525588a38 100644 --- a/lib/rest/messaging/v1/session/message.js +++ b/lib/rest/studio/v2/flow/execution.js @@ -12,112 +12,55 @@ var Q = require('q'); /* jshint ignore:line */ var _ = require('lodash'); /* jshint ignore:line */ var util = require('util'); /* jshint ignore:line */ +var ExecutionContextList = require( + './execution/executionContext').ExecutionContextList; +var ExecutionStepList = require('./execution/executionStep').ExecutionStepList; var Page = require('../../../../base/Page'); /* jshint ignore:line */ var deserialize = require( '../../../../base/deserialize'); /* jshint ignore:line */ var serialize = require('../../../../base/serialize'); /* jshint ignore:line */ var values = require('../../../../base/values'); /* jshint ignore:line */ -var MessageList; -var MessagePage; -var MessageInstance; -var MessageContext; +var ExecutionList; +var ExecutionPage; +var ExecutionInstance; +var ExecutionContext; /* jshint ignore:start */ /** - * Initialize the MessageList + * Initialize the ExecutionList * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. * - * @constructor Twilio.Messaging.V1.SessionContext.MessageList + * @constructor Twilio.Studio.V2.FlowContext.ExecutionList * - * @param {Twilio.Messaging.V1} version - Version of the resource - * @param {string} sessionSid - The SID of the Session for the message + * @param {Twilio.Studio.V2} version - Version of the resource + * @param {string} flowSid - The flow_sid */ /* jshint ignore:end */ -MessageList = function MessageList(version, sessionSid) { +ExecutionList = function ExecutionList(version, flowSid) { /* jshint ignore:start */ /** - * @function messages - * @memberof Twilio.Messaging.V1.SessionContext# + * @function executions + * @memberof Twilio.Studio.V2.FlowContext# * * @param {string} sid - sid of instance * - * @returns {Twilio.Messaging.V1.SessionContext.MessageContext} + * @returns {Twilio.Studio.V2.FlowContext.ExecutionContext} */ /* jshint ignore:end */ - function MessageListInstance(sid) { - return MessageListInstance.get(sid); + function ExecutionListInstance(sid) { + return ExecutionListInstance.get(sid); } - MessageListInstance._version = version; + ExecutionListInstance._version = version; // Path Solution - MessageListInstance._solution = {sessionSid: sessionSid}; - MessageListInstance._uri = `/Sessions/${sessionSid}/Messages`; + ExecutionListInstance._solution = {flowSid: flowSid}; + ExecutionListInstance._uri = `/Flows/${flowSid}/Executions`; /* jshint ignore:start */ /** - * create a MessageInstance - * - * @function create - * @memberof Twilio.Messaging.V1.SessionContext.MessageList# - * - * @param {object} [opts] - Options for request - * @param {string} [opts.author] - The identity of the message's author - * @param {string} [opts.attributes] - - * A JSON string that stores application-specific data - * @param {Date} [opts.dateCreated] - - * The ISO 8601 date and time in GMT when the resource was created - * @param {Date} [opts.dateUpdated] - - * The ISO 8601 date and time in GMT when the resource was updated - * @param {string} [opts.body] - The message body - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed MessageInstance - */ - /* jshint ignore:end */ - MessageListInstance.create = function create(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - - var deferred = Q.defer(); - var data = values.of({ - 'Author': _.get(opts, 'author'), - 'Attributes': _.get(opts, 'attributes'), - 'DateCreated': serialize.iso8601DateTime(_.get(opts, 'dateCreated')), - 'DateUpdated': serialize.iso8601DateTime(_.get(opts, 'dateUpdated')), - 'Body': _.get(opts, 'body') - }); - - var promise = this._version.create({uri: this._uri, method: 'POST', data: data}); - - promise = promise.then(function(payload) { - deferred.resolve(new MessageInstance( - this._version, - payload, - this._solution.sessionSid, - this._solution.sid - )); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; - }; - - /* jshint ignore:start */ - /** - * Streams MessageInstance records from the API. + * Streams ExecutionInstance records from the API. * * This operation lazily loads records as efficiently as possible until the limit * is reached. @@ -129,9 +72,11 @@ MessageList = function MessageList(version, sessionSid) { * function. * * @function each - * @memberof Twilio.Messaging.V1.SessionContext.MessageList# + * @memberof Twilio.Studio.V2.FlowContext.ExecutionList# * * @param {object} [opts] - Options for request + * @param {Date} [opts.dateCreatedFrom] - The date_created_from + * @param {Date} [opts.dateCreatedTo] - The date_created_to * @param {number} [opts.limit] - * Upper limit for the number of records to return. * each() guarantees never to return more than limit. @@ -150,7 +95,7 @@ MessageList = function MessageList(version, sessionSid) { * @param {Function} [callback] - Function to process each record */ /* jshint ignore:end */ - MessageListInstance.each = function each(opts, callback) { + ExecutionListInstance.each = function each(opts, callback) { if (_.isFunction(opts)) { callback = opts; opts = {}; @@ -212,15 +157,17 @@ MessageList = function MessageList(version, sessionSid) { /* jshint ignore:start */ /** - * Lists MessageInstance records from the API as a list. + * Lists ExecutionInstance records from the API as a list. * * If a function is passed as the first argument, it will be used as the callback * function. * * @function list - * @memberof Twilio.Messaging.V1.SessionContext.MessageList# + * @memberof Twilio.Studio.V2.FlowContext.ExecutionList# * * @param {object} [opts] - Options for request + * @param {Date} [opts.dateCreatedFrom] - The date_created_from + * @param {Date} [opts.dateCreatedTo] - The date_created_to * @param {number} [opts.limit] - * Upper limit for the number of records to return. * list() guarantees never to return more than limit. @@ -236,7 +183,7 @@ MessageList = function MessageList(version, sessionSid) { * @returns {Promise} Resolves to a list of records */ /* jshint ignore:end */ - MessageListInstance.list = function list(opts, callback) { + ExecutionListInstance.list = function list(opts, callback) { if (_.isFunction(opts)) { callback = opts; opts = {}; @@ -270,7 +217,7 @@ MessageList = function MessageList(version, sessionSid) { /* jshint ignore:start */ /** - * Retrieve a single page of MessageInstance records from the API. + * Retrieve a single page of ExecutionInstance records from the API. * * The request is executed immediately. * @@ -278,9 +225,11 @@ MessageList = function MessageList(version, sessionSid) { * function. * * @function page - * @memberof Twilio.Messaging.V1.SessionContext.MessageList# + * @memberof Twilio.Studio.V2.FlowContext.ExecutionList# * * @param {object} [opts] - Options for request + * @param {Date} [opts.dateCreatedFrom] - The date_created_from + * @param {Date} [opts.dateCreatedTo] - The date_created_to * @param {string} [opts.pageToken] - PageToken provided by the API * @param {number} [opts.pageNumber] - * Page Number, this value is simply for client state @@ -290,7 +239,7 @@ MessageList = function MessageList(version, sessionSid) { * @returns {Promise} Resolves to a list of records */ /* jshint ignore:end */ - MessageListInstance.page = function page(opts, callback) { + ExecutionListInstance.page = function page(opts, callback) { if (_.isFunction(opts)) { callback = opts; opts = {}; @@ -299,6 +248,8 @@ MessageList = function MessageList(version, sessionSid) { var deferred = Q.defer(); var data = values.of({ + 'DateCreatedFrom': serialize.iso8601DateTime(_.get(opts, 'dateCreatedFrom')), + 'DateCreatedTo': serialize.iso8601DateTime(_.get(opts, 'dateCreatedTo')), 'PageToken': opts.pageToken, 'Page': opts.pageNumber, 'PageSize': opts.pageSize @@ -307,7 +258,7 @@ MessageList = function MessageList(version, sessionSid) { var promise = this._version.page({uri: this._uri, method: 'GET', params: data}); promise = promise.then(function(payload) { - deferred.resolve(new MessagePage(this._version, payload, this._solution)); + deferred.resolve(new ExecutionPage(this._version, payload, this._solution)); }.bind(this)); promise.catch(function(error) { @@ -323,7 +274,7 @@ MessageList = function MessageList(version, sessionSid) { /* jshint ignore:start */ /** - * Retrieve a single target page of MessageInstance records from the API. + * Retrieve a single target page of ExecutionInstance records from the API. * * The request is executed immediately. * @@ -331,7 +282,7 @@ MessageList = function MessageList(version, sessionSid) { * function. * * @function getPage - * @memberof Twilio.Messaging.V1.SessionContext.MessageList# + * @memberof Twilio.Studio.V2.FlowContext.ExecutionList# * * @param {string} [targetUrl] - API-generated URL for the requested results page * @param {function} [callback] - Callback to handle list of records @@ -339,13 +290,69 @@ MessageList = function MessageList(version, sessionSid) { * @returns {Promise} Resolves to a list of records */ /* jshint ignore:end */ - MessageListInstance.getPage = function getPage(targetUrl, callback) { + ExecutionListInstance.getPage = function getPage(targetUrl, callback) { var deferred = Q.defer(); var promise = this._version._domain.twilio.request({method: 'GET', uri: targetUrl}); promise = promise.then(function(payload) { - deferred.resolve(new MessagePage(this._version, payload, this._solution)); + deferred.resolve(new ExecutionPage(this._version, payload, this._solution)); + }.bind(this)); + + promise.catch(function(error) { + deferred.reject(error); + }); + + if (_.isFunction(callback)) { + deferred.promise.nodeify(callback); + } + + return deferred.promise; + }; + + /* jshint ignore:start */ + /** + * create a ExecutionInstance + * + * @function create + * @memberof Twilio.Studio.V2.FlowContext.ExecutionList# + * + * @param {object} opts - Options for request + * @param {string} opts.to - The to + * @param {string} opts.from - The from + * @param {object} [opts.parameters] - The parameters + * @param {function} [callback] - Callback to handle processed record + * + * @returns {Promise} Resolves to processed ExecutionInstance + */ + /* jshint ignore:end */ + ExecutionListInstance.create = function create(opts, callback) { + if (_.isUndefined(opts)) { + throw new Error('Required parameter "opts" missing.'); + } + if (_.isUndefined(opts.to)) { + throw new Error('Required parameter "opts.to" missing.'); + } + if (_.isUndefined(opts.from)) { + throw new Error('Required parameter "opts.from" missing.'); + } + + var deferred = Q.defer(); + var data = values.of({ + 'To': _.get(opts, 'to'), + 'From': _.get(opts, 'from'), + 'Parameters': serialize.object(_.get(opts, 'parameters')) + }); + + var promise = this._version.create({uri: this._uri, method: 'POST', data: data}); + + promise = promise.then(function(payload) { + deferred.resolve(new ExecutionInstance( + this._version, + payload, + this._solution.flowSid, + this._solution.sid + )); }.bind(this)); promise.catch(function(error) { @@ -361,18 +368,18 @@ MessageList = function MessageList(version, sessionSid) { /* jshint ignore:start */ /** - * Constructs a message + * Constructs a execution * * @function get - * @memberof Twilio.Messaging.V1.SessionContext.MessageList# + * @memberof Twilio.Studio.V2.FlowContext.ExecutionList# * - * @param {string} sid - The SID that identifies the resource to fetch + * @param {string} sid - The sid * - * @returns {Twilio.Messaging.V1.SessionContext.MessageContext} + * @returns {Twilio.Studio.V2.FlowContext.ExecutionContext} */ /* jshint ignore:end */ - MessageListInstance.get = function get(sid) { - return new MessageContext(this._version, this._solution.sessionSid, sid); + ExecutionListInstance.get = function get(sid) { + return new ExecutionContext(this._version, this._solution.flowSid, sid); }; /* jshint ignore:start */ @@ -380,64 +387,63 @@ MessageList = function MessageList(version, sessionSid) { * Provide a user-friendly representation * * @function toJSON - * @memberof Twilio.Messaging.V1.SessionContext.MessageList# + * @memberof Twilio.Studio.V2.FlowContext.ExecutionList# * * @returns Object */ /* jshint ignore:end */ - MessageListInstance.toJSON = function toJSON() { + ExecutionListInstance.toJSON = function toJSON() { return this._solution; }; - MessageListInstance[util.inspect.custom] = function inspect(depth, options) { + ExecutionListInstance[util.inspect.custom] = function inspect(depth, options) { return util.inspect(this.toJSON(), options); }; - return MessageListInstance; + return ExecutionListInstance; }; /* jshint ignore:start */ /** - * Initialize the MessagePage + * Initialize the ExecutionPage * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. * - * @constructor Twilio.Messaging.V1.SessionContext.MessagePage + * @constructor Twilio.Studio.V2.FlowContext.ExecutionPage * - * @param {V1} version - Version of the resource + * @param {V2} version - Version of the resource * @param {Response} response - Response from the API - * @param {MessageSolution} solution - Path solution + * @param {ExecutionSolution} solution - Path solution * - * @returns MessagePage + * @returns ExecutionPage */ /* jshint ignore:end */ -MessagePage = function MessagePage(version, response, solution) { +ExecutionPage = function ExecutionPage(version, response, solution) { // Path Solution this._solution = solution; Page.prototype.constructor.call(this, version, response, this._solution); }; -_.extend(MessagePage.prototype, Page.prototype); -MessagePage.prototype.constructor = MessagePage; +_.extend(ExecutionPage.prototype, Page.prototype); +ExecutionPage.prototype.constructor = ExecutionPage; /* jshint ignore:start */ /** - * Build an instance of MessageInstance + * Build an instance of ExecutionInstance * * @function getInstance - * @memberof Twilio.Messaging.V1.SessionContext.MessagePage# + * @memberof Twilio.Studio.V2.FlowContext.ExecutionPage# * - * @param {MessagePayload} payload - Payload response from the API + * @param {ExecutionPayload} payload - Payload response from the API * - * @returns MessageInstance + * @returns ExecutionInstance */ /* jshint ignore:end */ -MessagePage.prototype.getInstance = function getInstance(payload) { - return new MessageInstance(this._version, payload, this._solution.sessionSid); +ExecutionPage.prototype.getInstance = function getInstance(payload) { + return new ExecutionInstance(this._version, payload, this._solution.flowSid); }; /* jshint ignore:start */ @@ -445,12 +451,12 @@ MessagePage.prototype.getInstance = function getInstance(payload) { * Provide a user-friendly representation * * @function toJSON - * @memberof Twilio.Messaging.V1.SessionContext.MessagePage# + * @memberof Twilio.Studio.V2.FlowContext.ExecutionPage# * * @returns Object */ /* jshint ignore:end */ -MessagePage.prototype.toJSON = function toJSON() { +ExecutionPage.prototype.toJSON = function toJSON() { let clone = {}; _.forOwn(this, function(value, key) { if (!_.startsWith(key, '_') && ! _.isFunction(value)) { @@ -460,73 +466,63 @@ MessagePage.prototype.toJSON = function toJSON() { return clone; }; -MessagePage.prototype[util.inspect.custom] = function inspect(depth, options) { +ExecutionPage.prototype[util.inspect.custom] = function inspect(depth, options) + { return util.inspect(this.toJSON(), options); }; /* jshint ignore:start */ /** - * Initialize the MessageContext - * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - * - * @constructor Twilio.Messaging.V1.SessionContext.MessageInstance - * - * @property {string} accountSid - The SID of the Account that created the resource - * @property {string} serviceSid - - * The SID of the Service that the resource is associated with - * @property {string} messagingServiceSid - - * The SID of the Messaging Service the message belongs to - * @property {string} sessionSid - The SID of the Session for the message - * @property {string} sid - The unique string that identifies the resource - * @property {number} index - The index of the message within the Session - * @property {string} author - - * The identity or the address of the device of the message's author - * @property {string} body - The message body - * @property {string} attributes - - * The JSON string that stores application-specific data - * @property {Date} dateCreated - - * The ISO 8601 date and time in GMT when the resource was created - * @property {Date} dateUpdated - - * The ISO 8601 date and time in GMT when the resource was last updated - * @property {string} url - The absolute URL of the message - * - * @param {V1} version - Version of the resource - * @param {MessagePayload} payload - The instance payload - * @param {sid} sessionSid - The SID of the Session for the message - * @param {sid} sid - The SID that identifies the resource to fetch + * Initialize the ExecutionContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.ExecutionInstance + * + * @property {string} sid - The sid + * @property {string} accountSid - The account_sid + * @property {string} flowSid - The flow_sid + * @property {string} contactChannelAddress - The contact_channel_address + * @property {object} context - The context + * @property {execution.status} status - The status + * @property {Date} dateCreated - The date_created + * @property {Date} dateUpdated - The date_updated + * @property {string} url - The url + * @property {string} links - The links + * + * @param {V2} version - Version of the resource + * @param {ExecutionPayload} payload - The instance payload + * @param {sid} flowSid - The flow_sid + * @param {sid} sid - The sid */ /* jshint ignore:end */ -MessageInstance = function MessageInstance(version, payload, sessionSid, sid) { +ExecutionInstance = function ExecutionInstance(version, payload, flowSid, sid) { this._version = version; // Marshaled Properties - this.accountSid = payload.account_sid; // jshint ignore:line - this.serviceSid = payload.service_sid; // jshint ignore:line - this.messagingServiceSid = payload.messaging_service_sid; // jshint ignore:line - this.sessionSid = payload.session_sid; // jshint ignore:line this.sid = payload.sid; // jshint ignore:line - this.index = deserialize.integer(payload.index); // jshint ignore:line - this.author = payload.author; // jshint ignore:line - this.body = payload.body; // jshint ignore:line - this.attributes = payload.attributes; // jshint ignore:line + this.accountSid = payload.account_sid; // jshint ignore:line + this.flowSid = payload.flow_sid; // jshint ignore:line + this.contactChannelAddress = payload.contact_channel_address; // jshint ignore:line + this.context = payload.context; // jshint ignore:line + this.status = payload.status; // jshint ignore:line this.dateCreated = deserialize.iso8601DateTime(payload.date_created); // jshint ignore:line this.dateUpdated = deserialize.iso8601DateTime(payload.date_updated); // jshint ignore:line this.url = payload.url; // jshint ignore:line + this.links = payload.links; // jshint ignore:line // Context this._context = undefined; - this._solution = {sessionSid: sessionSid, sid: sid || this.sid, }; + this._solution = {flowSid: flowSid, sid: sid || this.sid, }; }; -Object.defineProperty(MessageInstance.prototype, +Object.defineProperty(ExecutionInstance.prototype, '_proxy', { get: function() { if (!this._context) { - this._context = new MessageContext(this._version, this._solution.sessionSid, this._solution.sid); + this._context = new ExecutionContext(this._version, this._solution.flowSid, this._solution.sid); } return this._context; @@ -535,59 +531,62 @@ Object.defineProperty(MessageInstance.prototype, /* jshint ignore:start */ /** - * fetch a MessageInstance + * fetch a ExecutionInstance * * @function fetch - * @memberof Twilio.Messaging.V1.SessionContext.MessageInstance# + * @memberof Twilio.Studio.V2.FlowContext.ExecutionInstance# * * @param {function} [callback] - Callback to handle processed record * - * @returns {Promise} Resolves to processed MessageInstance + * @returns {Promise} Resolves to processed ExecutionInstance */ /* jshint ignore:end */ -MessageInstance.prototype.fetch = function fetch(callback) { +ExecutionInstance.prototype.fetch = function fetch(callback) { return this._proxy.fetch(callback); }; /* jshint ignore:start */ /** - * update a MessageInstance - * - * @function update - * @memberof Twilio.Messaging.V1.SessionContext.MessageInstance# - * - * @param {object} [opts] - Options for request - * @param {string} [opts.author] - The identity of the message's author - * @param {string} [opts.attributes] - - * A JSON string that stores application-specific data - * @param {Date} [opts.dateCreated] - - * The ISO 8601 date and time in GMT when the resource was created - * @param {Date} [opts.dateUpdated] - - * The ISO 8601 date and time in GMT when the resource was updated - * @param {string} [opts.body] - The message body + * remove a ExecutionInstance + * + * @function remove + * @memberof Twilio.Studio.V2.FlowContext.ExecutionInstance# + * * @param {function} [callback] - Callback to handle processed record * - * @returns {Promise} Resolves to processed MessageInstance + * @returns {Promise} Resolves to processed ExecutionInstance */ /* jshint ignore:end */ -MessageInstance.prototype.update = function update(opts, callback) { - return this._proxy.update(opts, callback); +ExecutionInstance.prototype.remove = function remove(callback) { + return this._proxy.remove(callback); }; /* jshint ignore:start */ /** - * remove a MessageInstance + * Access the steps * - * @function remove - * @memberof Twilio.Messaging.V1.SessionContext.MessageInstance# + * @function steps + * @memberof Twilio.Studio.V2.FlowContext.ExecutionInstance# * - * @param {function} [callback] - Callback to handle processed record + * @returns {Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepList} + */ +/* jshint ignore:end */ +ExecutionInstance.prototype.steps = function steps() { + return this._proxy.steps; +}; + +/* jshint ignore:start */ +/** + * Access the executionContext + * + * @function executionContext + * @memberof Twilio.Studio.V2.FlowContext.ExecutionInstance# * - * @returns {Promise} Resolves to processed MessageInstance + * @returns {Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextList} */ /* jshint ignore:end */ -MessageInstance.prototype.remove = function remove(callback) { - return this._proxy.remove(callback); +ExecutionInstance.prototype.executionContext = function executionContext() { + return this._proxy.executionContext; }; /* jshint ignore:start */ @@ -595,12 +594,12 @@ MessageInstance.prototype.remove = function remove(callback) { * Provide a user-friendly representation * * @function toJSON - * @memberof Twilio.Messaging.V1.SessionContext.MessageInstance# + * @memberof Twilio.Studio.V2.FlowContext.ExecutionInstance# * * @returns Object */ /* jshint ignore:end */ -MessageInstance.prototype.toJSON = function toJSON() { +ExecutionInstance.prototype.toJSON = function toJSON() { let clone = {}; _.forOwn(this, function(value, key) { if (!_.startsWith(key, '_') && ! _.isFunction(value)) { @@ -610,7 +609,7 @@ MessageInstance.prototype.toJSON = function toJSON() { return clone; }; -MessageInstance.prototype[util.inspect.custom] = function inspect(depth, +ExecutionInstance.prototype[util.inspect.custom] = function inspect(depth, options) { return util.inspect(this.toJSON(), options); }; @@ -618,107 +617,56 @@ MessageInstance.prototype[util.inspect.custom] = function inspect(depth, /* jshint ignore:start */ /** - * Initialize the MessageContext + * Initialize the ExecutionContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. * - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. + * @constructor Twilio.Studio.V2.FlowContext.ExecutionContext * - * @constructor Twilio.Messaging.V1.SessionContext.MessageContext + * @property {Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepList} steps - + * steps resource + * @property {Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextList} executionContext - + * executionContext resource * - * @param {V1} version - Version of the resource - * @param {sid} sessionSid - The SID of the Session with the message to fetch - * @param {sid} sid - The SID that identifies the resource to fetch + * @param {V2} version - Version of the resource + * @param {sid} flowSid - The flow_sid + * @param {sid} sid - The sid */ /* jshint ignore:end */ -MessageContext = function MessageContext(version, sessionSid, sid) { +ExecutionContext = function ExecutionContext(version, flowSid, sid) { this._version = version; // Path Solution - this._solution = {sessionSid: sessionSid, sid: sid, }; - this._uri = `/Sessions/${sessionSid}/Messages/${sid}`; + this._solution = {flowSid: flowSid, sid: sid, }; + this._uri = `/Flows/${flowSid}/Executions/${sid}`; + + // Dependents + this._steps = undefined; + this._executionContext = undefined; }; /* jshint ignore:start */ /** - * fetch a MessageInstance + * fetch a ExecutionInstance * * @function fetch - * @memberof Twilio.Messaging.V1.SessionContext.MessageContext# + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext# * * @param {function} [callback] - Callback to handle processed record * - * @returns {Promise} Resolves to processed MessageInstance + * @returns {Promise} Resolves to processed ExecutionInstance */ /* jshint ignore:end */ -MessageContext.prototype.fetch = function fetch(callback) { +ExecutionContext.prototype.fetch = function fetch(callback) { var deferred = Q.defer(); var promise = this._version.fetch({uri: this._uri, method: 'GET'}); promise = promise.then(function(payload) { - deferred.resolve(new MessageInstance( - this._version, - payload, - this._solution.sessionSid, - this._solution.sid - )); - }.bind(this)); - - promise.catch(function(error) { - deferred.reject(error); - }); - - if (_.isFunction(callback)) { - deferred.promise.nodeify(callback); - } - - return deferred.promise; -}; - -/* jshint ignore:start */ -/** - * update a MessageInstance - * - * @function update - * @memberof Twilio.Messaging.V1.SessionContext.MessageContext# - * - * @param {object} [opts] - Options for request - * @param {string} [opts.author] - The identity of the message's author - * @param {string} [opts.attributes] - - * A JSON string that stores application-specific data - * @param {Date} [opts.dateCreated] - - * The ISO 8601 date and time in GMT when the resource was created - * @param {Date} [opts.dateUpdated] - - * The ISO 8601 date and time in GMT when the resource was updated - * @param {string} [opts.body] - The message body - * @param {function} [callback] - Callback to handle processed record - * - * @returns {Promise} Resolves to processed MessageInstance - */ -/* jshint ignore:end */ -MessageContext.prototype.update = function update(opts, callback) { - if (_.isFunction(opts)) { - callback = opts; - opts = {}; - } - opts = opts || {}; - - var deferred = Q.defer(); - var data = values.of({ - 'Author': _.get(opts, 'author'), - 'Attributes': _.get(opts, 'attributes'), - 'DateCreated': serialize.iso8601DateTime(_.get(opts, 'dateCreated')), - 'DateUpdated': serialize.iso8601DateTime(_.get(opts, 'dateUpdated')), - 'Body': _.get(opts, 'body') - }); - - var promise = this._version.update({uri: this._uri, method: 'POST', data: data}); - - promise = promise.then(function(payload) { - deferred.resolve(new MessageInstance( + deferred.resolve(new ExecutionInstance( this._version, payload, - this._solution.sessionSid, + this._solution.flowSid, this._solution.sid )); }.bind(this)); @@ -736,17 +684,17 @@ MessageContext.prototype.update = function update(opts, callback) { /* jshint ignore:start */ /** - * remove a MessageInstance + * remove a ExecutionInstance * * @function remove - * @memberof Twilio.Messaging.V1.SessionContext.MessageContext# + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext# * * @param {function} [callback] - Callback to handle processed record * - * @returns {Promise} Resolves to processed MessageInstance + * @returns {Promise} Resolves to processed ExecutionInstance */ /* jshint ignore:end */ -MessageContext.prototype.remove = function remove(callback) { +ExecutionContext.prototype.remove = function remove(callback) { var deferred = Q.defer(); var promise = this._version.remove({uri: this._uri, method: 'DELETE'}); @@ -765,28 +713,52 @@ MessageContext.prototype.remove = function remove(callback) { return deferred.promise; }; +Object.defineProperty(ExecutionContext.prototype, + 'steps', { + get: function() { + if (!this._steps) { + this._steps = new ExecutionStepList(this._version, this._solution.flowSid, this._solution.sid); + } + return this._steps; + } +}); + +Object.defineProperty(ExecutionContext.prototype, + 'executionContext', { + get: function() { + if (!this._executionContext) { + this._executionContext = new ExecutionContextList( + this._version, + this._solution.flowSid, + this._solution.sid + ); + } + return this._executionContext; + } +}); + /* jshint ignore:start */ /** * Provide a user-friendly representation * * @function toJSON - * @memberof Twilio.Messaging.V1.SessionContext.MessageContext# + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext# * * @returns Object */ /* jshint ignore:end */ -MessageContext.prototype.toJSON = function toJSON() { +ExecutionContext.prototype.toJSON = function toJSON() { return this._solution; }; -MessageContext.prototype[util.inspect.custom] = function inspect(depth, options) - { +ExecutionContext.prototype[util.inspect.custom] = function inspect(depth, + options) { return util.inspect(this.toJSON(), options); }; module.exports = { - MessageList: MessageList, - MessagePage: MessagePage, - MessageInstance: MessageInstance, - MessageContext: MessageContext + ExecutionList: ExecutionList, + ExecutionPage: ExecutionPage, + ExecutionInstance: ExecutionInstance, + ExecutionContext: ExecutionContext }; diff --git a/lib/rest/studio/v2/flow/execution/executionContext.d.ts b/lib/rest/studio/v2/flow/execution/executionContext.d.ts new file mode 100644 index 0000000000..a30fb6595d --- /dev/null +++ b/lib/rest/studio/v2/flow/execution/executionContext.d.ts @@ -0,0 +1,141 @@ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ + +import Page = require('../../../../../base/Page'); +import Response = require('../../../../../http/response'); +import V2 = require('../../../V2'); +import { SerializableClass } from '../../../../../interfaces'; + +/** + * Initialize the ExecutionContextList + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param flowSid - The flow_sid + * @param executionSid - The execution_sid + */ +declare function ExecutionContextList(version: V2, flowSid: string, executionSid: string): ExecutionContextListInstance; + +interface ExecutionContextListInstance { + /** + * @param sid - sid of instance + */ + (sid: string): ExecutionContextContext; + /** + * Constructs a execution_context + */ + get(): ExecutionContextContext; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + +interface ExecutionContextPayload extends ExecutionContextResource, Page.TwilioResponsePayload { +} + +interface ExecutionContextResource { + account_sid: string; + context: object; + execution_sid: string; + flow_sid: string; + url: string; +} + +interface ExecutionContextSolution { + executionSid?: string; + flowSid?: string; +} + + +declare class ExecutionContextContext { + /** + * Initialize the ExecutionContextContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param flowSid - The flow_sid + * @param executionSid - The execution_sid + */ + constructor(version: V2, flowSid: string, executionSid: string); + + /** + * fetch a ExecutionContextInstance + * + * @param callback - Callback to handle processed record + */ + fetch(callback?: (error: Error | null, items: ExecutionContextInstance) => any): Promise; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + + +declare class ExecutionContextInstance extends SerializableClass { + /** + * Initialize the ExecutionContextContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param payload - The instance payload + * @param flowSid - The flow_sid + * @param executionSid - The execution_sid + */ + constructor(version: V2, payload: ExecutionContextPayload, flowSid: string, executionSid: string); + + private _proxy: ExecutionContextContext; + accountSid: string; + context: object; + executionSid: string; + /** + * fetch a ExecutionContextInstance + * + * @param callback - Callback to handle processed record + */ + fetch(callback?: (error: Error | null, items: ExecutionContextInstance) => any): Promise; + flowSid: string; + /** + * Provide a user-friendly representation + */ + toJSON(): any; + url: string; +} + + +declare class ExecutionContextPage extends Page { + /** + * Initialize the ExecutionContextPage + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param response - Response from the API + * @param solution - Path solution + */ + constructor(version: V2, response: Response, solution: ExecutionContextSolution); + + /** + * Build an instance of ExecutionContextInstance + * + * @param payload - Payload response from the API + */ + getInstance(payload: ExecutionContextPayload): ExecutionContextInstance; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + +export { ExecutionContextContext, ExecutionContextInstance, ExecutionContextList, ExecutionContextListInstance, ExecutionContextPage, ExecutionContextPayload, ExecutionContextResource, ExecutionContextSolution } diff --git a/lib/rest/studio/v2/flow/execution/executionContext.js b/lib/rest/studio/v2/flow/execution/executionContext.js new file mode 100644 index 0000000000..dba5496f8f --- /dev/null +++ b/lib/rest/studio/v2/flow/execution/executionContext.js @@ -0,0 +1,348 @@ +'use strict'; + +/* jshint ignore:start */ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ +/* jshint ignore:end */ + +var Q = require('q'); /* jshint ignore:line */ +var _ = require('lodash'); /* jshint ignore:line */ +var util = require('util'); /* jshint ignore:line */ +var Page = require('../../../../../base/Page'); /* jshint ignore:line */ +var values = require('../../../../../base/values'); /* jshint ignore:line */ + +var ExecutionContextList; +var ExecutionContextPage; +var ExecutionContextInstance; +var ExecutionContextContext; + +/* jshint ignore:start */ +/** + * Initialize the ExecutionContextList + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextList + * + * @param {Twilio.Studio.V2} version - Version of the resource + * @param {string} flowSid - The flow_sid + * @param {string} executionSid - The execution_sid + */ +/* jshint ignore:end */ +ExecutionContextList = function ExecutionContextList(version, flowSid, + executionSid) { + /* jshint ignore:start */ + /** + * @function executionContext + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext# + * + * @param {string} sid - sid of instance + * + * @returns {Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextContext} + */ + /* jshint ignore:end */ + function ExecutionContextListInstance(sid) { + return ExecutionContextListInstance.get(sid); + } + + ExecutionContextListInstance._version = version; + // Path Solution + ExecutionContextListInstance._solution = {flowSid: flowSid, executionSid: executionSid}; + /* jshint ignore:start */ + /** + * Constructs a execution_context + * + * @function get + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextList# + * + * @returns {Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextContext} + */ + /* jshint ignore:end */ + ExecutionContextListInstance.get = function get() { + return new ExecutionContextContext( + this._version, + this._solution.flowSid, + this._solution.executionSid + ); + }; + + /* jshint ignore:start */ + /** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextList# + * + * @returns Object + */ + /* jshint ignore:end */ + ExecutionContextListInstance.toJSON = function toJSON() { + return this._solution; + }; + + ExecutionContextListInstance[util.inspect.custom] = function inspect(depth, + options) { + return util.inspect(this.toJSON(), options); + }; + + return ExecutionContextListInstance; +}; + + +/* jshint ignore:start */ +/** + * Initialize the ExecutionContextPage + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextPage + * + * @param {V2} version - Version of the resource + * @param {Response} response - Response from the API + * @param {ExecutionContextSolution} solution - Path solution + * + * @returns ExecutionContextPage + */ +/* jshint ignore:end */ +ExecutionContextPage = function ExecutionContextPage(version, response, + solution) { + // Path Solution + this._solution = solution; + + Page.prototype.constructor.call(this, version, response, this._solution); +}; + +_.extend(ExecutionContextPage.prototype, Page.prototype); +ExecutionContextPage.prototype.constructor = ExecutionContextPage; + +/* jshint ignore:start */ +/** + * Build an instance of ExecutionContextInstance + * + * @function getInstance + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextPage# + * + * @param {ExecutionContextPayload} payload - Payload response from the API + * + * @returns ExecutionContextInstance + */ +/* jshint ignore:end */ +ExecutionContextPage.prototype.getInstance = function getInstance(payload) { + return new ExecutionContextInstance( + this._version, + payload, + this._solution.flowSid, + this._solution.executionSid + ); +}; + +/* jshint ignore:start */ +/** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextPage# + * + * @returns Object + */ +/* jshint ignore:end */ +ExecutionContextPage.prototype.toJSON = function toJSON() { + let clone = {}; + _.forOwn(this, function(value, key) { + if (!_.startsWith(key, '_') && ! _.isFunction(value)) { + clone[key] = value; + } + }); + return clone; +}; + +ExecutionContextPage.prototype[util.inspect.custom] = function inspect(depth, + options) { + return util.inspect(this.toJSON(), options); +}; + + +/* jshint ignore:start */ +/** + * Initialize the ExecutionContextContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextInstance + * + * @property {string} accountSid - The account_sid + * @property {object} context - The context + * @property {string} flowSid - The flow_sid + * @property {string} executionSid - The execution_sid + * @property {string} url - The url + * + * @param {V2} version - Version of the resource + * @param {ExecutionContextPayload} payload - The instance payload + * @param {sid} flowSid - The flow_sid + * @param {sid} executionSid - The execution_sid + */ +/* jshint ignore:end */ +ExecutionContextInstance = function ExecutionContextInstance(version, payload, + flowSid, executionSid) { + this._version = version; + + // Marshaled Properties + this.accountSid = payload.account_sid; // jshint ignore:line + this.context = payload.context; // jshint ignore:line + this.flowSid = payload.flow_sid; // jshint ignore:line + this.executionSid = payload.execution_sid; // jshint ignore:line + this.url = payload.url; // jshint ignore:line + + // Context + this._context = undefined; + this._solution = {flowSid: flowSid, executionSid: executionSid, }; +}; + +Object.defineProperty(ExecutionContextInstance.prototype, + '_proxy', { + get: function() { + if (!this._context) { + this._context = new ExecutionContextContext( + this._version, + this._solution.flowSid, + this._solution.executionSid + ); + } + + return this._context; + } +}); + +/* jshint ignore:start */ +/** + * fetch a ExecutionContextInstance + * + * @function fetch + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextInstance# + * + * @param {function} [callback] - Callback to handle processed record + * + * @returns {Promise} Resolves to processed ExecutionContextInstance + */ +/* jshint ignore:end */ +ExecutionContextInstance.prototype.fetch = function fetch(callback) { + return this._proxy.fetch(callback); +}; + +/* jshint ignore:start */ +/** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextInstance# + * + * @returns Object + */ +/* jshint ignore:end */ +ExecutionContextInstance.prototype.toJSON = function toJSON() { + let clone = {}; + _.forOwn(this, function(value, key) { + if (!_.startsWith(key, '_') && ! _.isFunction(value)) { + clone[key] = value; + } + }); + return clone; +}; + +ExecutionContextInstance.prototype[util.inspect.custom] = function + inspect(depth, options) { + return util.inspect(this.toJSON(), options); +}; + + +/* jshint ignore:start */ +/** + * Initialize the ExecutionContextContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextContext + * + * @param {V2} version - Version of the resource + * @param {sid} flowSid - The flow_sid + * @param {sid} executionSid - The execution_sid + */ +/* jshint ignore:end */ +ExecutionContextContext = function ExecutionContextContext(version, flowSid, + executionSid) { + this._version = version; + + // Path Solution + this._solution = {flowSid: flowSid, executionSid: executionSid, }; + this._uri = `/Flows/${flowSid}/Executions/${executionSid}/Context`; +}; + +/* jshint ignore:start */ +/** + * fetch a ExecutionContextInstance + * + * @function fetch + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextContext# + * + * @param {function} [callback] - Callback to handle processed record + * + * @returns {Promise} Resolves to processed ExecutionContextInstance + */ +/* jshint ignore:end */ +ExecutionContextContext.prototype.fetch = function fetch(callback) { + var deferred = Q.defer(); + var promise = this._version.fetch({uri: this._uri, method: 'GET'}); + + promise = promise.then(function(payload) { + deferred.resolve(new ExecutionContextInstance( + this._version, + payload, + this._solution.flowSid, + this._solution.executionSid + )); + }.bind(this)); + + promise.catch(function(error) { + deferred.reject(error); + }); + + if (_.isFunction(callback)) { + deferred.promise.nodeify(callback); + } + + return deferred.promise; +}; + +/* jshint ignore:start */ +/** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionContextContext# + * + * @returns Object + */ +/* jshint ignore:end */ +ExecutionContextContext.prototype.toJSON = function toJSON() { + return this._solution; +}; + +ExecutionContextContext.prototype[util.inspect.custom] = function inspect(depth, + options) { + return util.inspect(this.toJSON(), options); +}; + +module.exports = { + ExecutionContextList: ExecutionContextList, + ExecutionContextPage: ExecutionContextPage, + ExecutionContextInstance: ExecutionContextInstance, + ExecutionContextContext: ExecutionContextContext +}; diff --git a/lib/rest/studio/v2/flow/execution/executionStep.d.ts b/lib/rest/studio/v2/flow/execution/executionStep.d.ts new file mode 100644 index 0000000000..49a3bb26c9 --- /dev/null +++ b/lib/rest/studio/v2/flow/execution/executionStep.d.ts @@ -0,0 +1,273 @@ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ + +import Page = require('../../../../../base/Page'); +import Response = require('../../../../../http/response'); +import V2 = require('../../../V2'); +import { ExecutionStepContextList } from './executionStep/executionStepContext'; +import { ExecutionStepContextListInstance } from './executionStep/executionStepContext'; +import { SerializableClass } from '../../../../../interfaces'; + +/** + * Initialize the ExecutionStepList + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param flowSid - The flow_sid + * @param executionSid - The execution_sid + */ +declare function ExecutionStepList(version: V2, flowSid: string, executionSid: string): ExecutionStepListInstance; + +interface ExecutionStepListInstance { + /** + * @param sid - sid of instance + */ + (sid: string): ExecutionStepContext; + /** + * Streams ExecutionStepInstance records from the API. + * + * This operation lazily loads records as efficiently as possible until the limit + * is reached. + * + * The results are passed into the callback function, so this operation is memory + * efficient. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @param opts - Options for request + * @param callback - Function to process each record + */ + each(opts?: ExecutionStepListInstanceEachOptions, callback?: (item: ExecutionStepInstance, done: (err?: Error) => void) => void): void; + /** + * Constructs a execution_step + * + * @param sid - The sid + */ + get(sid: string): ExecutionStepContext; + /** + * Retrieve a single target page of ExecutionStepInstance records from the API. + * + * The request is executed immediately. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @param targetUrl - API-generated URL for the requested results page + * @param callback - Callback to handle list of records + */ + getPage(targetUrl?: string, callback?: (error: Error | null, items: ExecutionStepPage) => any): Promise; + /** + * Lists ExecutionStepInstance records from the API as a list. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @param opts - Options for request + * @param callback - Callback to handle list of records + */ + list(opts?: ExecutionStepListInstanceOptions, callback?: (error: Error | null, items: ExecutionStepInstance[]) => any): Promise; + /** + * Retrieve a single page of ExecutionStepInstance records from the API. + * + * The request is executed immediately. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @param opts - Options for request + * @param callback - Callback to handle list of records + */ + page(opts?: ExecutionStepListInstancePageOptions, callback?: (error: Error | null, items: ExecutionStepPage) => any): Promise; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + +/** + * Options to pass to each + * + * @property callback - + * Function to process each record. If this and a positional + * callback are passed, this one will be used + * @property done - Function to be called upon completion of streaming + * @property limit - + * Upper limit for the number of records to return. + * each() guarantees never to return more than limit. + * Default is no limit + * @property pageSize - + * Number of records to fetch per request, + * when not set will use the default value of 50 records. + * If no pageSize is defined but a limit is defined, + * each() will attempt to read the limit with the most efficient + * page size, i.e. min(limit, 1000) + */ +interface ExecutionStepListInstanceEachOptions { + callback?: (item: ExecutionStepInstance, done: (err?: Error) => void) => void; + done?: Function; + limit?: number; + pageSize?: number; +} + +/** + * Options to pass to list + * + * @property limit - + * Upper limit for the number of records to return. + * list() guarantees never to return more than limit. + * Default is no limit + * @property pageSize - + * Number of records to fetch per request, + * when not set will use the default value of 50 records. + * If no page_size is defined but a limit is defined, + * list() will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + */ +interface ExecutionStepListInstanceOptions { + limit?: number; + pageSize?: number; +} + +/** + * Options to pass to page + * + * @property pageNumber - Page Number, this value is simply for client state + * @property pageSize - Number of records to return, defaults to 50 + * @property pageToken - PageToken provided by the API + */ +interface ExecutionStepListInstancePageOptions { + pageNumber?: number; + pageSize?: number; + pageToken?: string; +} + +interface ExecutionStepPayload extends ExecutionStepResource, Page.TwilioResponsePayload { +} + +interface ExecutionStepResource { + account_sid: string; + context: object; + date_created: Date; + date_updated: Date; + execution_sid: string; + flow_sid: string; + links: string; + name: string; + sid: string; + transitioned_from: string; + transitioned_to: string; + url: string; +} + +interface ExecutionStepSolution { + executionSid?: string; + flowSid?: string; +} + + +declare class ExecutionStepContext { + /** + * Initialize the ExecutionStepContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param flowSid - The flow_sid + * @param executionSid - The execution_sid + * @param sid - The sid + */ + constructor(version: V2, flowSid: string, executionSid: string, sid: string); + + /** + * fetch a ExecutionStepInstance + * + * @param callback - Callback to handle processed record + */ + fetch(callback?: (error: Error | null, items: ExecutionStepInstance) => any): Promise; + stepContext: ExecutionStepContextListInstance; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + + +declare class ExecutionStepInstance extends SerializableClass { + /** + * Initialize the ExecutionStepContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param payload - The instance payload + * @param flowSid - The flow_sid + * @param executionSid - The execution_sid + * @param sid - The sid + */ + constructor(version: V2, payload: ExecutionStepPayload, flowSid: string, executionSid: string, sid: string); + + private _proxy: ExecutionStepContext; + accountSid: string; + context: object; + dateCreated: Date; + dateUpdated: Date; + executionSid: string; + /** + * fetch a ExecutionStepInstance + * + * @param callback - Callback to handle processed record + */ + fetch(callback?: (error: Error | null, items: ExecutionStepInstance) => any): Promise; + flowSid: string; + links: string; + name: string; + sid: string; + /** + * Access the stepContext + */ + stepContext(): ExecutionStepContextListInstance; + /** + * Provide a user-friendly representation + */ + toJSON(): any; + transitionedFrom: string; + transitionedTo: string; + url: string; +} + + +declare class ExecutionStepPage extends Page { + /** + * Initialize the ExecutionStepPage + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param response - Response from the API + * @param solution - Path solution + */ + constructor(version: V2, response: Response, solution: ExecutionStepSolution); + + /** + * Build an instance of ExecutionStepInstance + * + * @param payload - Payload response from the API + */ + getInstance(payload: ExecutionStepPayload): ExecutionStepInstance; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + +export { ExecutionStepContext, ExecutionStepInstance, ExecutionStepList, ExecutionStepListInstance, ExecutionStepListInstanceEachOptions, ExecutionStepListInstanceOptions, ExecutionStepListInstancePageOptions, ExecutionStepPage, ExecutionStepPayload, ExecutionStepResource, ExecutionStepSolution } diff --git a/lib/rest/studio/v2/flow/execution/executionStep.js b/lib/rest/studio/v2/flow/execution/executionStep.js new file mode 100644 index 0000000000..8d4c994f18 --- /dev/null +++ b/lib/rest/studio/v2/flow/execution/executionStep.js @@ -0,0 +1,652 @@ +'use strict'; + +/* jshint ignore:start */ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ +/* jshint ignore:end */ + +var Q = require('q'); /* jshint ignore:line */ +var _ = require('lodash'); /* jshint ignore:line */ +var util = require('util'); /* jshint ignore:line */ +var ExecutionStepContextList = require( + './executionStep/executionStepContext').ExecutionStepContextList; +var Page = require('../../../../../base/Page'); /* jshint ignore:line */ +var deserialize = require( + '../../../../../base/deserialize'); /* jshint ignore:line */ +var values = require('../../../../../base/values'); /* jshint ignore:line */ + +var ExecutionStepList; +var ExecutionStepPage; +var ExecutionStepInstance; +var ExecutionStepContext; + +/* jshint ignore:start */ +/** + * Initialize the ExecutionStepList + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepList + * + * @param {Twilio.Studio.V2} version - Version of the resource + * @param {string} flowSid - The flow_sid + * @param {string} executionSid - The execution_sid + */ +/* jshint ignore:end */ +ExecutionStepList = function ExecutionStepList(version, flowSid, executionSid) { + /* jshint ignore:start */ + /** + * @function steps + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext# + * + * @param {string} sid - sid of instance + * + * @returns {Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext} + */ + /* jshint ignore:end */ + function ExecutionStepListInstance(sid) { + return ExecutionStepListInstance.get(sid); + } + + ExecutionStepListInstance._version = version; + // Path Solution + ExecutionStepListInstance._solution = {flowSid: flowSid, executionSid: executionSid}; + ExecutionStepListInstance._uri = `/Flows/${flowSid}/Executions/${executionSid}/Steps`; + /* jshint ignore:start */ + /** + * Streams ExecutionStepInstance records from the API. + * + * This operation lazily loads records as efficiently as possible until the limit + * is reached. + * + * The results are passed into the callback function, so this operation is memory + * efficient. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @function each + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepList# + * + * @param {object} [opts] - Options for request + * @param {number} [opts.limit] - + * Upper limit for the number of records to return. + * each() guarantees never to return more than limit. + * Default is no limit + * @param {number} [opts.pageSize] - + * Number of records to fetch per request, + * when not set will use the default value of 50 records. + * If no pageSize is defined but a limit is defined, + * each() will attempt to read the limit with the most efficient + * page size, i.e. min(limit, 1000) + * @param {Function} [opts.callback] - + * Function to process each record. If this and a positional + * callback are passed, this one will be used + * @param {Function} [opts.done] - + * Function to be called upon completion of streaming + * @param {Function} [callback] - Function to process each record + */ + /* jshint ignore:end */ + ExecutionStepListInstance.each = function each(opts, callback) { + if (_.isFunction(opts)) { + callback = opts; + opts = {}; + } + opts = opts || {}; + if (opts.callback) { + callback = opts.callback; + } + if (_.isUndefined(callback)) { + throw new Error('Callback function must be provided'); + } + + var done = false; + var currentPage = 1; + var currentResource = 0; + var limits = this._version.readLimits({ + limit: opts.limit, + pageSize: opts.pageSize + }); + + function onComplete(error) { + done = true; + if (_.isFunction(opts.done)) { + opts.done(error); + } + } + + function fetchNextPage(fn) { + var promise = fn(); + if (_.isUndefined(promise)) { + onComplete(); + return; + } + + promise.then(function(page) { + _.each(page.instances, function(instance) { + if (done || (!_.isUndefined(opts.limit) && currentResource >= opts.limit)) { + done = true; + return false; + } + + currentResource++; + callback(instance, onComplete); + }); + + if ((limits.pageLimit && limits.pageLimit <= currentPage)) { + onComplete(); + } else if (!done) { + currentPage++; + fetchNextPage(_.bind(page.nextPage, page)); + } + }); + + promise.catch(onComplete); + } + + fetchNextPage(_.bind(this.page, this, _.merge(opts, limits))); + }; + + /* jshint ignore:start */ + /** + * Lists ExecutionStepInstance records from the API as a list. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @function list + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepList# + * + * @param {object} [opts] - Options for request + * @param {number} [opts.limit] - + * Upper limit for the number of records to return. + * list() guarantees never to return more than limit. + * Default is no limit + * @param {number} [opts.pageSize] - + * Number of records to fetch per request, + * when not set will use the default value of 50 records. + * If no page_size is defined but a limit is defined, + * list() will attempt to read the limit with the most + * efficient page size, i.e. min(limit, 1000) + * @param {function} [callback] - Callback to handle list of records + * + * @returns {Promise} Resolves to a list of records + */ + /* jshint ignore:end */ + ExecutionStepListInstance.list = function list(opts, callback) { + if (_.isFunction(opts)) { + callback = opts; + opts = {}; + } + opts = opts || {}; + var deferred = Q.defer(); + var allResources = []; + opts.callback = function(resource, done) { + allResources.push(resource); + + if (!_.isUndefined(opts.limit) && allResources.length === opts.limit) { + done(); + } + }; + + opts.done = function(error) { + if (_.isUndefined(error)) { + deferred.resolve(allResources); + } else { + deferred.reject(error); + } + }; + + if (_.isFunction(callback)) { + deferred.promise.nodeify(callback); + } + + this.each(opts); + return deferred.promise; + }; + + /* jshint ignore:start */ + /** + * Retrieve a single page of ExecutionStepInstance records from the API. + * + * The request is executed immediately. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @function page + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepList# + * + * @param {object} [opts] - Options for request + * @param {string} [opts.pageToken] - PageToken provided by the API + * @param {number} [opts.pageNumber] - + * Page Number, this value is simply for client state + * @param {number} [opts.pageSize] - Number of records to return, defaults to 50 + * @param {function} [callback] - Callback to handle list of records + * + * @returns {Promise} Resolves to a list of records + */ + /* jshint ignore:end */ + ExecutionStepListInstance.page = function page(opts, callback) { + if (_.isFunction(opts)) { + callback = opts; + opts = {}; + } + opts = opts || {}; + + var deferred = Q.defer(); + var data = values.of({ + 'PageToken': opts.pageToken, + 'Page': opts.pageNumber, + 'PageSize': opts.pageSize + }); + + var promise = this._version.page({uri: this._uri, method: 'GET', params: data}); + + promise = promise.then(function(payload) { + deferred.resolve(new ExecutionStepPage(this._version, payload, this._solution)); + }.bind(this)); + + promise.catch(function(error) { + deferred.reject(error); + }); + + if (_.isFunction(callback)) { + deferred.promise.nodeify(callback); + } + + return deferred.promise; + }; + + /* jshint ignore:start */ + /** + * Retrieve a single target page of ExecutionStepInstance records from the API. + * + * The request is executed immediately. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @function getPage + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepList# + * + * @param {string} [targetUrl] - API-generated URL for the requested results page + * @param {function} [callback] - Callback to handle list of records + * + * @returns {Promise} Resolves to a list of records + */ + /* jshint ignore:end */ + ExecutionStepListInstance.getPage = function getPage(targetUrl, callback) { + var deferred = Q.defer(); + + var promise = this._version._domain.twilio.request({method: 'GET', uri: targetUrl}); + + promise = promise.then(function(payload) { + deferred.resolve(new ExecutionStepPage(this._version, payload, this._solution)); + }.bind(this)); + + promise.catch(function(error) { + deferred.reject(error); + }); + + if (_.isFunction(callback)) { + deferred.promise.nodeify(callback); + } + + return deferred.promise; + }; + + /* jshint ignore:start */ + /** + * Constructs a execution_step + * + * @function get + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepList# + * + * @param {string} sid - The sid + * + * @returns {Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext} + */ + /* jshint ignore:end */ + ExecutionStepListInstance.get = function get(sid) { + return new ExecutionStepContext( + this._version, + this._solution.flowSid, + this._solution.executionSid, + sid + ); + }; + + /* jshint ignore:start */ + /** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepList# + * + * @returns Object + */ + /* jshint ignore:end */ + ExecutionStepListInstance.toJSON = function toJSON() { + return this._solution; + }; + + ExecutionStepListInstance[util.inspect.custom] = function inspect(depth, + options) { + return util.inspect(this.toJSON(), options); + }; + + return ExecutionStepListInstance; +}; + + +/* jshint ignore:start */ +/** + * Initialize the ExecutionStepPage + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepPage + * + * @param {V2} version - Version of the resource + * @param {Response} response - Response from the API + * @param {ExecutionStepSolution} solution - Path solution + * + * @returns ExecutionStepPage + */ +/* jshint ignore:end */ +ExecutionStepPage = function ExecutionStepPage(version, response, solution) { + // Path Solution + this._solution = solution; + + Page.prototype.constructor.call(this, version, response, this._solution); +}; + +_.extend(ExecutionStepPage.prototype, Page.prototype); +ExecutionStepPage.prototype.constructor = ExecutionStepPage; + +/* jshint ignore:start */ +/** + * Build an instance of ExecutionStepInstance + * + * @function getInstance + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepPage# + * + * @param {ExecutionStepPayload} payload - Payload response from the API + * + * @returns ExecutionStepInstance + */ +/* jshint ignore:end */ +ExecutionStepPage.prototype.getInstance = function getInstance(payload) { + return new ExecutionStepInstance( + this._version, + payload, + this._solution.flowSid, + this._solution.executionSid + ); +}; + +/* jshint ignore:start */ +/** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepPage# + * + * @returns Object + */ +/* jshint ignore:end */ +ExecutionStepPage.prototype.toJSON = function toJSON() { + let clone = {}; + _.forOwn(this, function(value, key) { + if (!_.startsWith(key, '_') && ! _.isFunction(value)) { + clone[key] = value; + } + }); + return clone; +}; + +ExecutionStepPage.prototype[util.inspect.custom] = function inspect(depth, + options) { + return util.inspect(this.toJSON(), options); +}; + + +/* jshint ignore:start */ +/** + * Initialize the ExecutionStepContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepInstance + * + * @property {string} sid - The sid + * @property {string} accountSid - The account_sid + * @property {string} flowSid - The flow_sid + * @property {string} executionSid - The execution_sid + * @property {string} name - The name + * @property {object} context - The context + * @property {string} transitionedFrom - The transitioned_from + * @property {string} transitionedTo - The transitioned_to + * @property {Date} dateCreated - The date_created + * @property {Date} dateUpdated - The date_updated + * @property {string} url - The url + * @property {string} links - The links + * + * @param {V2} version - Version of the resource + * @param {ExecutionStepPayload} payload - The instance payload + * @param {sid} flowSid - The flow_sid + * @param {sid} executionSid - The execution_sid + * @param {sid} sid - The sid + */ +/* jshint ignore:end */ +ExecutionStepInstance = function ExecutionStepInstance(version, payload, + flowSid, executionSid, + sid) { + this._version = version; + + // Marshaled Properties + this.sid = payload.sid; // jshint ignore:line + this.accountSid = payload.account_sid; // jshint ignore:line + this.flowSid = payload.flow_sid; // jshint ignore:line + this.executionSid = payload.execution_sid; // jshint ignore:line + this.name = payload.name; // jshint ignore:line + this.context = payload.context; // jshint ignore:line + this.transitionedFrom = payload.transitioned_from; // jshint ignore:line + this.transitionedTo = payload.transitioned_to; // jshint ignore:line + this.dateCreated = deserialize.iso8601DateTime(payload.date_created); // jshint ignore:line + this.dateUpdated = deserialize.iso8601DateTime(payload.date_updated); // jshint ignore:line + this.url = payload.url; // jshint ignore:line + this.links = payload.links; // jshint ignore:line + + // Context + this._context = undefined; + this._solution = {flowSid: flowSid, executionSid: executionSid, sid: sid || this.sid, }; +}; + +Object.defineProperty(ExecutionStepInstance.prototype, + '_proxy', { + get: function() { + if (!this._context) { + this._context = new ExecutionStepContext( + this._version, + this._solution.flowSid, + this._solution.executionSid, + this._solution.sid + ); + } + + return this._context; + } +}); + +/* jshint ignore:start */ +/** + * fetch a ExecutionStepInstance + * + * @function fetch + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepInstance# + * + * @param {function} [callback] - Callback to handle processed record + * + * @returns {Promise} Resolves to processed ExecutionStepInstance + */ +/* jshint ignore:end */ +ExecutionStepInstance.prototype.fetch = function fetch(callback) { + return this._proxy.fetch(callback); +}; + +/* jshint ignore:start */ +/** + * Access the stepContext + * + * @function stepContext + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepInstance# + * + * @returns {Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextList} + */ +/* jshint ignore:end */ +ExecutionStepInstance.prototype.stepContext = function stepContext() { + return this._proxy.stepContext; +}; + +/* jshint ignore:start */ +/** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepInstance# + * + * @returns Object + */ +/* jshint ignore:end */ +ExecutionStepInstance.prototype.toJSON = function toJSON() { + let clone = {}; + _.forOwn(this, function(value, key) { + if (!_.startsWith(key, '_') && ! _.isFunction(value)) { + clone[key] = value; + } + }); + return clone; +}; + +ExecutionStepInstance.prototype[util.inspect.custom] = function inspect(depth, + options) { + return util.inspect(this.toJSON(), options); +}; + + +/* jshint ignore:start */ +/** + * Initialize the ExecutionStepContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext + * + * @property {Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextList} stepContext - + * stepContext resource + * + * @param {V2} version - Version of the resource + * @param {sid} flowSid - The flow_sid + * @param {sid} executionSid - The execution_sid + * @param {sid} sid - The sid + */ +/* jshint ignore:end */ +ExecutionStepContext = function ExecutionStepContext(version, flowSid, + executionSid, sid) { + this._version = version; + + // Path Solution + this._solution = {flowSid: flowSid, executionSid: executionSid, sid: sid, }; + this._uri = `/Flows/${flowSid}/Executions/${executionSid}/Steps/${sid}`; + + // Dependents + this._stepContext = undefined; +}; + +/* jshint ignore:start */ +/** + * fetch a ExecutionStepInstance + * + * @function fetch + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext# + * + * @param {function} [callback] - Callback to handle processed record + * + * @returns {Promise} Resolves to processed ExecutionStepInstance + */ +/* jshint ignore:end */ +ExecutionStepContext.prototype.fetch = function fetch(callback) { + var deferred = Q.defer(); + var promise = this._version.fetch({uri: this._uri, method: 'GET'}); + + promise = promise.then(function(payload) { + deferred.resolve(new ExecutionStepInstance( + this._version, + payload, + this._solution.flowSid, + this._solution.executionSid, + this._solution.sid + )); + }.bind(this)); + + promise.catch(function(error) { + deferred.reject(error); + }); + + if (_.isFunction(callback)) { + deferred.promise.nodeify(callback); + } + + return deferred.promise; +}; + +Object.defineProperty(ExecutionStepContext.prototype, + 'stepContext', { + get: function() { + if (!this._stepContext) { + this._stepContext = new ExecutionStepContextList( + this._version, + this._solution.flowSid, + this._solution.executionSid, + this._solution.sid + ); + } + return this._stepContext; + } +}); + +/* jshint ignore:start */ +/** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext# + * + * @returns Object + */ +/* jshint ignore:end */ +ExecutionStepContext.prototype.toJSON = function toJSON() { + return this._solution; +}; + +ExecutionStepContext.prototype[util.inspect.custom] = function inspect(depth, + options) { + return util.inspect(this.toJSON(), options); +}; + +module.exports = { + ExecutionStepList: ExecutionStepList, + ExecutionStepPage: ExecutionStepPage, + ExecutionStepInstance: ExecutionStepInstance, + ExecutionStepContext: ExecutionStepContext +}; diff --git a/lib/rest/studio/v2/flow/execution/executionStep/executionStepContext.d.ts b/lib/rest/studio/v2/flow/execution/executionStep/executionStepContext.d.ts new file mode 100644 index 0000000000..11293edf14 --- /dev/null +++ b/lib/rest/studio/v2/flow/execution/executionStep/executionStepContext.d.ts @@ -0,0 +1,147 @@ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ + +import Page = require('../../../../../../base/Page'); +import Response = require('../../../../../../http/response'); +import V2 = require('../../../../V2'); +import { SerializableClass } from '../../../../../../interfaces'; + +/** + * Initialize the ExecutionStepContextList + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param flowSid - The flow_sid + * @param executionSid - The execution_sid + * @param stepSid - The step_sid + */ +declare function ExecutionStepContextList(version: V2, flowSid: string, executionSid: string, stepSid: string): ExecutionStepContextListInstance; + +interface ExecutionStepContextListInstance { + /** + * @param sid - sid of instance + */ + (sid: string): ExecutionStepContextContext; + /** + * Constructs a execution_step_context + */ + get(): ExecutionStepContextContext; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + +interface ExecutionStepContextPayload extends ExecutionStepContextResource, Page.TwilioResponsePayload { +} + +interface ExecutionStepContextResource { + account_sid: string; + context: object; + execution_sid: string; + flow_sid: string; + step_sid: string; + url: string; +} + +interface ExecutionStepContextSolution { + executionSid?: string; + flowSid?: string; + stepSid?: string; +} + + +declare class ExecutionStepContextContext { + /** + * Initialize the ExecutionStepContextContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param flowSid - The flow_sid + * @param executionSid - The execution_sid + * @param stepSid - The step_sid + */ + constructor(version: V2, flowSid: string, executionSid: string, stepSid: string); + + /** + * fetch a ExecutionStepContextInstance + * + * @param callback - Callback to handle processed record + */ + fetch(callback?: (error: Error | null, items: ExecutionStepContextInstance) => any): Promise; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + + +declare class ExecutionStepContextInstance extends SerializableClass { + /** + * Initialize the ExecutionStepContextContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param payload - The instance payload + * @param flowSid - The flow_sid + * @param executionSid - The execution_sid + * @param stepSid - The step_sid + */ + constructor(version: V2, payload: ExecutionStepContextPayload, flowSid: string, executionSid: string, stepSid: string); + + private _proxy: ExecutionStepContextContext; + accountSid: string; + context: object; + executionSid: string; + /** + * fetch a ExecutionStepContextInstance + * + * @param callback - Callback to handle processed record + */ + fetch(callback?: (error: Error | null, items: ExecutionStepContextInstance) => any): Promise; + flowSid: string; + stepSid: string; + /** + * Provide a user-friendly representation + */ + toJSON(): any; + url: string; +} + + +declare class ExecutionStepContextPage extends Page { + /** + * Initialize the ExecutionStepContextPage + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param response - Response from the API + * @param solution - Path solution + */ + constructor(version: V2, response: Response, solution: ExecutionStepContextSolution); + + /** + * Build an instance of ExecutionStepContextInstance + * + * @param payload - Payload response from the API + */ + getInstance(payload: ExecutionStepContextPayload): ExecutionStepContextInstance; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + +export { ExecutionStepContextContext, ExecutionStepContextInstance, ExecutionStepContextList, ExecutionStepContextListInstance, ExecutionStepContextPage, ExecutionStepContextPayload, ExecutionStepContextResource, ExecutionStepContextSolution } diff --git a/lib/rest/studio/v2/flow/execution/executionStep/executionStepContext.js b/lib/rest/studio/v2/flow/execution/executionStep/executionStepContext.js new file mode 100644 index 0000000000..c566b2d5c3 --- /dev/null +++ b/lib/rest/studio/v2/flow/execution/executionStep/executionStepContext.js @@ -0,0 +1,361 @@ +'use strict'; + +/* jshint ignore:start */ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ +/* jshint ignore:end */ + +var Q = require('q'); /* jshint ignore:line */ +var _ = require('lodash'); /* jshint ignore:line */ +var util = require('util'); /* jshint ignore:line */ +var Page = require('../../../../../../base/Page'); /* jshint ignore:line */ +var values = require('../../../../../../base/values'); /* jshint ignore:line */ + +var ExecutionStepContextList; +var ExecutionStepContextPage; +var ExecutionStepContextInstance; +var ExecutionStepContextContext; + +/* jshint ignore:start */ +/** + * Initialize the ExecutionStepContextList + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextList + * + * @param {Twilio.Studio.V2} version - Version of the resource + * @param {string} flowSid - The flow_sid + * @param {string} executionSid - The execution_sid + * @param {string} stepSid - The step_sid + */ +/* jshint ignore:end */ +ExecutionStepContextList = function ExecutionStepContextList(version, flowSid, + executionSid, stepSid) { + /* jshint ignore:start */ + /** + * @function stepContext + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext# + * + * @param {string} sid - sid of instance + * + * @returns {Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextContext} + */ + /* jshint ignore:end */ + function ExecutionStepContextListInstance(sid) { + return ExecutionStepContextListInstance.get(sid); + } + + ExecutionStepContextListInstance._version = version; + // Path Solution + ExecutionStepContextListInstance._solution = { + flowSid: flowSid, + executionSid: executionSid, + stepSid: stepSid + }; + /* jshint ignore:start */ + /** + * Constructs a execution_step_context + * + * @function get + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextList# + * + * @returns {Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextContext} + */ + /* jshint ignore:end */ + ExecutionStepContextListInstance.get = function get() { + return new ExecutionStepContextContext( + this._version, + this._solution.flowSid, + this._solution.executionSid, + this._solution.stepSid + ); + }; + + /* jshint ignore:start */ + /** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextList# + * + * @returns Object + */ + /* jshint ignore:end */ + ExecutionStepContextListInstance.toJSON = function toJSON() { + return this._solution; + }; + + ExecutionStepContextListInstance[util.inspect.custom] = function inspect(depth, + options) { + return util.inspect(this.toJSON(), options); + }; + + return ExecutionStepContextListInstance; +}; + + +/* jshint ignore:start */ +/** + * Initialize the ExecutionStepContextPage + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextPage + * + * @param {V2} version - Version of the resource + * @param {Response} response - Response from the API + * @param {ExecutionStepContextSolution} solution - Path solution + * + * @returns ExecutionStepContextPage + */ +/* jshint ignore:end */ +ExecutionStepContextPage = function ExecutionStepContextPage(version, response, + solution) { + // Path Solution + this._solution = solution; + + Page.prototype.constructor.call(this, version, response, this._solution); +}; + +_.extend(ExecutionStepContextPage.prototype, Page.prototype); +ExecutionStepContextPage.prototype.constructor = ExecutionStepContextPage; + +/* jshint ignore:start */ +/** + * Build an instance of ExecutionStepContextInstance + * + * @function getInstance + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextPage# + * + * @param {ExecutionStepContextPayload} payload - Payload response from the API + * + * @returns ExecutionStepContextInstance + */ +/* jshint ignore:end */ +ExecutionStepContextPage.prototype.getInstance = function getInstance(payload) { + return new ExecutionStepContextInstance( + this._version, + payload, + this._solution.flowSid, + this._solution.executionSid, + this._solution.stepSid + ); +}; + +/* jshint ignore:start */ +/** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextPage# + * + * @returns Object + */ +/* jshint ignore:end */ +ExecutionStepContextPage.prototype.toJSON = function toJSON() { + let clone = {}; + _.forOwn(this, function(value, key) { + if (!_.startsWith(key, '_') && ! _.isFunction(value)) { + clone[key] = value; + } + }); + return clone; +}; + +ExecutionStepContextPage.prototype[util.inspect.custom] = function + inspect(depth, options) { + return util.inspect(this.toJSON(), options); +}; + + +/* jshint ignore:start */ +/** + * Initialize the ExecutionStepContextContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextInstance + * + * @property {string} accountSid - The account_sid + * @property {object} context - The context + * @property {string} executionSid - The execution_sid + * @property {string} flowSid - The flow_sid + * @property {string} stepSid - The step_sid + * @property {string} url - The url + * + * @param {V2} version - Version of the resource + * @param {ExecutionStepContextPayload} payload - The instance payload + * @param {sid} flowSid - The flow_sid + * @param {sid} executionSid - The execution_sid + * @param {sid} stepSid - The step_sid + */ +/* jshint ignore:end */ +ExecutionStepContextInstance = function ExecutionStepContextInstance(version, + payload, flowSid, executionSid, stepSid) { + this._version = version; + + // Marshaled Properties + this.accountSid = payload.account_sid; // jshint ignore:line + this.context = payload.context; // jshint ignore:line + this.executionSid = payload.execution_sid; // jshint ignore:line + this.flowSid = payload.flow_sid; // jshint ignore:line + this.stepSid = payload.step_sid; // jshint ignore:line + this.url = payload.url; // jshint ignore:line + + // Context + this._context = undefined; + this._solution = {flowSid: flowSid, executionSid: executionSid, stepSid: stepSid, }; +}; + +Object.defineProperty(ExecutionStepContextInstance.prototype, + '_proxy', { + get: function() { + if (!this._context) { + this._context = new ExecutionStepContextContext( + this._version, + this._solution.flowSid, + this._solution.executionSid, + this._solution.stepSid + ); + } + + return this._context; + } +}); + +/* jshint ignore:start */ +/** + * fetch a ExecutionStepContextInstance + * + * @function fetch + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextInstance# + * + * @param {function} [callback] - Callback to handle processed record + * + * @returns {Promise} Resolves to processed ExecutionStepContextInstance + */ +/* jshint ignore:end */ +ExecutionStepContextInstance.prototype.fetch = function fetch(callback) { + return this._proxy.fetch(callback); +}; + +/* jshint ignore:start */ +/** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextInstance# + * + * @returns Object + */ +/* jshint ignore:end */ +ExecutionStepContextInstance.prototype.toJSON = function toJSON() { + let clone = {}; + _.forOwn(this, function(value, key) { + if (!_.startsWith(key, '_') && ! _.isFunction(value)) { + clone[key] = value; + } + }); + return clone; +}; + +ExecutionStepContextInstance.prototype[util.inspect.custom] = function + inspect(depth, options) { + return util.inspect(this.toJSON(), options); +}; + + +/* jshint ignore:start */ +/** + * Initialize the ExecutionStepContextContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextContext + * + * @param {V2} version - Version of the resource + * @param {sid} flowSid - The flow_sid + * @param {sid} executionSid - The execution_sid + * @param {sid} stepSid - The step_sid + */ +/* jshint ignore:end */ +ExecutionStepContextContext = function ExecutionStepContextContext(version, + flowSid, executionSid, stepSid) { + this._version = version; + + // Path Solution + this._solution = {flowSid: flowSid, executionSid: executionSid, stepSid: stepSid, }; + this._uri = `/Flows/${flowSid}/Executions/${executionSid}/Steps/${stepSid}/Context`; +}; + +/* jshint ignore:start */ +/** + * fetch a ExecutionStepContextInstance + * + * @function fetch + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextContext# + * + * @param {function} [callback] - Callback to handle processed record + * + * @returns {Promise} Resolves to processed ExecutionStepContextInstance + */ +/* jshint ignore:end */ +ExecutionStepContextContext.prototype.fetch = function fetch(callback) { + var deferred = Q.defer(); + var promise = this._version.fetch({uri: this._uri, method: 'GET'}); + + promise = promise.then(function(payload) { + deferred.resolve(new ExecutionStepContextInstance( + this._version, + payload, + this._solution.flowSid, + this._solution.executionSid, + this._solution.stepSid + )); + }.bind(this)); + + promise.catch(function(error) { + deferred.reject(error); + }); + + if (_.isFunction(callback)) { + deferred.promise.nodeify(callback); + } + + return deferred.promise; +}; + +/* jshint ignore:start */ +/** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.ExecutionContext.ExecutionStepContext.ExecutionStepContextContext# + * + * @returns Object + */ +/* jshint ignore:end */ +ExecutionStepContextContext.prototype.toJSON = function toJSON() { + return this._solution; +}; + +ExecutionStepContextContext.prototype[util.inspect.custom] = function + inspect(depth, options) { + return util.inspect(this.toJSON(), options); +}; + +module.exports = { + ExecutionStepContextList: ExecutionStepContextList, + ExecutionStepContextPage: ExecutionStepContextPage, + ExecutionStepContextInstance: ExecutionStepContextInstance, + ExecutionStepContextContext: ExecutionStepContextContext +}; diff --git a/lib/rest/studio/v2/flow/testUser.d.ts b/lib/rest/studio/v2/flow/testUser.d.ts new file mode 100644 index 0000000000..ec13a949b3 --- /dev/null +++ b/lib/rest/studio/v2/flow/testUser.d.ts @@ -0,0 +1,157 @@ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ + +import Page = require('../../../../base/Page'); +import Response = require('../../../../http/response'); +import V2 = require('../../V2'); +import serialize = require('../../../../base/serialize'); +import { SerializableClass } from '../../../../interfaces'; + +/** + * Initialize the FlowTestUserList + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param sid - The sid + */ +declare function FlowTestUserList(version: V2, sid: string): FlowTestUserListInstance; + +/** + * Options to pass to update + * + * @property testUsers - The test_users + */ +interface FlowTestUserInstanceUpdateOptions { + testUsers: string | string[]; +} + +interface FlowTestUserListInstance { + /** + * @param sid - sid of instance + */ + (sid: string): FlowTestUserContext; + /** + * Constructs a flow_test_user + */ + get(): FlowTestUserContext; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + +interface FlowTestUserPayload extends FlowTestUserResource, Page.TwilioResponsePayload { +} + +interface FlowTestUserResource { + sid: string; + test_users: string[]; + url: string; +} + +interface FlowTestUserSolution { + sid?: string; +} + + +declare class FlowTestUserContext { + /** + * Initialize the FlowTestUserContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param sid - The sid + */ + constructor(version: V2, sid: string); + + /** + * fetch a FlowTestUserInstance + * + * @param callback - Callback to handle processed record + */ + fetch(callback?: (error: Error | null, items: FlowTestUserInstance) => any): Promise; + /** + * Provide a user-friendly representation + */ + toJSON(): any; + /** + * update a FlowTestUserInstance + * + * @param opts - Options for request + * @param callback - Callback to handle processed record + */ + update(opts: FlowTestUserInstanceUpdateOptions, callback?: (error: Error | null, items: FlowTestUserInstance) => any): Promise; +} + + +declare class FlowTestUserInstance extends SerializableClass { + /** + * Initialize the FlowTestUserContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param payload - The instance payload + * @param sid - The sid + */ + constructor(version: V2, payload: FlowTestUserPayload, sid: string); + + private _proxy: FlowTestUserContext; + /** + * fetch a FlowTestUserInstance + * + * @param callback - Callback to handle processed record + */ + fetch(callback?: (error: Error | null, items: FlowTestUserInstance) => any): Promise; + sid: string; + testUsers: string[]; + /** + * Provide a user-friendly representation + */ + toJSON(): any; + /** + * update a FlowTestUserInstance + * + * @param opts - Options for request + * @param callback - Callback to handle processed record + */ + update(opts: FlowTestUserInstanceUpdateOptions, callback?: (error: Error | null, items: FlowTestUserInstance) => any): Promise; + url: string; +} + + +declare class FlowTestUserPage extends Page { + /** + * Initialize the FlowTestUserPage + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @param version - Version of the resource + * @param response - Response from the API + * @param solution - Path solution + */ + constructor(version: V2, response: Response, solution: FlowTestUserSolution); + + /** + * Build an instance of FlowTestUserInstance + * + * @param payload - Payload response from the API + */ + getInstance(payload: FlowTestUserPayload): FlowTestUserInstance; + /** + * Provide a user-friendly representation + */ + toJSON(): any; +} + +export { FlowTestUserContext, FlowTestUserInstance, FlowTestUserInstanceUpdateOptions, FlowTestUserList, FlowTestUserListInstance, FlowTestUserPage, FlowTestUserPayload, FlowTestUserResource, FlowTestUserSolution } diff --git a/lib/rest/studio/v2/flow/testUser.js b/lib/rest/studio/v2/flow/testUser.js new file mode 100644 index 0000000000..fb5fd811ce --- /dev/null +++ b/lib/rest/studio/v2/flow/testUser.js @@ -0,0 +1,382 @@ +'use strict'; + +/* jshint ignore:start */ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ +/* jshint ignore:end */ + +var Q = require('q'); /* jshint ignore:line */ +var _ = require('lodash'); /* jshint ignore:line */ +var util = require('util'); /* jshint ignore:line */ +var Page = require('../../../../base/Page'); /* jshint ignore:line */ +var serialize = require('../../../../base/serialize'); /* jshint ignore:line */ +var values = require('../../../../base/values'); /* jshint ignore:line */ + +var FlowTestUserList; +var FlowTestUserPage; +var FlowTestUserInstance; +var FlowTestUserContext; + +/* jshint ignore:start */ +/** + * Initialize the FlowTestUserList + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.FlowTestUserList + * + * @param {Twilio.Studio.V2} version - Version of the resource + * @param {string} sid - The sid + */ +/* jshint ignore:end */ +FlowTestUserList = function FlowTestUserList(version, sid) { + /* jshint ignore:start */ + /** + * @function testUsers + * @memberof Twilio.Studio.V2.FlowContext# + * + * @param {string} sid - sid of instance + * + * @returns {Twilio.Studio.V2.FlowContext.FlowTestUserContext} + */ + /* jshint ignore:end */ + function FlowTestUserListInstance(sid) { + return FlowTestUserListInstance.get(sid); + } + + FlowTestUserListInstance._version = version; + // Path Solution + FlowTestUserListInstance._solution = {sid: sid}; + /* jshint ignore:start */ + /** + * Constructs a flow_test_user + * + * @function get + * @memberof Twilio.Studio.V2.FlowContext.FlowTestUserList# + * + * @returns {Twilio.Studio.V2.FlowContext.FlowTestUserContext} + */ + /* jshint ignore:end */ + FlowTestUserListInstance.get = function get() { + return new FlowTestUserContext(this._version, this._solution.sid); + }; + + /* jshint ignore:start */ + /** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.FlowTestUserList# + * + * @returns Object + */ + /* jshint ignore:end */ + FlowTestUserListInstance.toJSON = function toJSON() { + return this._solution; + }; + + FlowTestUserListInstance[util.inspect.custom] = function inspect(depth, options) + { + return util.inspect(this.toJSON(), options); + }; + + return FlowTestUserListInstance; +}; + + +/* jshint ignore:start */ +/** + * Initialize the FlowTestUserPage + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.FlowTestUserPage + * + * @param {V2} version - Version of the resource + * @param {Response} response - Response from the API + * @param {FlowTestUserSolution} solution - Path solution + * + * @returns FlowTestUserPage + */ +/* jshint ignore:end */ +FlowTestUserPage = function FlowTestUserPage(version, response, solution) { + // Path Solution + this._solution = solution; + + Page.prototype.constructor.call(this, version, response, this._solution); +}; + +_.extend(FlowTestUserPage.prototype, Page.prototype); +FlowTestUserPage.prototype.constructor = FlowTestUserPage; + +/* jshint ignore:start */ +/** + * Build an instance of FlowTestUserInstance + * + * @function getInstance + * @memberof Twilio.Studio.V2.FlowContext.FlowTestUserPage# + * + * @param {FlowTestUserPayload} payload - Payload response from the API + * + * @returns FlowTestUserInstance + */ +/* jshint ignore:end */ +FlowTestUserPage.prototype.getInstance = function getInstance(payload) { + return new FlowTestUserInstance(this._version, payload, this._solution.sid); +}; + +/* jshint ignore:start */ +/** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.FlowTestUserPage# + * + * @returns Object + */ +/* jshint ignore:end */ +FlowTestUserPage.prototype.toJSON = function toJSON() { + let clone = {}; + _.forOwn(this, function(value, key) { + if (!_.startsWith(key, '_') && ! _.isFunction(value)) { + clone[key] = value; + } + }); + return clone; +}; + +FlowTestUserPage.prototype[util.inspect.custom] = function inspect(depth, + options) { + return util.inspect(this.toJSON(), options); +}; + + +/* jshint ignore:start */ +/** + * Initialize the FlowTestUserContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.FlowTestUserInstance + * + * @property {string} sid - The sid + * @property {string} testUsers - The test_users + * @property {string} url - The url + * + * @param {V2} version - Version of the resource + * @param {FlowTestUserPayload} payload - The instance payload + * @param {sid} sid - The sid + */ +/* jshint ignore:end */ +FlowTestUserInstance = function FlowTestUserInstance(version, payload, sid) { + this._version = version; + + // Marshaled Properties + this.sid = payload.sid; // jshint ignore:line + this.testUsers = payload.test_users; // jshint ignore:line + this.url = payload.url; // jshint ignore:line + + // Context + this._context = undefined; + this._solution = {sid: sid, }; +}; + +Object.defineProperty(FlowTestUserInstance.prototype, + '_proxy', { + get: function() { + if (!this._context) { + this._context = new FlowTestUserContext(this._version, this._solution.sid); + } + + return this._context; + } +}); + +/* jshint ignore:start */ +/** + * fetch a FlowTestUserInstance + * + * @function fetch + * @memberof Twilio.Studio.V2.FlowContext.FlowTestUserInstance# + * + * @param {function} [callback] - Callback to handle processed record + * + * @returns {Promise} Resolves to processed FlowTestUserInstance + */ +/* jshint ignore:end */ +FlowTestUserInstance.prototype.fetch = function fetch(callback) { + return this._proxy.fetch(callback); +}; + +/* jshint ignore:start */ +/** + * update a FlowTestUserInstance + * + * @function update + * @memberof Twilio.Studio.V2.FlowContext.FlowTestUserInstance# + * + * @param {object} opts - Options for request + * @param {string|list} opts.testUsers - The test_users + * @param {function} [callback] - Callback to handle processed record + * + * @returns {Promise} Resolves to processed FlowTestUserInstance + */ +/* jshint ignore:end */ +FlowTestUserInstance.prototype.update = function update(opts, callback) { + return this._proxy.update(opts, callback); +}; + +/* jshint ignore:start */ +/** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.FlowTestUserInstance# + * + * @returns Object + */ +/* jshint ignore:end */ +FlowTestUserInstance.prototype.toJSON = function toJSON() { + let clone = {}; + _.forOwn(this, function(value, key) { + if (!_.startsWith(key, '_') && ! _.isFunction(value)) { + clone[key] = value; + } + }); + return clone; +}; + +FlowTestUserInstance.prototype[util.inspect.custom] = function inspect(depth, + options) { + return util.inspect(this.toJSON(), options); +}; + + +/* jshint ignore:start */ +/** + * Initialize the FlowTestUserContext + * + * PLEASE NOTE that this class contains beta products that are subject to change. + * Use them with caution. + * + * @constructor Twilio.Studio.V2.FlowContext.FlowTestUserContext + * + * @param {V2} version - Version of the resource + * @param {sid} sid - The sid + */ +/* jshint ignore:end */ +FlowTestUserContext = function FlowTestUserContext(version, sid) { + this._version = version; + + // Path Solution + this._solution = {sid: sid, }; + this._uri = `/Flows/${sid}/TestUsers`; +}; + +/* jshint ignore:start */ +/** + * fetch a FlowTestUserInstance + * + * @function fetch + * @memberof Twilio.Studio.V2.FlowContext.FlowTestUserContext# + * + * @param {function} [callback] - Callback to handle processed record + * + * @returns {Promise} Resolves to processed FlowTestUserInstance + */ +/* jshint ignore:end */ +FlowTestUserContext.prototype.fetch = function fetch(callback) { + var deferred = Q.defer(); + var promise = this._version.fetch({uri: this._uri, method: 'GET'}); + + promise = promise.then(function(payload) { + deferred.resolve(new FlowTestUserInstance(this._version, payload, this._solution.sid)); + }.bind(this)); + + promise.catch(function(error) { + deferred.reject(error); + }); + + if (_.isFunction(callback)) { + deferred.promise.nodeify(callback); + } + + return deferred.promise; +}; + +/* jshint ignore:start */ +/** + * update a FlowTestUserInstance + * + * @function update + * @memberof Twilio.Studio.V2.FlowContext.FlowTestUserContext# + * + * @param {object} opts - Options for request + * @param {string|list} opts.testUsers - The test_users + * @param {function} [callback] - Callback to handle processed record + * + * @returns {Promise} Resolves to processed FlowTestUserInstance + */ +/* jshint ignore:end */ +FlowTestUserContext.prototype.update = function update(opts, callback) { + if (_.isUndefined(opts)) { + throw new Error('Required parameter "opts" missing.'); + } + if (_.isUndefined(opts.testUsers)) { + throw new Error('Required parameter "opts.testUsers" missing.'); + } + + var deferred = Q.defer(); + var data = values.of({ + 'TestUsers': serialize.map(_.get(opts, 'testUsers'), function(e) { return e; }) + }); + + var promise = this._version.update({uri: this._uri, method: 'POST', data: data}); + + promise = promise.then(function(payload) { + deferred.resolve(new FlowTestUserInstance(this._version, payload, this._solution.sid)); + }.bind(this)); + + promise.catch(function(error) { + deferred.reject(error); + }); + + if (_.isFunction(callback)) { + deferred.promise.nodeify(callback); + } + + return deferred.promise; +}; + +/* jshint ignore:start */ +/** + * Provide a user-friendly representation + * + * @function toJSON + * @memberof Twilio.Studio.V2.FlowContext.FlowTestUserContext# + * + * @returns Object + */ +/* jshint ignore:end */ +FlowTestUserContext.prototype.toJSON = function toJSON() { + return this._solution; +}; + +FlowTestUserContext.prototype[util.inspect.custom] = function inspect(depth, + options) { + return util.inspect(this.toJSON(), options); +}; + +module.exports = { + FlowTestUserList: FlowTestUserList, + FlowTestUserPage: FlowTestUserPage, + FlowTestUserInstance: FlowTestUserInstance, + FlowTestUserContext: FlowTestUserContext +}; diff --git a/lib/rest/taskrouter/v1/workspace/task.d.ts b/lib/rest/taskrouter/v1/workspace/task.d.ts index d40c94af63..a29c10b322 100644 --- a/lib/rest/taskrouter/v1/workspace/task.d.ts +++ b/lib/rest/taskrouter/v1/workspace/task.d.ts @@ -259,6 +259,7 @@ interface TaskResource { sid: string; task_channel_sid: string; task_channel_unique_name: string; + task_queue_entered_date: Date; task_queue_friendly_name: string; task_queue_sid: string; timeout: number; @@ -351,6 +352,7 @@ declare class TaskInstance extends SerializableClass { sid: string; taskChannelSid: string; taskChannelUniqueName: string; + taskQueueEnteredDate: Date; taskQueueFriendlyName: string; taskQueueSid: string; timeout: number; diff --git a/lib/rest/taskrouter/v1/workspace/task.js b/lib/rest/taskrouter/v1/workspace/task.js index 492ab65ddf..25d814efb6 100644 --- a/lib/rest/taskrouter/v1/workspace/task.js +++ b/lib/rest/taskrouter/v1/workspace/task.js @@ -521,7 +521,7 @@ TaskPage.prototype[util.inspect.custom] = function inspect(depth, options) { * @constructor Twilio.Taskrouter.V1.WorkspaceContext.TaskInstance * * @property {string} accountSid - The SID of the Account that created the resource - * @property {number} age - The number of seconds since the task was created + * @property {number} age - The number of seconds since the Task was created * @property {task.status} assignmentStatus - * The current status of the Task's assignment * @property {string} attributes - @@ -532,16 +532,18 @@ TaskPage.prototype[util.inspect.custom] = function inspect(depth, options) { * The ISO 8601 date and time in GMT when the resource was created * @property {Date} dateUpdated - * The ISO 8601 date and time in GMT when the resource was last updated + * @property {Date} taskQueueEnteredDate - + * The ISO 8601 date and time in GMT when the Task entered the TaskQueue. * @property {number} priority - * Retrieve the list of all Tasks in the Workspace with the specified priority - * @property {string} reason - The reason the task was canceled or completed + * @property {string} reason - The reason the Task was canceled or completed * @property {string} sid - The unique string that identifies the resource * @property {string} taskQueueSid - The SID of the TaskQueue * @property {string} taskQueueFriendlyName - The friendly name of the TaskQueue * @property {string} taskChannelSid - The SID of the TaskChannel * @property {string} taskChannelUniqueName - The unique name of the TaskChannel * @property {number} timeout - - * The amount of time in seconds that the task is allowed to live + * The amount of time in seconds that the Task is allowed to live * @property {string} workflowSid - * The SID of the Workflow that is controlling the Task * @property {string} workflowFriendlyName - @@ -568,6 +570,7 @@ TaskInstance = function TaskInstance(version, payload, workspaceSid, sid) { this.addons = payload.addons; // jshint ignore:line this.dateCreated = deserialize.iso8601DateTime(payload.date_created); // jshint ignore:line this.dateUpdated = deserialize.iso8601DateTime(payload.date_updated); // jshint ignore:line + this.taskQueueEnteredDate = deserialize.iso8601DateTime(payload.task_queue_entered_date); // jshint ignore:line this.priority = deserialize.integer(payload.priority); // jshint ignore:line this.reason = payload.reason; // jshint ignore:line this.sid = payload.sid; // jshint ignore:line diff --git a/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueCumulativeStatistics.d.ts b/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueCumulativeStatistics.d.ts index 2524f00420..c1ddb14ddd 100644 --- a/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueCumulativeStatistics.d.ts +++ b/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueCumulativeStatistics.d.ts @@ -74,6 +74,7 @@ interface TaskQueueCumulativeStatisticsResource { tasks_entered: number; tasks_moved: number; url: string; + wait_duration_in_queue_until_accepted: object; wait_duration_until_accepted: object; wait_duration_until_canceled: object; workspace_sid: string; @@ -150,6 +151,7 @@ declare class TaskQueueCumulativeStatisticsInstance extends SerializableClass { */ toJSON(): any; url: string; + waitDurationInQueueUntilAccepted: object; waitDurationUntilAccepted: object; waitDurationUntilCanceled: object; workspaceSid: string; diff --git a/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueCumulativeStatistics.js b/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueCumulativeStatistics.js index c1c70a69e8..3837a11ce0 100644 --- a/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueCumulativeStatistics.js +++ b/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueCumulativeStatistics.js @@ -206,6 +206,8 @@ TaskQueueCumulativeStatisticsPage.prototype[util.inspect.custom] = function * The wait duration statistics for Tasks accepted while in the TaskQueue * @property {object} waitDurationUntilCanceled - * The wait duration statistics for Tasks canceled while in the TaskQueue + * @property {object} waitDurationInQueueUntilAccepted - + * The relative wait duration statistics for Tasks accepted while in the TaskQueue * @property {number} tasksCanceled - * The total number of Tasks canceled in the TaskQueue * @property {number} tasksCompleted - @@ -247,6 +249,7 @@ TaskQueueCumulativeStatisticsInstance = function this.taskQueueSid = payload.task_queue_sid; // jshint ignore:line this.waitDurationUntilAccepted = payload.wait_duration_until_accepted; // jshint ignore:line this.waitDurationUntilCanceled = payload.wait_duration_until_canceled; // jshint ignore:line + this.waitDurationInQueueUntilAccepted = payload.wait_duration_in_queue_until_accepted; // jshint ignore:line this.tasksCanceled = deserialize.integer(payload.tasks_canceled); // jshint ignore:line this.tasksCompleted = deserialize.integer(payload.tasks_completed); // jshint ignore:line this.tasksDeleted = deserialize.integer(payload.tasks_deleted); // jshint ignore:line diff --git a/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueRealTimeStatistics.d.ts b/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueRealTimeStatistics.d.ts index 9929fae53b..c5be1eb702 100644 --- a/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueRealTimeStatistics.d.ts +++ b/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueRealTimeStatistics.d.ts @@ -49,6 +49,8 @@ interface TaskQueueRealTimeStatisticsPayload extends TaskQueueRealTimeStatistics interface TaskQueueRealTimeStatisticsResource { account_sid: string; activity_statistics: object[]; + longest_relative_task_age_in_queue: number; + longest_relative_task_sid_in_queue: string; longest_task_waiting_age: number; longest_task_waiting_sid: string; task_queue_sid: string; @@ -112,6 +114,8 @@ declare class TaskQueueRealTimeStatisticsInstance extends SerializableClass { * @param callback - Callback to handle processed record */ fetch(opts?: TaskQueueRealTimeStatisticsInstanceFetchOptions, callback?: (error: Error | null, items: TaskQueueRealTimeStatisticsInstance) => any): Promise; + longestRelativeTaskAgeInQueue: number; + longestRelativeTaskSidInQueue: string; longestTaskWaitingAge: number; longestTaskWaitingSid: string; taskQueueSid: string; diff --git a/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueRealTimeStatistics.js b/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueRealTimeStatistics.js index 8f03340826..6f1dd96a37 100644 --- a/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueRealTimeStatistics.js +++ b/lib/rest/taskrouter/v1/workspace/taskQueue/taskQueueRealTimeStatistics.js @@ -182,6 +182,10 @@ TaskQueueRealTimeStatisticsPage.prototype[util.inspect.custom] = function * The number of current Workers by Activity * @property {number} longestTaskWaitingAge - The age of the longest waiting Task * @property {string} longestTaskWaitingSid - The SID of the longest waiting Task + * @property {number} longestRelativeTaskAgeInQueue - + * The relative age in the TaskQueue for the longest waiting Task. + * @property {string} longestRelativeTaskSidInQueue - + * The SID of the Task waiting in the TaskQueue the longest. * @property {string} taskQueueSid - * The SID of the TaskQueue from which these statistics were calculated * @property {object} tasksByPriority - The number of Tasks by priority @@ -212,6 +216,8 @@ TaskQueueRealTimeStatisticsInstance = function this.activityStatistics = payload.activity_statistics; // jshint ignore:line this.longestTaskWaitingAge = deserialize.integer(payload.longest_task_waiting_age); // jshint ignore:line this.longestTaskWaitingSid = payload.longest_task_waiting_sid; // jshint ignore:line + this.longestRelativeTaskAgeInQueue = deserialize.integer(payload.longest_relative_task_age_in_queue); // jshint ignore:line + this.longestRelativeTaskSidInQueue = payload.longest_relative_task_sid_in_queue; // jshint ignore:line this.taskQueueSid = payload.task_queue_sid; // jshint ignore:line this.tasksByPriority = payload.tasks_by_priority; // jshint ignore:line this.tasksByStatus = payload.tasks_by_status; // jshint ignore:line diff --git a/lib/rest/verify/v2/service.d.ts b/lib/rest/verify/v2/service.d.ts index a030353ea5..51a8e2d0ab 100644 --- a/lib/rest/verify/v2/service.d.ts +++ b/lib/rest/verify/v2/service.d.ts @@ -127,7 +127,7 @@ interface ServiceListInstance { * Options to pass to create * * @property codeLength - The length of the verification code to generate - * @property doNotShareWarningEnabled - Whether to add a privacy warning at the end of an SMS. + * @property doNotShareWarningEnabled - Whether to add a security warning at the end of an SMS. * @property dtmfInputRequired - Whether to ask the user to press a number before delivering the verify code in a phone call * @property friendlyName - A string to describe the verification service * @property lookupEnabled - Whether to perform a lookup with each verification diff --git a/lib/rest/verify/v2/service.js b/lib/rest/verify/v2/service.js index 556a8dc773..df8687aeaf 100644 --- a/lib/rest/verify/v2/service.js +++ b/lib/rest/verify/v2/service.js @@ -80,7 +80,7 @@ ServiceList = function ServiceList(version) { * @param {boolean} [opts.psd2Enabled] - * Whether to pass PSD2 transaction parameters when starting a verification * @param {boolean} [opts.doNotShareWarningEnabled] - - * Whether to add a privacy warning at the end of an SMS. + * Whether to add a security warning at the end of an SMS. * @param {function} [callback] - Callback to handle processed record * * @returns {Promise} Resolves to processed ServiceInstance @@ -491,7 +491,7 @@ ServicePage.prototype[util.inspect.custom] = function inspect(depth, options) { * @property {string} ttsName - * The name of an alternative text-to-speech service to use in phone calls * @property {boolean} doNotShareWarningEnabled - - * Whether to add a privacy warning at the end of an SMS. + * Whether to add a security warning at the end of an SMS. * @property {Date} dateCreated - * The RFC 2822 date and time in GMT when the resource was created * @property {Date} dateUpdated - diff --git a/lib/rest/verify/v2/service/verification.d.ts b/lib/rest/verify/v2/service/verification.d.ts index 15adfe1fbb..92a2780bc7 100644 --- a/lib/rest/verify/v2/service/verification.d.ts +++ b/lib/rest/verify/v2/service/verification.d.ts @@ -60,7 +60,7 @@ interface VerificationListInstance { * Options to pass to create * * @property amount - The amount of the associated PSD2 compliant transaction. - * @property appHash - App Hash to be included at the end of an SMS. + * @property appHash - Your App Hash to be appended at the end of an SMS. * @property channel - The verification method to use * @property channelConfiguration - Channel specific configuration in json format. * @property customCode - A pre-generated code diff --git a/lib/rest/verify/v2/service/verification.js b/lib/rest/verify/v2/service/verification.js index b1da02d1fe..984a61ba13 100644 --- a/lib/rest/verify/v2/service/verification.js +++ b/lib/rest/verify/v2/service/verification.js @@ -78,7 +78,8 @@ VerificationList = function VerificationList(version, serviceSid) { * The custom key-value pairs of Programmable Rate Limits. * @param {object} [opts.channelConfiguration] - * Channel specific configuration in json format. - * @param {string} [opts.appHash] - App Hash to be included at the end of an SMS. + * @param {string} [opts.appHash] - + * Your App Hash to be appended at the end of an SMS. * @param {function} [callback] - Callback to handle processed record * * @returns {Promise} Resolves to processed VerificationInstance diff --git a/package-lock.json b/package-lock.json index 4a8e26f85b..f2bf2f95c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -217,9 +217,9 @@ "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=" }, "aws4": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", - "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==" + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz", + "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==" }, "balanced-match": { "version": "1.0.0", @@ -381,9 +381,9 @@ "dev": true }, "combined-stream": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.7.tgz", - "integrity": "sha512-brWl9y6vOB1xYPZcpZde3N9zDByXTosAeMDo4p1wzo6UMOX4vumB+TP1RZ76sfE6Md68Q0NJSrE/gbezd4Ul+w==", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", "requires": { "delayed-stream": "~1.0.0" } @@ -1499,16 +1499,16 @@ "dev": true }, "mime-db": { - "version": "1.38.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.38.0.tgz", - "integrity": "sha512-bqVioMFFzc2awcdJZIzR3HjZFX20QhilVS7hytkKrv7xFAn8bM1gzc/FOX2awLISvWe0PV8ptFKcon+wZ5qYkg==" + "version": "1.43.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.43.0.tgz", + "integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ==" }, "mime-types": { - "version": "2.1.22", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.22.tgz", - "integrity": "sha512-aGl6TZGnhm/li6F7yx82bJiBZwgiEa4Hf6CNr8YO+r5UHr53tSTYZb102zyU50DOWWKeOv0uQLRL0/9EiKWCog==", + "version": "2.1.26", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.26.tgz", + "integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==", "requires": { - "mime-db": "~1.38.0" + "mime-db": "1.43.0" } }, "mimic-fn": { @@ -1740,14 +1740,14 @@ } }, "psl": { - "version": "1.1.31", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.31.tgz", - "integrity": "sha512-/6pt4+C+T+wZUieKR620OpzN/LlnNKuWjy1iFLQ/UG35JqHlR/89MP1d96dUfkf6Dne3TuLQzOYEYshJ+Hx8mw==" + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.7.0.tgz", + "integrity": "sha512-5NsSEDv8zY70ScRnOTn7bK7eanl2MvFrOrS/R6x+dBt5g1ghnj9Zv90kO8GwT8gxcu2ANyFprnFYB85IogIJOQ==" }, "punycode": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", - "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" }, "q": { "version": "2.0.3", @@ -1806,9 +1806,9 @@ "dev": true }, "request": { - "version": "2.88.0", - "resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz", - "integrity": "sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==", + "version": "2.88.2", + "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", + "integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==", "requires": { "aws-sign2": "~0.7.0", "aws4": "^1.8.0", @@ -1817,7 +1817,7 @@ "extend": "~3.0.2", "forever-agent": "~0.6.1", "form-data": "~2.3.2", - "har-validator": "~5.1.0", + "har-validator": "~5.1.3", "http-signature": "~1.2.0", "is-typedarray": "~1.0.0", "isstream": "~0.1.2", @@ -1827,15 +1827,15 @@ "performance-now": "^2.1.0", "qs": "~6.5.2", "safe-buffer": "^5.1.2", - "tough-cookie": "~2.4.3", + "tough-cookie": "~2.5.0", "tunnel-agent": "^0.6.0", "uuid": "^3.3.2" }, "dependencies": { "safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", + "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" } } }, @@ -2168,12 +2168,12 @@ "dev": true }, "tough-cookie": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", - "integrity": "sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ==", + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", + "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", "requires": { - "psl": "^1.1.24", - "punycode": "^1.4.1" + "psl": "^1.1.28", + "punycode": "^2.1.1" } }, "tslib": { @@ -2286,9 +2286,9 @@ "dev": true }, "uuid": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", - "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==" + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" }, "vary": { "version": "1.1.2", diff --git a/package.json b/package.json index ac35c45ba0..158deefdc6 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "jsonwebtoken": "^8.5.1", "lodash": "^4.17.15", "q": "2.0.x", - "request": "^2.88.0", + "request": "^2.88.2", "rootpath": "^0.1.2", "scmp": "^2.1.0", "url-parse": "^1.4.7", diff --git a/spec/integration/rest/api/v2010/account.spec.js b/spec/integration/rest/api/v2010/account.spec.js index e0255b9d1d..b67f581e40 100644 --- a/spec/integration/rest/api/v2010/account.spec.js +++ b/spec/integration/rest/api/v2010/account.spec.js @@ -494,4 +494,51 @@ describe('Account', function() { }).done(); } ); + it('should generate valid update_with_numeric_status response', + function(done) { + var body = JSON.stringify({ + 'auth_token': 'auth_token', + 'date_created': 'Thu, 30 Jul 2015 20:00:00 +0000', + 'date_updated': 'Thu, 30 Jul 2015 20:00:00 +0000', + 'friendly_name': 'friendly_name', + 'owner_account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'status': 'active', + 'subresource_uris': { + 'available_phone_numbers': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/AvailablePhoneNumbers.json', + 'calls': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls.json', + 'conferences': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Conferences.json', + 'incoming_phone_numbers': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers.json', + 'notifications': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications.json', + 'outgoing_caller_ids': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/OutgoingCallerIds.json', + 'recordings': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Recordings.json', + 'transcriptions': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions.json', + 'addresses': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Addresses.json', + 'signing_keys': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/SigningKeys.json', + 'connect_apps': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ConnectApps.json', + 'sip': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/SIP.json', + 'authorized_connect_apps': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/AuthorizedConnectApps.json', + 'usage': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Usage.json', + 'keys': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Keys.json', + 'applications': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Applications.json', + 'short_codes': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/SMS/ShortCodes.json', + 'queues': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Queues.json', + 'messages': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages.json', + 'balance': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Balance.json' + }, + 'type': 'Full', + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json' + }); + + holodeck.mock(new Response(200, body)); + + var promise = client.api.v2010.accounts('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').update(); + promise.then(function(response) { + expect(response).toBeDefined(); + done(); + }, function() { + throw new Error('failed'); + }).done(); + } + ); }); diff --git a/spec/integration/rest/api/v2010/account/call.spec.js b/spec/integration/rest/api/v2010/account/call.spec.js index 8632d6686c..e87272e39b 100644 --- a/spec/integration/rest/api/v2010/account/call.spec.js +++ b/spec/integration/rest/api/v2010/account/call.spec.js @@ -87,7 +87,9 @@ describe('Call', function() { }, 'to': '+14158675309', 'to_formatted': '(415) 867-5309', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json' + 'trunk_sid': null, + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json', + 'queue_time': '1000' }); holodeck.mock(new Response(201, body)); @@ -136,7 +138,9 @@ describe('Call', function() { }, 'to': '+14158675309', 'to_formatted': '(415) 867-5309', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json' + 'trunk_sid': null, + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json', + 'queue_time': '1000' }); holodeck.mock(new Response(201, body)); @@ -247,7 +251,9 @@ describe('Call', function() { }, 'to': '+13051913581', 'to_formatted': '(305) 191-3581', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json' + 'trunk_sid': 'TRdeadbeefdeadbeefdeadbeefdeadbeef', + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json', + 'queue_time': '1000' }); holodeck.mock(new Response(200, body)); @@ -297,7 +303,9 @@ describe('Call', function() { }, 'to': '+13051913581', 'to_formatted': '(305) 191-3581', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json' + 'trunk_sid': 'TRdeadbeefdeadbeefdeadbeefdeadbeef', + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json', + 'queue_time': '1000' }, { 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', @@ -330,7 +338,9 @@ describe('Call', function() { }, 'to': '+13051913580', 'to_formatted': '(305) 191-3580', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0.json' + 'trunk_sid': 'TRdeadbeefdeadbeefdeadbeefdeadbeef', + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0.json', + 'queue_time': '1000' } ], 'end': 1, @@ -382,7 +392,9 @@ describe('Call', function() { }, 'to': '+13051913581', 'to_formatted': '(305) 191-3581', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json' + 'trunk_sid': 'TRdeadbeefdeadbeefdeadbeefdeadbeef', + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json', + 'queue_time': '1000' }, { 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', @@ -415,7 +427,9 @@ describe('Call', function() { }, 'to': '+13051913580', 'to_formatted': '(305) 191-3580', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0.json' + 'trunk_sid': 'TRdeadbeefdeadbeefdeadbeefdeadbeef', + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0.json', + 'queue_time': '1000' } ], 'end': 1, @@ -472,7 +486,9 @@ describe('Call', function() { }, 'to': '+13051913581', 'to_formatted': '(305) 191-3581', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json' + 'trunk_sid': 'TRdeadbeefdeadbeefdeadbeefdeadbeef', + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json', + 'queue_time': '1000' }, { 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', @@ -505,7 +521,9 @@ describe('Call', function() { }, 'to': '+13051913580', 'to_formatted': '(305) 191-3580', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0.json' + 'trunk_sid': 'TRdeadbeefdeadbeefdeadbeefdeadbeef', + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0.json', + 'queue_time': '1000' } ], 'end': 1, @@ -579,7 +597,9 @@ describe('Call', function() { }, 'to': '+13051913581', 'to_formatted': '(305) 191-3581', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json' + 'trunk_sid': 'TRdeadbeefdeadbeefdeadbeefdeadbeef', + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json', + 'queue_time': '1000' }, { 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', @@ -612,7 +632,9 @@ describe('Call', function() { }, 'to': '+13051913580', 'to_formatted': '(305) 191-3580', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0.json' + 'trunk_sid': 'TRdeadbeefdeadbeefdeadbeefdeadbeef', + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0.json', + 'queue_time': '1000' } ], 'end': 1, @@ -672,7 +694,9 @@ describe('Call', function() { }, 'to': '+13051913581', 'to_formatted': '(305) 191-3581', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json' + 'trunk_sid': 'TRdeadbeefdeadbeefdeadbeefdeadbeef', + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json', + 'queue_time': '1000' }, { 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', @@ -705,7 +729,9 @@ describe('Call', function() { }, 'to': '+13051913580', 'to_formatted': '(305) 191-3580', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0.json' + 'trunk_sid': 'TRdeadbeefdeadbeefdeadbeefdeadbeef', + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0.json', + 'queue_time': '1000' } ], 'end': 3, @@ -864,7 +890,9 @@ describe('Call', function() { }, 'to': '+14158675309', 'to_formatted': '(415) 867-5309', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json' + 'trunk_sid': null, + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json', + 'queue_time': '1000' }); holodeck.mock(new Response(200, body)); @@ -912,7 +940,9 @@ describe('Call', function() { }, 'to': '+14158675309', 'to_formatted': '(415) 867-5309', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json' + 'trunk_sid': null, + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json', + 'queue_time': '1000' }); holodeck.mock(new Response(200, body)); @@ -960,7 +990,9 @@ describe('Call', function() { }, 'to': '+14158675309', 'to_formatted': '(415) 867-5309', - 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json' + 'trunk_sid': null, + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json', + 'queue_time': '1000' }); holodeck.mock(new Response(200, body)); diff --git a/spec/integration/rest/api/v2010/account/conference/participant.spec.js b/spec/integration/rest/api/v2010/account/conference/participant.spec.js index 67770e004a..1ce66c0196 100644 --- a/spec/integration/rest/api/v2010/account/conference/participant.spec.js +++ b/spec/integration/rest/api/v2010/account/conference/participant.spec.js @@ -327,6 +327,38 @@ describe('Participant', function() { }).done(); } ); + it('should generate valid create_with_friendly_name_byoc response', + function(done) { + var body = JSON.stringify({ + 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'call_sid': 'CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'conference_sid': 'CFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'date_created': 'Fri, 18 Feb 2011 21:07:19 +0000', + 'date_updated': 'Fri, 18 Feb 2011 21:07:19 +0000', + 'end_conference_on_exit': false, + 'muted': false, + 'hold': false, + 'status': 'complete', + 'start_conference_on_enter': true, + 'coaching': false, + 'call_sid_to_coach': null, + 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Conferences/CFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json' + }); + + holodeck.mock(new Response(201, body)); + + var opts = {from: '+15017122661', to: '+15558675310'}; + var promise = client.api.v2010.accounts('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .conferences('CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .participants.create(opts); + promise.then(function(response) { + expect(response).toBeDefined(); + done(); + }, function() { + throw new Error('failed'); + }).done(); + } + ); it('should generate valid remove request', function(done) { holodeck.mock(new Response(500, '{}')); diff --git a/spec/integration/rest/api/v2010/account/notification.spec.js b/spec/integration/rest/api/v2010/account/notification.spec.js index ef264087b8..0a870b86f9 100644 --- a/spec/integration/rest/api/v2010/account/notification.spec.js +++ b/spec/integration/rest/api/v2010/account/notification.spec.js @@ -68,7 +68,7 @@ describe('Notification', function() { 'request_method': 'get', 'request_url': 'https://voiceforms4000.appspot.com/twiml/9436/question/0', 'request_variables': 'AccountSid=ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&CallStatus=in-progress&ToZip=94937&ToCity=INVERNESS&ToState=CA&Called=%2B14156694923&To=%2B14156694923&ToCountry=US&CalledZip=94937&Direction=inbound&ApiVersion=2010-04-01&Caller=%2B17378742833&CalledCity=INVERNESS&CalledCountry=US&CallSid=CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&CalledState=CA&From=%2B17378742833', - 'response_body': 'blah blah', + 'response_body': 'Response body from your webhook URL as a string.', 'response_headers': 'Date=Mon%2C+13+Sep+2010+20%3A02%3A00+GMT&Content-Length=466&Connection=close&Content-Type=text%2Fhtml%3B+charset%3DUTF-8&Server=Google+Frontend', 'sid': 'NOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'uri': '/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications/NOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json' diff --git a/spec/integration/rest/flexApi/v1/configuration.spec.js b/spec/integration/rest/flexApi/v1/configuration.spec.js index 0c4f213cb5..8ec90f37d3 100644 --- a/spec/integration/rest/flexApi/v1/configuration.spec.js +++ b/spec/integration/rest/flexApi/v1/configuration.spec.js @@ -121,6 +121,7 @@ describe('Configuration', function() { 'chat_service_instance_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'ui_language': 'en', 'ui_attributes': {}, + 'ui_dependencies': {}, 'ui_version': '1.0', 'service_version': '1.0', 'call_recording_enabled': true, @@ -274,6 +275,7 @@ describe('Configuration', function() { 'chat_service_instance_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'ui_language': 'en', 'ui_attributes': {}, + 'ui_dependencies': {}, 'ui_version': '1.0', 'service_version': '1.0', 'call_recording_enabled': true, @@ -427,6 +429,7 @@ describe('Configuration', function() { 'chat_service_instance_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'ui_language': 'en', 'ui_attributes': {}, + 'ui_dependencies': {}, 'ui_version': '1.0', 'service_version': '1.0', 'call_recording_enabled': true, diff --git a/spec/integration/rest/messaging/v1/session.spec.js b/spec/integration/rest/messaging/v1/session.spec.js deleted file mode 100644 index ce28660264..0000000000 --- a/spec/integration/rest/messaging/v1/session.spec.js +++ /dev/null @@ -1,404 +0,0 @@ -'use strict'; - -/* jshint ignore:start */ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ -/* jshint ignore:end */ - -var Holodeck = require('../../../holodeck'); /* jshint ignore:line */ -var Request = require( - '../../../../../lib/http/request'); /* jshint ignore:line */ -var Response = require( - '../../../../../lib/http/response'); /* jshint ignore:line */ -var RestException = require( - '../../../../../lib/base/RestException'); /* jshint ignore:line */ -var Twilio = require('../../../../../lib'); /* jshint ignore:line */ - - -var client; -var holodeck; - -describe('Session', function() { - beforeEach(function() { - holodeck = new Holodeck(); - client = new Twilio('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'AUTHTOKEN', { - httpClient: holodeck - }); - }); - it('should generate valid fetch request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sid}`; - - holodeck.assertHasRequest(new Request({ - method: 'GET', - url: url - })); - } - ); - it('should generate valid fetch response', - function(done) { - var body = JSON.stringify({ - 'sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MG80af39294fe338b3848294685d097e04', - 'friendly_name': 'friendly_name', - 'attributes': '{ \'foo\': \'bar\' }', - 'date_created': '2015-12-16T22:18:37Z', - 'date_updated': '2015-12-16T22:18:38Z', - 'created_by': 'creator', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'links': { - 'participants': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants', - 'messages': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages', - 'webhooks': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks' - } - }); - - holodeck.mock(new Response(200, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid remove request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').remove(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sid}`; - - holodeck.assertHasRequest(new Request({ - method: 'DELETE', - url: url - })); - } - ); - it('should generate valid delete response', - function(done) { - var body = JSON.stringify(null); - - holodeck.mock(new Response(204, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').remove(); - promise.then(function(response) { - expect(response).toBe(true); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid create request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var opts = {messagingServiceSid: 'messaging_service_sid'}; - var promise = client.messaging.v1.sessions.create(opts); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var url = 'https://messaging.twilio.com/v1/Sessions'; - - var values = {MessagingServiceSid: 'messaging_service_sid', }; - holodeck.assertHasRequest(new Request({ - method: 'POST', - url: url, - data: values - })); - } - ); - it('should generate valid create response', - function(done) { - var body = JSON.stringify({ - 'sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MG80af39294fe338b3848294685d097e04', - 'friendly_name': 'friendly_name', - 'attributes': '{ \'foo\': \'bar\' }', - 'date_created': '2015-12-16T22:18:37Z', - 'date_updated': '2015-12-16T22:18:38Z', - 'created_by': 'creator', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'links': { - 'participants': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants', - 'messages': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages', - 'webhooks': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks' - } - }); - - holodeck.mock(new Response(201, body)); - - var opts = {messagingServiceSid: 'messaging_service_sid'}; - var promise = client.messaging.v1.sessions.create(opts); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid update request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').update(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sid}`; - - holodeck.assertHasRequest(new Request({ - method: 'POST', - url: url - })); - } - ); - it('should generate valid update response', - function(done) { - var body = JSON.stringify({ - 'sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MG80af39294fe338b3848294685d097e04', - 'friendly_name': 'friendly_name', - 'attributes': '{ \'foo\': \'bar\' }', - 'date_created': '2015-12-16T22:18:37Z', - 'date_updated': '2015-12-16T22:18:38Z', - 'created_by': 'creator', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'links': { - 'participants': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants', - 'messages': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages', - 'webhooks': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks' - } - }); - - holodeck.mock(new Response(200, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').update(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should treat the first each arg as a callback', - function(done) { - var body = JSON.stringify({ - 'sessions': [ - { - 'sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MG80af39294fe338b3848294685d097e04', - 'friendly_name': 'friendly_name', - 'attributes': '{ \'foo\': \'bar\' }', - 'date_created': '2015-12-16T22:18:37Z', - 'date_updated': '2015-12-16T22:18:38Z', - 'created_by': 'creator', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'links': { - 'participants': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants', - 'messages': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages', - 'webhooks': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks' - } - } - ], - 'meta': { - 'page': 0, - 'page_size': 50, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions?PageSize=50&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions?PageSize=50&Page=0', - 'next_page_url': null, - 'key': 'sessions' - } - }); - holodeck.mock(new Response(200, body)); - client.messaging.v1.sessions.each(() => done()); - } - ); - it('should treat the second arg as a callback', - function(done) { - var body = JSON.stringify({ - 'sessions': [ - { - 'sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MG80af39294fe338b3848294685d097e04', - 'friendly_name': 'friendly_name', - 'attributes': '{ \'foo\': \'bar\' }', - 'date_created': '2015-12-16T22:18:37Z', - 'date_updated': '2015-12-16T22:18:38Z', - 'created_by': 'creator', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'links': { - 'participants': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants', - 'messages': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages', - 'webhooks': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks' - } - } - ], - 'meta': { - 'page': 0, - 'page_size': 50, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions?PageSize=50&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions?PageSize=50&Page=0', - 'next_page_url': null, - 'key': 'sessions' - } - }); - holodeck.mock(new Response(200, body)); - client.messaging.v1.sessions.each({pageSize: 20}, () => done()); - holodeck.assertHasRequest(new Request({ - method: 'GET', - url: 'https://messaging.twilio.com/v1/Sessions', - params: {PageSize: 20}, - })); - } - ); - it('should find the callback in the opts object', - function(done) { - var body = JSON.stringify({ - 'sessions': [ - { - 'sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MG80af39294fe338b3848294685d097e04', - 'friendly_name': 'friendly_name', - 'attributes': '{ \'foo\': \'bar\' }', - 'date_created': '2015-12-16T22:18:37Z', - 'date_updated': '2015-12-16T22:18:38Z', - 'created_by': 'creator', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'links': { - 'participants': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants', - 'messages': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages', - 'webhooks': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks' - } - } - ], - 'meta': { - 'page': 0, - 'page_size': 50, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions?PageSize=50&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions?PageSize=50&Page=0', - 'next_page_url': null, - 'key': 'sessions' - } - }); - holodeck.mock(new Response(200, body)); - client.messaging.v1.sessions.each({callback: () => done()}, () => fail('wrong callback!')); - } - ); - it('should generate valid list request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions.list(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var url = 'https://messaging.twilio.com/v1/Sessions'; - - holodeck.assertHasRequest(new Request({ - method: 'GET', - url: url - })); - } - ); - it('should generate valid read_full response', - function(done) { - var body = JSON.stringify({ - 'sessions': [ - { - 'sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MG80af39294fe338b3848294685d097e04', - 'friendly_name': 'friendly_name', - 'attributes': '{ \'foo\': \'bar\' }', - 'date_created': '2015-12-16T22:18:37Z', - 'date_updated': '2015-12-16T22:18:38Z', - 'created_by': 'creator', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'links': { - 'participants': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants', - 'messages': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages', - 'webhooks': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks' - } - } - ], - 'meta': { - 'page': 0, - 'page_size': 50, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions?PageSize=50&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions?PageSize=50&Page=0', - 'next_page_url': null, - 'key': 'sessions' - } - }); - - holodeck.mock(new Response(200, body)); - - var promise = client.messaging.v1.sessions.list(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); -}); diff --git a/spec/integration/rest/messaging/v1/session/message.spec.js b/spec/integration/rest/messaging/v1/session/message.spec.js deleted file mode 100644 index f52ad9d4df..0000000000 --- a/spec/integration/rest/messaging/v1/session/message.spec.js +++ /dev/null @@ -1,453 +0,0 @@ -'use strict'; - -/* jshint ignore:start */ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ -/* jshint ignore:end */ - -var Holodeck = require('../../../../holodeck'); /* jshint ignore:line */ -var Request = require( - '../../../../../../lib/http/request'); /* jshint ignore:line */ -var Response = require( - '../../../../../../lib/http/response'); /* jshint ignore:line */ -var RestException = require( - '../../../../../../lib/base/RestException'); /* jshint ignore:line */ -var Twilio = require('../../../../../../lib'); /* jshint ignore:line */ - - -var client; -var holodeck; - -describe('Message', function() { - beforeEach(function() { - holodeck = new Holodeck(); - client = new Twilio('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'AUTHTOKEN', { - httpClient: holodeck - }); - }); - it('should generate valid fetch request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .messages('IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sessionSid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var sid = 'IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sessionSid}/Messages/${sid}`; - - holodeck.assertHasRequest(new Request({ - method: 'GET', - url: url - })); - } - ); - it('should generate valid fetch response', - function(done) { - var body = JSON.stringify({ - 'sid': 'IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'body': 'Hello', - 'attributes': '{}', - 'author': 'system', - 'date_created': '2016-03-24T20:37:57Z', - 'date_updated': '2016-03-24T20:37:57Z', - 'index': 0, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }); - - holodeck.mock(new Response(200, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .messages('IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid create request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .messages.create(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sessionSid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sessionSid}/Messages`; - - holodeck.assertHasRequest(new Request({ - method: 'POST', - url: url - })); - } - ); - it('should generate valid create response', - function(done) { - var body = JSON.stringify({ - 'sid': 'IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'body': 'Hello', - 'attributes': '{ \'foo\': \'bar\' }', - 'author': 'message author', - 'date_created': '2015-12-16T22:18:37Z', - 'date_updated': '2015-12-16T22:18:38Z', - 'index': 0, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }); - - holodeck.mock(new Response(201, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .messages.create(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid update request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .messages('IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').update(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sessionSid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var sid = 'IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sessionSid}/Messages/${sid}`; - - holodeck.assertHasRequest(new Request({ - method: 'POST', - url: url - })); - } - ); - it('should generate valid update response', - function(done) { - var body = JSON.stringify({ - 'sid': 'IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'body': 'Hello', - 'attributes': '{ \'foo\': \'bar\' }', - 'author': 'message author', - 'date_created': '2015-12-16T22:18:37Z', - 'date_updated': '2015-12-16T22:18:38Z', - 'index': 0, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }); - - holodeck.mock(new Response(200, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .messages('IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').update(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should treat the first each arg as a callback', - function(done) { - var body = JSON.stringify({ - 'meta': { - 'page': 0, - 'page_size': 50, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages?PageSize=50&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages?PageSize=50&Page=0', - 'next_page_url': null, - 'key': 'messages' - }, - 'messages': [ - { - 'sid': 'IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'body': 'Hello', - 'attributes': '{}', - 'author': 'system', - 'date_created': '2016-03-24T20:37:57Z', - 'date_updated': '2016-03-24T20:37:57Z', - 'index': 0, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }, - { - 'sid': 'IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'body': 'Hello', - 'attributes': '{}', - 'author': 'system', - 'date_created': '2016-03-24T20:37:57Z', - 'date_updated': '2016-03-24T20:37:57Z', - 'index': 0, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - } - ] - }); - holodeck.mock(new Response(200, body)); - client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .messages.each(() => done()); - } - ); - it('should treat the second arg as a callback', - function(done) { - var body = JSON.stringify({ - 'meta': { - 'page': 0, - 'page_size': 50, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages?PageSize=50&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages?PageSize=50&Page=0', - 'next_page_url': null, - 'key': 'messages' - }, - 'messages': [ - { - 'sid': 'IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'body': 'Hello', - 'attributes': '{}', - 'author': 'system', - 'date_created': '2016-03-24T20:37:57Z', - 'date_updated': '2016-03-24T20:37:57Z', - 'index': 0, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }, - { - 'sid': 'IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'body': 'Hello', - 'attributes': '{}', - 'author': 'system', - 'date_created': '2016-03-24T20:37:57Z', - 'date_updated': '2016-03-24T20:37:57Z', - 'index': 0, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - } - ] - }); - holodeck.mock(new Response(200, body)); - client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .messages.each({pageSize: 20}, () => done()); - holodeck.assertHasRequest(new Request({ - method: 'GET', - url: 'https://messaging.twilio.com/v1/Sessions/${sessionSid}/Messages', - params: {PageSize: 20}, - })); - } - ); - it('should find the callback in the opts object', - function(done) { - var body = JSON.stringify({ - 'meta': { - 'page': 0, - 'page_size': 50, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages?PageSize=50&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages?PageSize=50&Page=0', - 'next_page_url': null, - 'key': 'messages' - }, - 'messages': [ - { - 'sid': 'IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'body': 'Hello', - 'attributes': '{}', - 'author': 'system', - 'date_created': '2016-03-24T20:37:57Z', - 'date_updated': '2016-03-24T20:37:57Z', - 'index': 0, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }, - { - 'sid': 'IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'body': 'Hello', - 'attributes': '{}', - 'author': 'system', - 'date_created': '2016-03-24T20:37:57Z', - 'date_updated': '2016-03-24T20:37:57Z', - 'index': 0, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - } - ] - }); - holodeck.mock(new Response(200, body)); - client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .messages.each({callback: () => done()}, () => fail('wrong callback!')); - } - ); - it('should generate valid list request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .messages.list(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sessionSid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sessionSid}/Messages`; - - holodeck.assertHasRequest(new Request({ - method: 'GET', - url: url - })); - } - ); - it('should generate valid read_full response', - function(done) { - var body = JSON.stringify({ - 'meta': { - 'page': 0, - 'page_size': 50, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages?PageSize=50&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages?PageSize=50&Page=0', - 'next_page_url': null, - 'key': 'messages' - }, - 'messages': [ - { - 'sid': 'IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'body': 'Hello', - 'attributes': '{}', - 'author': 'system', - 'date_created': '2016-03-24T20:37:57Z', - 'date_updated': '2016-03-24T20:37:57Z', - 'index': 0, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }, - { - 'sid': 'IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'body': 'Hello', - 'attributes': '{}', - 'author': 'system', - 'date_created': '2016-03-24T20:37:57Z', - 'date_updated': '2016-03-24T20:37:57Z', - 'index': 0, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - } - ] - }); - - holodeck.mock(new Response(200, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .messages.list(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid remove request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .messages('IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').remove(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sessionSid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var sid = 'IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sessionSid}/Messages/${sid}`; - - holodeck.assertHasRequest(new Request({ - method: 'DELETE', - url: url - })); - } - ); - it('should generate valid delete response', - function(done) { - var body = JSON.stringify(null); - - holodeck.mock(new Response(204, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .messages('IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').remove(); - promise.then(function(response) { - expect(response).toBe(true); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); -}); diff --git a/spec/integration/rest/messaging/v1/session/participant.spec.js b/spec/integration/rest/messaging/v1/session/participant.spec.js deleted file mode 100644 index 16e211c69c..0000000000 --- a/spec/integration/rest/messaging/v1/session/participant.spec.js +++ /dev/null @@ -1,434 +0,0 @@ -'use strict'; - -/* jshint ignore:start */ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ -/* jshint ignore:end */ - -var Holodeck = require('../../../../holodeck'); /* jshint ignore:line */ -var Request = require( - '../../../../../../lib/http/request'); /* jshint ignore:line */ -var Response = require( - '../../../../../../lib/http/response'); /* jshint ignore:line */ -var RestException = require( - '../../../../../../lib/base/RestException'); /* jshint ignore:line */ -var Twilio = require('../../../../../../lib'); /* jshint ignore:line */ - - -var client; -var holodeck; - -describe('Participant', function() { - beforeEach(function() { - holodeck = new Holodeck(); - client = new Twilio('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'AUTHTOKEN', { - httpClient: holodeck - }); - }); - it('should generate valid create request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .participants.create(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sessionSid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sessionSid}/Participants`; - - holodeck.assertHasRequest(new Request({ - method: 'POST', - url: url - })); - } - ); - it('should generate valid create_identity response', - function(done) { - var body = JSON.stringify({ - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'identity': 'Twilio', - 'attributes': '{ \'foo\': \'bar\' }', - 'date_created': '2015-12-16T22:18:37Z', - 'date_updated': '2015-12-16T22:18:38Z', - 'type': 'chat', - 'twilio_address': '+372666555', - 'user_address': '+372666556', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }); - - holodeck.mock(new Response(201, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .participants.create(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid create_address response', - function(done) { - var body = JSON.stringify({ - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'identity': null, - 'attributes': '{}', - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'type': 'chat', - 'twilio_address': '+372666555', - 'user_address': '+372666556', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }); - - holodeck.mock(new Response(201, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .participants.create(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid update request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .participants('MBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').update(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sessionSid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var sid = 'MBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sessionSid}/Participants/${sid}`; - - holodeck.assertHasRequest(new Request({ - method: 'POST', - url: url - })); - } - ); - it('should generate valid update response', - function(done) { - var body = JSON.stringify({ - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'identity': 'Twilio', - 'attributes': '{ \'foo\': \'bar\' }', - 'date_created': '2015-12-16T22:18:37Z', - 'date_updated': '2015-12-16T22:18:38Z', - 'type': 'chat', - 'twilio_address': '+372666555', - 'user_address': '+372666556', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }); - - holodeck.mock(new Response(200, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .participants('MBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').update(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid fetch request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .participants('MBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sessionSid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var sid = 'MBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sessionSid}/Participants/${sid}`; - - holodeck.assertHasRequest(new Request({ - method: 'GET', - url: url - })); - } - ); - it('should generate valid fetch response', - function(done) { - var body = JSON.stringify({ - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'identity': 'Twilio', - 'attributes': '{}', - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'type': 'chat', - 'twilio_address': '+372666555', - 'user_address': '+372666556', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }); - - holodeck.mock(new Response(200, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .participants('MBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should treat the first each arg as a callback', - function(done) { - var body = JSON.stringify({ - 'meta': { - 'page': 0, - 'page_size': 50, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants?PageSize=50&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants?PageSize=50&Page=0', - 'next_page_url': null, - 'key': 'participants' - }, - 'participants': [ - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'identity': 'Twilio', - 'attributes': '{}', - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'type': 'chat', - 'twilio_address': '+372666555', - 'user_address': '+372666556', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - } - ] - }); - holodeck.mock(new Response(200, body)); - client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .participants.each(() => done()); - } - ); - it('should treat the second arg as a callback', - function(done) { - var body = JSON.stringify({ - 'meta': { - 'page': 0, - 'page_size': 50, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants?PageSize=50&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants?PageSize=50&Page=0', - 'next_page_url': null, - 'key': 'participants' - }, - 'participants': [ - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'identity': 'Twilio', - 'attributes': '{}', - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'type': 'chat', - 'twilio_address': '+372666555', - 'user_address': '+372666556', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - } - ] - }); - holodeck.mock(new Response(200, body)); - client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .participants.each({pageSize: 20}, () => done()); - holodeck.assertHasRequest(new Request({ - method: 'GET', - url: 'https://messaging.twilio.com/v1/Sessions/${sessionSid}/Participants', - params: {PageSize: 20}, - })); - } - ); - it('should find the callback in the opts object', - function(done) { - var body = JSON.stringify({ - 'meta': { - 'page': 0, - 'page_size': 50, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants?PageSize=50&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants?PageSize=50&Page=0', - 'next_page_url': null, - 'key': 'participants' - }, - 'participants': [ - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'identity': 'Twilio', - 'attributes': '{}', - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'type': 'chat', - 'twilio_address': '+372666555', - 'user_address': '+372666556', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - } - ] - }); - holodeck.mock(new Response(200, body)); - client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .participants.each({callback: () => done()}, () => fail('wrong callback!')); - } - ); - it('should generate valid list request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .participants.list(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sessionSid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sessionSid}/Participants`; - - holodeck.assertHasRequest(new Request({ - method: 'GET', - url: url - })); - } - ); - it('should generate valid read response', - function(done) { - var body = JSON.stringify({ - 'meta': { - 'page': 0, - 'page_size': 50, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants?PageSize=50&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants?PageSize=50&Page=0', - 'next_page_url': null, - 'key': 'participants' - }, - 'participants': [ - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'messaging_service_sid': 'MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'identity': 'Twilio', - 'attributes': '{}', - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'type': 'chat', - 'twilio_address': '+372666555', - 'user_address': '+372666556', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - } - ] - }); - - holodeck.mock(new Response(200, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .participants.list(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid remove request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .participants('MBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').remove(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sessionSid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var sid = 'MBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sessionSid}/Participants/${sid}`; - - holodeck.assertHasRequest(new Request({ - method: 'DELETE', - url: url - })); - } - ); - it('should generate valid delete response', - function(done) { - var body = JSON.stringify(null); - - holodeck.mock(new Response(204, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .participants('MBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').remove(); - promise.then(function(response) { - expect(response).toBe(true); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); -}); diff --git a/spec/integration/rest/messaging/v1/session/webhook.spec.js b/spec/integration/rest/messaging/v1/session/webhook.spec.js deleted file mode 100644 index a524be2d05..0000000000 --- a/spec/integration/rest/messaging/v1/session/webhook.spec.js +++ /dev/null @@ -1,595 +0,0 @@ -'use strict'; - -/* jshint ignore:start */ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ -/* jshint ignore:end */ - -var Holodeck = require('../../../../holodeck'); /* jshint ignore:line */ -var Request = require( - '../../../../../../lib/http/request'); /* jshint ignore:line */ -var Response = require( - '../../../../../../lib/http/response'); /* jshint ignore:line */ -var RestException = require( - '../../../../../../lib/base/RestException'); /* jshint ignore:line */ -var Twilio = require('../../../../../../lib'); /* jshint ignore:line */ - - -var client; -var holodeck; - -describe('Webhook', function() { - beforeEach(function() { - holodeck = new Holodeck(); - client = new Twilio('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'AUTHTOKEN', { - httpClient: holodeck - }); - }); - it('should treat the first each arg as a callback', - function(done) { - var body = JSON.stringify({ - 'meta': { - 'page': 0, - 'page_size': 5, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks?PageSize=5&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks?PageSize=5&Page=0', - 'next_page_url': null, - 'key': 'webhooks' - }, - 'webhooks': [ - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'target': 'webhook', - 'configuration': { - 'url': 'dummy', - 'method': 'get', - 'filters': [ - 'onMessageSent', - 'onSessionDestroyed' - ], - 'retry_count': 2, - 'buffer_messages': false - }, - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }, - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'target': 'trigger', - 'configuration': { - 'url': 'dummy', - 'method': 'post', - 'filters': [ - 'keyword1', - 'keyword2' - ], - 'retry_count': 3, - 'buffer_messages': true, - 'buffer_window': 3000 - }, - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }, - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'target': 'studio', - 'configuration': { - 'flow_sid': 'FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'buffer_messages': false, - 'buffer_window': 4000 - }, - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - } - ] - }); - holodeck.mock(new Response(200, body)); - client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .webhooks.each(() => done()); - } - ); - it('should treat the second arg as a callback', - function(done) { - var body = JSON.stringify({ - 'meta': { - 'page': 0, - 'page_size': 5, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks?PageSize=5&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks?PageSize=5&Page=0', - 'next_page_url': null, - 'key': 'webhooks' - }, - 'webhooks': [ - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'target': 'webhook', - 'configuration': { - 'url': 'dummy', - 'method': 'get', - 'filters': [ - 'onMessageSent', - 'onSessionDestroyed' - ], - 'retry_count': 2, - 'buffer_messages': false - }, - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }, - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'target': 'trigger', - 'configuration': { - 'url': 'dummy', - 'method': 'post', - 'filters': [ - 'keyword1', - 'keyword2' - ], - 'retry_count': 3, - 'buffer_messages': true, - 'buffer_window': 3000 - }, - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }, - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'target': 'studio', - 'configuration': { - 'flow_sid': 'FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'buffer_messages': false, - 'buffer_window': 4000 - }, - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - } - ] - }); - holodeck.mock(new Response(200, body)); - client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .webhooks.each({pageSize: 20}, () => done()); - holodeck.assertHasRequest(new Request({ - method: 'GET', - url: 'https://messaging.twilio.com/v1/Sessions/${sessionSid}/Webhooks', - params: {PageSize: 20}, - })); - } - ); - it('should find the callback in the opts object', - function(done) { - var body = JSON.stringify({ - 'meta': { - 'page': 0, - 'page_size': 5, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks?PageSize=5&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks?PageSize=5&Page=0', - 'next_page_url': null, - 'key': 'webhooks' - }, - 'webhooks': [ - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'target': 'webhook', - 'configuration': { - 'url': 'dummy', - 'method': 'get', - 'filters': [ - 'onMessageSent', - 'onSessionDestroyed' - ], - 'retry_count': 2, - 'buffer_messages': false - }, - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }, - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'target': 'trigger', - 'configuration': { - 'url': 'dummy', - 'method': 'post', - 'filters': [ - 'keyword1', - 'keyword2' - ], - 'retry_count': 3, - 'buffer_messages': true, - 'buffer_window': 3000 - }, - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }, - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'target': 'studio', - 'configuration': { - 'flow_sid': 'FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'buffer_messages': false, - 'buffer_window': 4000 - }, - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - } - ] - }); - holodeck.mock(new Response(200, body)); - client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .webhooks.each({callback: () => done()}, () => fail('wrong callback!')); - } - ); - it('should generate valid list request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .webhooks.list(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sessionSid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sessionSid}/Webhooks`; - - holodeck.assertHasRequest(new Request({ - method: 'GET', - url: url - })); - } - ); - it('should generate valid read_full response', - function(done) { - var body = JSON.stringify({ - 'meta': { - 'page': 0, - 'page_size': 5, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks?PageSize=5&Page=0', - 'previous_page_url': null, - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks?PageSize=5&Page=0', - 'next_page_url': null, - 'key': 'webhooks' - }, - 'webhooks': [ - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'target': 'webhook', - 'configuration': { - 'url': 'dummy', - 'method': 'get', - 'filters': [ - 'onMessageSent', - 'onSessionDestroyed' - ], - 'retry_count': 2, - 'buffer_messages': false - }, - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }, - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'target': 'trigger', - 'configuration': { - 'url': 'dummy', - 'method': 'post', - 'filters': [ - 'keyword1', - 'keyword2' - ], - 'retry_count': 3, - 'buffer_messages': true, - 'buffer_window': 3000 - }, - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }, - { - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'target': 'studio', - 'configuration': { - 'flow_sid': 'FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'buffer_messages': false, - 'buffer_window': 4000 - }, - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - } - ] - }); - - holodeck.mock(new Response(200, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .webhooks.list(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid read_empty response', - function(done) { - var body = JSON.stringify({ - 'meta': { - 'page': 0, - 'page_size': 5, - 'first_page_url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks?PageSize=5&Page=0', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks?PageSize=5&Page=0', - 'previous_page_url': null, - 'next_page_url': null, - 'key': 'webhooks' - }, - 'webhooks': [] - }); - - holodeck.mock(new Response(200, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .webhooks.list(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid fetch request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .webhooks('WHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sessionSid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var sid = 'WHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sessionSid}/Webhooks/${sid}`; - - holodeck.assertHasRequest(new Request({ - method: 'GET', - url: url - })); - } - ); - it('should generate valid fetch response', - function(done) { - var body = JSON.stringify({ - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'target': 'studio', - 'configuration': { - 'flow_sid': 'FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'buffer_messages': false - }, - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }); - - holodeck.mock(new Response(200, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .webhooks('WHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid create request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var opts = {target: 'webhook'}; - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .webhooks.create(opts); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sessionSid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sessionSid}/Webhooks`; - - var values = {Target: 'webhook', }; - holodeck.assertHasRequest(new Request({ - method: 'POST', - url: url, - data: values - })); - } - ); - it('should generate valid create response', - function(done) { - var body = JSON.stringify({ - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'target': 'webhook', - 'configuration': { - 'url': 'dummy', - 'method': 'get', - 'filters': [ - 'onMessageSent', - 'onSessionDestroyed' - ], - 'retry_count': 2, - 'buffer_messages': true, - 'buffer_window': 3000 - }, - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:50Z', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }); - - holodeck.mock(new Response(201, body)); - - var opts = {target: 'webhook'}; - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .webhooks.create(opts); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid update request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .webhooks('WHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').update(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sessionSid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var sid = 'WHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sessionSid}/Webhooks/${sid}`; - - holodeck.assertHasRequest(new Request({ - method: 'POST', - url: url - })); - } - ); - it('should generate valid update response', - function(done) { - var body = JSON.stringify({ - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'session_sid': 'CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'sid': 'WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'target': 'trigger', - 'configuration': { - 'url': 'dummy', - 'method': 'post', - 'filters': [ - 'keyword1', - 'keyword2' - ], - 'retry_count': 3, - 'buffer_messages': true, - 'buffer_window': 5000 - }, - 'date_created': '2016-03-24T21:05:50Z', - 'date_updated': '2016-03-24T21:05:51Z', - 'url': 'https://messaging.twilio.com/v1/Sessions/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/WHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' - }); - - holodeck.mock(new Response(200, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .webhooks('WHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').update(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid remove request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .webhooks('WHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').remove(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var sessionSid = 'CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var sid = 'WHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; - var url = `https://messaging.twilio.com/v1/Sessions/${sessionSid}/Webhooks/${sid}`; - - holodeck.assertHasRequest(new Request({ - method: 'DELETE', - url: url - })); - } - ); - it('should generate valid delete response', - function(done) { - var body = JSON.stringify(null); - - holodeck.mock(new Response(204, body)); - - var promise = client.messaging.v1.sessions('CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') - .webhooks('WHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').remove(); - promise.then(function(response) { - expect(response).toBe(true); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); -}); diff --git a/spec/integration/rest/messaging/v1/webhook.spec.js b/spec/integration/rest/messaging/v1/webhook.spec.js deleted file mode 100644 index b85d4940c5..0000000000 --- a/spec/integration/rest/messaging/v1/webhook.spec.js +++ /dev/null @@ -1,129 +0,0 @@ -'use strict'; - -/* jshint ignore:start */ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ -/* jshint ignore:end */ - -var Holodeck = require('../../../holodeck'); /* jshint ignore:line */ -var Request = require( - '../../../../../lib/http/request'); /* jshint ignore:line */ -var Response = require( - '../../../../../lib/http/response'); /* jshint ignore:line */ -var RestException = require( - '../../../../../lib/base/RestException'); /* jshint ignore:line */ -var Twilio = require('../../../../../lib'); /* jshint ignore:line */ - - -var client; -var holodeck; - -describe('Webhook', function() { - beforeEach(function() { - holodeck = new Holodeck(); - client = new Twilio('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'AUTHTOKEN', { - httpClient: holodeck - }); - }); - it('should generate valid fetch request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.webhooks().fetch(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var url = 'https://messaging.twilio.com/v1/Sessions/Webhooks'; - - holodeck.assertHasRequest(new Request({ - method: 'GET', - url: url - })); - } - ); - it('should generate valid fetch response', - function(done) { - var body = JSON.stringify({ - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'pre_webhook_url': 'http://pre.url', - 'post_webhook_url': 'http://post.url', - 'webhook_method': 'GET', - 'webhook_filters': [ - 'onMessageSend', - 'onSessionAdded' - ], - 'pre_webhook_retry_count': 1, - 'post_webhook_retry_count': 2, - 'target': 'http', - 'url': 'https://messaging.twilio.com/v1/Sessions/Webhooks' - }); - - holodeck.mock(new Response(200, body)); - - var promise = client.messaging.v1.webhooks().fetch(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); - it('should generate valid update request', - function(done) { - holodeck.mock(new Response(500, '{}')); - - var promise = client.messaging.v1.webhooks().update(); - promise.then(function() { - throw new Error('failed'); - }, function(error) { - expect(error.constructor).toBe(RestException.prototype.constructor); - done(); - }).done(); - - var url = 'https://messaging.twilio.com/v1/Sessions/Webhooks'; - - holodeck.assertHasRequest(new Request({ - method: 'POST', - url: url - })); - } - ); - it('should generate valid update response', - function(done) { - var body = JSON.stringify({ - 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'service_sid': 'ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - 'pre_webhook_url': 'http://pre.url', - 'post_webhook_url': 'http://post.url', - 'webhook_method': 'GET', - 'webhook_filters': [ - 'onSessionAdded' - ], - 'pre_webhook_retry_count': 1, - 'post_webhook_retry_count': 2, - 'target': 'flex', - 'url': 'https://messaging.twilio.com/v1/Sessions/Webhooks' - }); - - holodeck.mock(new Response(200, body)); - - var promise = client.messaging.v1.webhooks().update(); - promise.then(function(response) { - expect(response).toBeDefined(); - done(); - }, function() { - throw new Error('failed'); - }).done(); - } - ); -}); diff --git a/spec/integration/rest/numbers/v2/regulatoryCompliance/regulation.spec.js b/spec/integration/rest/numbers/v2/regulatoryCompliance/regulation.spec.js new file mode 100644 index 0000000000..1575b6d646 --- /dev/null +++ b/spec/integration/rest/numbers/v2/regulatoryCompliance/regulation.spec.js @@ -0,0 +1,400 @@ +'use strict'; + +/* jshint ignore:start */ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ +/* jshint ignore:end */ + +var Holodeck = require('../../../../holodeck'); /* jshint ignore:line */ +var Request = require( + '../../../../../../lib/http/request'); /* jshint ignore:line */ +var Response = require( + '../../../../../../lib/http/response'); /* jshint ignore:line */ +var RestException = require( + '../../../../../../lib/base/RestException'); /* jshint ignore:line */ +var Twilio = require('../../../../../../lib'); /* jshint ignore:line */ + + +var client; +var holodeck; + +describe('Regulation', function() { + beforeEach(function() { + holodeck = new Holodeck(); + client = new Twilio('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'AUTHTOKEN', { + httpClient: holodeck + }); + }); + it('should treat the first each arg as a callback', + function(done) { + var body = JSON.stringify({ + 'results': [ + { + 'sid': 'RNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'friendly_name': 'Australia: Local - Individual', + 'iso_country': 'AU', + 'number_type': 'local', + 'end_user_type': 'individual', + 'requirements': { + 'end_user': [ + { + 'name': 'Individual', + 'type': 'individual', + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations/individual', + 'fields': [ + 'first_name', + 'last_name' + ] + } + ], + 'supporting_document': [ + [ + { + 'name': 'Address', + 'type': 'document', + 'description': 'The physical location of the individual or business. Must be within locality or region covered by the phone numbers prefix; a PO Box is not acceptable where a local address is required.', + 'accepted_documents': [ + { + 'name': 'Address Validation', + 'type': 'address', + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/DocumentTypes/address', + 'fields': [] + } + ] + } + ] + ] + }, + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations/RNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + } + ], + 'meta': { + 'page': 0, + 'page_size': 50, + 'first_page_url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations?PageSize=50&Page=0', + 'previous_page_url': null, + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations?PageSize=50&Page=0', + 'next_page_url': null, + 'key': 'results' + } + }); + holodeck.mock(new Response(200, body)); + client.numbers.v2.regulatoryCompliance + .regulations.each(() => done()); + } + ); + it('should treat the second arg as a callback', + function(done) { + var body = JSON.stringify({ + 'results': [ + { + 'sid': 'RNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'friendly_name': 'Australia: Local - Individual', + 'iso_country': 'AU', + 'number_type': 'local', + 'end_user_type': 'individual', + 'requirements': { + 'end_user': [ + { + 'name': 'Individual', + 'type': 'individual', + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations/individual', + 'fields': [ + 'first_name', + 'last_name' + ] + } + ], + 'supporting_document': [ + [ + { + 'name': 'Address', + 'type': 'document', + 'description': 'The physical location of the individual or business. Must be within locality or region covered by the phone numbers prefix; a PO Box is not acceptable where a local address is required.', + 'accepted_documents': [ + { + 'name': 'Address Validation', + 'type': 'address', + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/DocumentTypes/address', + 'fields': [] + } + ] + } + ] + ] + }, + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations/RNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + } + ], + 'meta': { + 'page': 0, + 'page_size': 50, + 'first_page_url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations?PageSize=50&Page=0', + 'previous_page_url': null, + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations?PageSize=50&Page=0', + 'next_page_url': null, + 'key': 'results' + } + }); + holodeck.mock(new Response(200, body)); + client.numbers.v2.regulatoryCompliance + .regulations.each({pageSize: 20}, () => done()); + holodeck.assertHasRequest(new Request({ + method: 'GET', + url: 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations', + params: {PageSize: 20}, + })); + } + ); + it('should find the callback in the opts object', + function(done) { + var body = JSON.stringify({ + 'results': [ + { + 'sid': 'RNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'friendly_name': 'Australia: Local - Individual', + 'iso_country': 'AU', + 'number_type': 'local', + 'end_user_type': 'individual', + 'requirements': { + 'end_user': [ + { + 'name': 'Individual', + 'type': 'individual', + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations/individual', + 'fields': [ + 'first_name', + 'last_name' + ] + } + ], + 'supporting_document': [ + [ + { + 'name': 'Address', + 'type': 'document', + 'description': 'The physical location of the individual or business. Must be within locality or region covered by the phone numbers prefix; a PO Box is not acceptable where a local address is required.', + 'accepted_documents': [ + { + 'name': 'Address Validation', + 'type': 'address', + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/DocumentTypes/address', + 'fields': [] + } + ] + } + ] + ] + }, + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations/RNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + } + ], + 'meta': { + 'page': 0, + 'page_size': 50, + 'first_page_url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations?PageSize=50&Page=0', + 'previous_page_url': null, + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations?PageSize=50&Page=0', + 'next_page_url': null, + 'key': 'results' + } + }); + holodeck.mock(new Response(200, body)); + client.numbers.v2.regulatoryCompliance + .regulations.each({callback: () => done()}, () => fail('wrong callback!')); + } + ); + it('should generate valid list request', + function(done) { + holodeck.mock(new Response(500, '{}')); + + var promise = client.numbers.v2.regulatoryCompliance + .regulations.list(); + promise.then(function() { + throw new Error('failed'); + }, function(error) { + expect(error.constructor).toBe(RestException.prototype.constructor); + done(); + }).done(); + + var url = 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations'; + + holodeck.assertHasRequest(new Request({ + method: 'GET', + url: url + })); + } + ); + it('should generate valid read_empty response', + function(done) { + var body = JSON.stringify({ + 'results': [], + 'meta': { + 'page': 0, + 'page_size': 50, + 'first_page_url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations?IsoCountry=US&EndUserType=business&NumberType=mobile&PageSize=50&Page=0', + 'previous_page_url': null, + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations?IsoCountry=US&EndUserType=business&NumberType=mobile&PageSize=50&Page=0', + 'next_page_url': null, + 'key': 'results' + } + }); + + holodeck.mock(new Response(200, body)); + + var promise = client.numbers.v2.regulatoryCompliance + .regulations.list(); + promise.then(function(response) { + expect(response).toBeDefined(); + done(); + }, function() { + throw new Error('failed'); + }).done(); + } + ); + it('should generate valid read_full response', + function(done) { + var body = JSON.stringify({ + 'results': [ + { + 'sid': 'RNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'friendly_name': 'Australia: Local - Individual', + 'iso_country': 'AU', + 'number_type': 'local', + 'end_user_type': 'individual', + 'requirements': { + 'end_user': [ + { + 'name': 'Individual', + 'type': 'individual', + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations/individual', + 'fields': [ + 'first_name', + 'last_name' + ] + } + ], + 'supporting_document': [ + [ + { + 'name': 'Address', + 'type': 'document', + 'description': 'The physical location of the individual or business. Must be within locality or region covered by the phone numbers prefix; a PO Box is not acceptable where a local address is required.', + 'accepted_documents': [ + { + 'name': 'Address Validation', + 'type': 'address', + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/DocumentTypes/address', + 'fields': [] + } + ] + } + ] + ] + }, + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations/RNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + } + ], + 'meta': { + 'page': 0, + 'page_size': 50, + 'first_page_url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations?PageSize=50&Page=0', + 'previous_page_url': null, + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations?PageSize=50&Page=0', + 'next_page_url': null, + 'key': 'results' + } + }); + + holodeck.mock(new Response(200, body)); + + var promise = client.numbers.v2.regulatoryCompliance + .regulations.list(); + promise.then(function(response) { + expect(response).toBeDefined(); + done(); + }, function() { + throw new Error('failed'); + }).done(); + } + ); + it('should generate valid fetch request', + function(done) { + holodeck.mock(new Response(500, '{}')); + + var promise = client.numbers.v2.regulatoryCompliance + .regulations('RNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch(); + promise.then(function() { + throw new Error('failed'); + }, function(error) { + expect(error.constructor).toBe(RestException.prototype.constructor); + done(); + }).done(); + + var sid = 'RNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var url = `https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations/${sid}`; + + holodeck.assertHasRequest(new Request({ + method: 'GET', + url: url + })); + } + ); + it('should generate valid fetch response', + function(done) { + var body = JSON.stringify({ + 'sid': 'RNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'friendly_name': 'Australia: Local - Individual', + 'iso_country': 'AU', + 'number_type': 'local', + 'end_user_type': 'individual', + 'requirements': { + 'end_user': [ + { + 'name': 'Individual', + 'type': 'individual', + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations/individual', + 'fields': [ + 'first_name', + 'last_name' + ] + } + ], + 'supporting_document': [ + [ + { + 'name': 'Address', + 'type': 'document', + 'description': 'The physical location of the individual or business. Must be within locality or region covered by the phone numbers prefix; a PO Box is not acceptable where a local address is required.', + 'accepted_documents': [ + { + 'name': 'Address Validation', + 'type': 'address', + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/DocumentTypes/address', + 'fields': [] + } + ] + } + ] + ] + }, + 'url': 'https://numbers.twilio.com/v2/RegulatoryCompliance/Regulations/RNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + }); + + holodeck.mock(new Response(200, body)); + + var promise = client.numbers.v2.regulatoryCompliance + .regulations('RNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch(); + promise.then(function(response) { + expect(response).toBeDefined(); + done(); + }, function() { + throw new Error('failed'); + }).done(); + } + ); +}); diff --git a/spec/integration/rest/studio/v2/flow.spec.js b/spec/integration/rest/studio/v2/flow.spec.js index c7069a5ee0..370deb8436 100644 --- a/spec/integration/rest/studio/v2/flow.spec.js +++ b/spec/integration/rest/studio/v2/flow.spec.js @@ -68,11 +68,14 @@ describe('Flow', function() { 'commit_message': null, 'valid': true, 'errors': [], + 'webhook_url': 'http://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'date_created': '2017-11-06T12:00:00Z', 'date_updated': null, 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'links': { - 'revisions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions' + 'test_users': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TestUsers', + 'revisions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions', + 'executions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions' } }); @@ -126,11 +129,14 @@ describe('Flow', function() { 'commit_message': null, 'valid': true, 'errors': [], + 'webhook_url': 'http://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'date_created': '2017-11-06T12:00:00Z', 'date_updated': '2017-11-06T12:00:00Z', 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'links': { - 'revisions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions' + 'test_users': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TestUsers', + 'revisions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions', + 'executions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions' } }); @@ -169,11 +175,14 @@ describe('Flow', function() { 'commit_message': null, 'valid': null, 'errors': null, + 'webhook_url': 'http://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'date_created': '2017-11-06T12:00:00Z', 'date_updated': '2017-11-06T12:00:00Z', 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'links': { - 'revisions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions' + 'test_users': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TestUsers', + 'revisions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions', + 'executions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions' } } ] @@ -205,11 +214,14 @@ describe('Flow', function() { 'commit_message': null, 'valid': null, 'errors': null, + 'webhook_url': 'http://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'date_created': '2017-11-06T12:00:00Z', 'date_updated': '2017-11-06T12:00:00Z', 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'links': { - 'revisions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions' + 'test_users': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TestUsers', + 'revisions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions', + 'executions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions' } } ] @@ -246,11 +258,14 @@ describe('Flow', function() { 'commit_message': null, 'valid': null, 'errors': null, + 'webhook_url': 'http://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'date_created': '2017-11-06T12:00:00Z', 'date_updated': '2017-11-06T12:00:00Z', 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'links': { - 'revisions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions' + 'test_users': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TestUsers', + 'revisions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions', + 'executions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions' } } ] @@ -302,11 +317,14 @@ describe('Flow', function() { 'commit_message': null, 'valid': null, 'errors': null, + 'webhook_url': 'http://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'date_created': '2017-11-06T12:00:00Z', 'date_updated': '2017-11-06T12:00:00Z', 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'links': { - 'revisions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions' + 'test_users': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TestUsers', + 'revisions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions', + 'executions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions' } } ] @@ -358,11 +376,14 @@ describe('Flow', function() { 'commit_message': 'commit', 'valid': true, 'errors': [], + 'webhook_url': 'http://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'date_created': '2017-11-06T12:00:00Z', 'date_updated': null, 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'links': { - 'revisions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions' + 'test_users': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TestUsers', + 'revisions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions', + 'executions': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions' } }); diff --git a/spec/integration/rest/studio/v2/flow/execution.spec.js b/spec/integration/rest/studio/v2/flow/execution.spec.js new file mode 100644 index 0000000000..8b3e8aa7af --- /dev/null +++ b/spec/integration/rest/studio/v2/flow/execution.spec.js @@ -0,0 +1,229 @@ +'use strict'; + +/* jshint ignore:start */ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ +/* jshint ignore:end */ + +var Holodeck = require('../../../../holodeck'); /* jshint ignore:line */ +var Request = require( + '../../../../../../lib/http/request'); /* jshint ignore:line */ +var Response = require( + '../../../../../../lib/http/response'); /* jshint ignore:line */ +var RestException = require( + '../../../../../../lib/base/RestException'); /* jshint ignore:line */ +var Twilio = require('../../../../../../lib'); /* jshint ignore:line */ + + +var client; +var holodeck; + +describe('Execution', function() { + beforeEach(function() { + holodeck = new Holodeck(); + client = new Twilio('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'AUTHTOKEN', { + httpClient: holodeck + }); + }); + it('should generate valid list request', + function(done) { + holodeck.mock(new Response(500, '{}')); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions.list(); + promise.then(function() { + throw new Error('failed'); + }, function(error) { + expect(error.constructor).toBe(RestException.prototype.constructor); + done(); + }).done(); + + var flowSid = 'FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var url = `https://studio.twilio.com/v2/Flows/${flowSid}/Executions`; + + holodeck.assertHasRequest(new Request({ + method: 'GET', + url: url + })); + } + ); + it('should generate valid read_empty response', + function(done) { + var body = JSON.stringify({ + 'meta': { + 'previous_page_url': null, + 'next_page_url': null, + 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions?PageSize=50&Page=0', + 'page': 0, + 'first_page_url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions?PageSize=50&Page=0', + 'page_size': 50, + 'key': 'executions' + }, + 'executions': [] + }); + + holodeck.mock(new Response(200, body)); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions.list(); + promise.then(function(response) { + expect(response).toBeDefined(); + done(); + }, function() { + throw new Error('failed'); + }).done(); + } + ); + it('should generate valid fetch request', + function(done) { + holodeck.mock(new Response(500, '{}')); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions('FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch(); + promise.then(function() { + throw new Error('failed'); + }, function(error) { + expect(error.constructor).toBe(RestException.prototype.constructor); + done(); + }).done(); + + var flowSid = 'FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var sid = 'FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var url = `https://studio.twilio.com/v2/Flows/${flowSid}/Executions/${sid}`; + + holodeck.assertHasRequest(new Request({ + method: 'GET', + url: url + })); + } + ); + it('should generate valid fetch response', + function(done) { + var body = JSON.stringify({ + 'sid': 'FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'flow_sid': 'FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'contact_channel_address': '+14155555555', + 'status': 'ended', + 'context': {}, + 'date_created': '2017-11-06T12:00:00Z', + 'date_updated': null, + 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'links': { + 'steps': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Steps', + 'execution_context': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Context' + } + }); + + holodeck.mock(new Response(200, body)); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions('FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch(); + promise.then(function(response) { + expect(response).toBeDefined(); + done(); + }, function() { + throw new Error('failed'); + }).done(); + } + ); + it('should generate valid create request', + function(done) { + holodeck.mock(new Response(500, '{}')); + + var opts = {to: '+15558675310', from: '+15017122661'}; + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions.create(opts); + promise.then(function() { + throw new Error('failed'); + }, function(error) { + expect(error.constructor).toBe(RestException.prototype.constructor); + done(); + }).done(); + + var flowSid = 'FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var url = `https://studio.twilio.com/v2/Flows/${flowSid}/Executions`; + + var values = {To: '+15558675310', From: '+15017122661', }; + holodeck.assertHasRequest(new Request({ + method: 'POST', + url: url, + data: values + })); + } + ); + it('should generate valid create response', + function(done) { + var body = JSON.stringify({ + 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'sid': 'FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'flow_sid': 'FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'context': {}, + 'contact_channel_address': '+18001234567', + 'status': 'active', + 'date_created': '2015-07-30T20:00:00Z', + 'date_updated': '2015-07-30T20:00:00Z', + 'links': { + 'steps': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Steps', + 'execution_context': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Context' + } + }); + + holodeck.mock(new Response(201, body)); + + var opts = {to: '+15558675310', from: '+15017122661'}; + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions.create(opts); + promise.then(function(response) { + expect(response).toBeDefined(); + done(); + }, function() { + throw new Error('failed'); + }).done(); + } + ); + it('should generate valid remove request', + function(done) { + holodeck.mock(new Response(500, '{}')); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions('FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').remove(); + promise.then(function() { + throw new Error('failed'); + }, function(error) { + expect(error.constructor).toBe(RestException.prototype.constructor); + done(); + }).done(); + + var flowSid = 'FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var sid = 'FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var url = `https://studio.twilio.com/v2/Flows/${flowSid}/Executions/${sid}`; + + holodeck.assertHasRequest(new Request({ + method: 'DELETE', + url: url + })); + } + ); + it('should generate valid delete response', + function(done) { + var body = JSON.stringify(null); + + holodeck.mock(new Response(204, body)); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions('FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').remove(); + promise.then(function(response) { + expect(response).toBe(true); + done(); + }, function() { + throw new Error('failed'); + }).done(); + } + ); +}); diff --git a/spec/integration/rest/studio/v2/flow/execution/executionContext.spec.js b/spec/integration/rest/studio/v2/flow/execution/executionContext.spec.js new file mode 100644 index 0000000000..83f3a01339 --- /dev/null +++ b/spec/integration/rest/studio/v2/flow/execution/executionContext.spec.js @@ -0,0 +1,81 @@ +'use strict'; + +/* jshint ignore:start */ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ +/* jshint ignore:end */ + +var Holodeck = require('../../../../../holodeck'); /* jshint ignore:line */ +var Request = require( + '../../../../../../../lib/http/request'); /* jshint ignore:line */ +var Response = require( + '../../../../../../../lib/http/response'); /* jshint ignore:line */ +var RestException = require( + '../../../../../../../lib/base/RestException'); /* jshint ignore:line */ +var Twilio = require('../../../../../../../lib'); /* jshint ignore:line */ + + +var client; +var holodeck; + +describe('ExecutionContext', function() { + beforeEach(function() { + holodeck = new Holodeck(); + client = new Twilio('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'AUTHTOKEN', { + httpClient: holodeck + }); + }); + it('should generate valid fetch request', + function(done) { + holodeck.mock(new Response(500, '{}')); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions('FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executionContext().fetch(); + promise.then(function() { + throw new Error('failed'); + }, function(error) { + expect(error.constructor).toBe(RestException.prototype.constructor); + done(); + }).done(); + + var flowSid = 'FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var executionSid = 'FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var url = `https://studio.twilio.com/v2/Flows/${flowSid}/Executions/${executionSid}/Context`; + + holodeck.assertHasRequest(new Request({ + method: 'GET', + url: url + })); + } + ); + it('should generate valid fetch response', + function(done) { + var body = JSON.stringify({ + 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'context': { + 'foo': 'bar' + }, + 'flow_sid': 'FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'execution_sid': 'FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Context' + }); + + holodeck.mock(new Response(200, body)); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions('FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executionContext().fetch(); + promise.then(function(response) { + expect(response).toBeDefined(); + done(); + }, function() { + throw new Error('failed'); + }).done(); + } + ); +}); diff --git a/spec/integration/rest/studio/v2/flow/execution/executionStep.spec.js b/spec/integration/rest/studio/v2/flow/execution/executionStep.spec.js new file mode 100644 index 0000000000..383a0976b1 --- /dev/null +++ b/spec/integration/rest/studio/v2/flow/execution/executionStep.spec.js @@ -0,0 +1,141 @@ +'use strict'; + +/* jshint ignore:start */ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ +/* jshint ignore:end */ + +var Holodeck = require('../../../../../holodeck'); /* jshint ignore:line */ +var Request = require( + '../../../../../../../lib/http/request'); /* jshint ignore:line */ +var Response = require( + '../../../../../../../lib/http/response'); /* jshint ignore:line */ +var RestException = require( + '../../../../../../../lib/base/RestException'); /* jshint ignore:line */ +var Twilio = require('../../../../../../../lib'); /* jshint ignore:line */ + + +var client; +var holodeck; + +describe('ExecutionStep', function() { + beforeEach(function() { + holodeck = new Holodeck(); + client = new Twilio('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'AUTHTOKEN', { + httpClient: holodeck + }); + }); + it('should generate valid list request', + function(done) { + holodeck.mock(new Response(500, '{}')); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions('FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .steps.list(); + promise.then(function() { + throw new Error('failed'); + }, function(error) { + expect(error.constructor).toBe(RestException.prototype.constructor); + done(); + }).done(); + + var flowSid = 'FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var executionSid = 'FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var url = `https://studio.twilio.com/v2/Flows/${flowSid}/Executions/${executionSid}/Steps`; + + holodeck.assertHasRequest(new Request({ + method: 'GET', + url: url + })); + } + ); + it('should generate valid read_empty response', + function(done) { + var body = JSON.stringify({ + 'meta': { + 'previous_page_url': null, + 'next_page_url': null, + 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Steps?PageSize=50&Page=0', + 'page': 0, + 'first_page_url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Steps?PageSize=50&Page=0', + 'page_size': 50, + 'key': 'steps' + }, + 'steps': [] + }); + + holodeck.mock(new Response(200, body)); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions('FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .steps.list(); + promise.then(function(response) { + expect(response).toBeDefined(); + done(); + }, function() { + throw new Error('failed'); + }).done(); + } + ); + it('should generate valid fetch request', + function(done) { + holodeck.mock(new Response(500, '{}')); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions('FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .steps('FTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch(); + promise.then(function() { + throw new Error('failed'); + }, function(error) { + expect(error.constructor).toBe(RestException.prototype.constructor); + done(); + }).done(); + + var flowSid = 'FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var executionSid = 'FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var sid = 'FTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var url = `https://studio.twilio.com/v2/Flows/${flowSid}/Executions/${executionSid}/Steps/${sid}`; + + holodeck.assertHasRequest(new Request({ + method: 'GET', + url: url + })); + } + ); + it('should generate valid fetch response', + function(done) { + var body = JSON.stringify({ + 'sid': 'FTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'flow_sid': 'FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'execution_sid': 'FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'name': 'incomingRequest', + 'context': {}, + 'transitioned_from': 'Trigger', + 'transitioned_to': 'Ended', + 'date_created': '2017-11-06T12:00:00Z', + 'date_updated': null, + 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Steps/FTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'links': { + 'step_context': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Steps/FTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Context' + } + }); + + holodeck.mock(new Response(200, body)); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions('FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .steps('FTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').fetch(); + promise.then(function(response) { + expect(response).toBeDefined(); + done(); + }, function() { + throw new Error('failed'); + }).done(); + } + ); +}); diff --git a/spec/integration/rest/studio/v2/flow/execution/executionStep/executionStepContext.spec.js b/spec/integration/rest/studio/v2/flow/execution/executionStep/executionStepContext.spec.js new file mode 100644 index 0000000000..3105a6fb9f --- /dev/null +++ b/spec/integration/rest/studio/v2/flow/execution/executionStep/executionStepContext.spec.js @@ -0,0 +1,85 @@ +'use strict'; + +/* jshint ignore:start */ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ +/* jshint ignore:end */ + +var Holodeck = require('../../../../../../holodeck'); /* jshint ignore:line */ +var Request = require( + '../../../../../../../../lib/http/request'); /* jshint ignore:line */ +var Response = require( + '../../../../../../../../lib/http/response'); /* jshint ignore:line */ +var RestException = require( + '../../../../../../../../lib/base/RestException'); /* jshint ignore:line */ +var Twilio = require('../../../../../../../../lib'); /* jshint ignore:line */ + + +var client; +var holodeck; + +describe('ExecutionStepContext', function() { + beforeEach(function() { + holodeck = new Holodeck(); + client = new Twilio('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'AUTHTOKEN', { + httpClient: holodeck + }); + }); + it('should generate valid fetch request', + function(done) { + holodeck.mock(new Response(500, '{}')); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions('FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .steps('FTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .stepContext().fetch(); + promise.then(function() { + throw new Error('failed'); + }, function(error) { + expect(error.constructor).toBe(RestException.prototype.constructor); + done(); + }).done(); + + var flowSid = 'FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var executionSid = 'FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var stepSid = 'FTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var url = `https://studio.twilio.com/v2/Flows/${flowSid}/Executions/${executionSid}/Steps/${stepSid}/Context`; + + holodeck.assertHasRequest(new Request({ + method: 'GET', + url: url + })); + } + ); + it('should generate valid fetch response', + function(done) { + var body = JSON.stringify({ + 'account_sid': 'ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'context': { + 'foo': 'bar' + }, + 'flow_sid': 'FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'execution_sid': 'FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'step_sid': 'FTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Steps/FTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Context' + }); + + holodeck.mock(new Response(200, body)); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .executions('FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .steps('FTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .stepContext().fetch(); + promise.then(function(response) { + expect(response).toBeDefined(); + done(); + }, function() { + throw new Error('failed'); + }).done(); + } + ); +}); diff --git a/spec/integration/rest/studio/v2/flow/testUser.spec.js b/spec/integration/rest/studio/v2/flow/testUser.spec.js new file mode 100644 index 0000000000..cdb846218b --- /dev/null +++ b/spec/integration/rest/studio/v2/flow/testUser.spec.js @@ -0,0 +1,128 @@ +'use strict'; + +/* jshint ignore:start */ +/** + * This code was generated by + * \ / _ _ _| _ _ + * | (_)\/(_)(_|\/| |(/_ v1.0.0 + * / / + */ +/* jshint ignore:end */ + +var Holodeck = require('../../../../holodeck'); /* jshint ignore:line */ +var Request = require( + '../../../../../../lib/http/request'); /* jshint ignore:line */ +var Response = require( + '../../../../../../lib/http/response'); /* jshint ignore:line */ +var RestException = require( + '../../../../../../lib/base/RestException'); /* jshint ignore:line */ +var Twilio = require('../../../../../../lib'); /* jshint ignore:line */ +var serialize = require( + '../../../../../../lib/base/serialize'); /* jshint ignore:line */ + + +var client; +var holodeck; + +describe('FlowTestUser', function() { + beforeEach(function() { + holodeck = new Holodeck(); + client = new Twilio('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'AUTHTOKEN', { + httpClient: holodeck + }); + }); + it('should generate valid fetch request', + function(done) { + holodeck.mock(new Response(500, '{}')); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .testUsers().fetch(); + promise.then(function() { + throw new Error('failed'); + }, function(error) { + expect(error.constructor).toBe(RestException.prototype.constructor); + done(); + }).done(); + + var sid = 'FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var url = `https://studio.twilio.com/v2/Flows/${sid}/TestUsers`; + + holodeck.assertHasRequest(new Request({ + method: 'GET', + url: url + })); + } + ); + it('should generate valid fetch response', + function(done) { + var body = JSON.stringify({ + 'sid': 'FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'test_users': [ + 'user1', + 'user2' + ], + 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TestUsers' + }); + + holodeck.mock(new Response(200, body)); + + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .testUsers().fetch(); + promise.then(function(response) { + expect(response).toBeDefined(); + done(); + }, function() { + throw new Error('failed'); + }).done(); + } + ); + it('should generate valid update request', + function(done) { + holodeck.mock(new Response(500, '{}')); + + var opts = {testUsers: ['test_users']}; + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .testUsers().update(opts); + promise.then(function() { + throw new Error('failed'); + }, function(error) { + expect(error.constructor).toBe(RestException.prototype.constructor); + done(); + }).done(); + + var sid = 'FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; + var url = `https://studio.twilio.com/v2/Flows/${sid}/TestUsers`; + + var values = {TestUsers: serialize.map(['test_users'], function(e) { return e; }), }; + holodeck.assertHasRequest(new Request({ + method: 'POST', + url: url, + data: values + })); + } + ); + it('should generate valid update response', + function(done) { + var body = JSON.stringify({ + 'sid': 'FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'test_users': [ + 'user1', + 'user2' + ], + 'url': 'https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TestUsers' + }); + + holodeck.mock(new Response(200, body)); + + var opts = {testUsers: ['test_users']}; + var promise = client.studio.v2.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') + .testUsers().update(opts); + promise.then(function(response) { + expect(response).toBeDefined(); + done(); + }, function() { + throw new Error('failed'); + }).done(); + } + ); +}); diff --git a/spec/integration/rest/taskrouter/v1/workspace/task.spec.js b/spec/integration/rest/taskrouter/v1/workspace/task.spec.js index 06a6abe31b..e231e560b3 100644 --- a/spec/integration/rest/taskrouter/v1/workspace/task.spec.js +++ b/spec/integration/rest/taskrouter/v1/workspace/task.spec.js @@ -61,6 +61,7 @@ describe('Task', function() { 'attributes': '{\'body\': \'hello\'}', 'date_created': '2014-05-14T18:50:02Z', 'date_updated': '2014-05-15T07:26:06Z', + 'task_queue_entered_date': '2014-05-14T18:50:02Z', 'priority': 0, 'reason': 'Test Reason', 'sid': 'WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', @@ -126,6 +127,7 @@ describe('Task', function() { 'attributes': '{\'body\': \'hello\'}', 'date_created': '2014-05-14T18:50:02Z', 'date_updated': '2014-05-15T07:26:06Z', + 'task_queue_entered_date': '2014-05-14T18:50:02Z', 'priority': 0, 'reason': 'Test Reason', 'sid': 'WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', @@ -218,6 +220,7 @@ describe('Task', function() { 'attributes': '{\'body\': \'hello\'}', 'date_created': '2014-05-14T14:26:54Z', 'date_updated': '2014-05-15T16:03:42Z', + 'task_queue_entered_date': '2014-05-14T14:26:54Z', 'priority': 0, 'reason': 'Test Reason', 'sid': 'WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', @@ -265,6 +268,7 @@ describe('Task', function() { 'attributes': '{\'body\': \'hello\'}', 'date_created': '2014-05-14T14:26:54Z', 'date_updated': '2014-05-15T16:03:42Z', + 'task_queue_entered_date': '2014-05-14T14:26:54Z', 'priority': 0, 'reason': 'Test Reason', 'sid': 'WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', @@ -317,6 +321,7 @@ describe('Task', function() { 'attributes': '{\'body\': \'hello\'}', 'date_created': '2014-05-14T14:26:54Z', 'date_updated': '2014-05-15T16:03:42Z', + 'task_queue_entered_date': '2014-05-14T14:26:54Z', 'priority': 0, 'reason': 'Test Reason', 'sid': 'WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', @@ -386,6 +391,7 @@ describe('Task', function() { 'attributes': '{\'body\': \'hello\'}', 'date_created': '2014-05-14T14:26:54Z', 'date_updated': '2014-05-15T16:03:42Z', + 'task_queue_entered_date': '2014-05-14T14:26:54Z', 'priority': 0, 'reason': 'Test Reason', 'sid': 'WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', @@ -506,6 +512,7 @@ describe('Task', function() { 'attributes': '{\'body\': \'attributes\'}', 'date_created': '2014-05-14T18:50:02Z', 'date_updated': '2014-05-15T07:26:06Z', + 'task_queue_entered_date': null, 'priority': 1, 'reason': 'Test Reason', 'sid': 'WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', diff --git a/spec/integration/rest/taskrouter/v1/workspace/taskQueue/taskQueueCumulativeStatistics.spec.js b/spec/integration/rest/taskrouter/v1/workspace/taskQueue/taskQueueCumulativeStatistics.spec.js index 4879069ab3..0e36721e8f 100644 --- a/spec/integration/rest/taskrouter/v1/workspace/taskQueue/taskQueueCumulativeStatistics.spec.js +++ b/spec/integration/rest/taskrouter/v1/workspace/taskQueue/taskQueueCumulativeStatistics.spec.js @@ -79,6 +79,12 @@ describe('TaskQueueCumulativeStatistics', function() { 'max': 0, 'total': 0 }, + 'wait_duration_in_queue_until_accepted': { + 'avg': 0, + 'min': 0, + 'max': 0, + 'total': 0 + }, 'split_by_wait_time': { '5': { 'above': { diff --git a/spec/integration/rest/taskrouter/v1/workspace/taskQueue/taskQueueRealTimeStatistics.spec.js b/spec/integration/rest/taskrouter/v1/workspace/taskQueue/taskQueueRealTimeStatistics.spec.js index 768a84d9cd..a9eafd8577 100644 --- a/spec/integration/rest/taskrouter/v1/workspace/taskQueue/taskQueueRealTimeStatistics.spec.js +++ b/spec/integration/rest/taskrouter/v1/workspace/taskQueue/taskQueueRealTimeStatistics.spec.js @@ -58,6 +58,8 @@ describe('TaskQueueRealTimeStatistics', function() { var body = JSON.stringify({ 'longest_task_waiting_age': 100, 'longest_task_waiting_sid': 'WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'longest_relative_task_age_in_queue': 100, + 'longest_relative_task_sid_in_queue': 'WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'task_queue_sid': 'WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'tasks_by_status': { 'reserved': 0,