avi-l-lotr-sdk
Version:
An SDK for interacting with the Lord of the Rings API.
77 lines (76 loc) • 3.04 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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = __importDefault(require("axios"));
const BASE_URL = "https://the-one-api.dev/v2";
class AviLoTRSDK {
constructor(apiKey) {
this.axiosApi = axios_1.default.create({
baseURL: BASE_URL,
headers: {
Accept: "application/json",
Authorization: `Bearer ${apiKey}`,
},
});
}
getMovies(limit, offset, page) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosApi.get("/movie", {
params: { limit, offset, page },
});
return response.data.docs;
});
}
getMovieQuotes(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosApi.get(`/movie/${id}/quote`);
return response.data.docs;
});
}
getQuotes(limit, offset, page) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosApi.get("/quote", {
params: { limit, offset, page },
});
return response.data.docs;
});
}
getCharacters(limit, offset, page) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosApi.get("/character", {
params: { limit, offset, page },
});
return response.data.docs;
});
}
getMovieById(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosApi.get(`/movie/${id}`);
return response.data.docs[0];
});
}
getQuoteById(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosApi.get(`/quote/${id}`);
return response.data.docs[0];
});
}
getCharacterById(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosApi.get(`/character/${id}`);
return response.data.docs[0];
});
}
}
exports.default = AviLoTRSDK;