UNPKG

splatoon3api

Version:

A simple Method to get current and next Splatoon 3 maps, Salmonrun Schedules and Splatnet gear

233 lines (232 loc) 9.46 kB
"use strict"; 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 (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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 }); exports.Types = exports.Client = void 0; const Types = __importStar(require("./types")); exports.Types = Types; const node_fetch_1 = __importDefault(require("node-fetch")); const utils_1 = require("./utils"); const gearTypeLang_1 = __importDefault(require("./gearTypeLang")); const allStagesParser_1 = __importDefault(require("./parser/stages/allStagesParser")); const currentStagesParser_1 = __importDefault(require("./parser/stages/currentStagesParser")); const nextStagesParser_1 = __importDefault(require("./parser/stages/nextStagesParser")); const challengesParser_1 = __importDefault(require("./parser/challengesParser")); const salmonRunParser_1 = __importDefault(require("./parser/salmonRunParser")); const splatNetGearParser_1 = __importDefault(require("./parser/splatNetGearParser")); const pastSplatfestsParser_1 = __importDefault(require("./parser/splatfests/pastSplatfestsParser")); const upcomingSplatfestsParser_1 = __importDefault(require("./parser/splatfests/upcomingSplatfestsParser")); const runningSplatfestsParser_1 = __importDefault(require("./parser/splatfests/runningSplatfestsParser")); class Client { /** * @param {Types.Lang} [lang="en-US"] - The language for map names, challenge descriptions etc. * @param {Types.Options} [options] - The options for the client */ constructor(lang = "en-US", options = new Types.Options()) { this.lang = (0, utils_1.formatLang)(lang); this.options = options; this.langPromise = new Promise((resolve, reject) => { (0, node_fetch_1.default)(`https://splatoon3.ink/data/locale/${this.lang}.json`) .then((res) => { if (!res || !res.ok) throw new Error("Network response was not ok while loading lang file!"); return res.json(); }) .then((json) => { this.translation = Object.assign(Object.assign({}, json), { gearType: gearTypeLang_1.default[this.lang] }); resolve(this.translation); }) .catch((err) => { console.error(err); reject(err); }); }); } /** * Get 11 upcoming and the current Turf War, Ranked and XBattle maps * @returns {Promise<Types.AllStagesResponse>} - The promise */ getStages() { return __awaiter(this, void 0, void 0, function* () { yield this.langPromise; try { const json = yield (0, utils_1.fetchData)(this.options.schedulesURL, this.options); return (0, allStagesParser_1.default)(json, this.translation); } catch (err) { console.error(err); throw err; } }); } /** * Get the current Turf War, Ranked and XBattle maps * @returns {Promise<Types.StagesResponse>} - The promise */ getCurrentStages() { return __awaiter(this, void 0, void 0, function* () { yield this.langPromise; try { const json = yield (0, utils_1.fetchData)(this.options.schedulesURL, this.options); return (0, currentStagesParser_1.default)(json, this.translation); } catch (err) { console.error(err); throw err; } }); } /** * Get the upcoming Turf War, Ranked and XBattle maps * @returns {Promise<Types.StagesResponse>} - The promise */ getNextStages() { return __awaiter(this, void 0, void 0, function* () { yield this.langPromise; try { const json = yield (0, utils_1.fetchData)(this.options.schedulesURL, this.options); return (0, nextStagesParser_1.default)(json, this.translation); } catch (err) { console.error(err); throw err; } }); } /** * Get the current challenges * @returns {Promise<Types.SplatChallenge[]>} - The promise */ getChallenges() { return __awaiter(this, void 0, void 0, function* () { yield this.langPromise; try { const json = yield (0, utils_1.fetchData)(this.options.schedulesURL, this.options); return (0, challengesParser_1.default)(json, this.translation); } catch (err) { console.error(err); throw err; } }); } /** * To get the current and next Salmonruns Schedules * @returns {Promise<import('./types').SalmonResult>} - The promise */ getSalmonRun() { return __awaiter(this, void 0, void 0, function* () { yield this.langPromise; try { const json = yield (0, utils_1.fetchData)(this.options.schedulesURL, this.options); return (0, salmonRunParser_1.default)(json, this.translation, this.options.salmonGearURL); } catch (err) { console.error(err); throw err; } }); } /** * Get the current gear that is available in the splatnet shop * @returns {Promise<import('./types').SplatnetResult>} - The promise */ getSplatnetGear() { return __awaiter(this, void 0, void 0, function* () { yield this.langPromise; try { const json = yield (0, utils_1.fetchData)(this.options.gearURL, this.options); return (0, splatNetGearParser_1.default)(json, this.translation); } catch (err) { console.error(err); throw err; } }); } /** * Get already scheduled Splatfests * @returns {Promise<import('./types').FestData>} - The promise */ getUpcomingSplatfests() { return __awaiter(this, void 0, void 0, function* () { yield this.langPromise; try { const json = yield (0, utils_1.fetchData)(this.options.festURL, this.options); return (0, upcomingSplatfestsParser_1.default)(json, this.translation); } catch (err) { console.error(err); throw err; } }); } /** * Get past Splatfests * @returns {Promise<import('./types').PastFestData>} - The promise */ getPastSplatfests() { return __awaiter(this, void 0, void 0, function* () { yield this.langPromise; try { const json = yield (0, utils_1.fetchData)(this.options.festURL, this.options); return (0, pastSplatfestsParser_1.default)(json, this.translation); } catch (err) { console.error(err); throw err; } }); } /** * Get the currently running Splatfests * @returns {Promise<import('./types').FestData>} - The promise */ getRunningSplatfests() { return __awaiter(this, void 0, void 0, function* () { yield this.langPromise; try { const json = yield (0, utils_1.fetchData)(this.options.festURL, this.options); return (0, runningSplatfestsParser_1.default)(json, this.translation); } catch (err) { console.error(err); throw err; } }); } } exports.Client = Client;