UNPKG

deepgram

Version:
118 lines (99 loc) 3.87 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); 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; }; }(); require('isomorphic-fetch'); var _frisbee = require('frisbee'); var _frisbee2 = _interopRequireDefault(_frisbee); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Deepgram = function () { function Deepgram(opts) { _classCallCheck(this, Deepgram); this.opts = opts || {}; this.api = new _frisbee2.default({ baseURI: 'http://api.deepgram.com', headers: { 'Content-Type': 'application/json' } }); } _createClass(Deepgram, [{ key: 'indexContent', value: function indexContent(dataUrl) { var _this = this; var payload = { action: 'index_content', data_url: dataUrl }; return new Promise(function (resolve, reject) { _this.api.post('/', _this._authenticatedPayload(payload)).then(function (data) { return resolve(data.body.contentID); }).catch(function (err) { return reject(err); }); }); } }, { key: 'getBalance', value: function getBalance() { var _this2 = this; var payload = { action: 'get_balance' }; return new Promise(function (resolve, reject) { _this2.api.post('/', _this2._authenticatedPayload(payload)).then(function (data) { return resolve(data.body.balance); }).catch(function (err) { return reject(err); }); }); } }, { key: 'getObjectStatus', value: function getObjectStatus(contentID) { var _this3 = this; var payload = { action: 'get_object_status', contentID: contentID }; return new Promise(function (resolve, reject) { _this3.api.post('/', _this3._authenticatedPayload(payload)).then(function (data) { return resolve(data.body.status); }).catch(function (err) { return reject(err); }); }); } }, { key: 'getObjectTranscript', value: function getObjectTranscript(contentID) { var _this4 = this; var payload = { action: 'get_object_transcript', contentID: contentID }; return new Promise(function (resolve, reject) { _this4.api.post('/', _this4._authenticatedPayload(payload)).then(function (data) { return resolve(data.body); }).catch(function (err) { return reject(err); }); }); } }, { key: 'objectSearch', value: function objectSearch(query) { var _this5 = this; var payload = query || {}; payload.action = 'object_search'; return new Promise(function (resolve, reject) { _this5.api.post('/', _this5._authenticatedPayload(payload)).then(function (data) { return resolve(data.body); }).catch(function (err) { return reject(err); }); }); } }, { key: '_authenticatedPayload', value: function _authenticatedPayload(object) { var wrapper = {}; object.userID = this.opts.userId; wrapper.body = JSON.stringify(object); return wrapper; } }]); return Deepgram; }(); exports.default = Deepgram;