Skip to content

Commit

Permalink
Merge pull request #4 from arubinofaux/Experimental
Browse files Browse the repository at this point in the history
1.3.0
  • Loading branch information
King-BR committed Nov 26, 2020
2 parents 1bb129b + 05dc4c8 commit 0bae296
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 130 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
node_modules
node_modules/
tests/
Cache/
gamedata/
gamedataPrettyPrint/
Binary file modified DOCS.md
Binary file not shown.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -12,7 +15,7 @@ $ cd /path/to/app
$ npm install --save mozambique-api-wrapper
```

### Usage
## Usage

```js
// Require Wrapper Library
Expand Down
206 changes: 87 additions & 119 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 4 additions & 4 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -22,6 +22,7 @@
"API"
],
"dependencies": {
"node-fetch": "^2.6.0"
}
"node-fetch": "^2.6.1"
},
"devDependencies": {}
}

0 comments on commit 0bae296

Please sign in to comment.