diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f390780 --- /dev/null +++ b/.gitignore @@ -0,0 +1,61 @@ +# Created by .ignore support plugin (hsz.mobi) +### Windows template +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk +### Node template +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +.idea/ +api-test.js \ No newline at end of file diff --git a/config/config.js b/config/config.js new file mode 100644 index 0000000..5843821 --- /dev/null +++ b/config/config.js @@ -0,0 +1,21 @@ +module.exports = { + base_url: 'http://api.mineplex.com:8081/', + routes: { + server: { + url: 'server', + token: false + }, + player: { + url: 'player/', + token: true + }, + 'player.status': { + url: 'player/', + token: true + }, + 'player.friends': { + url: 'player/', + token: true + } + } +} \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..b57be56 --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +module.exports = require(`./lib/MineplexAPIWrapper`); \ No newline at end of file diff --git a/lib/Amplifier/Amplifier.js b/lib/Amplifier/Amplifier.js new file mode 100644 index 0000000..77b61e5 --- /dev/null +++ b/lib/Amplifier/Amplifier.js @@ -0,0 +1,44 @@ +var Player = require('../Player/'); + +class Amplifier extends Player.Components.Data{ + constructor(data, group){ + super(data, 'playerName'); + this._group = group; + this._duration = data.duration; + this._activationTime = new Date(data.activationTime); + this._startTime = new Date(data.startTime); + this._endTime = new Date(data.endTime); + this._multiplier = data.multiplier; + } + + getGroup(){ + return this._group; + } + + getDuration(){ + return this._duration; + } + + getActivationTime(){ + return this._activationTime; + } + + getStartTime(){ + return this._startTime; + } + + getEndTime(){ + return this._endTime; + } + + isActive(){ + var now = Date.now(); + return (now >= this.getStartTime().getTime() && now <= this.getEndTime().getTime()); + } + + getMultiplier(){ + return this._multiplier; + } +} + +module.exports = Amplifier; \ No newline at end of file diff --git a/lib/Amplifier/AmplifierGroup.js b/lib/Amplifier/AmplifierGroup.js new file mode 100644 index 0000000..578d81b --- /dev/null +++ b/lib/Amplifier/AmplifierGroup.js @@ -0,0 +1,21 @@ +var Amplifier = require('./Amplifier'); + +class AmplifierGroup{ + constructor(data, group){ + this._group = group; + this._amplifiers = []; + data.forEach((amplifier)=>{ + this._amplifiers.push(new Amplifier(amplifier)); + }); + } + + getGroup(){ + return this._group; + } + + getAmplifiers(){ + return this._amplifiers; + } +} + +module.exports = AmplifierGroup; \ No newline at end of file diff --git a/lib/Amplifier/AmplifierGroups.js b/lib/Amplifier/AmplifierGroups.js new file mode 100644 index 0000000..9e9e16a --- /dev/null +++ b/lib/Amplifier/AmplifierGroups.js @@ -0,0 +1,19 @@ +var AmplifierGroup = require('./AmplifierGroup'); + +class AmplifierGroups{ + constructor(data){ + this._groups = {}; + for(var group in data){ + groups[group] = new AmplifierGroup(data[group], group); + } + } + + getGroups(){ + return this._groups; + } + + getGroup(group){ + return this._groups[group]; + } + +} \ No newline at end of file diff --git a/lib/Amplifier/index.js b/lib/Amplifier/index.js new file mode 100644 index 0000000..ffad91f --- /dev/null +++ b/lib/Amplifier/index.js @@ -0,0 +1,5 @@ +exports.Amplifier = require('./Amplifier'); + +exports.AmplifierGroup = require('./AmplifierGroup'); + +exports.AmplifierGroups = require('./AmplifierGroups'); \ No newline at end of file diff --git a/lib/MineplexAPIWrapper.js b/lib/MineplexAPIWrapper.js new file mode 100644 index 0000000..b71fdf7 --- /dev/null +++ b/lib/MineplexAPIWrapper.js @@ -0,0 +1,87 @@ +var MineplexAPI = require('../../mineplex-api'); +var ServerStatus = require('./ServerStatus'); +var Player = require('./Player'); +var Amplifiers = require('./Amplifier'); + +class MineplexAPIWrapper{ + constructor(apikey){ + this.api = new MineplexAPI(apikey); + } + + getServerStatus(callback){ + this.api.get.server((success, res)=>{ + if(!success) return callback(false, res); + + var status = new ServerStatus(res); + callback(true, status); + }); + } + + getServerTotal(callback){ + this.api.get.server((success, res)=>{ + if(!success) return callback(false, res); + + var status = new ServerStatus(res); + callback(true, status.getTotal()); + }); + } + + getServerGroups(callback){ + this.api.get.server((success, res)=>{ + if(!success) return callback(false, res); + + var status = new ServerStatus(res); + callback(true, status.getGroups()); + }); + } + + getPlayerInfo(player, callback){ + this.api.get.player.info(player, (success, res)=>{ + if(!success) return callback(false, res); + + callback(true, new Player.Player(res)); + }); + } + + getPlayerFriends(player, callback){ + this.api.get.player.friends(player, (success, res)=>{ + if(!success) return callback(false, res); + + callback(true, new Player.Components.Friends(res)); + }); + } + + getPlayerStatus(player, callback){ + this.api.get.player.status(player, (success, res)=>{ + if(!success) return callback(false, res); + + callback(true, new Player.Components.Status(res)); + }); + } + + getAmplifierGroups(callback){ + this.api.get.amplifierGroup((success, res)=>{ + if(!success) return callback(false, res); + + callback(true, res); + }); + } + + getAmplifiers(callback){ + this.api.get.amplifier.all((success, res)=>{ + if(!success) return callback(false, res); + + callback(true, new Amplifiers.AmplifierGroups(res)); + }); + } + + getAmplifiersForGroup(group, callback){ + this.api.get.amplifier.specific(group, (success, res)=>{ + if(!success) return callback(false, res); + + callback(true, new Amplifiers.AmplifierGroup(res)); + }); + } +} + +module.exports = MineplexAPIWrapper; \ No newline at end of file diff --git a/lib/Player/Components/PlayerData.js b/lib/Player/Components/PlayerData.js new file mode 100644 index 0000000..2315df5 --- /dev/null +++ b/lib/Player/Components/PlayerData.js @@ -0,0 +1,16 @@ +class PlayerData{ + constructor(data, nameKey){ + this._uuid = data.uuid; + this._name = (nameKey) ? data[nameKey] : data.name; + } + + getUUID(){ + return this._uuid; + } + + getName(){ + return this._name; + } +} + +module.exports = PlayerData; \ No newline at end of file diff --git a/lib/Player/Components/PlayerFriends.js b/lib/Player/Components/PlayerFriends.js new file mode 100644 index 0000000..bdea1f8 --- /dev/null +++ b/lib/Player/Components/PlayerFriends.js @@ -0,0 +1,19 @@ +class PlayerFriends{ + constructor(data){ + this._friends = data; + } + + getFriends(){ + return this._friends; + } + + isFriend(player){ + return (this._friends.indexOf(player) > -1); + } + + getAmount(){ + return this._friends.length; + } +} + +module.exports = PlayerFriends; \ No newline at end of file diff --git a/lib/Player/Components/PlayerStats.js b/lib/Player/Components/PlayerStats.js new file mode 100644 index 0000000..4e3f841 --- /dev/null +++ b/lib/Player/Components/PlayerStats.js @@ -0,0 +1,35 @@ +class PlayerStats{ + constructor(data){ + this._stats = {}; + + for(var item in data){ + var info = item.split('.'); + var game = info[0]; + var stat = info[1]; + var value = data[item]; + + this.addStat(game, stat, value); + } + } + + getStats(game){ + if(!this._stats[game]) this._stats[game] = {}; + return this._stats[game]; + } + + getStat(game, stat){ + var gameStats = this.getStats(game); + return (gameStats[stat]) ? gameStats[stat] : 0; + } + + addStat(game, stat, value){ + if(!this._stats[game]) this._stats[game] = {}; + this._stats[game][stat] = value; + } + + toString(){ + return JSON.stringify(this._stats); + } +} + +module.exports = PlayerStats; \ No newline at end of file diff --git a/lib/Player/Components/PlayerStatsCategory.js b/lib/Player/Components/PlayerStatsCategory.js new file mode 100644 index 0000000..292a325 --- /dev/null +++ b/lib/Player/Components/PlayerStatsCategory.js @@ -0,0 +1,3 @@ +/** + * Created by Spencer on 10/12/2016. + */ diff --git a/lib/Player/Components/PlayerStatus.js b/lib/Player/Components/PlayerStatus.js new file mode 100644 index 0000000..2fa61b6 --- /dev/null +++ b/lib/Player/Components/PlayerStatus.js @@ -0,0 +1,20 @@ +class PlayerStatus{ + constructor(data){ + this._online = data.online; + this._server = data.server; + } + + isOnline(){ + return this._online; + } + + getServer(){ + return this._server; + } + + toString(){ + return (this._online) ? `online` : `offline`; + } +} + +module.exports = PlayerStatus; \ No newline at end of file diff --git a/lib/Player/Components/index.js b/lib/Player/Components/index.js new file mode 100644 index 0000000..2ac7fbf --- /dev/null +++ b/lib/Player/Components/index.js @@ -0,0 +1,4 @@ +exports.Friends = require('./PlayerFriends'); +exports.Stats = require('./PlayerStats'); +exports.Status = require('./PlayerStatus'); +exports.Data = require('./PlayerData'); \ No newline at end of file diff --git a/lib/Player/Player.js b/lib/Player/Player.js new file mode 100644 index 0000000..39037fb --- /dev/null +++ b/lib/Player/Player.js @@ -0,0 +1,39 @@ +var PlayerComponents = require('./Components'); + +class Player extends PlayerComponents.Data{ + constructor(data){ + super(data); + this._accountId = data.accountId; + this._rank = data.rank; + this._lastLogin = new Date(data.lastLogin); + this.status = new PlayerComponents.Status(data.playerStatus); + this.friends = new PlayerComponents.Friends(data.friends); + this.stats = new PlayerComponents.Stats(data.playerStats); + } + + getAccountId(){ + return this._accountId; + } + + getRank(){ + return this._rank; + } + + getLastLogin(){ + return this._lastLogin; + } + + getStatus(){ + return this.status; + } + + getFriends(){ + return this.friends + } + + getStats(){ + return this.stats; + } +} + +module.exports = Player; \ No newline at end of file diff --git a/lib/Player/index.js b/lib/Player/index.js new file mode 100644 index 0000000..ac87a32 --- /dev/null +++ b/lib/Player/index.js @@ -0,0 +1,2 @@ +exports.Player = require('./Player'); +exports.Components = require('./Components'); \ No newline at end of file diff --git a/lib/ServerStatus.js b/lib/ServerStatus.js new file mode 100644 index 0000000..5bb39eb --- /dev/null +++ b/lib/ServerStatus.js @@ -0,0 +1,24 @@ +class ServerStatus{ + constructor(data){ + this._total = data.total; + this._groups = data.groups; + } + + getTotal(){ + return this._total; + } + + isGroup(group){ + return (this._groups) ? true : false; + } + + getGroups(){ + return this._groups; + } + + getGroup(group){ + return this._groups[group]; + } +} + +module.exports = ServerStatus; \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..19435d4 --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "mineplex-api-wrapper", + "version": "1.0.0", + "description": "Higher-level API wrapper for the Mineplex API.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "ArcticZeroo", + "license": "ISC" +}