battlerite-api v1.2.0
battlerite-api
a promise based library for accessing the battlerite api for nodejs
battlerite-api is a Node.js package wrapping the official Battlerite API, this is unopinionated-ish and returns the response data or the axios error if something went wrong. You can use the rawResponses option when creating the BattleriteAPI object to return the raw axios response instead
You can find the documentation for the Battlerite API here: http://battlerite-docs.readthedocs.io/en/latest/introduction.html
And I also recommend reading the JSON-API Specifications as well: http://jsonapi.org/
Table of Contents
Todo
- Add unit tests
- Make it work in browser
Dependencies
axios - for making promise based HTTP requests
Installation
This project uses nodejs and npm
npm install --save battlerite-apiUsage
const BattleriteAPI = require('battlerite-api');
// creates a new instance of the battlerite api
const api = new BattleriteAPI({
apiKey: '<api_key>',
});
// gets a collection of matches
api.getMatches().then((response) => {
// handle the reponse
}).catch((error) => {
// handle the error
});API
new BattleriteAPI(options)
Creates a new BattleriteAPI object with the options provided
Parameters:
optionsObject optionsapiKeyString a string containing the api key from here https://developer.battlerite.com/ REQUIREDdefaultDatacenterString a string defines the datacenter to use, defaults to'dc1'baseURLString a string defines the baseURL, passed to axios, defaults to`https://api.${this.defaultDatacenter}.gamelockerapp.com`timeoutNumber a number defining the maximum time in milliseconds before timing out the requests, passed to axios, defaults to2000defaultShardString a string that defines the default shard to use (http://battlerite-docs.readthedocs.io/en/master/makingrequests/makingrequests.html#regions)userAgentString a string defining the user agent, defaults to'js/battlerite-api'headersObject<String, String> an object that defines the additional headers to send with requests, defaults to adding the Accept, Accept-Encoding, Authorization, and User-Agent headers
Example:
const api = new BattleriteAPI({
apiKey: '<api_key>',
});BattleriteAPI#getStatus()
Gets the status of the api, including version, and release of the official api http://battlerite-docs.readthedocs.io/en/master/status/status.html
Returns:
Example:
api.getStatus().then((response) => {
// handle the response
}).catch((error) => {
// handle the error
});BattleriteAPI#getMatches(options = {})
Gets a collection of matches http://battlerite-docs.readthedocs.io/en/master/matches/matches.html#get-a-collection-of-matches
Parameters:
optionsObject optionsbashardString a string defining the shard to use with the request, defaults to defaultShard if not setsortString a string that defines how to sort the results, defaults tocreatedAt, add a minus in front of it to sort backwardspageObject allows for paging (http://jsonapi.org/format/#fetching-pagination)filterObject allows for filtering
Returns:
responseObject response objectdataArray an array with match objectsincludedArray an array with player, roster, participant, asset, and round structureslinksObject an object that includes the link to self and next
Example:
api.getMatches({
sort: '-createdAt',
filter: {
createdAt: { start: '2017-01-01T08:25:30Z', end: '2017-01-01T13:25:30Z', },
},
}).then((response) => {
// handle the response
}).catch((error) => {
// handle the error
});BattleriteAPI#getMatch(matchID, options = {})
Gets a specific match by id http://battlerite-docs.readthedocs.io/en/master/matches/matches.html#get-a-single-match Parameters:
matchIDString a string that defines the match to get by idoptionsObject optionsbashardString a string defining the shard to use with the request, defaults to defaultShard if not set
Returns:
responseObject response objectdataObject an object with match objectincludedArray an array with player, roster, participant, asset, and round structureslinksObject an object that includes the link to self and next
Example:
api.getMatch('<matchID>').then((response) => {
// handle the response
}).catch((error) => {
// handle the error
});BattleriteAPI#getPlayersById(playerIDs, options = {})
Gets a collection of players up to 6 from an array of player ids http://battlerite-docs.readthedocs.io/en/latest/players/players.html#get-a-collection-of-players
Parameters:
playerIDsArray[String] an array of player IDsoptionsObject optionsbashardString a string defining the shard to use with the request, defaults to defaultShard if not set
Returns:
responseObject response object
Example:
api.getPlayersById(['<id_1>', '<id_2>']).then((response) => {
// handle the response
}).catch((error) => {
// handle the error
});BattleriteAPI#getPlayerById(playerID, options = {})
Get a specific player by id http://battlerite-docs.readthedocs.io/en/latest/players/players.html#get-a-single-player
Parameters:
playerIDString a string with a player IDoptionsObject optionsbashardString a string defining the shard to use with the request, defaults to defaultShard if not set
Returns:
Example:
api.getPlayerById('<player_id>').then((response) => {
// handle the response
}).catch((error) => {
// handle the error
});BattleriteAPI#getPlayersByName(playerNames, options = {})
Gets a collection of players up to 6 from an array of player names http://battlerite-docs.readthedocs.io/en/latest/players/players.html#get-a-collection-of-players
Parameters:
playerNamesArray[String] an array of player namesoptionsObject optionsbashardString a string defining the shard to use with the request, defaults to defaultShard if not set
Returns:
responseObject response object
Example:
api.getPlayersByName(['<name_1>', '<name_2>']).then((response) => {
// handle the response
}).catch((error) => {
// handle the error
});BattleriteAPI#getPlayerByName(playerName, options = {})
Get a specific player by name http://battlerite-docs.readthedocs.io/en/latest/players/players.html#get-a-collection-of-players
Parameters:
playerNameString a string with a player nameoptionsObject optionsbashardString a string defining the shard to use with the request, defaults to defaultShard if not set
Returns:
responseObject response object
Example:
api.getPlayerByName('<player_id>').then((data) => {
// handle the data
}).catch((error) => {
// handle the error
});BattleriteAPI#getPlayersBySteamId(steamIDs, options = {})
Gets a collection of players up to 6 from an array of steam ids http://battlerite-docs.readthedocs.io/en/latest/players/players.html#get-a-collection-of-players
Parameters:
steamIDsArray[String] an array of steam idsoptionsObject optionsbashardString a string defining the shard to use with the request, defaults to defaultShard if not set
Returns:
responseObject response object
Example:
api.getPlayersBySteamId(['<id_1>', '<id_2>']).then((data) => {
// handle the data
}).catch((error) => {
// handle the error
});BattleriteAPI#getPlayerBySteamId(steamID, options = {})
Get a specific player by steam id http://battlerite-docs.readthedocs.io/en/latest/players/players.html#get-a-collection-of-players
Parameters:
steamIDString a string that defines the steam idoptionsObject optionsbashardString a string defining the shard to use with the request, defaults to defaultShard if not set
Returns:
Example:
api.getPlayerBySteamId('<steam_id>').then((data) => {
// handle the data
}).catch((error) => {
// handle the error
});BattleriteAPI#getTelemetry(matchID, options = {})
Get the telemetry by match id http://battlerite-docs.readthedocs.io/en/latest/telemetry/telemetry.html Uses BattleriteAPI#getMatch() and passes on the options object (uses a api request)
Parameters:
Returns:
if options.url is true
urlString a string with the url to telemetry
else
responseArray an array of match events
BattleriteAPI#getTeamsByPlayerIds(playerIDs, season, options = {})
Gets a collection of teams by player ids http://battlerite-docs.readthedocs.io/en/master/teams/teams.html
Parameters:
playerIDsArray an array with player idsseasonString a string that defines the season to search inoptionsObject optionsbashardString a string defining the shard to use with the request, defaults to defaultShard if not set
Returns:
responseObject response object
Example:
api.getTeamsByPlayerIds(['<id_1>', '<id_2>']).then((response) => {
// handle the response
}).catch((error) => {
// handle the error
});BattleriteAPI#getTeamsByPlayerId(playerID, season, options = {})
Gets a collection of teams from a player id http://battlerite-docs.readthedocs.io/en/master/teams/teams.html
Parameters:
playerIDString a string that defines the player idseasonString a string that defines the season to search inoptionsObject optionsbashardString a string defining the shard to use with the request, defaults to defaultShard if not set
Returns:
responseObject response object
Example:
api.getTeamsByPlayerId('<player_id>', '6').then((response) => {
// handle the response
}).catch((error) => {
// handle the error
});License
MIT @ Johan Jansson