Community Creation JavaScript Hive Api Library

Discussion in 'Development [Hive API and related]' started by Malte662, Jun 27, 2017.

  1. Lergin_

    Lergin_ The Bees Knees VIP

    Joined:
    Jan 3, 2014
    Messages:
    132
    Ratings:
    +179
    Node.js Hive Api Library

    A node.js wrapper for the api of https://hivemc.com, written in TypeScript and using Promises​

    I created this library to be able to use the api of the hive without needing to think about the requests and the sometimes inconsistent names. It automatically limits the amount of requests to the api server per minute and also caches the responses automatically (to get fresh data most functions have an argument with the maximum age the cache is allowed to have). I really recommend using the library with an IDE and TypeScript as this should give you proper autocompletion and typings so you know which properties everything has alternative there is also a generated Documentation available. To use this library on the serverside only a node.js installation (>= 7.8, async / await support) is needed and the library can easily be installed with npm.


    Installation
    Code:
    npm install hive-api
    Documentation

    https://lergin.github.io/hive-api/

    Note: some classes do not expose there properties in the documentation in the right way and only show them in the constructor

    Usage

    JavaScript
    Code:
    const hive = require('hive-api');
    
    let player = new hive.Player("Malte662");
    
    player.info().then(info => {
        console.log(`Tokens: ${info.tokens}`)
    });
    TypeScript
    Code:
    import {Player} from "hive-api";
    
    let player: Player = new Player("Malte662");
    
    player.info().then((info: PlayerInfo) => {
        console.log(`Tokens: ${info.tokens}`)
    });

    Examples

    Some examples are using async / await and therefor need to be wrapped into a async function. See: async_function


    Print the unique players of each game
    Code:
    import {GameTypes, GameType} from "hive-api";
    
    await GameTypes.update(); // update the list of GameTypes
    
    GameTypes.list.forEach((type: GameType) => {
        type.uniquePlayers().then((players) => {
            console.log(`${type.name}: ${players} players`);
        });
    });

    Get the global achievements of the winner of the latest survival games game
    Code:
    import {GameTypes, Game, SgGameInfo, PlayerInfo, ServerAchievement, AchievementInfo} from "hive-api";
    
    GameTypes.SG.latestGames()
        .then(games => games[0])
        .then((game: Game) => game.info())
        .then(async (gameInfo: SgGameInfo) => {
            let winnerInfo: PlayerInfo = await gameInfo.winner.info();
    
            winnerInfo.achievements.forEach((achievement: ServerAchievement) =>{
                achievement.info().then((info: AchievementInfo) => info.name)
                .then(console.log)
            });
        }).catch(console.error);

    List the names of the skywars maps
    Code:
    import {GameTypes, GameMap} from "hive-api";
    
    GameTypes.SKY.maps()
        .then((maps: GameMap[]) => maps.map((map: GameMap) => map.worldName))
        .then(console.log)

    Get the amount of Beds destroyed by Malte662 in Bedwars
    Code:
    import {Player, BedPlayerGameInfo, GameTypes} from "hive-api"
    
    let player: Player = new Player("Malte662");
    let playerBedInfo: BedPlayerGameInfo = (await player.gameInfo(GameTypes.BED)) as BedPlayerGameInfo;
    console.log(playerBedInfo.bedsDestroyed);

    Source Code and License

    The Source Code is available under the MIT License on GitHub: https://github.com/Lergin/hive-api

    Projects using the Api

    Issues / Suggestions

    If you have any suggestions or encounter any bugs feel free to leave a comment or create an issue on GitHub: https://github.com/Lergin/hive-api/issues
    Last edited: Aug 17, 2018
    #1
    • Award Worthy Award Worthy x 5
    • Like Like x 2
    • Useful Useful x 2
    • List
  2. The_BloodHound

    The_BloodHound V.I.BEE

    Joined:
    Mar 14, 2015
    Messages:
    3,049
    Ratings:
    +2,714
    I don't use NodeJS much but this looks very cool!
    #2
  3. Boxeh

    Boxeh The Bees Knees

    Joined:
    Jan 23, 2016
    Messages:
    1,179
    Ratings:
    +1,632
    I'm currently using Node.js for a project which includes Hive stuff, so thank you, this is amazing!
    I'll be sure to credit you once I've completed the project if you'd like that. :)
    #3
  4. Lergin_

    Lergin_ The Bees Knees VIP

    Joined:
    Jan 3, 2014
    Messages:
    132
    Ratings:
    +179
    A new version (1.1.0) has been released, it can be installed via npm install hive-api or updated with npm update hive-api

    #4
  5. Lergin_

    Lergin_ The Bees Knees VIP

    Joined:
    Jan 3, 2014
    Messages:
    132
    Ratings:
    +179
    A new version (1.3.0) has been released, it can be installed via npm install hive-api or updated with npm update hive-api. There also is a web version available at https://github.com/Lergin/hive-api/releases/tag/v1.3.0 or in the dist folder of the npm release.
    Some other changes that happened before 1.3.0:
    #5
  6. Lergin_

    Lergin_ The Bees Knees VIP

    Joined:
    Jan 3, 2014
    Messages:
    132
    Ratings:
    +179
    A new version (1.4.0) has been released, it can be installed via npm install hive-api or updated with npm update hive-api. There also is a web version available at https://github.com/Lergin/hive-api/releases/tag/v1.4.0 or in the dist folder of the npm release.
    #6
    • Award Worthy Award Worthy x 1
    • List
  7. Lergin_

    Lergin_ The Bees Knees VIP

    Joined:
    Jan 3, 2014
    Messages:
    132
    Ratings:
    +179
    A new version (1.6.0) has been released, it can be installed via npm install hive-api or updated with npm update hive-api. There also is a web version available at https://github.com/Lergin/hive-api/releases/tag/v1.6.0 or in the dist folder of the npm release.

    1.6.0
    • Updated DrPlayerGameInfo to contain mapKills, mapDeaths, trapClassKills and trapClassDeaths
    • Deprecated DrPlayerGameInfo's trapKills and trapDeaths properties

    1.5.0
    • added added date to maps
    #7
  8. Lergin_

    Lergin_ The Bees Knees VIP

    Joined:
    Jan 3, 2014
    Messages:
    132
    Ratings:
    +179
    A new version (1.7.0) has been released, it can be installed via npm install hive-api or updated with npm update hive-api. There also is a web version available at https://github.com/Lergin/hive-api/releases/tag/v1.7.0 or in the dist folder of the npm release.
    • Added noLongerOptainable property to AchievementInfo, this uses the list noLongerOptainableAchievementIds and the disabled to decide if an achievement is still optainable
    • Added TOKEN and BANNER as possible RewardTypes for achievements
    • Added Banner class to represent banners in the rewardArguments of AchievementInfos
    #8
  9. ThatTonybo

    ThatTonybo Regular Bee

    Joined:
    Aug 15, 2018
    Messages:
    23
    Ratings:
    +9
    The documentation link returns a GitHub Pages 404 for me, might want to fix that :p
    #9
  10. Lergin_

    Lergin_ The Bees Knees VIP

    Joined:
    Jan 3, 2014
    Messages:
    132
    Ratings:
    +179
    Oh yes github somehow isn't allowing me to use my custom domain, in the meantime you can find the documentation here: http://lergin.github.io/hive-api
    #10
  11. ThatTonybo

    ThatTonybo Regular Bee

    Joined:
    Aug 15, 2018
    Messages:
    23
    Ratings:
    +9
    Thanks :)
    #11
  12. Lergin_

    Lergin_ The Bees Knees VIP

    Joined:
    Jan 3, 2014
    Messages:
    132
    Ratings:
    +179
    A new version (1.8.0) has been released, it can be installed via npm install hive-api or updated with npm update hive-api. There also is a web version available at https://github.com/Lergin/hive-api/releases/tag/v1.8.0 or in the dist folder of the npm release.
    • added getBPServer() method to player to get the block party server the player is on if he has joined one currently
    • use proper names for BannerLayer
    • fixed loading of achievement infos
    • updated list of no longer obtainable Achievements
    #12
  13. Lergin_

    Lergin_ The Bees Knees VIP

    Joined:
    Jan 3, 2014
    Messages:
    132
    Ratings:
    +179
    A new version (1.9.0) has been released, it can be installed via npm install hive-api or updated with npm update hive-api. There also is a web version available at https://github.com/Lergin/hive-api/releases/tag/v1.9.0 or in the dist folder of the npm release.

    • added status() method to player that returns a PlayerStatus
    • added PlayerStatus, it contains the current area or game the player has joined and some utility methods see here
    • fixed title support for RR
    #13
  14. Lergin_

    Lergin_ The Bees Knees VIP

    Joined:
    Jan 3, 2014
    Messages:
    132
    Ratings:
    +179
    A new version (1.10.0) has been released, it can be installed via npm install hive-api or updated with npm update hive-api. There also is a web version available at https://github.com/Lergin/hive-api/releases/tag/v1.10.0 or in the dist folder of the npm release.

    • added title and winStreak to BedPlayerGameInfo
    • added support for group to GameTitle
    #14
  15. Lergin_

    Lergin_ The Bees Knees VIP

    Joined:
    Jan 3, 2014
    Messages:
    132
    Ratings:
    +179
    A new version (1.11.0) has been released, it can be installed via npm install hive-api or updated with npm update hive-api. There also is a web version available at https://github.com/Lergin/hive-api/releases/tag/v1.11.0 or in the dist folder of the npm release.

    • added support for subgametypes, thereby it is now supported to get e.g. player infos about BedWars:Solo by using GameTypes.BEDS or GameTypes.BED.subTypes() for a set of all subtypes.
    • thereby added BEDS, BEDD, BEDT and BEDX subtypes to BED
    • added support for special leaderboards (eg. win_streak for BED)
    • Leaderboards now should be loaded via GameType::leaderboard() or GameType::specialLeaderboard(key) otherwise subtypes wouldn't return the right data
    #15
  16. Lergin_

    Lergin_ The Bees Knees VIP

    Joined:
    Jan 3, 2014
    Messages:
    132
    Ratings:
    +179
    A new version (1.12.0) has been released, it can be installed via npm install hive-api or updated with npm update hive-api. There also is a web version available at https://github.com/Lergin/hive-api/releases/tag/v1.12.0 or in the dist folder of the npm release.

    • added support for the bedrock api
    #16

Share This Page