Skip to content

Commit

Permalink
1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
King-BR committed Nov 26, 2020
1 parent e4a0f1e commit 05dc4c8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 56 deletions.
Binary file modified DOCS.md
Binary file not shown.
71 changes: 28 additions & 43 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const fetch = require('node-fetch');
const fs = require('fs')

const BASE_URL = "https://api.mozambiquehe.re";

const DIRECTORY = {
SEARCH_URL: BASE_URL + "/bridge?version=4",
NEWS_URL: BASE_URL + "/news?",
SERVER_STATUS: BASE_URL + "/status?",
SERVER_STATUS: BASE_URL + "/servers?",
MATCH_HISTORY: BASE_URL + "/bridge?",
GAME_DATA: BASE_URL + "/gamedata?"
};
Expand All @@ -18,64 +17,58 @@ 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);
});
}

/**
* Core of mozambique-api-wrapper
*
* @constructor
* @param {String} apiKey Your apexlegendsapi Auth Key
* @param {String} apiKey Your [apexlegendsapi](https://apexlegendsapi.com) Auth Key
*/
class MozambiqueAPI {
constructor(apiKey) {
if (!apiKey) {
throw new Error("mozampique-api-wrapper: API Key missing");
}
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"
"Content-Type": "application/json",
"Authorization": self.apiKey
};
}

/**
* Search a player using player name or UID
*
* @param {Any} query Query parameters
* @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 {Player} Object with player info
* @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 + "&auth=" + this.apiKey;
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);
}

/**
* Get recent news about Apex Legends
*
* @param {String} [lang="en-us"] News language
* @returns {News} Object with an array of Apex Legends news
* @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 + "&auth=" + this.apiKey;
let url = DIRECTORY.NEWS_URL + "lang=" + lang;
return request(this, url);
}

Expand All @@ -90,42 +83,34 @@ class MozambiqueAPI {
}

/**
* Avaliable for everyone but with limitations depending on your access type
* Avaliable for everyone but with limitations depending on your api access type
*
* @param {Any} query Query parameters
* @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 for more info (https://apexlegendsapi/api)
* @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 + "&auth=" + this.apiKey + "&history=1&action=" + query.action;
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);
}

/**
* WARNING: endpoint data not updated anymore
*
* Get all game data avaliable on [apexlegendsapi](https://apexlegendsapi/) separated by data type
*
* 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 + "&auth=" + this.apiKey;
let url = DIRECTORY.GAME_DATA + "type=" + dataType;
return request(this, url);
}
}
Expand Down
13 changes: 4 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mozambique-api-wrapper",
"version": "1.3.0-beta.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": {
Expand All @@ -22,7 +22,7 @@
"API"
],
"dependencies": {
"fs": "0.0.1-security",
"node-fetch": "^2.6.0"
}
"node-fetch": "^2.6.1"
},
"devDependencies": {}
}

0 comments on commit 05dc4c8

Please sign in to comment.