diff --git a/.gitignore b/.gitignore index b512c09..4300af4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -node_modules \ No newline at end of file +node_modules/ +tests/ +Cache/ +gamedata/ +gamedataPrettyPrint/ \ No newline at end of file diff --git a/DOCS.md b/DOCS.md index 0b951a3..a569234 100644 Binary files a/DOCS.md and b/DOCS.md differ diff --git a/README.md b/README.md index 817f9b9..767ffad 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ # Mozambique Here API Wrapper -A simple wrapper to use the [Mozambique Here API](https://github.com/HugoDerave/ApexLegendsAPI/blob/master/README.md). Please refer to the API docs to undestand the inputs and expected results. +A simple wrapper to use the [Mozambique Here API](https://github.com/HugoDerave/ApexLegendsAPI/blob/master/README.md). Please refer to the [API docs](https://apexlegendsapi.com/) to undestand the inputs and expected results. Please refer to [DOCS.md](https://github.com/arubinofaux/mozambique-api-wrapper/blob/master/DOCS.md) to see a simple documentation for the NPM package -### Installation +## How to get an auth key +Request it at the start of the [documentation](https://apexlegendsapi.com/) + +## Installation Install the package @@ -12,7 +15,7 @@ $ cd /path/to/app $ npm install --save mozambique-api-wrapper ``` -### Usage +## Usage ```js // Require Wrapper Library diff --git a/index.js b/index.js index 60f9eb3..30a2421 100644 --- a/index.js +++ b/index.js @@ -4,147 +4,115 @@ const BASE_URL = "https://api.mozambiquehe.re"; const DIRECTORY = { SEARCH_URL: BASE_URL + "/bridge?version=4", - NEWS_URL: BASE_URL + "/news?version=4", - SERVER_STATUS: "https://apexlegendsstatus.com/servers.json", + NEWS_URL: BASE_URL + "/news?", + SERVER_STATUS: BASE_URL + "/servers?", MATCH_HISTORY: BASE_URL + "/bridge?", - GAME_DATA: BASE_URL + "/gamedata?", - MAP_ROTATION: BASE_URL + "/maprotation?" + GAME_DATA: BASE_URL + "/gamedata?" }; - /** - * Core of mozambique-api-wrapper - * - * @constructor - * @param {String} apiKey Your mozambiquehe.re Auth Key + * @private */ -function MozambiqueAPI(apiKey) { - if (!apiKey) { - throw new Error("API Key missing"); - } - let self = this; - - self.apiKey = apiKey; - - self.headers = { - "User-Agent": "mozambique-api-wrapper", - "Content-Type": "application/json" - }; -} - - function request(self, url) { return fetch(url, { headers: self.headers }) - .then(function (res) { - return res.json(); - }).catch(function (err) { - return Promise.reject(err); - }); + .then(function (res) { + return res.json(); + }) + .catch(function (err) { + return Promise.reject(err); + }); } - /** - * Search a player using player name or UID + * Core of mozambique-api-wrapper * - * @param {Any} query Query parameters - * @param {String} [query.player] Player name - * @param {String|Number} [query.uid] Player UID - * @param {String} [query.platform] Player platform (PC, PS4, X1) - * @returns {JSON} Json with player info + * @constructor + * @param {String} apiKey Your [apexlegendsapi](https://apexlegendsapi.com) Auth Key */ - -MozambiqueAPI.prototype.search = function (query) { - let type - - if (query.player) { - type = "player=" + query.player; +class MozambiqueAPI { + constructor(apiKey) { + if (!apiKey) throw new Error("mozampique-api-wrapper: API Key missing"); + + let self = this; + self.apiKey = apiKey; + self.headers = { + "User-Agent": "mozambique-api-wrapper", + "Content-Type": "application/json", + "Authorization": self.apiKey + }; } - if (query.uid) { - type = "uid=" + query.uid; + /** + * Search a player using player name or UID + * + * @param {Object} query Query parameters + * @param {String} [query.player] Player name + * @param {String|Number} [query.uid] Player UID + * @param {String} [query.platform] Player platform (PC, PS4, X1) + * @returns {Object} Object with player info + */ + search(query) { + let type; + if (query.player) type = "player=" + query.player; + if (query.uid) type = "uid=" + query.uid; + let url = DIRECTORY.SEARCH_URL + "&platform=" + query.platform + "&" + type; + return request(this, url); } - let url = DIRECTORY.SEARCH_URL + "&platform=" + query.platform + "&" + type + "&auth=" + this.apiKey; - return request(this, url); -}; - - -/** - * Get recent news about Apex Legends - * - * @param {String} [lang="en-us"] News language - * @returns {JSON} Json with an array of Apex Legends news - */ - -MozambiqueAPI.prototype.news = function (lang = "en-us") { - let url = DIRECTORY.NEWS_URL + "&lang=" + lang + "&auth=" + this.apiKey; - return request(this, url); -}; - - -/** - * Get server status for Origin, EA, Apex Legends and Mozambiquehe.re API - * - * @returns {JSON} Json with status of all servers - */ - -MozambiqueAPI.prototype.server = function() { - let url = DIRECTORY.SERVER_STATUS - return request(this, url) -} - - -/** - * Avaliable for everyone but with limitations depending on your access type - * - * @param {Any} query Query parameters - * @param {String} [query.player] Player name - * @param {String|Number} [query.uid] Player UID - * @param {String} [query.platform] Player platform (PC, PS4, X1) - * @param {String} [query.action] Action for the Match History API (info, get, delete, add) - * @returns {JSON} Json differs depending on action parameter. Please refer to API documentation for more info (https://mozambiquehe.re/api) - */ - -MozambiqueAPI.prototype.history = function(query) { - let type - - if (query.player) { - type = "player=" + query.player; + /** + * Get recent news about Apex Legends + * + * @param {String} [lang="en-us"] Language of the news + * @returns {Array} Array of Apex Legends news + */ + news(lang = "en-us") { + let url = DIRECTORY.NEWS_URL + "lang=" + lang; + return request(this, url); } - if (query.uid) { - type = "uid=" + query.uid; + /** + * Get server status for Origin, EA, Apex Legends and apexlegendsapi API + * + * @returns {ServerStatus} Object with status of all servers + */ + server() { + let url = DIRECTORY.SERVER_STATUS; + return request(this, url); } - let url = DIRECTORY.MATCH_HISTORY + type + "&platform" + query.platform + "&auth=" + this.apiKey + "&history=1&action=" + query.action; - return request(this, url) -} - -/** - * Get all game data avaliable on [mozambiquehe.re](https://mozambiquehe.re/) separated by data type - * - * Avaliable data types: - * assault_rifles, attachments, consumables, equipment, grenades, legends, light_machine_guns, pistols, shotguns, sniper_rifles, sub_machine_guns - * @param {String} dataType Type of data requested - * @returns {JSON} Json with requested game data - */ - -MozambiqueAPI.prototype.gamedata = function(dataType) { - let url = DIRECTORY.GAME_DATA + "type=" + dataType + "&auth=" + this.apiKey - return request(this, url) -} - -/** - * Get the map rotation - * - * @returns {JSON} Json with map rotation data - */ + /** + * Avaliable for everyone but with limitations depending on your api access type + * + * @param {Object} query Query parameters + * @param {String} [query.player] Player name + * @param {String|Number} [query.uid] Player UID + * @param {String} [query.platform] Player platform (PC, PS4, X1) + * @param {String} [query.action] Action for the Match History API (info, get, delete, add) + * @returns {Object} Object differs depending on action parameter. Please refer to [API documentation](https://apexlegendsapi.com) for more info + */ + history(query) { + let type; + if (query.player) type = "player=" + query.player; + if (query.uid) type = "uid=" + query.uid; + let url = DIRECTORY.MATCH_HISTORY + type + "&platform" + query.platform + "&history=1&action=" + query.action; + return request(this, url); + } -MozambiqueAPI.prototype.mapRotation = function() { - let url = DIRECTORY.MAP_ROTATION + "auth=" + this.apiKey - return request(this, url) + /** + * WARNING: endpoint data not updated anymore + * + * Avaliable data types: + * assault_rifles, attachments, consumables, equipment, grenades, legends, light_machine_guns, pistols, shotguns, sniper_rifles, sub_machine_guns + * @deprecated data not update anymore + * @param {String} dataType Type of data requested + * @returns {Object} Object with requested game data + */ + gamedata(dataType) { + let url = DIRECTORY.GAME_DATA + "type=" + dataType; + return request(this, url); + } } -module.exports = MozambiqueAPI; +module.exports = MozambiqueAPI; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index a796afd..6e1078b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,13 @@ { "name": "mozambique-api-wrapper", - "version": "1.2.1", + "version": "1.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { "node-fetch": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", - "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==" + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" } } } diff --git a/package.json b/package.json index 5992e0f..5ecc99d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mozambique-api-wrapper", - "version": "1.2.1", + "version": "1.3.0", "description": "Wrapper to make accessing mozambiquehe.re APIs when writing code in Javascript (Node.js) much easier.", "main": "index.js", "scripts": { @@ -22,6 +22,7 @@ "API" ], "dependencies": { - "node-fetch": "^2.6.0" - } + "node-fetch": "^2.6.1" + }, + "devDependencies": {} }