better-trakt
Version:
A Trakt.tv client with native Typescript support and quality of life features
56 lines • 2.31 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUserWatchedMedia = exports.Users = void 0;
const utils_1 = require("../utils");
/**
* Users api namespace
*/
class Users {
constructor(config) {
this.config = {
apiUrl: `${config.apiUrl}/users`,
client: config.client,
};
}
/**
* Returns all movies a user has watched sorted by most plays.
* @param client axios
* @param userId trakt user id
* @param accessToken oauth access token for private accounts
* @returns
*/
watchedMovies({ userId, accessToken, }) {
(0, utils_1.checkRequiredArg)(userId, 'userId', 'string');
return getUserWatchedMedia(this.config, userId, 'movies', accessToken);
}
/**
* Returns all shows a user has watched sorted by most plays.
* @param client axios
* @param userId trakt user id
* @param accessToken oauth access token for private accounts
* @returns
*/
watchedShows({ userId, accessToken }) {
(0, utils_1.checkRequiredArg)(userId, 'userId', 'string');
return getUserWatchedMedia(this.config, userId, 'shows', accessToken);
}
}
exports.Users = Users;
function getUserWatchedMedia({ client, apiUrl }, userId, type, accessToken) {
return __awaiter(this, void 0, void 0, function* () {
const url = `${apiUrl}/${userId}/watched/${type}`;
const response = yield (0, utils_1.fetch)(client, url, { accessToken });
return response;
});
}
exports.getUserWatchedMedia = getUserWatchedMedia;
//# sourceMappingURL=index.js.map