UNPKG

box-node-sdk

Version:

Official SDK for Box Plaform APIs

93 lines 4 kB
"use strict"; /** * @fileoverview Manager for the Device Pins resource * @author mwiller */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var url_path_1 = __importDefault(require("../util/url-path")); // ----------------------------------------------------------------------------- // Typedefs // ----------------------------------------------------------------------------- // ------------------------------------------------------------------------------ // Private // ------------------------------------------------------------------------------ var BASE_PATH = '/device_pinners', ENTERPRISES_PATH = '/enterprises', DEVICE_PINNERS_SUBRESOURCE = 'device_pinners'; // ------------------------------------------------------------------------------ // Public // ------------------------------------------------------------------------------ /** * Simple manager for interacting with all Device Pin endpoints and actions. * * @constructor * @param {BoxClient} client - The Box API Client that is responsible for making calls to the API * @returns {void} */ var DevicePins = /** @class */ (function () { function DevicePins(client) { this.client = client; } /** * Get a specific device pinning record * * API Endpoint: '/device_pinners/:pinID' * Method: GET * * @param {string} pinID - The ID of the pin to retrieve * @param {Object} [options] - Optional paramters, can be left null in many cases * @param {Function} [callback] - Passed the device pin if successful, error otherwise * @returns {Promise<Object>} A promise resolving to the device pin object */ DevicePins.prototype.get = function (pinID, options, callback) { var apiPath = (0, url_path_1.default)(BASE_PATH, pinID), params = { qs: options, }; return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback); }; /** * Delete a specific device pinning record * * API Endpoint: '/device_pinners/:pinID' * Method: DELETE * * @param {string} pinID - The ID of the pin to delete * @param {Object} [options] - Optional paramters, can be left null in many cases * @param {Function} [callback] - Passed nothing if successful, error otherwise * @returns {Promise<void>} A promise resolving to nothing */ DevicePins.prototype.delete = function (pinID, options, callback) { var apiPath = (0, url_path_1.default)(BASE_PATH, pinID), params = { qs: options, }; return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, params, callback); }; /** * Get all device pin records for the current enterprise * * API Endpoint: '/enterprises/:enterpriseID/device_pinners' * Method: GET * * @param {Object} [options] - Optional paramters, can be left null in many cases * @param {Function} [callback] - Passed a list of device pins if successful, error otherwise * @returns {Promise<Object>} A promise resolving to the collection of device pins */ DevicePins.prototype.getAll = function (options, callback) { var _this = this; return this.client.users .get(this.client.CURRENT_USER_ID, { fields: 'enterprise' }) .then(function (data /* FIXME */) { if (!data.enterprise || !data.enterprise.id) { throw new Error('User must be in an enterprise to view device pins'); } var apiPath = (0, url_path_1.default)(ENTERPRISES_PATH, data.enterprise.id, DEVICE_PINNERS_SUBRESOURCE), params = { qs: options, }; return _this.client.wrapWithDefaultHandler(_this.client.get)(apiPath, params); }) .asCallback(callback); }; return DevicePins; }()); module.exports = DevicePins; //# sourceMappingURL=device-pins.js.map