1.1.0 • Published 2 years ago

bhapi.js v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Contributors Forks Stargazers Issues MIT License

About The Project

TypeScript/JavaScript wrapper around Brawlhalla API. Consume the API easily through different methods and access extended functionalities not included originally in the API. This is not an official Brawlhalla Application and it has no connection with Brawlhalla nor its developers.

Built With

  • Node
  • TypeScript

Getting Started

You need to follow some steps to get this running.

Prerequisites

You need to acquire an API key from Brawlhalla. If you do not have an API key, please read this to know how to get one.

Installation

Install the package using your package manager of choice.

npm install bhapi.js --save

Usage

You may then import BrawlhallaAPI into your project.

// ES Modules
import BrawlhallaAPI from 'bhapi.js'

// CommonJS
const BrawlhallaAPI = require('bhapi.js')

After that, you need to instantiate the class providing the Brawlhalla API key in the config and you're ready to use it!

const bhapi = new BrawlhallaAPI({ apiKey: 'YOUR-API-KEY' })

const legends = await bhapi.getLegends()

Methods

new BrawlhallaAPI(config) ===> BrawlhallaAPI object

Constructor to create a new BrawlhallaAPI object. You need to provide a config object

  1. Constructor Arguments

    • config: {BrawlhallaAPIConfig}. Config object that contains the API key
  2. Example Use

const config = {
  apiKey: 'YOUR-API-KEY',
}

const bhapi = new BrawlhallaAPI(config)

searchBySteamID(steamId) ===> Promise<Player>

Find a player by Steam ID

  1. Method Arguments

    • steamId: {SteamId64} (string). A player’s Steam ID in format steamID64 (ex 76561198025185087).
  2. Example Use

const config = {
  apiKey: 'YOUR-API-KEY',
}

const bhapi = new BrawlhallaAPI(config)

const player = await bhapi.searchBySteamID('76561198025185087')

// {
//     "brawlhalla_id": 2,
//     "name": ""
// }

getRankings(options) ===> Promise<ReadonlyArray<Ranking>>

Get rankings ordered and paginated 50 at a time

  1. Method Arguments

    • options: {RankingsOptions}. Search options. Default values = { bracket: '1v1', region: 'all', page: 1, }
  2. Example Use

const config = {
  apiKey: 'YOUR-API-KEY',
}

const bhapi = new BrawlhallaAPI(config)

const options = {
  bracket: '1v1',
  region: 'brz',
  page: 1,
  name: 'John Doe',
}

const rankings = await bhapi.getRankings(options)

// [
//     {
//         "rank": "1",
//         "name": "John Doe",
//         "brawlhalla_id": 20877,
//         "best_legend": 25,
//         "best_legend_games": 719,
//         "best_legend_wins": 642,
//         "rating": 2872,
//         "tier": "Diamond",
//         "games": 719,
//         "wins": 642,
//         "region": "BRZ",
//         "peak_rating": 2872
//     },
//     ...
// ]

getPlayerStats(brawlhallaId) ===> Promise<PlayerStats>

Get all stats about a player

  1. Method Arguments

    • brawlhallaId: {number}. The Brawlhalla ID of a player.
  2. Example Use

const config = {
  apiKey: 'YOUR-API-KEY',
}

const bhapi = new BrawlhallaAPI(config)

const playerStats = await bhapi.getPlayerStats(2)

// {
//     "brawlhalla_id": 2,
//     "name": "bmg | dan",
//     "xp": 191718,
//     "level": 47,
//     "xp_percentage": 0.6252398209337,
//     "games": 8,
//     "wins": 2,
//     "damagebomb": "29",
//     "damagemine": "0",
//     "damagespikeball": "0",
//     "damagesidekick": "14",
//     "hitsnowball": 0,
//     "kobomb": 0,
//     "komine": 0,
//     "kospikeball": 0,
//     "kosidekick": 0,
//     ...(more data)
// }

getPlayerRankedData(brawlhallaId) ===> Promise<PlayerRankedData>

Get ranked data about a player

  1. Method Arguments

    • brawlhallaId: {number}. The Brawlhalla ID of a player.
  2. Example Use

const config = {
  apiKey: 'YOUR-API-KEY',
}

const bhapi = new BrawlhallaAPI(config)

const playerRankedData = await bhapi.getPlayerRankedData(2)

// {
//     "name": "bmg | dan",
//     "brawlhalla_id": 2,
//     "rating": 1745,
//     "peak_rating": 1792,
//     "tier": "Platinum 2",
//     "wins": 207,
//     "games": 391,
//     "region": "US-E",
//     "global_rank": 5698,
//     "region_rank": 1644,
//     "legends": [
//         {
//             "legend_id": 4,
//             "legend_name_key": "cassidy",
//             "rating": 1736,
//             "peak_rating": 1792,
//             "tier": "Platinum 1",
//             "wins": 161,
//             "games": 300
//         },
//      ... (more data)
// }

