twilio
Version:
A Twilio helper library
246 lines (223 loc) • 8.67 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 serialize = require('../../../../base/serialize'); /* jshint ignore:line */
var values = require('../../../../base/values'); /* jshint ignore:line */
var NotificationList;
var NotificationPage;
var NotificationInstance;
/* jshint ignore:start */
/**
* @constructor Twilio.Notify.V1.ServiceContext.NotificationList
* @description Initialize the NotificationList
* PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
*
* @param {Twilio.Notify.V1} version - Version of the resource
* @param {string} serviceSid - The service_sid
*/
/* jshint ignore:end */
NotificationList = function NotificationList(version, serviceSid) {
/* jshint ignore:start */
/**
* @function notifications
* @memberof Twilio.Notify.V1.ServiceContext
* @instance
*
* @param {string} sid - sid of instance
*
* @returns {Twilio.Notify.V1.ServiceContext.NotificationContext}
*/
/* jshint ignore:end */
function NotificationListInstance(sid) {
return NotificationListInstance.get(sid);
}
NotificationListInstance._version = version;
// Path Solution
NotificationListInstance._solution = {serviceSid: serviceSid};
NotificationListInstance._uri = _.template(
'/Services/<%= serviceSid %>/Notifications' // jshint ignore:line
)(NotificationListInstance._solution);
/* jshint ignore:start */
/**
* create a NotificationInstance
*
* @function create
* @memberof Twilio.Notify.V1.ServiceContext.NotificationList
* @instance
*
* @param {object|function} opts - ...
* @param {string} opts.serviceSid - The service_sid
* @param {string} [opts.body] - The body
* @param {notification.priority} [opts.priority] - The priority
* @param {number} [opts.ttl] - The ttl
* @param {string} [opts.title] - The title
* @param {string} [opts.sound] - The sound
* @param {string} [opts.action] - The action
* @param {string} [opts.data] - The data
* @param {string} [opts.apn] - The apn
* @param {string} [opts.gcm] - The gcm
* @param {string} [opts.sms] - The sms
* @param {string} [opts.facebookMessenger] - The facebook_messenger
* @param {string} [opts.fcm] - The fcm
* @param {string|list} [opts.segment] - The segment
* @param {string} [opts.alexa] - The alexa
* @param {string|list} [opts.toBinding] - The to_binding
* @param {string|list} [opts.identity] - The identity
* @param {string|list} [opts.tag] - The tag
* @param {function} [callback] - Callback to handle processed record
*
* @returns {Promise} Resolves to processed NotificationInstance
*/
/* jshint ignore:end */
NotificationListInstance.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'),
'Tag': _.get(opts, 'tag'),
'Body': _.get(opts, 'body'),
'Priority': _.get(opts, 'priority'),
'Ttl': _.get(opts, 'ttl'),
'Title': _.get(opts, 'title'),
'Sound': _.get(opts, 'sound'),
'Action': _.get(opts, 'action'),
'Data': serialize.object(_.get(opts, 'data')),
'Apn': serialize.object(_.get(opts, 'apn')),
'Gcm': serialize.object(_.get(opts, 'gcm')),
'Sms': serialize.object(_.get(opts, 'sms')),
'FacebookMessenger': serialize.object(_.get(opts, 'facebookMessenger')),
'Fcm': serialize.object(_.get(opts, 'fcm')),
'Segment': _.get(opts, 'segment'),
'Alexa': serialize.object(_.get(opts, 'alexa')),
'ToBinding': _.get(opts, 'toBinding')
});
var promise = this._version.create({uri: this._uri, method: 'POST', data: data});
promise = promise.then(function(payload) {
deferred.resolve(new NotificationInstance(this._version, payload));
}.bind(this));
promise.catch(function(error) {
deferred.reject(error);
});
if (_.isFunction(callback)) {
deferred.promise.nodeify(callback);
}
return deferred.promise;
};
return NotificationListInstance;
};
/* jshint ignore:start */
/**
* @constructor Twilio.Notify.V1.ServiceContext.NotificationPage
* @augments Page
* @description Initialize the NotificationPage
* PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
*
* @param {Twilio.Notify.V1} version - Version of the resource
* @param {object} response - Response from the API
* @param {object} solution - Path solution
*
* @returns NotificationPage
*/
/* jshint ignore:end */
NotificationPage = function NotificationPage(version, response, solution) {
// Path Solution
this._solution = solution;
Page.prototype.constructor.call(this, version, response, this._solution);
};
_.extend(NotificationPage.prototype, Page.prototype);
NotificationPage.prototype.constructor = NotificationPage;
/* jshint ignore:start */
/**
* Build an instance of NotificationInstance
*
* @function getInstance
* @memberof Twilio.Notify.V1.ServiceContext.NotificationPage
* @instance
*
* @param {object} payload - Payload response from the API
*
* @returns NotificationInstance
*/
/* jshint ignore:end */
NotificationPage.prototype.getInstance = function getInstance(payload) {
return new NotificationInstance(this._version, payload, this._solution.serviceSid);
};
/* jshint ignore:start */
/**
* @constructor Twilio.Notify.V1.ServiceContext.NotificationInstance
* @description Initialize the NotificationContext
* PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
*
* @property {string} sid - The sid
* @property {string} accountSid - The account_sid
* @property {string} serviceSid - The service_sid
* @property {Date} dateCreated - The date_created
* @property {string} identities - The identities
* @property {string} tags - The tags
* @property {string} segments - The segments
* @property {notification.priority} priority - The priority
* @property {number} ttl - The ttl
* @property {string} title - The title
* @property {string} body - The body
* @property {string} sound - The sound
* @property {string} action - The action
* @property {string} data - The data
* @property {string} apn - The apn
* @property {string} gcm - The gcm
* @property {string} fcm - The fcm
* @property {string} sms - The sms
* @property {string} facebookMessenger - The facebook_messenger
* @property {string} alexa - The alexa
*
* @param {Twilio.Notify.V1} version - Version of the resource
* @param {object} payload - The instance payload
*/
/* jshint ignore:end */
NotificationInstance = function NotificationInstance(version, payload,
serviceSid) {
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.dateCreated = deserialize.iso8601DateTime(payload.date_created); // jshint ignore:line
this.identities = payload.identities; // jshint ignore:line
this.tags = payload.tags; // jshint ignore:line
this.segments = payload.segments; // jshint ignore:line
this.priority = payload.priority; // jshint ignore:line
this.ttl = deserialize.integer(payload.ttl); // jshint ignore:line
this.title = payload.title; // jshint ignore:line
this.body = payload.body; // jshint ignore:line
this.sound = payload.sound; // jshint ignore:line
this.action = payload.action; // jshint ignore:line
this.data = payload.data; // jshint ignore:line
this.apn = payload.apn; // jshint ignore:line
this.gcm = payload.gcm; // jshint ignore:line
this.fcm = payload.fcm; // jshint ignore:line
this.sms = payload.sms; // jshint ignore:line
this.facebookMessenger = payload.facebook_messenger; // jshint ignore:line
this.alexa = payload.alexa; // jshint ignore:line
// Context
this._context = undefined;
this._solution = {serviceSid: serviceSid,};
};
module.exports = {
NotificationList: NotificationList,
NotificationPage: NotificationPage,
NotificationInstance: NotificationInstance
};