@erkjbro/the-one-sdk
Version:
50 lines (49 loc) • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "TheOneSdk", {
enumerable: true,
get: ()=>TheOneSdk
});
const _constants = require("./constants");
let TheOneSdk = class TheOneSdk {
async fetchMovieData(url) {
/**
* Fetches movie data from the API.
*
* @param url The URL to fetch data from.
* @returns Either movie or movie quote data.
*/ if (!this.access_token) throw new Error('No access token provided.');
const init = {
headers: {
Authorization: `Bearer ${this.access_token}`
}
};
const response = await fetch(url, init);
if (!response.ok) return Promise.reject(response);
return await response.json();
}
async getMovieData(params) {
/**
* Gets movie data from the API.
*
* @typedef {Object} MovieParams
* @property {string} movieId [] The ID of the movie to get data for.
* @property {boolean} quote [] Whether to get movie quotes or not.
*
* @param {...MovieParams} [] The parameters to use when fetching data.
*
* @returns Either movie or movie quote data.
*/ try {
const { movieId , quote , limit , page } = params != null ? params : {};
const endpoint_url = `${this.base_url}/movie` + `${movieId ? `/${movieId}` : ''}` + `${movieId && quote ? '/quote' : ''}` + `?limit=${limit != null ? limit : 100}` + `${page ? `&page=${page}` : ''}`;
return await this.fetchMovieData(endpoint_url);
} catch (error) {
console.error(error);
throw error;
}
}
constructor(access_token){
this.access_token = access_token;
this.base_url = _constants.API_BASE_URL;
}
};
//# sourceMappingURL=lotr-sdk.js.map