getClan(clanId) ===> Promise<Clan>

Get information about a specific clan and its members

  1. Method Arguments

    • clanId: {number}. The clan ID of a clan.
  2. Example Use

const config = {
  apiKey: 'YOUR-API-KEY',
}

const bhapi = new BrawlhallaAPI(config)

const clan = await bhapi.getClan(1)

// {
//     "clan_id": 1,
//     "clan_name": "Blue Mammoth Games",
//     "clan_create_date": 1464206400,
//     "clan_xp": "86962",
//     "clan": [
//         {
//             "brawlhalla_id": 3,
//             "name": "[BMG] Chill Penguin X",
//             "rank": "Leader",
//             "join_date": 1464206400,
//             "xp": 6664
//         },
//         {
//             "brawlhalla_id": 2,
//             "name": "bmg | dan",
//             "rank": "Officer",
//             "join_date": 1464221047,
//             "xp": 4492
//         }
//     ]
// }

getLegends() ===> Promise<ReadonlyArray<LegendData>>

Get summarized data for all legends. Use getLegend(legendId) for more details about a legend.

  1. Example Use
const config = {
  apiKey: 'YOUR-API-KEY',
}

const bhapi = new BrawlhallaAPI(config)

const legends = await bhapi.getLegends()

// [
//     {
//         "legend_id": 3,
//         "legend_name_key": "bodvar",
//         "bio_name": "B\u00f6dvar",
//         "bio_aka": "The Unconquered Viking, The Great Bear",
//         "weapon_one": "Hammer",
//         "weapon_two": "Sword",
//         "strength": "6",
//         "dexterity": "6",
//         "defense": "5",
//         "speed": "5"
//     },
//     {
//         "legend_id": 4,
//         "legend_name_key": "cassidy",
//         "bio_name": "Cassidy",
//         "bio_aka": "The Marshal of the Old West",
//         "weapon_one": "Pistol",
//         "weapon_two": "Hammer",
//         "strength": "6",
//         "dexterity": "8",
//         "defense": "4",
//         "speed": "4"
//     },  ...
// ]

getLegend(legendId) ===> Promise<Legend>

Get detailed data about a specific legend.

  1. Method Arguments

    • legendId: {number}. The legend ID of a legend.
  2. Example Use

const config = {
  apiKey: 'YOUR-API-KEY',
}

const bhapi = new BrawlhallaAPI(config)

const legend = await bhapi.getLegend(3)

// {
//     "legend_id": 3,
//     "legend_name_key": "bodvar",
//     "bio_name": "B\u00f6dvar",
//     "bio_aka": "The Unconquered Viking, The Great Bear",
//     "bio_quote": "\"I speak, you noble vikings, of a warrior who surpassed you all. I tell of a great bear-man who overcame giants and armies, and of how he came to leave our world and challenge the Gods.\"",
//     "bio_quote_about_attrib": "\"                   -The Saga of B\u00f6dvar Bearson, first stanza\"",
//     "bio_quote_from": "\"Listen you nine-mothered bridge troll, I'm coming in, and the first beer I'm drinking is the one in your fist.\"",
//     "bio_quote_from_attrib": "\"                   -B\u00f6dvar to Heimdall, guardian of the gates of Asgard\"",
//     "bio_text": "Born of a viking mother and bear father, ...",
//     "bot_name": "B\u00f6tvar",
//     "weapon_one": "Hammer",
//     "weapon_two": "Sword",
//     "strength": "6",
//     "dexterity": "6",
//     "defense": "5",
//     "speed": "5"
// }

getWeapons() ===> Promise<ReadonlyArray<Weapon>>

Get all weapons from legends.

  1. Example Use
const config = {
  apiKey: 'YOUR-API-KEY',
}

const bhapi = new BrawlhallaAPI(config)

const weapons = await bhapi.getWeapons()

// [
//     { name: 'Hammer' },
//     { name: 'Sword' },
//     { name: 'Pistol' },
//     { name: 'RocketLance' },
//     { name: 'Spear' },
//     { name: 'Katar' },
//     { name: 'Axe' },
//     { name: 'Bow' },
//     { name: 'Fists' },
//     { name: 'Scythe' },
//     { name: 'Cannon' },
//     { name: 'Orb' },
//     { name: 'Greatsword' }
// ]

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE.txt for more information.

Contact

Tomas Melone - @tomzdotjs

Project Link: https://github.com/tomimelo/bhapi.js