UNPKG

@aiozstream/nodejs-client

Version:
455 lines (454 loc) 19.3 kB
"use strict"; /** * @aiozstream/nodejs-client * Aioz Stream Service * * The version of the OpenAPI document: 1.0 * * * NOTE: This class is auto generated. * Do not edit the class manually. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = __importDefault(require("path")); const fs_1 = require("fs"); const url_1 = require("url"); const form_data_1 = __importDefault(require("form-data")); const ObjectSerializer_1 = __importStar(require("../ObjectSerializer")); const stream_1 = require("stream"); const HttpClient_1 = require("../HttpClient"); /** * no description */ class PlaylistApi { constructor(httpClient) { this.httpClient = httpClient; } /** * Add a specific video to a playlist for the authenticated user * Add a video to a playlist * @param id Playlist ID * @param payload Video details */ async addVideoToPlaylist(id, payload = {}) { return this.addVideoToPlaylistWithResponseHeaders(id, payload).then((res) => res.body); } /** * Add a specific video to a playlist for the authenticated user * Add a video to a playlist * @param id Playlist ID * @param payload Video details */ async addVideoToPlaylistWithResponseHeaders(id, payload = {}) { const queryParams = {}; queryParams.headers = {}; if (id === null || id === undefined) { throw new Error('Required parameter id was null or undefined when calling addVideoToPlaylist.'); } if (payload === null || payload === undefined) { throw new Error('Required parameter payload was null or undefined when calling addVideoToPlaylist.'); } // Path Params const localVarPath = '/playlists/{id}/items' .substring(1) .replace('{' + 'id' + '}', encodeURIComponent(String(id))); // Body Params const contentType = ObjectSerializer_1.default.getPreferredMediaType([ 'application/json', ]); queryParams.headers['Content-Type'] = contentType; queryParams.body = ObjectSerializer_1.default.stringify(ObjectSerializer_1.default.serialize(payload, 'AddVideoToPlaylistRequest', ''), contentType); queryParams.method = 'POST'; return this.httpClient.call(localVarPath, queryParams).then((response) => { return { headers: response.headers, body: ObjectSerializer_1.default.deserialize(ObjectSerializer_1.default.parse(response.body, response.headers['content-type']), 'ResponseSuccess', ''), }; }); } /** * Create a playlist for the authenticated user * Create a playlist * @param request Playlist input */ async createPlaylist(request = {}) { return this.createPlaylistWithResponseHeaders(request).then((res) => res.body); } /** * Create a playlist for the authenticated user * Create a playlist * @param request Playlist input */ async createPlaylistWithResponseHeaders(request = {}) { const queryParams = {}; queryParams.headers = {}; if (request === null || request === undefined) { throw new Error('Required parameter request was null or undefined when calling createPlaylist.'); } // Path Params const localVarPath = '/playlists/create'.substring(1); // Body Params const contentType = ObjectSerializer_1.default.getPreferredMediaType([ 'application/json', ]); queryParams.headers['Content-Type'] = contentType; queryParams.body = ObjectSerializer_1.default.stringify(ObjectSerializer_1.default.serialize(request, 'CreatePlaylistRequest', ''), contentType); queryParams.method = 'POST'; return this.httpClient.call(localVarPath, queryParams).then((response) => { return { headers: response.headers, body: ObjectSerializer_1.default.deserialize(ObjectSerializer_1.default.parse(response.body, response.headers['content-type']), 'CreatePlaylistResponse', ''), }; }); } /** * Delete a specific playlist by its ID for the authenticated user * Delete a playlist by ID * @param id Playlist ID */ async deletePlaylistById(id) { return this.deletePlaylistByIdWithResponseHeaders(id).then((res) => res.body); } /** * Delete a specific playlist by its ID for the authenticated user * Delete a playlist by ID * @param id Playlist ID */ async deletePlaylistByIdWithResponseHeaders(id) { const queryParams = {}; queryParams.headers = {}; if (id === null || id === undefined) { throw new Error('Required parameter id was null or undefined when calling deletePlaylistById.'); } // Path Params const localVarPath = '/playlists/{id}' .substring(1) .replace('{' + 'id' + '}', encodeURIComponent(String(id))); queryParams.method = 'DELETE'; return this.httpClient.call(localVarPath, queryParams).then((response) => { return { headers: response.headers, body: ObjectSerializer_1.default.deserialize(ObjectSerializer_1.default.parse(response.body, response.headers['content-type']), 'ResponseSuccess', ''), }; }); } /** * Delete the thumbnail of a specific playlist for the authenticated user * Delete a playlist thumbnail * @param id Playlist ID */ async deletePlaylistThumbnail(id) { return this.deletePlaylistThumbnailWithResponseHeaders(id).then((res) => res.body); } /** * Delete the thumbnail of a specific playlist for the authenticated user * Delete a playlist thumbnail * @param id Playlist ID */ async deletePlaylistThumbnailWithResponseHeaders(id) { const queryParams = {}; queryParams.headers = {}; if (id === null || id === undefined) { throw new Error('Required parameter id was null or undefined when calling deletePlaylistThumbnail.'); } // Path Params const localVarPath = '/playlists/{id}/thumbnail' .substring(1) .replace('{' + 'id' + '}', encodeURIComponent(String(id))); queryParams.method = 'DELETE'; return this.httpClient.call(localVarPath, queryParams).then((response) => { return { headers: response.headers, body: ObjectSerializer_1.default.deserialize(ObjectSerializer_1.default.parse(response.body, response.headers['content-type']), 'ResponseSuccess', ''), }; }); } /** * Retrieve a specific playlist by its ID for the current user. * Get playlist by ID * @param {Object} searchParams * @param { string } searchParams.id Playlist ID * @param { &#39;created_at&#39; | &#39;title&#39; | &#39;duration&#39; } searchParams.sortBy sort by * @param { &#39;asc&#39; | &#39;desc&#39; } searchParams.orderBy allowed: asc, desc. Default: asc */ async getPlaylistById(args) { return this.getPlaylistByIdWithResponseHeaders(args).then((res) => res.body); } /** * Retrieve a specific playlist by its ID for the current user. * Get playlist by ID * @param {Object} searchParams * @param { string } searchParams.id Playlist ID * @param { &#39;created_at&#39; | &#39;title&#39; | &#39;duration&#39; } searchParams.sortBy sort by * @param { &#39;asc&#39; | &#39;desc&#39; } searchParams.orderBy allowed: asc, desc. Default: asc */ async getPlaylistByIdWithResponseHeaders({ id, sortBy, orderBy, }) { const queryParams = {}; queryParams.headers = {}; if (id === null || id === undefined) { throw new Error('Required parameter id was null or undefined when calling getPlaylistById.'); } // Path Params const localVarPath = '/playlists/{id}' .substring(1) .replace('{' + 'id' + '}', encodeURIComponent(String(id))); // Query Params const urlSearchParams = new url_1.URLSearchParams(); if (sortBy !== undefined) { urlSearchParams.append('sort_by', ObjectSerializer_1.default.serialize(sortBy, "'created_at' | 'title' | 'duration'", '')); } if (orderBy !== undefined) { urlSearchParams.append('order_by', ObjectSerializer_1.default.serialize(orderBy, "'asc' | 'desc'", '')); } queryParams.searchParams = urlSearchParams; queryParams.method = 'GET'; return this.httpClient.call(localVarPath, queryParams).then((response) => { return { headers: response.headers, body: ObjectSerializer_1.default.deserialize(ObjectSerializer_1.default.parse(response.body, response.headers['content-type']), 'GetPlaylistByIdResponse', ''), }; }); } /** * Get a specific playlist public by its ID * Get a playlist public * @param id Playlist ID */ async getPlaylistPublicInfo(id) { return this.getPlaylistPublicInfoWithResponseHeaders(id).then((res) => res.body); } /** * Get a specific playlist public by its ID * Get a playlist public * @param id Playlist ID */ async getPlaylistPublicInfoWithResponseHeaders(id) { const queryParams = {}; queryParams.headers = {}; if (id === null || id === undefined) { throw new Error('Required parameter id was null or undefined when calling getPlaylistPublicInfo.'); } // Path Params const localVarPath = '/playlists/{id}/player.json' .substring(1) .replace('{' + 'id' + '}', encodeURIComponent(String(id))); queryParams.method = 'GET'; return this.httpClient.call(localVarPath, queryParams).then((response) => { return { headers: response.headers, body: ObjectSerializer_1.default.deserialize(ObjectSerializer_1.default.parse(response.body, response.headers['content-type']), 'PublicPlaylistObject', ''), }; }); } /** * Retrieve a list of playlists for the authenticated user * Get user's playlists * @param request Playlist filter */ async getPlaylists(request = {}) { return this.getPlaylistsWithResponseHeaders(request).then((res) => res.body); } /** * Retrieve a list of playlists for the authenticated user * Get user's playlists * @param request Playlist filter */ async getPlaylistsWithResponseHeaders(request = {}) { const queryParams = {}; queryParams.headers = {}; if (request === null || request === undefined) { throw new Error('Required parameter request was null or undefined when calling getPlaylists.'); } // Path Params const localVarPath = '/playlists'.substring(1); // Body Params const contentType = ObjectSerializer_1.default.getPreferredMediaType([ 'application/json', ]); queryParams.headers['Content-Type'] = contentType; queryParams.body = ObjectSerializer_1.default.stringify(ObjectSerializer_1.default.serialize(request, 'GetPlaylistListRequest', ''), contentType); queryParams.method = 'POST'; return this.httpClient.call(localVarPath, queryParams).then((response) => { return { headers: response.headers, body: ObjectSerializer_1.default.deserialize(ObjectSerializer_1.default.parse(response.body, response.headers['content-type']), 'GetPlaylistListResponse', ''), }; }); } /** * Move a specific video in a playlist for the authenticated user * Move a video in a playlist * @param id Playlist ID * @param payload Video details */ async moveVideoInPlaylist(id, payload = {}) { return this.moveVideoInPlaylistWithResponseHeaders(id, payload).then((res) => res.body); } /** * Move a specific video in a playlist for the authenticated user * Move a video in a playlist * @param id Playlist ID * @param payload Video details */ async moveVideoInPlaylistWithResponseHeaders(id, payload = {}) { const queryParams = {}; queryParams.headers = {}; if (id === null || id === undefined) { throw new Error('Required parameter id was null or undefined when calling moveVideoInPlaylist.'); } if (payload === null || payload === undefined) { throw new Error('Required parameter payload was null or undefined when calling moveVideoInPlaylist.'); } // Path Params const localVarPath = '/playlists/{id}/items' .substring(1) .replace('{' + 'id' + '}', encodeURIComponent(String(id))); // Body Params const contentType = ObjectSerializer_1.default.getPreferredMediaType([ 'application/json', ]); queryParams.headers['Content-Type'] = contentType; queryParams.body = ObjectSerializer_1.default.stringify(ObjectSerializer_1.default.serialize(payload, 'MoveVideoInPlaylistRequest', ''), contentType); queryParams.method = 'PUT'; return this.httpClient.call(localVarPath, queryParams).then((response) => { return { headers: response.headers, body: ObjectSerializer_1.default.deserialize(ObjectSerializer_1.default.parse(response.body, response.headers['content-type']), 'ResponseSuccess', ''), }; }); } /** * Remove a specific video from a playlist for the authenticated user * Remove a video from a playlist * @param id Playlist ID * @param itemId Playlist Item ID */ async removeVideoFromPlaylist(id, itemId) { return this.removeVideoFromPlaylistWithResponseHeaders(id, itemId).then((res) => res.body); } /** * Remove a specific video from a playlist for the authenticated user * Remove a video from a playlist * @param id Playlist ID * @param itemId Playlist Item ID */ async removeVideoFromPlaylistWithResponseHeaders(id, itemId) { const queryParams = {}; queryParams.headers = {}; if (id === null || id === undefined) { throw new Error('Required parameter id was null or undefined when calling removeVideoFromPlaylist.'); } if (itemId === null || itemId === undefined) { throw new Error('Required parameter itemId was null or undefined when calling removeVideoFromPlaylist.'); } // Path Params const localVarPath = '/playlists/{id}/items/{item_id}' .substring(1) .replace('{' + 'id' + '}', encodeURIComponent(String(id))) .replace('{' + 'item_id' + '}', encodeURIComponent(String(itemId))); queryParams.method = 'DELETE'; return this.httpClient.call(localVarPath, queryParams).then((response) => { return { headers: response.headers, body: ObjectSerializer_1.default.deserialize(ObjectSerializer_1.default.parse(response.body, response.headers['content-type']), 'ResponseSuccess', ''), }; }); } /** * Update a specific playlist for the authenticated user * Update a playlist * @param id Playlist ID * @param file * @param metadata * @param name * @param tags */ async updatePlaylist(id, file, metadata, name, tags) { return this.updatePlaylistWithResponseHeaders(id, file, metadata, name, tags).then((res) => res.body); } /** * Update a specific playlist for the authenticated user * Update a playlist * @param id Playlist ID * @param file * @param metadata * @param name * @param tags */ async updatePlaylistWithResponseHeaders(id, file, metadata, name, tags) { const queryParams = {}; queryParams.headers = {}; if (id === null || id === undefined) { throw new Error('Required parameter id was null or undefined when calling updatePlaylist.'); } let fileName = 'file'; let fileBuffer = file; if (typeof file === 'string') { fileName = path_1.default.basename(file); fileBuffer = (0, fs_1.createReadStream)(file); } if (file instanceof stream_1.Readable) { fileBuffer = await (0, HttpClient_1.readableToBuffer)(file); } // Path Params const localVarPath = '/playlists/{id}' .substring(1) .replace('{' + 'id' + '}', encodeURIComponent(String(id))); queryParams.method = 'PATCH'; const formData = new form_data_1.default(); formData.append(fileName, fileBuffer, fileName); if (metadata) { formData.append('metadata', metadata.join(ObjectSerializer_1.COLLECTION_FORMATS['csv'])); } if (typeof name !== undefined) { formData.append('name', name); } if (tags) { formData.append('tags', tags.join(ObjectSerializer_1.COLLECTION_FORMATS['csv'])); } queryParams.body = formData; return this.httpClient.call(localVarPath, queryParams).then((response) => { return { headers: response.headers, body: ObjectSerializer_1.default.deserialize(ObjectSerializer_1.default.parse(response.body, response.headers['content-type']), 'ResponseSuccess', ''), }; }); } } exports.default = PlaylistApi;