UNPKG

twilio

Version:
199 lines (176 loc) 6.95 kB
'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 Page = require('../../../../base/Page'); /* jshint ignore:line */ var deserialize = require( '../../../../base/deserialize'); /* jshint ignore:line */ var values = require('../../../../base/values'); /* jshint ignore:line */ var VerificationList; var VerificationPage; var VerificationInstance; /* jshint ignore:start */ /** * @constructor Twilio.Preview.AccSecurity.ServiceContext.VerificationList * @description Initialize the VerificationList * 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 {Twilio.Preview.AccSecurity} version - Version of the resource * @param {string} serviceSid - Service Sid. */ /* jshint ignore:end */ VerificationList = function VerificationList(version, serviceSid) { /* jshint ignore:start */ /** * @function verifications * @memberof Twilio.Preview.AccSecurity.ServiceContext * @instance * * @param {string} sid - sid of instance * * @returns {Twilio.Preview.AccSecurity.ServiceContext.VerificationContext} */ /* jshint ignore:end */ function VerificationListInstance(sid) { return VerificationListInstance.get(sid); } VerificationListInstance._version = version; // Path Solution VerificationListInstance._solution = {serviceSid: serviceSid}; VerificationListInstance._uri = _.template( '/Services/<%= serviceSid %>/Verifications' // jshint ignore:line )(VerificationListInstance._solution); /* jshint ignore:start */ /** * create a VerificationInstance * * @function create * @memberof Twilio.Preview.AccSecurity.ServiceContext.VerificationList * @instance * * @param {object} opts - ... * @param {string} opts.serviceSid - Service Sid. * @param {string} opts.to - To phonenumber * @param {string} opts.channel - sms or call * @param {string} [opts.customMessage] - A custom message for this verification * @param {function} [callback] - Callback to handle processed record * * @returns {Promise} Resolves to processed VerificationInstance */ /* jshint ignore:end */ VerificationListInstance.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.channel)) { throw new Error('Required parameter "opts.channel" missing.'); } var deferred = Q.defer(); var data = values.of({ 'To': _.get(opts, 'to'), 'Channel': _.get(opts, 'channel'), 'CustomMessage': _.get(opts, 'customMessage') }); var promise = this._version.create({uri: this._uri, method: 'POST', data: data}); promise = promise.then(function(payload) { deferred.resolve(new VerificationInstance(this._version, payload)); }.bind(this)); promise.catch(function(error) { deferred.reject(error); }); if (_.isFunction(callback)) { deferred.promise.nodeify(callback); } return deferred.promise; }; return VerificationListInstance; }; /* jshint ignore:start */ /** * @constructor Twilio.Preview.AccSecurity.ServiceContext.VerificationPage * @augments Page * @description Initialize the VerificationPage * 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 {Twilio.Preview.AccSecurity} version - Version of the resource * @param {object} response - Response from the API * @param {object} solution - Path solution * * @returns VerificationPage */ /* jshint ignore:end */ VerificationPage = function VerificationPage(version, response, solution) { // Path Solution this._solution = solution; Page.prototype.constructor.call(this, version, response, this._solution); }; _.extend(VerificationPage.prototype, Page.prototype); VerificationPage.prototype.constructor = VerificationPage; /* jshint ignore:start */ /** * Build an instance of VerificationInstance * * @function getInstance * @memberof Twilio.Preview.AccSecurity.ServiceContext.VerificationPage * @instance * * @param {object} payload - Payload response from the API * * @returns VerificationInstance */ /* jshint ignore:end */ VerificationPage.prototype.getInstance = function getInstance(payload) { return new VerificationInstance(this._version, payload, this._solution.serviceSid); }; /* jshint ignore:start */ /** * @constructor Twilio.Preview.AccSecurity.ServiceContext.VerificationInstance * @description Initialize the VerificationContext * 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. * * @property {string} sid - A string that uniquely identifies this Verification. * @property {string} serviceSid - Service Sid. * @property {string} accountSid - Account Sid. * @property {string} to - To phonenumber * @property {verification.channel} channel - sms or call * @property {string} status - pending, approved, denied or expired * @property {boolean} valid - successful verification * @property {Date} dateCreated - The date this Verification was created * @property {Date} dateUpdated - The date this Verification was updated * * @param {Twilio.Preview.AccSecurity} version - Version of the resource * @param {object} payload - The instance payload */ /* jshint ignore:end */ VerificationInstance = function VerificationInstance(version, payload, serviceSid) { this._version = version; // Marshaled Properties this.sid = payload.sid; // jshint ignore:line this.serviceSid = payload.service_sid; // jshint ignore:line this.accountSid = payload.account_sid; // jshint ignore:line this.to = payload.to; // jshint ignore:line this.channel = payload.channel; // jshint ignore:line this.status = payload.status; // jshint ignore:line this.valid = payload.valid; // 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 = {serviceSid: serviceSid,}; }; module.exports = { VerificationList: VerificationList, VerificationPage: VerificationPage, VerificationInstance: VerificationInstance };