twilio
Version:
A Twilio helper library
187 lines (164 loc) • 5.63 kB
JavaScript
'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 FeedbackList;
var FeedbackPage;
var FeedbackInstance;
/* jshint ignore:start */
/**
* @constructor Twilio.Api.V2010.AccountContext.MessageContext.FeedbackList
* @description Initialize the FeedbackList
*
* @param {Twilio.Api.V2010} version - Version of the resource
* @param {string} accountSid - The account_sid
* @param {string} messageSid - The message_sid
*/
/* jshint ignore:end */
FeedbackList = function FeedbackList(version, accountSid, messageSid) {
/* jshint ignore:start */
/**
* @function feedback
* @memberof Twilio.Api.V2010.AccountContext.MessageContext
* @instance
*
* @param {string} sid - sid of instance
*
* @returns {Twilio.Api.V2010.AccountContext.MessageContext.FeedbackContext}
*/
/* jshint ignore:end */
function FeedbackListInstance(sid) {
return FeedbackListInstance.get(sid);
}
FeedbackListInstance._version = version;
// Path Solution
FeedbackListInstance._solution = {accountSid: accountSid, messageSid: messageSid};
FeedbackListInstance._uri = _.template(
'/Accounts/<%= accountSid %>/Messages/<%= messageSid %>/Feedback.json' // jshint ignore:line
)(FeedbackListInstance._solution);
/* jshint ignore:start */
/**
* create a FeedbackInstance
*
* @function create
* @memberof Twilio.Api.V2010.AccountContext.MessageContext.FeedbackList
* @instance
*
* @param {object|function} opts - ...
* @param {string} opts.accountSid - The account_sid
* @param {string} opts.messageSid - The message_sid
* @param {feedback.outcome} [opts.outcome] - The outcome
* @param {function} [callback] - Callback to handle processed record
*
* @returns {Promise} Resolves to processed FeedbackInstance
*/
/* jshint ignore:end */
FeedbackListInstance.create = function create(opts, callback) {
if (_.isFunction(opts)) {
callback = opts;
opts = {};
}
opts = opts || {};
var deferred = Q.defer();
var data = values.of({'Outcome': _.get(opts, 'outcome')});
var promise = this._version.create({uri: this._uri, method: 'POST', data: data});
promise = promise.then(function(payload) {
deferred.resolve(new FeedbackInstance(this._version, payload));
}.bind(this));
promise.catch(function(error) {
deferred.reject(error);
});
if (_.isFunction(callback)) {
deferred.promise.nodeify(callback);
}
return deferred.promise;
};
return FeedbackListInstance;
};
/* jshint ignore:start */
/**
* @constructor Twilio.Api.V2010.AccountContext.MessageContext.FeedbackPage
* @augments Page
* @description Initialize the FeedbackPage
*
* @param {Twilio.Api.V2010} version - Version of the resource
* @param {object} response - Response from the API
* @param {object} solution - Path solution
*
* @returns FeedbackPage
*/
/* jshint ignore:end */
FeedbackPage = function FeedbackPage(version, response, solution) {
// Path Solution
this._solution = solution;
Page.prototype.constructor.call(this, version, response, this._solution);
};
_.extend(FeedbackPage.prototype, Page.prototype);
FeedbackPage.prototype.constructor = FeedbackPage;
/* jshint ignore:start */
/**
* Build an instance of FeedbackInstance
*
* @function getInstance
* @memberof Twilio.Api.V2010.AccountContext.MessageContext.FeedbackPage
* @instance
*
* @param {object} payload - Payload response from the API
*
* @returns FeedbackInstance
*/
/* jshint ignore:end */
FeedbackPage.prototype.getInstance = function getInstance(payload) {
return new FeedbackInstance(
this._version,
payload,
this._solution.accountSid,
this._solution.messageSid
);
};
/* jshint ignore:start */
/**
* @constructor Twilio.Api.V2010.AccountContext.MessageContext.FeedbackInstance
* @description Initialize the FeedbackContext
*
* @property {string} accountSid - The account_sid
* @property {string} messageSid - The message_sid
* @property {feedback.outcome} outcome - The outcome
* @property {Date} dateCreated - The date_created
* @property {Date} dateUpdated - The date_updated
* @property {string} uri - The uri
*
* @param {Twilio.Api.V2010} version - Version of the resource
* @param {object} payload - The instance payload
*/
/* jshint ignore:end */
FeedbackInstance = function FeedbackInstance(version, payload, accountSid,
messageSid) {
this._version = version;
// Marshaled Properties
this.accountSid = payload.account_sid; // jshint ignore:line
this.messageSid = payload.message_sid; // jshint ignore:line
this.outcome = payload.outcome; // jshint ignore:line
this.dateCreated = deserialize.rfc2822DateTime(payload.date_created); // jshint ignore:line
this.dateUpdated = deserialize.rfc2822DateTime(payload.date_updated); // jshint ignore:line
this.uri = payload.uri; // jshint ignore:line
// Context
this._context = undefined;
this._solution = {accountSid: accountSid, messageSid: messageSid,};
};
module.exports = {
FeedbackList: FeedbackList,
FeedbackPage: FeedbackPage,
FeedbackInstance: FeedbackInstance
};