UNPKG

node-ciscospark

Version:

Super-Simple Lightweight Javascript wrapper for Cisco Spark API

141 lines (111 loc) 4.11 kB
'use strict'; /** @ignore */ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var CiscoSpark = require('./CiscoSpark'); /** * Cisco Spark Factory class * @extends {CiscoSpark} * @example * const CiscoSpark = require('node-ciscospark') * const spark = new CiscoSpark('Access Token'); * spark.messages({ roomId: 'your-room-id', text: 'Message'}) */ var CiscoSparkFactory = function (_CiscoSpark) { _inherits(CiscoSparkFactory, _CiscoSpark); /** * @constructor * @param {string} [accessToken] - Your Cisco Spark accesstoken * @param {string} [userAgent] - User Agent request header */ function CiscoSparkFactory(accessToken, userAgent) { _classCallCheck(this, CiscoSparkFactory); /** * @type {string} * @protected */ var _this = _possibleConstructorReturn(this, (CiscoSparkFactory.__proto__ || Object.getPrototypeOf(CiscoSparkFactory)).call(this, accessToken)); _this.userAgent = userAgent || 'node-ciscospark (https://github.com/joelee/ciscospark)'; /** @private */ _this._instances = {}; return _this; } /** * Spark Messages * @return {Messages} - Message Object */ _createClass(CiscoSparkFactory, [{ key: '_getInstance', /** @private */ value: function _getInstance(name) { if (!this._instances[name]) { var InstanceClass = require('./' + name); this._instances[name] = new InstanceClass(this); } return this._instances[name]; } }, { key: 'messages', get: function get() { return this._getInstance('Messages'); } /** * Spark People * @return {People} */ }, { key: 'people', get: function get() { return this._getInstance('People'); } /** * Spark Teams * @return {Teams} */ }, { key: 'teams', get: function get() { return this._getInstance('Teams'); } /** * Spark Rooms * @return {Rooms} */ }, { key: 'rooms', get: function get() { return this._getInstance('Rooms'); } /** * Spark Memberships * @return {Memberships} */ }, { key: 'memberships', get: function get() { return this._getInstance('Memberships'); } /** * Spark Team Memberships * @return {TeamMemberships} */ }, { key: 'teamMemberships', get: function get() { return this._getInstance('TeamMemberships'); } /** * Spark Webhooks * @return {Webhooks} */ }, { key: 'webhooks', get: function get() { return this._getInstance('Webhooks'); } }]); return CiscoSparkFactory; }(CiscoSpark); module.exports = CiscoSparkFactory;