UNPKG

twilio

Version:
253 lines (223 loc) 7.64 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 values = require('../../../../base/values'); /* jshint ignore:line */ var UsageList; var UsagePage; var UsageInstance; var UsageContext; /* jshint ignore:start */ /** * @constructor Twilio.Preview.Wireless.SimContext.UsageList * @description Initialize the UsageList * 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.Wireless} version - Version of the resource * @param {string} simSid - The sim_sid */ /* jshint ignore:end */ UsageList = function UsageList(version, simSid) { /* jshint ignore:start */ /** * @function usage * @memberof Twilio.Preview.Wireless.SimContext * @instance * * @param {string} sid - sid of instance * * @returns {Twilio.Preview.Wireless.SimContext.UsageContext} */ /* jshint ignore:end */ function UsageListInstance(sid) { return UsageListInstance.get(sid); } UsageListInstance._version = version; // Path Solution UsageListInstance._solution = {simSid: simSid}; /* jshint ignore:start */ /** * Constructs a usage * * @function get * @memberof Twilio.Preview.Wireless.SimContext.UsageList * @instance * * @returns {Twilio.Preview.Wireless.SimContext.UsageContext} */ /* jshint ignore:end */ UsageListInstance.get = function get() { return new UsageContext(this._version, this._solution.simSid); }; return UsageListInstance; }; /* jshint ignore:start */ /** * @constructor Twilio.Preview.Wireless.SimContext.UsagePage * @augments Page * @description Initialize the UsagePage * 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.Wireless} version - Version of the resource * @param {object} response - Response from the API * @param {object} solution - Path solution * * @returns UsagePage */ /* jshint ignore:end */ UsagePage = function UsagePage(version, response, solution) { // Path Solution this._solution = solution; Page.prototype.constructor.call(this, version, response, this._solution); }; _.extend(UsagePage.prototype, Page.prototype); UsagePage.prototype.constructor = UsagePage; /* jshint ignore:start */ /** * Build an instance of UsageInstance * * @function getInstance * @memberof Twilio.Preview.Wireless.SimContext.UsagePage * @instance * * @param {object} payload - Payload response from the API * * @returns UsageInstance */ /* jshint ignore:end */ UsagePage.prototype.getInstance = function getInstance(payload) { return new UsageInstance(this._version, payload, this._solution.simSid); }; /* jshint ignore:start */ /** * @constructor Twilio.Preview.Wireless.SimContext.UsageInstance * @description Initialize the UsageContext * 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} simSid - The sim_sid * @property {string} simUniqueName - The sim_unique_name * @property {string} accountSid - The account_sid * @property {string} period - The period * @property {string} commandsUsage - The commands_usage * @property {string} commandsCosts - The commands_costs * @property {string} dataUsage - The data_usage * @property {string} dataCosts - The data_costs * @property {string} url - The url * * @param {Twilio.Preview.Wireless} version - Version of the resource * @param {object} payload - The instance payload * @param {sid_like} simSid - The sim_sid */ /* jshint ignore:end */ UsageInstance = function UsageInstance(version, payload, simSid) { this._version = version; // Marshaled Properties this.simSid = payload.sim_sid; // jshint ignore:line this.simUniqueName = payload.sim_unique_name; // jshint ignore:line this.accountSid = payload.account_sid; // jshint ignore:line this.period = payload.period; // jshint ignore:line this.commandsUsage = payload.commands_usage; // jshint ignore:line this.commandsCosts = payload.commands_costs; // jshint ignore:line this.dataUsage = payload.data_usage; // jshint ignore:line this.dataCosts = payload.data_costs; // jshint ignore:line this.url = payload.url; // jshint ignore:line // Context this._context = undefined; this._solution = {simSid: simSid,}; }; Object.defineProperty(UsageInstance.prototype, '_proxy', { get: function() { if (!this._context) { this._context = new UsageContext(this._version, this._solution.simSid); } return this._context; } }); /* jshint ignore:start */ /** * fetch a UsageInstance * * @function fetch * @memberof Twilio.Preview.Wireless.SimContext.UsageInstance * @instance * * @param {object|function} opts - ... * @param {string} [opts.end] - The end * @param {string} [opts.start] - The start * @param {function} [callback] - Callback to handle processed record * * @returns {Promise} Resolves to processed UsageInstance */ /* jshint ignore:end */ UsageInstance.prototype.fetch = function fetch(opts, callback) { return this._proxy.fetch(opts, callback); }; /* jshint ignore:start */ /** * @constructor Twilio.Preview.Wireless.SimContext.UsageContext * @description Initialize the UsageContext * 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.Wireless} version - Version of the resource * @param {sid_like} simSid - The sim_sid */ /* jshint ignore:end */ UsageContext = function UsageContext(version, simSid) { this._version = version; // Path Solution this._solution = {simSid: simSid,}; this._uri = _.template( '/Sims/<%= simSid %>/Usage' // jshint ignore:line )(this._solution); }; /* jshint ignore:start */ /** * fetch a UsageInstance * * @function fetch * @memberof Twilio.Preview.Wireless.SimContext.UsageContext * @instance * * @param {object|function} opts - ... * @param {string} [opts.end] - The end * @param {string} [opts.start] - The start * @param {function} [callback] - Callback to handle processed record * * @returns {Promise} Resolves to processed UsageInstance */ /* jshint ignore:end */ UsageContext.prototype.fetch = function fetch(opts, callback) { if (_.isFunction(opts)) { callback = opts; opts = {}; } opts = opts || {}; var deferred = Q.defer(); var data = values.of({'End': _.get(opts, 'end'), 'Start': _.get(opts, 'start')}); var promise = this._version.fetch({uri: this._uri, method: 'GET', params: data}); promise = promise.then(function(payload) { deferred.resolve(new UsageInstance(this._version, payload, this._solution.simSid)); }.bind(this)); promise.catch(function(error) { deferred.reject(error); }); if (_.isFunction(callback)) { deferred.promise.nodeify(callback); } return deferred.promise; }; module.exports = { UsageList: UsageList, UsagePage: UsagePage, UsageInstance: UsageInstance, UsageContext: UsageContext };