albion-api
Version:
A basic API implementation for Albion online using the limited gameinfo API.
292 lines (251 loc) • 9.64 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>index.js - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading"><a href="global.html">Globals</a></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#getEventDetails">getEventDetails</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#getEventsBetween">getEventsBetween</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#getGuildData">getGuildData</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#getGuildFued">getGuildFued</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#getGuildInfo">getGuildInfo</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#getGuildMembers">getGuildMembers</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#getGuildStats">getGuildStats</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#getGuildTopKills">getGuildTopKills</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#getPlayerInfo">getPlayerInfo</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#getRecentEvents">getRecentEvents</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#getServerStatus">getServerStatus</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#search">search</a></span></li>
</nav>
<div id="main">
<h1 class="page-title">index.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>var debug = require('debug')('AlbionAPI');
var async = require('async');
var request = require('request');
var BASE_URL = process.env.ALBION_API_BASE || 'https://gameinfo.albiononline.com/api/gameinfo';
/**
* baseRequest - description
*
* @param {type} uri description
* @param {callback} cb description
* @private
*/
function baseRequest(uri, cb) {
var url = `${BASE_URL}${uri}`;
request(url, function (error, response, body) {
debug(`Url: ${url} statusCode: ${response && response.statusCode}`);
if(error || (response && response.statusCode === 404)) {
cb(error || response);
}
cb(null, JSON.parse(body));
});
}
/**
* getServerStatus - description
*
* @param {callback} cb description
*/
function getServerStatus(cb) {
async.parallel({
live: (cb) => {
request('http://live.albiononline.com/status.txt', (error, response, body) => {
if(error) {
return cb(error);
}
cb(null, JSON.parse(body.trim()));
});
},
staging: (cb) => {
request('http://staging.albiononline.com/status.txt', (error, response, body) => {
if(error) {
return cb(error);
}
cb(null, JSON.parse(body.trim()));
});
}
}, (e, rs) => {
if(e) {
return cb(e);
}
cb(null, {
live: {
status: rs.live.status,
message: rs.live.message,
},
staging: {
status: rs.staging.status,
message: rs.staging.message,
}
});
});
}
// -- Searching
//
/**
* search - description
*
* @param {string} query description
* @param {callback} cb description
*/
function search(query, cb) {
debug(`Searching for: ${query}`);
baseRequest(`/search?q=${query}`, cb);
}
// -- Events / Kills
//
/**
* getRecentEvents - description
*
* @param {object} opts description
* @param {callback} cb description
*/
function getRecentEvents(opts, cb) {
opts = opts || {};
query = "?";
if(opts.limit) {
query += `limit=${opts.limit}`;
}
if(opts.offset) {
query += `offset=${opts.offset}`;
}
// https://gameinfo.albiononline.com/api/gameinfo/events?limit=51&offset=0
baseRequest(`/events`, cb);
}
var getRecentKills = getRecentEvents;
/**
* getEventDetails - description
*
* @param {string} eventId description
* @param {callback} cb description
*/
function getEventDetails(eventId, cb) {
// https://gameinfo.albiononline.com/api/gameinfo/events/2484174
baseRequest(`/events/${eventId}`, cb);
}
var getKillDetails = getEventDetails;
/**
* getEventsBetween - description
*
* @param {string} eventId1 description
* @param {string} eventId2 description
* @param {callback} cb description
*/
function getEventsBetween(eventId1, eventId2, cb) {
// https://gameinfo.albiononline.com/api/gameinfo/events/p_BN_ZrdSwSgtOdebp-8mw/history/4RpreMJdRqev6t6dm1zKUg
baseRequest(`/events/${eventId1}/history/${eventId2}`, cb);
}
var getPlayerFued = getEventsBetween;
// -- Guild
//
/**
* getGuildInfo - description
*
* @param {string} guildId description
* @param {callback} cb description
*/
function getGuildInfo(guildId, cb) {
// https://gameinfo.albiononline.com/api/gameinfo/guilds/vFUVDtWgQwK-4NNwf0xo_w
baseRequest(`/guilds/${guildId}`, cb);
}
/**
* getGuildData - description
*
* @param {string} guildId description
* @param {callback} cb description
*/
function getGuildData(guildId, cb) {
// https://gameinfo.albiononline.com/api/gameinfo/guilds/vFUVDtWgQwK-4NNwf0xo_w/data
baseRequest(`/guilds/${guildId}/data`, cb);
}
/**
* getGuildTopKills - description
*
* @param {string} guildId description
* @param {object} opts description
* @param {callback} cb description
*/
function getGuildTopKills(guildId, opts, cb) {
opts = opts || {};
query = "?";
if(opts.limit) {
query += `limit=${opts.limit}`;
}
if(opts.offset) {
query += `offset=${opts.offset}`;
}
if(opts.range) { // week, lastWeek, month, lastMonth
query += `range=${opts.range}`;
}
// https://gameinfo.albiononline.com/api/gameinfo/guilds/vFUVDtWgQwK-4NNwf0xo_w/data
baseRequest(`/guilds/${guildId}/top${query}`, cb);
}
/**
* getGuildStats - description
*
* @param {string} guildId description
* @param {callback} cb description
*/
function getGuildStats(guildId, cb) {
//https://gameinfo.albiononline.com/api/gameinfo/guilds/3InalPCfQL-GAmGZ-XafhQ/stats
baseRequest(`/guilds/${guildId}/stats`, cb);
}
/**
* getGuildMembers - description
*
* @param {string} guildId description
* @param {callback} cb description
*/
function getGuildMembers(guildId, cb) {
// https://gameinfo.albiononline.com/api/gameinfo/guilds/vFUVDtWgQwK-4NNwf0xo_w/members
baseRequest(`/guilds/${guildId}/members`, cb);
}
/**
* getGuildFued - description
*
* @param {string} guildId1 description
* @param {string} guildId2 description
* @param {callback} cb description
*/
function getGuildFued(guildId1, guildId2, cb) {
// https://gameinfo.albiononline.com/api/gameinfo/guilds/r-pjy3pRSMWx-OKqwT-SBg/feud/55EvzyTZQsG70sOuoGXgog
baseRequest(`/guilds/${guildId1}/fued/${guildId2}`, cb);
}
// -- Player
//
/**
* getPlayerInfo - description
*
* @param {string} playerId description
* @param {callback} cb description
*/
function getPlayerInfo(playerId, cb) {
// https://gameinfo.albiononline.com/api/gameinfo/players/Nubya8P6QWGhI6hDLQHIQQ
baseRequest(`/players/${playerId}`, cb);
}
module.exports = {
search,
getServerStatus,
getRecentKills, getKillDetails, getPlayerFued,
getRecentEvents, getEventDetails, getEventsBetween,
getGuildInfo, getGuildData, getGuildTopKills, getGuildStats, getGuildMembers, getGuildFued,
getPlayerInfo
};
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.1</a> on Sat Jul 29 2017 18:19:30 GMT+0100 (GMT Summer Time) using the Minami theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>