├── .gitignore ├── MIT-LICENSE ├── README.md ├── dist ├── battleNetWrapper.js ├── d3 │ ├── community.js │ └── gameData.js ├── hearthstone │ └── gameData.js ├── sc2 │ ├── community.js │ └── gameData.js ├── utils.js ├── wow │ ├── community.js │ ├── gameData.js │ └── profileData.js └── wowClassic │ └── gameData.js ├── index.js ├── package-lock.json ├── package.json ├── src ├── battleNetWrapper.ts ├── d3 │ ├── README.md │ ├── community.ts │ └── gameData.ts ├── hearthstone │ ├── README.md │ └── gameData.ts ├── sc2 │ ├── README.md │ ├── community.ts │ └── gameData.ts ├── utils.ts ├── wow │ ├── README.md │ ├── community.ts │ ├── gameData.ts │ └── profileData.ts └── wowClassic │ ├── README.md │ └── gameData.ts ├── tests ├── __mocks__ │ └── axios.js ├── battleNetWrapper.test.js ├── d3Community.test.js ├── d3GameData.test.js ├── hearthstoneGameData.test.js ├── sc2Community.test.js ├── sc2GameData.test.js ├── utils.test.js ├── wowClassicGameData.test.js ├── wowCommunity.test.js ├── wowGameData.test.js └── wowProfileData.test.js └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .idea 3 | test.js 4 | .DS_Store -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Shane Jeffery 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Battle.net API Wrapper 2 | 3 | [![Greenkeeper badge](https://badges.greenkeeper.io/QuadDamn/battlenet-api-wrapper.svg)](https://greenkeeper.io/) 4 | 5 | A promised-based Node.js wrapper for the Battle.net Community and Data APIs (supports WoW, WoW Classic, SC2, D3, and Hearthstone). 6 | 7 | ## Installation 8 | 9 | `$ npm install --save battlenet-api-wrapper` 10 | 11 | ## Prerequisites / General Information 12 | 13 | - To get your `Client ID` and `Client Secret` needed for this library, please refer to the steps in the [Battle.net API Getting Started documentation](https://develop.battle.net/documentation/guides/getting-started). 14 | - Battle.net API Documentation Reference: https://develop.battle.net/documentation 15 | 16 | ## Usage 17 | 18 | The basic implementation of this library is as follows: 19 | 20 | ``` 21 | const battleNetWrapper = require('battlenet-api-wrapper'); 22 | 23 | const clientId = 'YOUR_CLIENT_ID'; 24 | const clientSecret = 'YOUR_CLIENT_SECRET'; 25 | 26 | (async function() { 27 | const bnw = new battleNetWrapper(); 28 | await bnw.init(clientId, clientSecret); 29 | }()); 30 | ``` 31 | 32 | Once you have the `battleNetWrapper` class object instantiated, you then have access to all of the classes 33 | that exist under that umbrella. For each of the classes below, you will see a link to the full abstraction 34 | documentation. Each of functions are available on the respective class objects. 35 | 36 | - `bnw.Diablo3Community` [Usage Documentation](https://github.com/QuadDamn/battlenet-api-wrapper/tree/master/src/d3#diablo-3-community) 37 | - `bnw.Diablo3GameData` [Usage Documentation](https://github.com/QuadDamn/battlenet-api-wrapper/tree/master/src/d3#diablo-3-game-data) 38 | - `bnw.HearthstoneGameData` [Usage Documentation](https://github.com/QuadDamn/battlenet-api-wrapper/tree/master/src/hearthstone#hearthstone-game-data) 39 | - `bnw.Starcraft2Community` [Usage Documentation](https://github.com/QuadDamn/battlenet-api-wrapper/tree/master/src/sc2#starcraft-2-community) 40 | - `bnw.Starcraft2GameData` [Usage Documentation](https://github.com/QuadDamn/battlenet-api-wrapper/tree/master/src/sc2#starcraft-2-game-data) 41 | - `bnw.WowCommunity` [Usage Documentation](https://github.com/QuadDamn/battlenet-api-wrapper/tree/master/src/wow#wow-community) 42 | - `bnw.WowGameData` [Usage Documentation](https://github.com/QuadDamn/battlenet-api-wrapper/tree/master/src/wow#wow-game-data) 43 | - `bnw.WowProfileData` [Usage Documentation](https://github.com/QuadDamn/battlenet-api-wrapper/tree/master/src/wow#wow-profile-data) 44 | - `bnw.WowClassicGameData` [Usage Documentation](https://github.com/QuadDamn/battlenet-api-wrapper/tree/master/src/wowClassic#wow-classic-game-data) 45 | 46 | ## Having issues or have questions? 47 | 48 | [Post an issue](https://github.com/QuadDamn/battlenet-api-wrapper/issues) and it will be responded to ASAP! 49 | 50 | ## Want to contribute? 51 | 52 | Feel free! [Create a Pull Request](https://github.com/QuadDamn/battlenet-api-wrapper/pulls) and I'll review it ASAP! 53 | 54 | ## Todos 55 | 56 | - Add in test coverage. 57 | 58 | ## License 59 | 60 | Battle.net API Wrapper is released under the [MIT License](https://opensource.org/licenses/MIT). 61 | -------------------------------------------------------------------------------- /dist/battleNetWrapper.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | const axios_1 = require("axios"); 13 | const community_1 = require("./d3/community"); 14 | const gameData_1 = require("./d3/gameData"); 15 | const gameData_2 = require("./hearthstone/gameData"); 16 | const community_2 = require("./sc2/community"); 17 | const gameData_3 = require("./sc2/gameData"); 18 | const profileData_1 = require("./wow/profileData"); 19 | const gameData_4 = require("./wow/gameData"); 20 | const community_3 = require("./wow/community"); 21 | const gameData_5 = require("./wowClassic/gameData"); 22 | class BattleNetWrapper { 23 | // Unused constructor as we needed the ability to async the initialization 24 | // and await all of the underlying promises. 25 | constructor() { 26 | this.originObject = { 27 | us: { 28 | hostname: 'https://us.api.blizzard.com', 29 | defaultLocale: 'en_US', 30 | locales: ['en_US', 'es_MX', 'pt_BR', 'multi'], 31 | }, 32 | eu: { 33 | hostname: 'https://eu.api.blizzard.com', 34 | defaultLocale: 'en_GB', 35 | locales: ['en_GB', 'es_ES', 'fr_FR', 'ru_RU', 'de_DE', 'pt_PT', 'it_IT', 'multi'], 36 | }, 37 | sea: { 38 | hostname: 'https://sea.api.blizzard.com', 39 | defaultLocale: 'en_US', 40 | locales: ['en_US', 'multi'], 41 | }, 42 | kr: { 43 | hostname: 'https://kr.api.blizzard.com', 44 | defaultLocale: 'ko_KR', 45 | locales: ['ko_KR', 'en_GB', 'en_US', 'multi'], 46 | }, 47 | tw: { 48 | hostname: 'https://tw.api.blizzard.com', 49 | defaultLocale: 'zh_TW', 50 | locales: ['zh_TW', 'en_GB', 'en_US', 'multi'], 51 | }, 52 | cn: { 53 | hostname: 'https://gateway.battlenet.com.cn', 54 | defaultLocale: 'zh_CN', 55 | locales: ['zh_CN', 'en_GB', 'en_US', 'multi'], 56 | } 57 | }; 58 | } 59 | init(clientId, clientSecret, origin = 'us', locale = 'en_US') { 60 | return __awaiter(this, void 0, void 0, function* () { 61 | if (!clientId) 62 | throw new Error('You are missing your Client ID in the passed parameters. This parameter is required.'); 63 | if (!clientSecret) 64 | throw new Error('You are missing your Client Secret in the passed parameters. This parameter is required.'); 65 | this.origin = origin; 66 | this.locale = locale; 67 | this.clientId = clientId; 68 | this.clientSecret = clientSecret; 69 | this.defaultAxiosParams = { 70 | locale: this.locale 71 | }; 72 | // Handles the fetching of a new OAuth token from the Battle.net API 73 | // and then creates a reusable instance of axios for all subsequent API requests. 74 | try { 75 | this.axios = axios_1.default.create({ 76 | baseURL: this.originObject[this.origin].hostname, 77 | params: this.defaultAxiosParams 78 | }); 79 | yield this.setOAuthToken(); 80 | this.axios.defaults.headers.common['Authorization'] = `Bearer ${this.oauthToken}`; 81 | } 82 | catch (error) { 83 | console.log(error); 84 | } 85 | this.Diablo3Community = new community_1.default(this.axios); 86 | this.Diablo3GameData = new gameData_1.default(this.axios); 87 | this.HearthstoneGameData = new gameData_2.default(this.axios, this.defaultAxiosParams); 88 | this.Starcraft2Community = new community_2.default(this.axios); 89 | this.Starcraft2GameData = new gameData_3.default(this.axios); 90 | this.WowCommunity = new community_3.default(this.axios, this.defaultAxiosParams); 91 | this.WowGameData = new gameData_4.default(this.axios, this.defaultAxiosParams, this.origin); 92 | this.WowProfileData = new profileData_1.default(this.axios, this.defaultAxiosParams, this.origin); 93 | this.WowClassicGameData = new gameData_5.default(this.axios, this.defaultAxiosParams, this.origin); 94 | }); 95 | } 96 | // Sets a new access token for all of the subsequent API requests. 97 | // Every invocation of this method will create a new access token, 98 | // so you should never have to worry about the token ever expiring. 99 | setOAuthToken() { 100 | return __awaiter(this, void 0, void 0, function* () { 101 | try { 102 | const response = yield axios_1.default.get(`https://${this.origin}.battle.net/oauth/token`, { 103 | auth: { 104 | username: this.clientId, 105 | password: this.clientSecret, 106 | }, 107 | params: { 108 | grant_type: 'client_credentials', 109 | }, 110 | }); 111 | this.oauthToken = response.data.access_token; 112 | } 113 | catch (error) { 114 | console.log(error); 115 | throw new Error(`Problem getting the OAuth token from the Blizzard API. 116 | Please check that your Client ID and Secret are correct.`); 117 | } 118 | }); 119 | } 120 | } 121 | module.exports = BattleNetWrapper; 122 | -------------------------------------------------------------------------------- /dist/d3/community.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Diablo 3 Community API documentation: https://develop.battle.net/documentation/diablo-3/community-apis 3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 4 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 5 | return new (P || (P = Promise))(function (resolve, reject) { 6 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 7 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 8 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 9 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 10 | }); 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | const utils_1 = require("../utils"); 14 | class Diablo3Community { 15 | constructor(axiosInstance) { 16 | this.gameBaseUrlPath = '/d3/data'; 17 | this.axios = axiosInstance; 18 | } 19 | /**************************** 20 | * Act API 21 | ****************************/ 22 | /** 23 | * Returns an index of acts. 24 | */ 25 | getActIndex() { 26 | return __awaiter(this, void 0, void 0, function* () { 27 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/act`, 'Error fetching the act index.'); 28 | }); 29 | } 30 | /** 31 | * Returns a single act by ID. 32 | * 33 | * @param actId The ID of the act to retrieve. 34 | */ 35 | getAct(actId) { 36 | return __awaiter(this, void 0, void 0, function* () { 37 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/act/${actId}`, 'Error fetching the specified act.'); 38 | }); 39 | } 40 | /**************************** 41 | * Artisan and Recipe API 42 | ****************************/ 43 | /** 44 | * Returns a single artisan by slug. 45 | * 46 | * @param artisanSlug The slug of the artisan to retrieve. 47 | */ 48 | getArtisan(artisanSlug) { 49 | return __awaiter(this, void 0, void 0, function* () { 50 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/artisan/${artisanSlug}`, 'Error fetching the specified artisan.'); 51 | }); 52 | } 53 | /** 54 | * Returns a single recipe by slug for the specified artisan. 55 | * 56 | * @param artisanSlug The slug of the artisan to retrieve. 57 | * @param recipeSlug The slug of the recipe to retrieve. 58 | */ 59 | getRecipe(artisanSlug, recipeSlug) { 60 | return __awaiter(this, void 0, void 0, function* () { 61 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/artisan/${artisanSlug}/recipe/${recipeSlug}`, 'Error fetching specified recipe.'); 62 | }); 63 | } 64 | /**************************** 65 | * Follower API 66 | ****************************/ 67 | /** 68 | * Returns a single follower by slug. 69 | * 70 | * @param followerSlug The slug of the follower to retrieve. 71 | */ 72 | getFollower(followerSlug) { 73 | return __awaiter(this, void 0, void 0, function* () { 74 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/follower/${followerSlug}`, 'Error fetching the specified follower.'); 75 | }); 76 | } 77 | /**************************** 78 | * Character Class & Skill API 79 | ****************************/ 80 | /** 81 | * Returns a single character class by slug. 82 | * 83 | * @param classSlug The slug of the character class to retrieve. 84 | */ 85 | getCharacterClass(classSlug) { 86 | return __awaiter(this, void 0, void 0, function* () { 87 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/hero/${classSlug}`, 'Error fetching specified hero class.'); 88 | }); 89 | } 90 | /** 91 | * Returns a single skill by slug for a specific character class. 92 | * 93 | * @param classSlug The slug of the character class to retrieve. 94 | * @param skillSlug The slug of the skill to retrieve. 95 | */ 96 | getApiSkill(classSlug, skillSlug) { 97 | return __awaiter(this, void 0, void 0, function* () { 98 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/hero/${classSlug}/skill/${skillSlug}`, 'Error fetching specified hero class skill.'); 99 | }); 100 | } 101 | /**************************** 102 | * Item Type API 103 | ****************************/ 104 | /** 105 | * Returns an index of item types. 106 | */ 107 | getItemTypeIndex() { 108 | return __awaiter(this, void 0, void 0, function* () { 109 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/item-type`, 'Error fetching the item type index.'); 110 | }); 111 | } 112 | /** 113 | * Returns a single item type by slug. 114 | * 115 | * @param itemTypeSlug The slug of the item type to retrieve. 116 | */ 117 | getItemType(itemTypeSlug) { 118 | return __awaiter(this, void 0, void 0, function* () { 119 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/item-type/${itemTypeSlug}`, 'Error fetching the specified item type.'); 120 | }); 121 | } 122 | /**************************** 123 | * Item API 124 | ****************************/ 125 | /** 126 | * Returns a single item by item slug and ID. 127 | * 128 | * @param itemSlugAndId The slug and ID of the item to retrieve. 129 | */ 130 | getItem(itemSlugAndId) { 131 | return __awaiter(this, void 0, void 0, function* () { 132 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/item/${itemSlugAndId}`, 'Error fetching the specified item.'); 133 | }); 134 | } 135 | /**************************** 136 | * Profile API 137 | ****************************/ 138 | /** 139 | * Returns the specified account profile. 140 | * 141 | * IMPORTANT NOTE: Battletag is case-sensitive and will result in a 404 error response if it doesn't 142 | * match perfectly with what Blizzard has on record. 143 | * 144 | * @param account The BattleTag for the account to retrieve. 145 | */ 146 | getApiAccount(account) { 147 | return __awaiter(this, void 0, void 0, function* () { 148 | const formattedBattleTag = yield utils_1.formatBattleTag(account); 149 | return yield this._handleApiCall(`/d3/profile/${formattedBattleTag}/`, 'Error fetching profile information.'); 150 | }); 151 | } 152 | /** 153 | * Returns a single hero. 154 | * 155 | * IMPORTANT NOTE: Battletag is case-sensitive and will result in a 404 error response if it doesn't 156 | * match perfectly with what Blizzard has on record. 157 | * 158 | * @param account The BattleTag for the account to retrieve. 159 | * @param heroId The ID of the hero to retrieve. 160 | */ 161 | getApiHero(account, heroId) { 162 | return __awaiter(this, void 0, void 0, function* () { 163 | const formattedBattleTag = yield utils_1.formatBattleTag(account); 164 | return yield this._handleApiCall(`/d3/profile/${formattedBattleTag}/hero/${heroId}`, 'Error fetching specified hero.'); 165 | }); 166 | } 167 | /** 168 | * Returns a list of items for the specified hero. 169 | * 170 | * IMPORTANT NOTE: Battletag is case-sensitive and will result in a 404 error response if it doesn't 171 | * match perfectly with what Blizzard has on record. 172 | * 173 | * @param account The BattleTag for the account to retrieve. 174 | * @param heroId The ID of the hero to retrieve. 175 | */ 176 | getApiDetailedHeroItems(account, heroId) { 177 | return __awaiter(this, void 0, void 0, function* () { 178 | const formattedBattleTag = yield utils_1.formatBattleTag(account); 179 | return yield this._handleApiCall(`/d3/profile/${formattedBattleTag}/hero/${heroId}/items`, 'Error fetching specified hero items.'); 180 | }); 181 | } 182 | /** 183 | * Returns a list of items for the specified hero's followers. 184 | * 185 | * IMPORTANT NOTE: Battletag is case-sensitive and will result in a 404 error response if it doesn't 186 | * match perfectly with what Blizzard has on record. 187 | * 188 | * @param account The BattleTag for the account to retrieve. 189 | * @param heroId The ID of the hero to retrieve. 190 | */ 191 | getApiDetailedFollowerItems(account, heroId) { 192 | return __awaiter(this, void 0, void 0, function* () { 193 | const formattedBattleTag = yield utils_1.formatBattleTag(account); 194 | return yield this._handleApiCall(`/d3/profile/${formattedBattleTag}/hero/${heroId}/follower-items`, 'Error fetching specified hero follower items.'); 195 | }); 196 | } 197 | /******************************** 198 | * Private Class Helper Functions 199 | ********************************/ 200 | _handleApiCall(apiUrl, errorMessage) { 201 | return __awaiter(this, void 0, void 0, function* () { 202 | try { 203 | const response = yield this.axios.get(encodeURI(apiUrl)); 204 | return response.data; 205 | } 206 | catch (error) { 207 | console.log(error); 208 | throw new Error(`Diablo 3 Community Error :: ${errorMessage}`); 209 | } 210 | }); 211 | } 212 | } 213 | exports.default = Diablo3Community; 214 | -------------------------------------------------------------------------------- /dist/d3/gameData.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Diablo 3 Game Data API documentation: https://develop.battle.net/documentation/diablo-3/game-data-apis 3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 4 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 5 | return new (P || (P = Promise))(function (resolve, reject) { 6 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 7 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 8 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 9 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 10 | }); 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | class Diablo3GameData { 14 | constructor(axiosInstance) { 15 | this.gameBaseUrlPath = '/data/d3'; 16 | this.axios = axiosInstance; 17 | } 18 | /** 19 | * Returns an index of available seasons. 20 | */ 21 | getSeasonIndex() { 22 | return __awaiter(this, void 0, void 0, function* () { 23 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/season`, 'Error fetching the season index.'); 24 | }); 25 | } 26 | /** 27 | * Returns a leaderboard list for the specified season. 28 | * 29 | * @param seasonId The season for the leaderboard list; get a list of seasons with `getSeasonIndex`. 30 | */ 31 | getSeason(seasonId) { 32 | return __awaiter(this, void 0, void 0, function* () { 33 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/season/${seasonId}`, 'Error fetching the specified season.'); 34 | }); 35 | } 36 | /** 37 | * Returns a the specified leaderboard for the specified season. 38 | * 39 | * @param seasonId The season for the leaderboard; get a list of seasons with `getSeasonIndex`. 40 | * @param leaderboardId The leaderboard to retrieve; get a list of leaderboards with `getSeason`. 41 | */ 42 | getSeasonLeaderboard(seasonId, leaderboardId) { 43 | return __awaiter(this, void 0, void 0, function* () { 44 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/season/${seasonId}/leaderboard/${leaderboardId}`, 'Error fetching the specified season leaderboard.'); 45 | }); 46 | } 47 | /** 48 | * Returns an index of available eras. 49 | */ 50 | getEraIndex() { 51 | return __awaiter(this, void 0, void 0, function* () { 52 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/era`, 'Error fetching the era index.'); 53 | }); 54 | } 55 | /** 56 | * Returns a leaderboard list for a particular era. 57 | * 58 | * @param eraId The era to retrieve; get a list of eras with `getEraIndex`. 59 | */ 60 | getEra(eraId) { 61 | return __awaiter(this, void 0, void 0, function* () { 62 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/era/${eraId}`, 'Error fetching the specified era.'); 63 | }); 64 | } 65 | /** 66 | * Returns the specified leaderboard for the specified era. 67 | * 68 | * @param eraId The era for the leaderboard; get a list of eras with `getEraIndex`. 69 | * @param leaderboardId The leaderboard to retrieve; get a list of leaderboards with `getEra`. 70 | */ 71 | getEraLeaderboard(eraId, leaderboardId) { 72 | return __awaiter(this, void 0, void 0, function* () { 73 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/era/${eraId}/leaderboard/${leaderboardId}`, 'Error fetching the specified era leaderboard.'); 74 | }); 75 | } 76 | /******************************** 77 | * Private Class Helper Functions 78 | ********************************/ 79 | _handleApiCall(apiUrl, errorMessage) { 80 | return __awaiter(this, void 0, void 0, function* () { 81 | try { 82 | const response = yield this.axios.get(encodeURI(apiUrl)); 83 | return response.data; 84 | } 85 | catch (error) { 86 | console.log(error); 87 | throw new Error(`Diablo 3 Game Data Error :: ${errorMessage}`); 88 | } 89 | }); 90 | } 91 | } 92 | exports.default = Diablo3GameData; 93 | -------------------------------------------------------------------------------- /dist/hearthstone/gameData.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Hearthstone Game Data API documentation: https://develop.battle.net/documentation/hearthstone/game-data-apis 3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 4 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 5 | return new (P || (P = Promise))(function (resolve, reject) { 6 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 7 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 8 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 9 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 10 | }); 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | class HearthstoneGameData { 14 | constructor(axiosInstance, defaultAxiosParams) { 15 | this.gameBaseUrlPath = '/hearthstone'; 16 | this.axios = axiosInstance; 17 | this.defaultAxiosParams = defaultAxiosParams; 18 | } 19 | /**************************** 20 | * Cards API 21 | ****************************/ 22 | /** 23 | * Returns all of the cards that match the passed parameters. 24 | * 25 | * @param searchParams 26 | */ 27 | searchCards(searchParams) { 28 | return __awaiter(this, void 0, void 0, function* () { 29 | try { 30 | const response = yield this.axios.get(`${this.gameBaseUrlPath}/cards`, { 31 | params: Object.assign(Object.assign({}, searchParams), this.defaultAxiosParams) 32 | }); 33 | return response.data; 34 | } 35 | catch (error) { 36 | console.log(error); 37 | throw new Error('Error fetching cards that matched the passed parameters.'); 38 | } 39 | }); 40 | } 41 | /** 42 | * Returns the card with an ID or slug that matches the one you specify. 43 | * 44 | * @param cardSlug An ID or slug that uniquely identifies a card. You can discover these values by using the `/hearthstone/cards` search endpoint. 45 | */ 46 | getCard(cardSlug) { 47 | return __awaiter(this, void 0, void 0, function* () { 48 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/cards/${cardSlug}`, 'Error fetching the specified card.'); 49 | }); 50 | } 51 | /**************************** 52 | * Decks API 53 | ****************************/ 54 | /** 55 | * Finds a deck by its deck code. 56 | * 57 | * @param deckCode A code that identifies a deck. You can copy one from the game or various Hearthstone websites. 58 | */ 59 | getDeck(deckCode) { 60 | return __awaiter(this, void 0, void 0, function* () { 61 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/deck/${deckCode}`, 'Error fetching the specified deck.'); 62 | }); 63 | } 64 | /**************************** 65 | * Metadata API 66 | ****************************/ 67 | /** 68 | * Returns information about the categorization of cards. Metadata includes the card set, 69 | * set group (for example, Standard or Year of the Dragon), rarity, class, card type, minion type, and keywords. 70 | */ 71 | getMetadata() { 72 | return __awaiter(this, void 0, void 0, function* () { 73 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/metadata`, 'Error fetching the metadata.'); 74 | }); 75 | } 76 | /** 77 | * Returns information about just one type of metadata. 78 | * 79 | * @param type The type of the metadata to retrieve. Valid values include sets, setGroups, types, 80 | * rarities, classes, minionTypes, and keywords. 81 | */ 82 | getSpecificMetadata(type) { 83 | return __awaiter(this, void 0, void 0, function* () { 84 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/metadata/${type}`, 'Error fetching the specified metadata.'); 85 | }); 86 | } 87 | /******************************** 88 | * Private Class Helper Functions 89 | ********************************/ 90 | _handleApiCall(apiUrl, errorMessage) { 91 | return __awaiter(this, void 0, void 0, function* () { 92 | try { 93 | const response = yield this.axios.get(encodeURI(apiUrl)); 94 | return response.data; 95 | } 96 | catch (error) { 97 | console.log(error); 98 | throw new Error(`Hearthstone Game Data Error :: ${errorMessage}`); 99 | } 100 | }); 101 | } 102 | } 103 | exports.default = HearthstoneGameData; 104 | -------------------------------------------------------------------------------- /dist/sc2/community.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Starcraft 2 Community API documentation: https://develop.battle.net/documentation/starcraft-2/community-apis 3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 4 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 5 | return new (P || (P = Promise))(function (resolve, reject) { 6 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 7 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 8 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 9 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 10 | }); 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | class Starcraft2Community { 14 | constructor(axiosInstance) { 15 | this.gameBaseUrlPath = '/sc2'; 16 | this.axios = axiosInstance; 17 | } 18 | /**************************** 19 | * Profile API 20 | ****************************/ 21 | /** 22 | * Returns all static SC2 profile data (achievements, categories, criteria, and rewards). 23 | * 24 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 25 | */ 26 | getStaticProfileData(regionId) { 27 | return __awaiter(this, void 0, void 0, function* () { 28 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/static/profile/${regionId}`, 'Error fetching static profile data for the specified region.'); 29 | }); 30 | } 31 | /** 32 | * Returns metadata for an individual's profile. 33 | * 34 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 35 | * @param realmId The region of the profile (`1` or `2`). 36 | * @param profileId The profile ID. 37 | */ 38 | getMetadata(regionId, realmId, profileId) { 39 | return __awaiter(this, void 0, void 0, function* () { 40 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/static/profile/${regionId}/${realmId}/${profileId}`, 'Error fetching profile data for the specified region.'); 41 | }); 42 | } 43 | /** 44 | * Returns data about an individual SC2 profile. 45 | * 46 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 47 | * @param realmId The region of the profile (`1` or `2`). 48 | * @param profileId The profile ID. 49 | */ 50 | getProfile(regionId, realmId, profileId) { 51 | return __awaiter(this, void 0, void 0, function* () { 52 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/profile/${regionId}/${realmId}/${profileId}`, 'Error fetching specified profile data.'); 53 | }); 54 | } 55 | /** 56 | * Returns a ladder summary for an individual SC2 profile. 57 | * 58 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 59 | * @param realmId The region of the profile (`1` or `2`). 60 | * @param profileId The profile ID. 61 | */ 62 | getLadderSummary(regionId, realmId, profileId) { 63 | return __awaiter(this, void 0, void 0, function* () { 64 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/profile/${regionId}/${realmId}/${profileId}/ladder/summary`, 'Error fetching specified ladder summary.'); 65 | }); 66 | } 67 | /** 68 | * Returns data about an individual profile's ladder. 69 | * 70 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 71 | * @param realmId The region of the profile (`1` or `2`). 72 | * @param profileId The profile ID. 73 | * @param ladderId The ID of the ladder for which to retrieve data. 74 | */ 75 | getLadder(regionId, realmId, profileId, ladderId) { 76 | return __awaiter(this, void 0, void 0, function* () { 77 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/profile/${regionId}/${realmId}/${profileId}/ladder/${ladderId}`, 'Error fetching specified ladder.'); 78 | }); 79 | } 80 | /**************************** 81 | * Ladder API 82 | ****************************/ 83 | /** 84 | * Returns ladder data for the current season's grandmaster leaderboard. 85 | * 86 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 87 | */ 88 | getGrandmasterLeaderboard(regionId) { 89 | return __awaiter(this, void 0, void 0, function* () { 90 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/ladder/grandmaster/${regionId}`, 'Error fetching static profile data for the specified region.'); 91 | }); 92 | } 93 | /** 94 | * Returns data about the current season. 95 | * 96 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 97 | */ 98 | getSeason(regionId) { 99 | return __awaiter(this, void 0, void 0, function* () { 100 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/ladder/season/${regionId}`, 'Error fetching static profile data for the specified region.'); 101 | }); 102 | } 103 | /**************************** 104 | * Account API 105 | ****************************/ 106 | /** 107 | * Returns metadata for an individual's account. 108 | * 109 | * @param accountId The ID of the account for which to retrieve data. 110 | */ 111 | getPlayer(accountId) { 112 | return __awaiter(this, void 0, void 0, function* () { 113 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/player/${accountId}`, 'Error fetching metadata for player account.'); 114 | }); 115 | } 116 | /**************************** 117 | * Legacy API 118 | ****************************/ 119 | /** 120 | * Retrieves data about an individual SC2 profile. 121 | * 122 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 123 | * @param realmId The region of the profile (`1` or `2`). 124 | * @param profileId The profile ID. 125 | */ 126 | getLegacyProfile(regionId, realmId, profileId) { 127 | return __awaiter(this, void 0, void 0, function* () { 128 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/legacy/profile/${regionId}/${realmId}/${profileId}`, 'Error fetching specified legacy profile data.'); 129 | }); 130 | } 131 | /** 132 | * Retrieves data about an individual SC2 profile's ladders. 133 | * 134 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 135 | * @param realmId The region of the profile (`1` or `2`). 136 | * @param profileId The profile ID. 137 | */ 138 | getLegacyProfileLadders(regionId, realmId, profileId) { 139 | return __awaiter(this, void 0, void 0, function* () { 140 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/legacy/profile/${regionId}/${realmId}/${profileId}/ladders`, 'Error fetching specified legacy profile ladder data.'); 141 | }); 142 | } 143 | /** 144 | * Returns data about an individual SC2 profile's match history. 145 | * 146 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 147 | * @param realmId The region of the profile (`1` or `2`). 148 | * @param profileId The profile ID. 149 | */ 150 | getLegacyProfileMatches(regionId, realmId, profileId) { 151 | return __awaiter(this, void 0, void 0, function* () { 152 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/legacy/profile/${regionId}/${realmId}/${profileId}/matches`, 'Error fetching specified legacy profile match data.'); 153 | }); 154 | } 155 | /** 156 | * Returns data about the achievements available in SC2. 157 | * 158 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 159 | */ 160 | getLegacyAchievements(regionId) { 161 | return __awaiter(this, void 0, void 0, function* () { 162 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/legacy/data/achievements/${regionId}`, 'Error fetching specified legacy achievement data.'); 163 | }); 164 | } 165 | /** 166 | * Returns data about the rewards available in SC2. 167 | * 168 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 169 | */ 170 | getLegacyRewards(regionId) { 171 | return __awaiter(this, void 0, void 0, function* () { 172 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/legacy/data/rewards/${regionId}`, 'Error fetching specified legacy rewards data.'); 173 | }); 174 | } 175 | /******************************** 176 | * Private Class Helper Functions 177 | ********************************/ 178 | _handleApiCall(apiUrl, errorMessage) { 179 | return __awaiter(this, void 0, void 0, function* () { 180 | try { 181 | const response = yield this.axios.get(encodeURI(apiUrl)); 182 | return response.data; 183 | } 184 | catch (error) { 185 | console.log(error); 186 | throw new Error(`Starcraft 2 Community Error :: ${errorMessage}`); 187 | } 188 | }); 189 | } 190 | } 191 | exports.default = Starcraft2Community; 192 | -------------------------------------------------------------------------------- /dist/sc2/gameData.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Starcraft 2 Game Data API documentation: https://develop.battle.net/documentation/starcraft-2/game-data-apis 3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 4 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 5 | return new (P || (P = Promise))(function (resolve, reject) { 6 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 7 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 8 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 9 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 10 | }); 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | class Starcraft2GameData { 14 | constructor(axiosInstance) { 15 | this.gameBaseUrlPath = '/data/sc2'; 16 | this.axios = axiosInstance; 17 | } 18 | /** 19 | * Returns data for the specified season, queue, team, and league. 20 | * 21 | * **queueId**: the standard available queueIds are: 22 | * `1`=WoL 1v1, `2`=WoL 2v2, `3`=WoL 3v3, `4`=WoL 4v4, `101`=HotS 1v1, `102`=HotS 2v2, `103`=HotS 3v3, `104`=HotS 4v4, 23 | * `201`=LotV 1v1, `202`=LotV 2v2, `203`=LotV 3v3, `204`=LotV 4v4, `206`=LotV Archon. 24 | * 25 | * Note that other available queues may not be listed here. 26 | * 27 | * **teamType**: there are two available teamTypes: `0`=arranged, `1`=random. **leagueId**: 28 | * available leagueIds are: `0`=Bronze, `1`=Silver, `2`=Gold, `3`=Platinum, `4`=Diamond, `5`=Master, `6`=Grandmaster. 29 | * 30 | * @param seasonId The season ID of the data to retrieve. 31 | * @param queueId The queue ID of the data to retrieve. 32 | * @param teamType The team type of the data to retrieve. 33 | * @param leagueId The league ID of the data to retrieve. 34 | */ 35 | getLeagueData(seasonId, queueId, teamType, leagueId) { 36 | return __awaiter(this, void 0, void 0, function* () { 37 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/league/${seasonId}/${queueId}/${teamType}/${leagueId}`, 'Error fetching the league data.'); 38 | }); 39 | } 40 | /******************************** 41 | * Private Class Helper Functions 42 | ********************************/ 43 | _handleApiCall(apiUrl, errorMessage) { 44 | return __awaiter(this, void 0, void 0, function* () { 45 | try { 46 | const response = yield this.axios.get(encodeURI(apiUrl)); 47 | return response.data; 48 | } 49 | catch (error) { 50 | console.log(error); 51 | throw new Error(`Starcraft 2 Game Data Error :: ${errorMessage}`); 52 | } 53 | }); 54 | } 55 | } 56 | exports.default = Starcraft2GameData; 57 | -------------------------------------------------------------------------------- /dist/utils.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | function formatBattleTag(battleTag) { 13 | return __awaiter(this, void 0, void 0, function* () { 14 | return battleTag.replace('#', '-'); 15 | }); 16 | } 17 | exports.formatBattleTag = formatBattleTag; 18 | -------------------------------------------------------------------------------- /dist/wow/community.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // WoW Game Data API documentation: https://develop.battle.net/documentation/world-of-warcraft/game-data-apis 3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 4 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 5 | return new (P || (P = Promise))(function (resolve, reject) { 6 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 7 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 8 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 9 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 10 | }); 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | class WowCommunity { 14 | constructor(axiosInstance, defaultAxiosParams) { 15 | this.gameBaseUrlPath = '/wow'; 16 | this.axios = axiosInstance; 17 | this.defaultAxiosParams = defaultAxiosParams; 18 | } 19 | /**************************** 20 | * Achievement API 21 | ****************************/ 22 | /** 23 | * Returns data about an individual achievement. 24 | * 25 | * @param achievementId The ID of the achievement to retrieve. 26 | */ 27 | getAchievement(achievementId) { 28 | return __awaiter(this, void 0, void 0, function* () { 29 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/achievement/${achievementId}`, 'Error fetching specified achievement.'); 30 | }); 31 | } 32 | /**************************** 33 | * Boss API 34 | ****************************/ 35 | /** 36 | * Returns a list of all supported bosses. A "boss" in this context should be considered a boss encounter, 37 | * which may include more than one NPC. 38 | */ 39 | getBossMasterList() { 40 | return __awaiter(this, void 0, void 0, function* () { 41 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/boss`, 'Error fetching master boss list.'); 42 | }); 43 | } 44 | /** 45 | * Returns information about the specified boss. A "boss" in this context should be considered a boss encounter, 46 | * which may include more than one NPC. 47 | * 48 | * @param bossId The ID of the boss to retrieve. 49 | */ 50 | getBoss(bossId) { 51 | return __awaiter(this, void 0, void 0, function* () { 52 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/boss/${bossId}`, 'Error fetching specified boss.'); 53 | }); 54 | } 55 | /**************************** 56 | * Challenge Mode API 57 | ****************************/ 58 | /** 59 | * The request returns data for all nine challenge mode maps (currently). The map field includes the current medal 60 | * times for each dungeon. Each ladder provides data about each character that was part of each run. The 61 | * character data includes the current cached specialization of the character while the member field includes the 62 | * specialization of the character during the challenge mode run. 63 | * 64 | * @param realmSlug The realm to request. 65 | */ 66 | getChallengeModeRealmLeaderboard(realmSlug) { 67 | return __awaiter(this, void 0, void 0, function* () { 68 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/challenge/${realmSlug}`, 'Error fetching challenge mode realm leaderboard.'); 69 | }); 70 | } 71 | /** 72 | * The region leaderboard has the exact same data format as the realm leaderboards except there is no `realm` field. 73 | * Instead, the response has the top 100 results gathered for each map for all of the available realm leaderboards 74 | * in a region. 75 | */ 76 | getChallengeModeRegionLeaderboard() { 77 | return __awaiter(this, void 0, void 0, function* () { 78 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/challenge/region`, 'Error fetching challenge mode region leaderboard.'); 79 | }); 80 | } 81 | /**************************** 82 | * Character Profile API 83 | ****************************/ 84 | /** 85 | * Returns a character profile. In order to get additional fields, you have to specify them in the fields parameter 86 | * as comma-delimited list. 87 | * 88 | * Your options for the fields are: 89 | * 90 | * achievements, appearance, feed, guild, hunterPets, items, mounts, pets, petSlots, professions, progression, 91 | * pvp, quests, reputation, statistics, stats, talents, titles, audit. 92 | * 93 | * @param realm The character's realm. Can be provided as the proper realm name or the normalized realm name. 94 | * @param characterName The name of the character to retrieve. 95 | * @param fields Specifies the data to retrieve. 96 | */ 97 | getCharacterProfile(realm, characterName, fields) { 98 | return __awaiter(this, void 0, void 0, function* () { 99 | try { 100 | const response = yield this.axios.get(encodeURI(`${this.gameBaseUrlPath}/character/${realm}/${characterName}`), { 101 | params: Object.assign({ fields: fields }, this.defaultAxiosParams) 102 | }); 103 | return response.data; 104 | } 105 | catch (error) { 106 | console.log(error); 107 | throw new Error(`WoW Community Error :: Error fetching character profile.`); 108 | } 109 | }); 110 | } 111 | /**************************** 112 | * Guild API 113 | ****************************/ 114 | /** 115 | * Returns a guild profile. In order to get additional fields, you have to specify them in the fields parameter 116 | * as comma-delimited list. 117 | * 118 | * Your options for the fields are: 119 | * 120 | * achievements, challenges, members, news 121 | * 122 | * @param realm The guild's realm. 123 | * @param guildName The name of the guild to query. 124 | * @param fields The optional data to retrieve about the guild. 125 | */ 126 | getGuildProfile(realm, guildName, fields) { 127 | return __awaiter(this, void 0, void 0, function* () { 128 | try { 129 | const response = yield this.axios.get(encodeURI(`${this.gameBaseUrlPath}/guild/${realm}/${guildName}`), { 130 | params: Object.assign({ fields: fields }, this.defaultAxiosParams) 131 | }); 132 | return response.data; 133 | } 134 | catch (error) { 135 | console.log(error); 136 | throw new Error(`WoW Community Error :: Error fetching guild profile.`); 137 | } 138 | }); 139 | } 140 | /**************************** 141 | * Item API 142 | ****************************/ 143 | /** 144 | * Returns detailed information about the item. 145 | * 146 | * @param itemId The requested item's unique ID. 147 | */ 148 | getItem(itemId) { 149 | return __awaiter(this, void 0, void 0, function* () { 150 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/item/${itemId}`, 'Error fetching specified item.'); 151 | }); 152 | } 153 | /** 154 | * Returns detailed information about the item set. 155 | * 156 | * @param setId The requested set's unique ID. 157 | */ 158 | getItemSet(setId) { 159 | return __awaiter(this, void 0, void 0, function* () { 160 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/item/set/${setId}`, 'Error fetching specified item set.'); 161 | }); 162 | } 163 | /**************************** 164 | * Mount API 165 | ****************************/ 166 | /** 167 | * Returns a list of all supported mounts. 168 | */ 169 | getMountMasterList() { 170 | return __awaiter(this, void 0, void 0, function* () { 171 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/mount`, 'Error fetching mount master list'); 172 | }); 173 | } 174 | /**************************** 175 | * Pet API 176 | ****************************/ 177 | /** 178 | * Returns a list of all supported battle and vanity pets. 179 | */ 180 | getPetMasterList() { 181 | return __awaiter(this, void 0, void 0, function* () { 182 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/pet`, 'Error fetching pet master list.'); 183 | }); 184 | } 185 | /** 186 | * Returns data about a individual battle pet ability ID. This resource does not provide ability tooltips. 187 | * 188 | * @param abilityId The ID of the ability to retrieve. 189 | */ 190 | getPetAbilities(abilityId) { 191 | return __awaiter(this, void 0, void 0, function* () { 192 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/pet/ability/${abilityId}`, 'Error fetching specified pet abilities.'); 193 | }); 194 | } 195 | /** 196 | * Returns data about an individual pet species. Use pets as the `field` value in a 197 | * character profile request to get species IDs. Each species also has data about its six abilities. 198 | * 199 | * @param speciesId 200 | */ 201 | getPetSpecies(speciesId) { 202 | return __awaiter(this, void 0, void 0, function* () { 203 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/pet/species/${speciesId}`, 'Error fetching specified pet species.'); 204 | }); 205 | } 206 | /** 207 | * Returns detailed information about a given species of pet. 208 | * 209 | * @param speciesId The pet's species ID. This can be found by querying a user's list of pets via the Character Profile API. 210 | * @param level The pet's level. Pet levels max out at 25. If omitted, the API assumes a default value of 1. 211 | * @param breedId The pet's breed. Retrievable via the Character Profile API. If omitted the API assumes a default value of 3. 212 | * @param qualityId The pet's quality. Retrievable via the Character Profile API. Pet quality can range from 0 to 5 213 | * (0 is poor quality and 5 is legendary). If omitted, the API will assume a default value of 1. 214 | */ 215 | getPetStats(speciesId, level = 1, breedId = 3, qualityId = 1) { 216 | return __awaiter(this, void 0, void 0, function* () { 217 | try { 218 | const response = yield this.axios.get(encodeURI(`${this.gameBaseUrlPath}/pet/stats/${speciesId}`), { 219 | params: Object.assign({ level: level, breedId: breedId, qualityId: qualityId }, this.defaultAxiosParams) 220 | }); 221 | return response.data; 222 | } 223 | catch (error) { 224 | console.log(error); 225 | throw new Error(`WoW Community Error :: Error fetching specified pet stats.`); 226 | } 227 | }); 228 | } 229 | /**************************** 230 | * PvP Leaderboard API 231 | ****************************/ 232 | /** 233 | * Returns leaderboard information for the 2v2, 3v3, 5v5, and Rated Battleground leaderboards. 234 | * 235 | * @param bracket The type of leaderboard to retrieve. Valid entries are `2v2`, `3v3`, `5v5`, and `rbg`. 236 | */ 237 | getPvpLeaderboards(bracket) { 238 | return __awaiter(this, void 0, void 0, function* () { 239 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/leaderboard/${bracket}`, 'Error fetching specified bracket leaderboard.'); 240 | }); 241 | } 242 | /**************************** 243 | * Quest API 244 | ****************************/ 245 | /** 246 | * Returns metadata for a specified quest. 247 | * 248 | * @param questId The ID of the quest to retrieve. 249 | */ 250 | getQuest(questId) { 251 | return __awaiter(this, void 0, void 0, function* () { 252 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/quest/${questId}`, 'Error fetching specified quest.'); 253 | }); 254 | } 255 | /**************************** 256 | * Realm Status API 257 | ****************************/ 258 | /** 259 | * Retrieves realm status information. This information is limited to whether or not the realm is up, the type 260 | * and state of the realm, and the current population. 261 | */ 262 | getRealmStatusList() { 263 | return __awaiter(this, void 0, void 0, function* () { 264 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/realm/status`, 'Error fetching realm status list.'); 265 | }); 266 | } 267 | /**************************** 268 | * Recipe API 269 | ****************************/ 270 | /** 271 | * Returns basic recipe information. 272 | * 273 | * @param recipeId Unique ID for the desired recipe. 274 | */ 275 | getRecipe(recipeId) { 276 | return __awaiter(this, void 0, void 0, function* () { 277 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/recipe/${recipeId}`, 'Error fetching specified recipe.'); 278 | }); 279 | } 280 | /**************************** 281 | * Spell API 282 | ****************************/ 283 | /** 284 | * Returns information about spells. 285 | * 286 | * @param spellId The ID of the spell to retrieve. 287 | */ 288 | getSpell(spellId) { 289 | return __awaiter(this, void 0, void 0, function* () { 290 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/spell/${spellId}`, 'Error fetching specified spell.'); 291 | }); 292 | } 293 | /**************************** 294 | * Zone API 295 | ****************************/ 296 | /** 297 | * Returns a list of all supported zones and their bosses. A "zone" in this context should be considered a 298 | * dungeon or a raid, not a world zone. A "boss" in this context should be considered a boss encounter, 299 | * which may include more than one NPC. 300 | */ 301 | getZoneMasterList() { 302 | return __awaiter(this, void 0, void 0, function* () { 303 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/zone`, 'Error fetching zone master list.'); 304 | }); 305 | } 306 | /** 307 | * Returns information about zones. 308 | * 309 | * @param zoneId The ID of the zone to retrieve. 310 | */ 311 | getZone(zoneId) { 312 | return __awaiter(this, void 0, void 0, function* () { 313 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/zone`, 'Error fetching specified zone.'); 314 | }); 315 | } 316 | /**************************** 317 | * Data Resources 318 | ****************************/ 319 | /** 320 | * Returns a list of battlegroups for the specified region. 321 | */ 322 | getBattlegroups() { 323 | return __awaiter(this, void 0, void 0, function* () { 324 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/data/battleground/`, 'Error fetching region battlegrounds.'); 325 | }); 326 | } 327 | /** 328 | * Returns a list of races and their associated faction, name, unique ID, and skin. 329 | */ 330 | getCharacterRaces() { 331 | return __awaiter(this, void 0, void 0, function* () { 332 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/data/character/races`, 'Error fetching character race list.'); 333 | }); 334 | } 335 | /** 336 | * Returns a list of character classes. 337 | */ 338 | getCharacterClasses() { 339 | return __awaiter(this, void 0, void 0, function* () { 340 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/data/character/classes`, 'Error fetching character class list.'); 341 | }); 342 | } 343 | /** 344 | * Returns a list of all achievements that characters can earn as well as the category structure and hierarchy. 345 | */ 346 | getCharacterAchievements() { 347 | return __awaiter(this, void 0, void 0, function* () { 348 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/data/character/achievements`, 'Error fetching character achievement list.'); 349 | }); 350 | } 351 | /** 352 | * The guild rewards data API provides a list of all guild rewards. 353 | */ 354 | getGuildRewards() { 355 | return __awaiter(this, void 0, void 0, function* () { 356 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/data/guild/rewards`, 'Error fetching guild reward list.'); 357 | }); 358 | } 359 | /** 360 | * Returns a list of all guild perks. 361 | */ 362 | getGuildPerks() { 363 | return __awaiter(this, void 0, void 0, function* () { 364 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/data/guild/perks`, 'Error fetching guild perk list.'); 365 | }); 366 | } 367 | /** 368 | * Returns a list of all guild achievements as well as the category structure and hierarchy. 369 | */ 370 | getGuildAchievements() { 371 | return __awaiter(this, void 0, void 0, function* () { 372 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/data/guild/achievements`, 'Error fetching guild achievement list.'); 373 | }); 374 | } 375 | /** 376 | * Returns a list of item classes. 377 | */ 378 | getItemClasses() { 379 | return __awaiter(this, void 0, void 0, function* () { 380 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/data/item/classes`, 'Error fetching item classes.'); 381 | }); 382 | } 383 | /** 384 | * Returns a list of talents, specs, and glyphs for each class. 385 | */ 386 | getTalents() { 387 | return __awaiter(this, void 0, void 0, function* () { 388 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/data/talents`, 'Error fetching talent list.'); 389 | }); 390 | } 391 | /** 392 | * Returns a list of the different battle pet types, including what they are strong and weak against. 393 | */ 394 | getPetTypes() { 395 | return __awaiter(this, void 0, void 0, function* () { 396 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/data/pet/types`, 'Error fetching pet type list.'); 397 | }); 398 | } 399 | /******************************** 400 | * Private Class Helper Functions 401 | ********************************/ 402 | _handleApiCall(apiUrl, errorMessage) { 403 | return __awaiter(this, void 0, void 0, function* () { 404 | try { 405 | const response = yield this.axios.get(encodeURI(apiUrl)); 406 | return response.data; 407 | } 408 | catch (error) { 409 | console.log(error); 410 | throw new Error(`WoW Community Error :: ${errorMessage}`); 411 | } 412 | }); 413 | } 414 | } 415 | exports.default = WowCommunity; 416 | -------------------------------------------------------------------------------- /dist/wow/profileData.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // WoW Profile Data API documentation: https://develop.battle.net/documentation/world-of-warcraft/profile-apis 3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 4 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 5 | return new (P || (P = Promise))(function (resolve, reject) { 6 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 7 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 8 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 9 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 10 | }); 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | class WowProfileData { 14 | constructor(axiosInstance, defaultAxiosParams, origin) { 15 | this.gameBaseUrlPath = '/profile/wow/character'; 16 | this.axios = axiosInstance; 17 | this.defaultAxiosParams = defaultAxiosParams; 18 | this.namespace = `profile-${origin}`; 19 | } 20 | /** 21 | * Returns a summary of the achievements a character has completed. 22 | * 23 | * @param realmSlug The slug of the realm. 24 | * @param characterName The lowercase name of the character. 25 | * 26 | */ 27 | getCharacterAchievements(realmSlug, characterName) { 28 | return __awaiter(this, void 0, void 0, function* () { 29 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/achievements`, 'Error fetching character achievements.'); 30 | }); 31 | } 32 | /** 33 | * Returns a summary of a character's appearance settings. 34 | * 35 | * @param realmSlug The slug of the realm. 36 | * @param characterName The lowercase name of the character. 37 | * 38 | */ 39 | getCharacterAppearance(realmSlug, characterName) { 40 | return __awaiter(this, void 0, void 0, function* () { 41 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/appearance`, 'Error fetching character appearance.'); 42 | }); 43 | } 44 | /** 45 | * Returns an index of collection types for a character. 46 | * 47 | * @param realmSlug The slug of the realm. 48 | * @param characterName The lowercase name of the character. 49 | * 50 | */ 51 | getCharacterCollectionsIndex(realmSlug, characterName) { 52 | return __awaiter(this, void 0, void 0, function* () { 53 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/collections`, 'Error fetching character collections.'); 54 | }); 55 | } 56 | /** 57 | * Returns a summary of the mounts a character has obtained. 58 | * 59 | * @param realmSlug The slug of the realm. 60 | * @param characterName The lowercase name of the character. 61 | * 62 | */ 63 | getCharacterMountsCollection(realmSlug, characterName) { 64 | return __awaiter(this, void 0, void 0, function* () { 65 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/collections/mounts`, 'Error fetching character mounts collection.'); 66 | }); 67 | } 68 | /** 69 | * Returns a summary of the battle pets a character has obtained. 70 | * 71 | * @param realmSlug The slug of the realm. 72 | * @param characterName The lowercase name of the character. 73 | * 74 | */ 75 | getCharacterPetsCollection(realmSlug, characterName) { 76 | return __awaiter(this, void 0, void 0, function* () { 77 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/collections/pets`, 'Error fetching character pets collection.'); 78 | }); 79 | } 80 | /** 81 | * Returns a summary of the items equipped by a character. 82 | * 83 | * @param realmSlug The slug of the realm. 84 | * @param characterName The lowercase name of the character. 85 | * 86 | */ 87 | getCharacterEquipment(realmSlug, characterName) { 88 | return __awaiter(this, void 0, void 0, function* () { 89 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/equipment`, 'Error fetching character equipment.'); 90 | }); 91 | } 92 | /** 93 | * If the character is a hunter, returns a summary of the character's hunter pets. 94 | * Otherwise, returns an HTTP 404 Not Found error. 95 | * 96 | * @param realmSlug The slug of the realm. 97 | * @param characterName The lowercase name of the character. 98 | * 99 | */ 100 | getCharacterHunterPets(realmSlug, characterName) { 101 | return __awaiter(this, void 0, void 0, function* () { 102 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/hunter-pets`, 'Error fetching character hunter pets.'); 103 | }); 104 | } 105 | /** 106 | * Returns a summary of the media assets available for a character (such as an avatar render). 107 | * 108 | * @param realmSlug The slug of the realm. 109 | * @param characterName The lowercase name of the character. 110 | * 111 | */ 112 | getCharacterMedia(realmSlug, characterName) { 113 | return __awaiter(this, void 0, void 0, function* () { 114 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/character-media`, 'Error fetching character media.'); 115 | }); 116 | } 117 | /** 118 | * Returns the Mythic Keystone profile index for a character. 119 | * 120 | * @param realmSlug The slug of the realm. 121 | * @param characterName The lowercase name of the character. 122 | * 123 | */ 124 | getCharacterMythicKeystoneProfile(realmSlug, characterName) { 125 | return __awaiter(this, void 0, void 0, function* () { 126 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/mythic-keystone-profile`, 'Error fetching character mythic keystone profile.'); 127 | }); 128 | } 129 | /** 130 | * Returns the Mythic Keystone season details for a character. 131 | * Returns a **404 Not Found** for characters that have not yet completed a Mythic Keystone dungeon for the specified season. 132 | * 133 | * @param realmSlug The slug of the realm. 134 | * @param characterName The lowercase name of the character. 135 | * 136 | */ 137 | getCharacterMythicKeystoneSeasonDetails(realmSlug, characterName, seasonId) { 138 | return __awaiter(this, void 0, void 0, function* () { 139 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/mythic-keystone-profile/season/${seasonId}`, 'Error fetching character mythic keystone profile for specified season.'); 140 | }); 141 | } 142 | /** 143 | * Returns a profile summary for a character. 144 | * 145 | * @param realmSlug The slug of the realm. 146 | * @param characterName The lowercase name of the character. 147 | * 148 | */ 149 | getCharacterSummary(realmSlug, characterName) { 150 | return __awaiter(this, void 0, void 0, function* () { 151 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}`, 'Error fetching character summary.'); 152 | }); 153 | } 154 | /** 155 | * Returns the PvP bracket statistics for a character. 156 | * 157 | * @param realmSlug The slug of the realm. 158 | * @param characterName The lowercase name of the character. 159 | * @param pvpBracket The PvP bracket type (1v1, 3v3, etc). 160 | * 161 | */ 162 | getCharacterPvpBracketStatistics(realmSlug, characterName, pvpBracket) { 163 | return __awaiter(this, void 0, void 0, function* () { 164 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/pvp-bracket/${pvpBracket}`, 'Error fetching character pvp bracket statistics.'); 165 | }); 166 | } 167 | /** 168 | * Returns a PvP summary for a character. 169 | * 170 | * @param realmSlug The slug of the realm. 171 | * @param characterName The lowercase name of the character. 172 | * 173 | */ 174 | getCharacterPvpSummary(realmSlug, characterName) { 175 | return __awaiter(this, void 0, void 0, function* () { 176 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/pvp-summary`, 'Error fetching character pvp summary.'); 177 | }); 178 | } 179 | /** 180 | * Returns a summary of a character's reputations. 181 | * 182 | * @param realmSlug The slug of the realm. 183 | * @param characterName The lowercase name of the character. 184 | * 185 | */ 186 | getCharacterReputations(realmSlug, characterName) { 187 | return __awaiter(this, void 0, void 0, function* () { 188 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/reputations`, 'Error fetching character reputations.'); 189 | }); 190 | } 191 | /** 192 | * Returns a summary of a character's specializations. 193 | * 194 | * @param realmSlug The slug of the realm. 195 | * @param characterName The lowercase name of the character. 196 | * 197 | */ 198 | getCharacterSpecializations(realmSlug, characterName) { 199 | return __awaiter(this, void 0, void 0, function* () { 200 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/specializations`, 'Error fetching character specializations.'); 201 | }); 202 | } 203 | /** 204 | * Returns a statistics summary for a character. 205 | * 206 | * @param realmSlug The slug of the realm. 207 | * @param characterName The lowercase name of the character. 208 | * 209 | */ 210 | getCharacterStatistics(realmSlug, characterName) { 211 | return __awaiter(this, void 0, void 0, function* () { 212 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/statistics`, 'Error fetching character statistics.'); 213 | }); 214 | } 215 | /** 216 | * Returns a summary of titles a character has obtained. 217 | * 218 | * @param realmSlug The slug of the realm. 219 | * @param characterName The lowercase name of the character. 220 | * 221 | */ 222 | getCharacterTitles(realmSlug, characterName) { 223 | return __awaiter(this, void 0, void 0, function* () { 224 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/${realmSlug}/${characterName}/titles`, 'Error fetching character titles.'); 225 | }); 226 | } 227 | /** 228 | * Returns a single guild summary by its name and realm. 229 | * 230 | * @param realmSlug The slug of the realm. 231 | * @param guildName The slug of the guild. 232 | * 233 | */ 234 | getGuildSummary(realmSlug, guildName) { 235 | return __awaiter(this, void 0, void 0, function* () { 236 | return yield this._handleApiCall(`/data/wow/guild//${realmSlug}/${guildName}`, 'Error fetching guild summary.'); 237 | }); 238 | } 239 | /** 240 | * Returns a single guild's achievements by name and realm. 241 | * 242 | * @param realmSlug The slug of the realm. 243 | * @param guildName The slug of the guild. 244 | * 245 | */ 246 | getGuildAchievements(realmSlug, guildName) { 247 | return __awaiter(this, void 0, void 0, function* () { 248 | return yield this._handleApiCall(`/data/wow/guild/${realmSlug}/${guildName}/achievements`, 'Error fetching guild achievements.'); 249 | }); 250 | } 251 | /** 252 | * Returns a single guild's roster by its name and realm. 253 | * 254 | * @param realmSlug The slug of the realm. 255 | * @param guildName The slug of the guild. 256 | * 257 | */ 258 | getGuildRoster(realmSlug, guildName) { 259 | return __awaiter(this, void 0, void 0, function* () { 260 | return yield this._handleApiCall(`/data/wow/guild/${realmSlug}/${guildName}/roster`, 'Error fetching guild roster.'); 261 | }); 262 | } 263 | /******************************** 264 | * Private Class Helper Functions 265 | ********************************/ 266 | _handleApiCall(apiUrl, errorMessage) { 267 | return __awaiter(this, void 0, void 0, function* () { 268 | try { 269 | const response = yield this.axios.get(encodeURI(apiUrl), { 270 | params: Object.assign({ namespace: this.namespace }, this.defaultAxiosParams) 271 | }); 272 | return response.data; 273 | } 274 | catch (error) { 275 | console.log(error); 276 | throw new Error(`WoW Profile Error :: ${errorMessage}`); 277 | } 278 | }); 279 | } 280 | } 281 | exports.default = WowProfileData; 282 | -------------------------------------------------------------------------------- /dist/wowClassic/gameData.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // WoW Classic Game Data API documentation: https://develop.battle.net/documentation/world-of-warcraft-classic/game-data-apis 3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 4 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 5 | return new (P || (P = Promise))(function (resolve, reject) { 6 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 7 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 8 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 9 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 10 | }); 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | class WowClassicGameData { 14 | constructor(axiosInstance, defaultAxiosParams, origin) { 15 | this.gameBaseUrlPath = '/data/wow'; 16 | this.axios = axiosInstance; 17 | this.defaultAxiosParams = defaultAxiosParams; 18 | this.namespace = `static-classic-${origin}`; 19 | } 20 | /** 21 | * Returns an index of creature families. 22 | */ 23 | getCreatureFamiliesIndex() { 24 | return __awaiter(this, void 0, void 0, function* () { 25 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/creature-family/index`, 'Error fetching creature families index.'); 26 | }); 27 | } 28 | /** 29 | * Returns a creature family by ID. 30 | * 31 | * @param creatureFamilyId The ID of the creature family. 32 | */ 33 | getCreatureFamily(creatureFamilyId) { 34 | return __awaiter(this, void 0, void 0, function* () { 35 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/creature-family/${creatureFamilyId}`, 'Error fetching specified creature family.'); 36 | }); 37 | } 38 | /** 39 | * Returns an index of creature types. 40 | */ 41 | getCreatureTypesIndex() { 42 | return __awaiter(this, void 0, void 0, function* () { 43 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/creature-type/index`, 'Error fetching creature types index.'); 44 | }); 45 | } 46 | /** 47 | * Returns a creature type by ID. 48 | * 49 | * @param creatureTypeId The ID of the creature type. 50 | */ 51 | getCreatureType(creatureTypeId) { 52 | return __awaiter(this, void 0, void 0, function* () { 53 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/creature-type/${creatureTypeId}`, 'Error fetching specified creature type.'); 54 | }); 55 | } 56 | /** 57 | * Returns a creature by ID. 58 | * 59 | * @param creatureId The ID of the creature. 60 | */ 61 | getCreature(creatureId) { 62 | return __awaiter(this, void 0, void 0, function* () { 63 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/creature/${creatureId}`, 'Error fetching specified creature.'); 64 | }); 65 | } 66 | /** 67 | * Returns media for a creature display by ID. 68 | * 69 | * @param creatureDisplayId The ID of the creature display. 70 | */ 71 | getCreatureDisplayMedia(creatureDisplayId) { 72 | return __awaiter(this, void 0, void 0, function* () { 73 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/media/creature-display/${creatureDisplayId}`, 'Error fetching specified creature display media.'); 74 | }); 75 | } 76 | /** 77 | * Returns media for a creature family by ID. 78 | * 79 | * @param creatureFamilyId The ID of the creature family. 80 | */ 81 | getCreatureFamilyMedia(creatureFamilyId) { 82 | return __awaiter(this, void 0, void 0, function* () { 83 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/media/creature-family/${creatureFamilyId}`, 'Error fetching specified creature family media.'); 84 | }); 85 | } 86 | /**************************** 87 | * Guild Crest API 88 | ****************************/ 89 | /** 90 | * Returns an index of guild crest media. 91 | */ 92 | getGuildCrestComponentsIndex() { 93 | return __awaiter(this, void 0, void 0, function* () { 94 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/guild-crest/index`, 'Error fetching guild crest components index.'); 95 | }); 96 | } 97 | /** 98 | * Returns media for a guild crest border by ID. 99 | * 100 | * @param borderId The ID of the guild crest border. 101 | */ 102 | getGuildCrestBorderMedia(borderId) { 103 | return __awaiter(this, void 0, void 0, function* () { 104 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/guild-crest/border/${borderId}`, 'Error fetching guild crest border media.'); 105 | }); 106 | } 107 | /** 108 | * Returns media for a guild crest emblem by ID. 109 | * 110 | * @param emblemId The ID of the guild crest emblem. 111 | */ 112 | getGuildCrestEmblemMedia(emblemId) { 113 | return __awaiter(this, void 0, void 0, function* () { 114 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/guild-crest/emblem/${emblemId}`, 'Error fetching guild crest emblem media.'); 115 | }); 116 | } 117 | /**************************** 118 | * Item API 119 | ****************************/ 120 | /** 121 | * Returns an index of item classes. 122 | */ 123 | getItemClassesIndex() { 124 | return __awaiter(this, void 0, void 0, function* () { 125 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/item-class/index`, 'Error fetching item class index.'); 126 | }); 127 | } 128 | /** 129 | * Returns an item class by ID. 130 | * 131 | * @param itemClassId The ID of the item class. 132 | */ 133 | getItemClass(itemClassId) { 134 | return __awaiter(this, void 0, void 0, function* () { 135 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/item-class/${itemClassId}`, 'Error fetching specified item class.'); 136 | }); 137 | } 138 | /** 139 | * Returns an item subclass by ID. 140 | * 141 | * @param itemClassId The ID of the item class. 142 | * @param itemSubclassId The ID of the item subclass. 143 | */ 144 | getItemSubclass(itemClassId, itemSubclassId) { 145 | return __awaiter(this, void 0, void 0, function* () { 146 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/item-class/${itemClassId}/item-subclass/${itemSubclassId}`, 'Error fetching specified item class subclass.'); 147 | }); 148 | } 149 | /** 150 | * Returns an item by ID. 151 | * 152 | * @param itemId The ID of the item. 153 | */ 154 | getItem(itemId) { 155 | return __awaiter(this, void 0, void 0, function* () { 156 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/item/${itemId}`, 'Error fetching specified item.'); 157 | }); 158 | } 159 | /** 160 | * Returns media for an item by ID. 161 | * 162 | * @param itemId The ID of the item. 163 | */ 164 | getItemMedia(itemId) { 165 | return __awaiter(this, void 0, void 0, function* () { 166 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/media/item/${itemId}`, 'Error fetching specified item media.'); 167 | }); 168 | } 169 | /**************************** 170 | * Playable Class API 171 | ****************************/ 172 | /** 173 | * Returns an index of playable classes. 174 | */ 175 | getPlayableClassIndex() { 176 | return __awaiter(this, void 0, void 0, function* () { 177 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/playable-class/index`, 'Error fetching playable class index.'); 178 | }); 179 | } 180 | /** 181 | * Returns a playable class by ID. 182 | * 183 | * @param playableClassId The ID of the playable class. 184 | */ 185 | getPlayableClass(playableClassId) { 186 | return __awaiter(this, void 0, void 0, function* () { 187 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/playable-class/${playableClassId}`, 'Error fetching specified playable class.'); 188 | }); 189 | } 190 | /** 191 | * Returns media for a playable class by ID. 192 | * 193 | * @param playableClassId The ID of the playable class. 194 | */ 195 | getPlayableClassMedia(playableClassId) { 196 | return __awaiter(this, void 0, void 0, function* () { 197 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/media/playable-class/${playableClassId}`, 'Error fetching specified playable class media.'); 198 | }); 199 | } 200 | /**************************** 201 | * Playable Race API 202 | ****************************/ 203 | /** 204 | * Returns an index of playable races. 205 | */ 206 | getPlayableRaceIndex() { 207 | return __awaiter(this, void 0, void 0, function* () { 208 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/playable-race/index`, 'Error fetching playable race index.'); 209 | }); 210 | } 211 | /** 212 | * Returns a playable race by ID. 213 | * 214 | * @param playableRaceId The ID of the playable race. 215 | */ 216 | getPlayableRace(playableRaceId) { 217 | return __awaiter(this, void 0, void 0, function* () { 218 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/playable-race/${playableRaceId}`, 'Error fetching specified playable race.'); 219 | }); 220 | } 221 | /**************************** 222 | * Power Type API 223 | ****************************/ 224 | /** 225 | * Returns an index of power types. 226 | */ 227 | getPowerTypesIndex() { 228 | return __awaiter(this, void 0, void 0, function* () { 229 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/power-type/index`, 'Error fetching power type index.'); 230 | }); 231 | } 232 | /** 233 | * Returns a power type by ID. 234 | * 235 | * @param powerTypeId 236 | */ 237 | getPowerType(powerTypeId) { 238 | return __awaiter(this, void 0, void 0, function* () { 239 | return yield this._handleApiCall(`${this.gameBaseUrlPath}/power-type/${powerTypeId}`, 'Error fetching specified power type.'); 240 | }); 241 | } 242 | /******************************** 243 | * Private Class Helper Functions 244 | ********************************/ 245 | _handleApiCall(apiUrl, errorMessage) { 246 | return __awaiter(this, void 0, void 0, function* () { 247 | try { 248 | const response = yield this.axios.get(encodeURI(apiUrl), { 249 | params: Object.assign({ namespace: this.namespace }, this.defaultAxiosParams) 250 | }); 251 | return response.data; 252 | } 253 | catch (error) { 254 | console.log(error); 255 | throw new Error(`WoW Classic Game Data Error :: ${errorMessage}`); 256 | } 257 | }); 258 | } 259 | } 260 | exports.default = WowClassicGameData; 261 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const battleNetWrapper = require('./dist/battleNetWrapper'); 2 | 3 | module.exports = battleNetWrapper; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "battlenet-api-wrapper", 3 | "version": "1.0.5", 4 | "description": "A promised-based Node.js wrapper for the Battle.net Community and Data APIs (supports WoW, WoW Classic, SC2, D3, and Hearthstone).", 5 | "main": "index.js", 6 | "scripts": { 7 | "clean": "rimraf dist", 8 | "build": "tsc --build tsconfig.json", 9 | "watch:build": "tsc --watch", 10 | "watch:server": "nodemon './dist/battleNetWrapper.js' --watch './dist'", 11 | "start": "npm-run-all clean build --parallel watch:build watch:server --print-label", 12 | "codecov": "./node_modules/.bin/codecov", 13 | "test": "./node_modules/.bin/jest" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "https://github.com/QuadDamn/battlenet-api-wrapper.git" 18 | }, 19 | "author": "Shane Jeffery", 20 | "license": "MIT", 21 | "devDependencies": { 22 | "@types/node": "^13.1.1", 23 | "codecov": "^3.6.1", 24 | "documentation": "^12.1.4", 25 | "nodemon": "^2.0.2", 26 | "npm-run-all": "^4.1.5", 27 | "rimraf": "^3.0.0", 28 | "typescript": "^3.7.4" 29 | }, 30 | "dependencies": { 31 | "axios": "^0.19.0", 32 | "jest": "^25.1.0" 33 | }, 34 | "jest": { 35 | "collectCoverage": true, 36 | "testEnvironment": "node" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/battleNetWrapper.ts: -------------------------------------------------------------------------------- 1 | import axios, {AxiosInstance} from "axios"; 2 | 3 | import Diablo3Community from './d3/community'; 4 | import Diablo3GameData from './d3/gameData'; 5 | import HearthstoneGameData from './hearthstone/gameData'; 6 | import Starcraft2Community from './sc2/community'; 7 | import Starcraft2GameData from './sc2/gameData'; 8 | import WowProfileData from './wow/profileData'; 9 | import WowGameData from './wow/gameData'; 10 | import WowCommunity from './wow/community'; 11 | import WowClassicGameData from './wowClassic/gameData'; 12 | 13 | class BattleNetWrapper { 14 | public WowCommunity: object; 15 | public WowGameData: object; 16 | public WowProfileData: object; 17 | public WowClassicGameData: object; 18 | public HearthstoneGameData: object; 19 | public Starcraft2Community: object; 20 | public Starcraft2GameData: object; 21 | public Diablo3Community: object; 22 | public Diablo3GameData: object; 23 | private clientId: string; 24 | private clientSecret: string; 25 | private origin: string; 26 | private locale: string; 27 | private oauthToken: string; 28 | private axios: AxiosInstance; 29 | private defaultAxiosParams: object; 30 | private originObject: object = { 31 | us: { 32 | hostname: 'https://us.api.blizzard.com', 33 | defaultLocale: 'en_US', 34 | locales: ['en_US', 'es_MX', 'pt_BR', 'multi'], 35 | }, 36 | eu: { 37 | hostname: 'https://eu.api.blizzard.com', 38 | defaultLocale: 'en_GB', 39 | locales: ['en_GB', 'es_ES', 'fr_FR', 'ru_RU', 'de_DE', 'pt_PT', 'it_IT', 'multi'], 40 | }, 41 | sea: { 42 | hostname: 'https://sea.api.blizzard.com', 43 | defaultLocale: 'en_US', 44 | locales: ['en_US', 'multi'], 45 | }, 46 | kr: { 47 | hostname: 'https://kr.api.blizzard.com', 48 | defaultLocale: 'ko_KR', 49 | locales: ['ko_KR', 'en_GB', 'en_US', 'multi'], 50 | }, 51 | tw: { 52 | hostname: 'https://tw.api.blizzard.com', 53 | defaultLocale: 'zh_TW', 54 | locales: ['zh_TW', 'en_GB', 'en_US', 'multi'], 55 | }, 56 | cn: { 57 | hostname: 'https://gateway.battlenet.com.cn', 58 | defaultLocale: 'zh_CN', 59 | locales: ['zh_CN', 'en_GB', 'en_US', 'multi'], 60 | } 61 | }; 62 | 63 | // Unused constructor as we needed the ability to async the initialization 64 | // and await all of the underlying promises. 65 | constructor() {} 66 | 67 | async init(clientId: string, clientSecret: string, origin: string = 'us', locale: string = 'en_US') { 68 | if (!clientId) throw new Error('You are missing your Client ID in the passed parameters. This parameter is required.'); 69 | if (!clientSecret) throw new Error('You are missing your Client Secret in the passed parameters. This parameter is required.'); 70 | 71 | this.origin = origin; 72 | this.locale = locale; 73 | this.clientId = clientId; 74 | this.clientSecret = clientSecret; 75 | 76 | this.defaultAxiosParams = { 77 | locale: this.locale 78 | }; 79 | 80 | // Handles the fetching of a new OAuth token from the Battle.net API 81 | // and then creates a reusable instance of axios for all subsequent API requests. 82 | try { 83 | this.axios = axios.create({ 84 | baseURL: this.originObject[this.origin].hostname, 85 | params: this.defaultAxiosParams 86 | }); 87 | 88 | await this.setOAuthToken(); 89 | this.axios.defaults.headers.common['Authorization'] = `Bearer ${this.oauthToken}`; 90 | } catch (error) { 91 | console.log(error); 92 | } 93 | 94 | this.Diablo3Community = new Diablo3Community(this.axios); 95 | this.Diablo3GameData = new Diablo3GameData(this.axios); 96 | this.HearthstoneGameData = new HearthstoneGameData(this.axios, this.defaultAxiosParams); 97 | this.Starcraft2Community = new Starcraft2Community(this.axios); 98 | this.Starcraft2GameData = new Starcraft2GameData(this.axios); 99 | this.WowCommunity = new WowCommunity(this.axios, this.defaultAxiosParams); 100 | this.WowGameData = new WowGameData(this.axios, this.defaultAxiosParams, this.origin); 101 | this.WowProfileData = new WowProfileData(this.axios, this.defaultAxiosParams, this.origin); 102 | this.WowClassicGameData = new WowClassicGameData(this.axios, this.defaultAxiosParams, this.origin); 103 | } 104 | 105 | // Sets a new access token for all of the subsequent API requests. 106 | // Every invocation of this method will create a new access token, 107 | // so you should never have to worry about the token ever expiring. 108 | async setOAuthToken() { 109 | try { 110 | const response = await axios.get(`https://${this.origin}.battle.net/oauth/token`, { 111 | auth: { 112 | username: this.clientId, 113 | password: this.clientSecret, 114 | }, 115 | params: { 116 | grant_type: 'client_credentials', 117 | }, 118 | }); 119 | 120 | this.oauthToken = response.data.access_token; 121 | } catch (error) { 122 | console.log(error); 123 | throw new Error(`Problem getting the OAuth token from the Blizzard API. 124 | Please check that your Client ID and Secret are correct.`); 125 | } 126 | } 127 | } 128 | 129 | module.exports = BattleNetWrapper; -------------------------------------------------------------------------------- /src/d3/README.md: -------------------------------------------------------------------------------- 1 | ## Diablo 3 Community 2 | 3 | In order to use these functions, you will need to have initialized the BattleNetWrapper class and then you can use these functions. 4 | 5 | ***Example implementation:*** 6 | ``` 7 | const battleNetWrapper = require('battlenet-api-wrapper'); 8 | 9 | const clientId = 'YOUR_CLIENT_ID'; 10 | const clientSecret = 'YOUR_CLIENT_SECRET'; 11 | 12 | (async function() { 13 | const bnw = new battleNetWrapper(); 14 | await bnw.init(clientId, clientSecret); 15 | const data = await bnw.Diablo3Community.getActIndex(); 16 | }()); 17 | ``` 18 | 19 | **Available Functions** 20 | 21 | - [getActIndex][1] 22 | - [getAct][2] 23 | - [getArtisan][4] 24 | - [getRecipe][6] 25 | - [getFollower][8] 26 | - [getCharacterClass][10] 27 | - [getApiSkill][12] 28 | - [getItemTypeIndex][14] 29 | - [getItemType][15] 30 | - [getItem][17] 31 | - [getApiAccount][19] 32 | - [getApiHero][21] 33 | - [getApiDetailedHeroItems][23] 34 | - [getApiDetailedFollowerItems][25] 35 | 36 | ### getActIndex 37 | 38 | Returns an index of acts. 39 | 40 | Returns **[Promise][310]<[object][311]>** 41 | 42 | ### getAct 43 | 44 | Returns a single act by ID. 45 | 46 | #### Parameters 47 | 48 | - `actId` **[number][312]** The ID of the act to retrieve. 49 | 50 | Returns **[Promise][310]<[object][311]>** 51 | 52 | ### getArtisan 53 | 54 | Returns a single artisan by slug. 55 | 56 | #### Parameters 57 | 58 | - `artisanSlug` **[string][313]** The slug of the artisan to retrieve. 59 | 60 | Returns **[Promise][310]<[object][311]>** 61 | 62 | ### getRecipe 63 | 64 | Returns a single recipe by slug for the specified artisan. 65 | 66 | #### Parameters 67 | 68 | - `artisanSlug` **[string][313]** The slug of the artisan to retrieve. 69 | - `recipeSlug` **[string][313]** The slug of the recipe to retrieve. 70 | 71 | Returns **[Promise][310]<[object][311]>** 72 | 73 | ### getFollower 74 | 75 | Returns a single follower by slug. 76 | 77 | #### Parameters 78 | 79 | - `followerSlug` **[string][313]** The slug of the follower to retrieve. 80 | 81 | Returns **[Promise][310]<[object][311]>** 82 | 83 | ### getCharacterClass 84 | 85 | Returns a single character class by slug. 86 | 87 | #### Parameters 88 | 89 | - `classSlug` **[string][313]** The slug of the character class to retrieve. 90 | 91 | Returns **[Promise][310]<[object][311]>** 92 | 93 | ### getApiSkill 94 | 95 | Returns a single skill by slug for a specific character class. 96 | 97 | #### Parameters 98 | 99 | - `classSlug` **[string][313]** The slug of the character class to retrieve. 100 | - `skillSlug` **[string][313]** The slug of the skill to retrieve. 101 | 102 | Returns **[Promise][310]<[object][311]>** 103 | 104 | ### getItemTypeIndex 105 | 106 | Returns an index of item types. 107 | 108 | Returns **[Promise][310]<[object][311]>** 109 | 110 | ### getItemType 111 | 112 | Returns a single item type by slug. 113 | 114 | #### Parameters 115 | 116 | - `itemTypeSlug` **[string][313]** The slug of the item type to retrieve. 117 | 118 | Returns **[Promise][310]<[object][311]>** 119 | 120 | ### getItem 121 | 122 | Returns a single item by item slug and ID. 123 | 124 | #### Parameters 125 | 126 | - `itemSlugAndId` The slug and ID of the item to retrieve. 127 | 128 | Returns **[Promise][310]<[object][311]>** 129 | 130 | ### getApiAccount 131 | 132 | Returns the specified account profile. 133 | 134 | **IMPORTANT NOTE: Battletag is case-sensitive and will result in a 404 error response if it doesn't match perfectly with what Blizzard has on record.** 135 | 136 | #### Parameters 137 | 138 | - `account` **[string][313]** The BattleTag for the account to retrieve. 139 | 140 | Returns **[Promise][310]<[object][311]>** 141 | 142 | ### getApiHero 143 | 144 | Returns a single hero. 145 | 146 | **IMPORTANT NOTE: Battletag is case-sensitive and will result in a 404 error response if it doesn't match perfectly with what Blizzard has on record.** 147 | 148 | #### Parameters 149 | 150 | - `account` **[string][313]** The BattleTag for the account to retrieve. 151 | - `heroId` **[string][313]** The ID of the hero to retrieve. 152 | 153 | Returns **[Promise][310]<[object][311]>** 154 | 155 | ### getApiDetailedHeroItems 156 | 157 | Returns a list of items for the specified hero. 158 | 159 | **IMPORTANT NOTE: Battletag is case-sensitive and will result in a 404 error response if it doesn't match perfectly with what Blizzard has on record.** 160 | 161 | #### Parameters 162 | 163 | - `account` **[string][313]** The BattleTag for the account to retrieve. 164 | - `heroId` **[string][313]** The ID of the hero to retrieve. 165 | 166 | Returns **[Promise][310]<[object][311]>** 167 | 168 | ### getApiDetailedFollowerItems 169 | 170 | Returns a list of items for the specified hero's followers. 171 | 172 | **IMPORTANT NOTE: Battletag is case-sensitive and will result in a 404 error response if it doesn't match perfectly with what Blizzard has on record.** 173 | 174 | #### Parameters 175 | 176 | - `account` **[string][313]** The BattleTag for the account to retrieve. 177 | - `heroId` **[string][313]** The ID of the hero to retrieve. 178 | 179 | Returns **[Promise][310]<[object][311]>** 180 | 181 | 182 | ## Diablo 3 Game Data 183 | 184 | In order to use these functions, you will need to have initialized the BattleNetWrapper class and then you can use these functions. 185 | 186 | ***Example implementation:*** 187 | ``` 188 | const battleNetWrapper = require('battlenet-api-wrapper'); 189 | 190 | const clientId = 'YOUR_CLIENT_ID'; 191 | const clientSecret = 'YOUR_CLIENT_SECRET'; 192 | 193 | (async function() { 194 | const bnw = new battleNetWrapper(); 195 | await bnw.init(clientId, clientSecret); 196 | const data = await bnw.Diablo3GameData.getSeasonIndex(); 197 | }()); 198 | ``` 199 | 200 | **Available Functions** 201 | 202 | - [getSeasonIndex][27] 203 | - [getSeason][28] 204 | - [getSeasonLeaderboard][30] 205 | - [getEraIndex][32] 206 | - [getEra][33] 207 | - [getEraLeaderboard][35] 208 | 209 | ### getSeasonIndex 210 | 211 | Returns an index of available seasons. 212 | 213 | Returns **[Promise][310]<[object][311]>** 214 | 215 | ### getSeason 216 | 217 | Returns a leaderboard list for the specified season. 218 | 219 | #### Parameters 220 | 221 | - `seasonId` **[number][312]** The season for the leaderboard list; get a list of seasons with `getSeasonIndex`. 222 | 223 | Returns **[Promise][310]<[object][311]>** 224 | 225 | ### getSeasonLeaderboard 226 | 227 | Returns a the specified leaderboard for the specified season. 228 | 229 | #### Parameters 230 | 231 | - `seasonId` **[number][312]** The season for the leaderboard; get a list of seasons with `getSeasonIndex`. 232 | - `leaderboardId` **[string][313]** The leaderboard to retrieve; get a list of leaderboards with `getSeason`. 233 | 234 | Returns **[Promise][310]<[object][311]>** 235 | 236 | ### getEraIndex 237 | 238 | Returns an index of available eras. 239 | 240 | Returns **[Promise][310]<[object][311]>** 241 | 242 | ### getEra 243 | 244 | Returns a leaderboard list for a particular era. 245 | 246 | #### Parameters 247 | 248 | - `eraId` **[number][312]** The era to retrieve; get a list of eras with `getEraIndex`. 249 | 250 | Returns **[Promise][310]<[object][311]>** 251 | 252 | ### getEraLeaderboard 253 | 254 | Returns the specified leaderboard for the specified era. 255 | 256 | #### Parameters 257 | 258 | - `eraId` **[number][312]** The era for the leaderboard; get a list of eras with `getEraIndex`. 259 | - `leaderboardId` **[string][313]** The leaderboard to retrieve; get a list of leaderboards with `getEra`. 260 | 261 | Returns **[Promise][310]<[object][311]>** 262 | 263 | [1]: #getactindex 264 | 265 | [2]: #getact 266 | 267 | [3]: #parameters 268 | 269 | [4]: #getartisan 270 | 271 | [5]: #parameters-1 272 | 273 | [6]: #getrecipe 274 | 275 | [7]: #parameters-2 276 | 277 | [8]: #getfollower 278 | 279 | [9]: #parameters-3 280 | 281 | [10]: #getcharacterclass 282 | 283 | [11]: #parameters-4 284 | 285 | [12]: #getapiskill 286 | 287 | [13]: #parameters-5 288 | 289 | [14]: #getitemtypeindex 290 | 291 | [15]: #getitemtype 292 | 293 | [16]: #parameters-6 294 | 295 | [17]: #getitem 296 | 297 | [18]: #parameters-7 298 | 299 | [19]: #getapiaccount 300 | 301 | [20]: #parameters-8 302 | 303 | [21]: #getapihero 304 | 305 | [22]: #parameters-9 306 | 307 | [23]: #getapidetailedheroitems 308 | 309 | [24]: #parameters-10 310 | 311 | [25]: #getapidetailedfolloweritems 312 | 313 | [26]: #parameters-11 314 | 315 | [27]: #getseasonindex 316 | 317 | [28]: #getseason 318 | 319 | [29]: #parameters-12 320 | 321 | [30]: #getseasonleaderboard 322 | 323 | [31]: #parameters-13 324 | 325 | [32]: #geteraindex 326 | 327 | [33]: #getera 328 | 329 | [34]: #parameters-14 330 | 331 | [35]: #geteraleaderboard 332 | 333 | [36]: #parameters-15 334 | 335 | [310]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise 336 | 337 | [311]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object 338 | 339 | [312]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number 340 | 341 | [313]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -------------------------------------------------------------------------------- /src/d3/community.ts: -------------------------------------------------------------------------------- 1 | // Diablo 3 Community API documentation: https://develop.battle.net/documentation/diablo-3/community-apis 2 | 3 | import {AxiosInstance} from "axios"; 4 | import {formatBattleTag} from '../utils'; 5 | 6 | class Diablo3Community { 7 | private readonly axios: AxiosInstance; 8 | private readonly gameBaseUrlPath: string = '/d3/data'; 9 | 10 | constructor(axiosInstance: AxiosInstance) { 11 | this.axios = axiosInstance; 12 | } 13 | 14 | /**************************** 15 | * Act API 16 | ****************************/ 17 | 18 | /** 19 | * Returns an index of acts. 20 | */ 21 | async getActIndex(): Promise { 22 | return await this._handleApiCall( 23 | `${this.gameBaseUrlPath}/act`, 24 | 'Error fetching the act index.' 25 | ); 26 | } 27 | 28 | /** 29 | * Returns a single act by ID. 30 | * 31 | * @param actId The ID of the act to retrieve. 32 | */ 33 | async getAct(actId: number): Promise { 34 | return await this._handleApiCall( 35 | `${this.gameBaseUrlPath}/act/${actId}`, 36 | 'Error fetching the specified act.' 37 | ); 38 | } 39 | 40 | /**************************** 41 | * Artisan and Recipe API 42 | ****************************/ 43 | 44 | /** 45 | * Returns a single artisan by slug. 46 | * 47 | * @param artisanSlug The slug of the artisan to retrieve. 48 | */ 49 | async getArtisan(artisanSlug: string): Promise { 50 | return await this._handleApiCall( 51 | `${this.gameBaseUrlPath}/artisan/${artisanSlug}`, 52 | 'Error fetching the specified artisan.' 53 | ); 54 | } 55 | 56 | /** 57 | * Returns a single recipe by slug for the specified artisan. 58 | * 59 | * @param artisanSlug The slug of the artisan to retrieve. 60 | * @param recipeSlug The slug of the recipe to retrieve. 61 | */ 62 | async getRecipe(artisanSlug: string, recipeSlug: string): Promise { 63 | return await this._handleApiCall( 64 | `${this.gameBaseUrlPath}/artisan/${artisanSlug}/recipe/${recipeSlug}`, 65 | 'Error fetching specified recipe.' 66 | ); 67 | } 68 | 69 | /**************************** 70 | * Follower API 71 | ****************************/ 72 | 73 | /** 74 | * Returns a single follower by slug. 75 | * 76 | * @param followerSlug The slug of the follower to retrieve. 77 | */ 78 | async getFollower(followerSlug: string): Promise { 79 | return await this._handleApiCall( 80 | `${this.gameBaseUrlPath}/follower/${followerSlug}`, 81 | 'Error fetching the specified follower.' 82 | ); 83 | } 84 | 85 | /**************************** 86 | * Character Class & Skill API 87 | ****************************/ 88 | 89 | /** 90 | * Returns a single character class by slug. 91 | * 92 | * @param classSlug The slug of the character class to retrieve. 93 | */ 94 | async getCharacterClass(classSlug: string): Promise { 95 | return await this._handleApiCall( 96 | `${this.gameBaseUrlPath}/hero/${classSlug}`, 97 | 'Error fetching specified hero class.' 98 | ); 99 | } 100 | 101 | /** 102 | * Returns a single skill by slug for a specific character class. 103 | * 104 | * @param classSlug The slug of the character class to retrieve. 105 | * @param skillSlug The slug of the skill to retrieve. 106 | */ 107 | async getApiSkill(classSlug: string, skillSlug: string): Promise { 108 | return await this._handleApiCall( 109 | `${this.gameBaseUrlPath}/hero/${classSlug}/skill/${skillSlug}`, 110 | 'Error fetching specified hero class skill.' 111 | ); 112 | } 113 | 114 | /**************************** 115 | * Item Type API 116 | ****************************/ 117 | 118 | /** 119 | * Returns an index of item types. 120 | */ 121 | async getItemTypeIndex(): Promise { 122 | return await this._handleApiCall( 123 | `${this.gameBaseUrlPath}/item-type`, 124 | 'Error fetching the item type index.' 125 | ); 126 | } 127 | 128 | /** 129 | * Returns a single item type by slug. 130 | * 131 | * @param itemTypeSlug The slug of the item type to retrieve. 132 | */ 133 | async getItemType(itemTypeSlug: string): Promise { 134 | return await this._handleApiCall( 135 | `${this.gameBaseUrlPath}/item-type/${itemTypeSlug}`, 136 | 'Error fetching the specified item type.' 137 | ); 138 | } 139 | 140 | /**************************** 141 | * Item API 142 | ****************************/ 143 | 144 | /** 145 | * Returns a single item by item slug and ID. 146 | * 147 | * @param itemSlugAndId The slug and ID of the item to retrieve. 148 | */ 149 | async getItem(itemSlugAndId): Promise { 150 | return await this._handleApiCall( 151 | `${this.gameBaseUrlPath}/item/${itemSlugAndId}`, 152 | 'Error fetching the specified item.' 153 | ); 154 | } 155 | 156 | /**************************** 157 | * Profile API 158 | ****************************/ 159 | 160 | /** 161 | * Returns the specified account profile. 162 | * 163 | * IMPORTANT NOTE: Battletag is case-sensitive and will result in a 404 error response if it doesn't 164 | * match perfectly with what Blizzard has on record. 165 | * 166 | * @param account The BattleTag for the account to retrieve. 167 | */ 168 | async getApiAccount(account: string): Promise { 169 | const formattedBattleTag = await formatBattleTag(account); 170 | 171 | return await this._handleApiCall( 172 | `/d3/profile/${formattedBattleTag}/`, 173 | 'Error fetching profile information.' 174 | ); 175 | } 176 | 177 | /** 178 | * Returns a single hero. 179 | * 180 | * IMPORTANT NOTE: Battletag is case-sensitive and will result in a 404 error response if it doesn't 181 | * match perfectly with what Blizzard has on record. 182 | * 183 | * @param account The BattleTag for the account to retrieve. 184 | * @param heroId The ID of the hero to retrieve. 185 | */ 186 | async getApiHero(account: string, heroId: string): Promise { 187 | const formattedBattleTag = await formatBattleTag(account); 188 | 189 | return await this._handleApiCall( 190 | `/d3/profile/${formattedBattleTag}/hero/${heroId}`, 191 | 'Error fetching specified hero.' 192 | ); 193 | } 194 | 195 | /** 196 | * Returns a list of items for the specified hero. 197 | * 198 | * IMPORTANT NOTE: Battletag is case-sensitive and will result in a 404 error response if it doesn't 199 | * match perfectly with what Blizzard has on record. 200 | * 201 | * @param account The BattleTag for the account to retrieve. 202 | * @param heroId The ID of the hero to retrieve. 203 | */ 204 | async getApiDetailedHeroItems(account: string, heroId: string): Promise { 205 | const formattedBattleTag = await formatBattleTag(account); 206 | 207 | return await this._handleApiCall( 208 | `/d3/profile/${formattedBattleTag}/hero/${heroId}/items`, 209 | 'Error fetching specified hero items.' 210 | ); 211 | } 212 | 213 | /** 214 | * Returns a list of items for the specified hero's followers. 215 | * 216 | * IMPORTANT NOTE: Battletag is case-sensitive and will result in a 404 error response if it doesn't 217 | * match perfectly with what Blizzard has on record. 218 | * 219 | * @param account The BattleTag for the account to retrieve. 220 | * @param heroId The ID of the hero to retrieve. 221 | */ 222 | async getApiDetailedFollowerItems(account: string, heroId: string): Promise { 223 | const formattedBattleTag = await formatBattleTag(account); 224 | 225 | return await this._handleApiCall( 226 | `/d3/profile/${formattedBattleTag}/hero/${heroId}/follower-items`, 227 | 'Error fetching specified hero follower items.' 228 | ); 229 | } 230 | 231 | /******************************** 232 | * Private Class Helper Functions 233 | ********************************/ 234 | 235 | async _handleApiCall(apiUrl: string, errorMessage: string): Promise { 236 | try { 237 | const response = await this.axios.get(encodeURI(apiUrl)); 238 | return response.data; 239 | } catch (error) { 240 | console.log(error); 241 | throw new Error(`Diablo 3 Community Error :: ${errorMessage}`); 242 | } 243 | } 244 | } 245 | 246 | export default Diablo3Community; -------------------------------------------------------------------------------- /src/d3/gameData.ts: -------------------------------------------------------------------------------- 1 | // Diablo 3 Game Data API documentation: https://develop.battle.net/documentation/diablo-3/game-data-apis 2 | 3 | import {AxiosInstance} from "axios"; 4 | 5 | class Diablo3GameData { 6 | private readonly axios: AxiosInstance; 7 | private readonly gameBaseUrlPath: string = '/data/d3'; 8 | 9 | constructor(axiosInstance: AxiosInstance) { 10 | this.axios = axiosInstance; 11 | } 12 | 13 | /** 14 | * Returns an index of available seasons. 15 | */ 16 | async getSeasonIndex(): Promise { 17 | return await this._handleApiCall( 18 | `${this.gameBaseUrlPath}/season`, 19 | 'Error fetching the season index.' 20 | ); 21 | } 22 | 23 | /** 24 | * Returns a leaderboard list for the specified season. 25 | * 26 | * @param seasonId The season for the leaderboard list; get a list of seasons with `getSeasonIndex`. 27 | */ 28 | async getSeason(seasonId: number): Promise { 29 | return await this._handleApiCall( 30 | `${this.gameBaseUrlPath}/season/${seasonId}`, 31 | 'Error fetching the specified season.' 32 | ); 33 | } 34 | 35 | /** 36 | * Returns a the specified leaderboard for the specified season. 37 | * 38 | * @param seasonId The season for the leaderboard; get a list of seasons with `getSeasonIndex`. 39 | * @param leaderboardId The leaderboard to retrieve; get a list of leaderboards with `getSeason`. 40 | */ 41 | async getSeasonLeaderboard(seasonId: number, leaderboardId: string): Promise { 42 | return await this._handleApiCall( 43 | `${this.gameBaseUrlPath}/season/${seasonId}/leaderboard/${leaderboardId}`, 44 | 'Error fetching the specified season leaderboard.' 45 | ); 46 | } 47 | 48 | /** 49 | * Returns an index of available eras. 50 | */ 51 | async getEraIndex(): Promise { 52 | return await this._handleApiCall( 53 | `${this.gameBaseUrlPath}/era`, 54 | 'Error fetching the era index.' 55 | ); 56 | } 57 | 58 | /** 59 | * Returns a leaderboard list for a particular era. 60 | * 61 | * @param eraId The era to retrieve; get a list of eras with `getEraIndex`. 62 | */ 63 | async getEra(eraId: number): Promise { 64 | return await this._handleApiCall( 65 | `${this.gameBaseUrlPath}/era/${eraId}`, 66 | 'Error fetching the specified era.' 67 | ); 68 | } 69 | 70 | /** 71 | * Returns the specified leaderboard for the specified era. 72 | * 73 | * @param eraId The era for the leaderboard; get a list of eras with `getEraIndex`. 74 | * @param leaderboardId The leaderboard to retrieve; get a list of leaderboards with `getEra`. 75 | */ 76 | async getEraLeaderboard(eraId: number, leaderboardId: string): Promise { 77 | return await this._handleApiCall( 78 | `${this.gameBaseUrlPath}/era/${eraId}/leaderboard/${leaderboardId}`, 79 | 'Error fetching the specified era leaderboard.' 80 | ); 81 | } 82 | 83 | /******************************** 84 | * Private Class Helper Functions 85 | ********************************/ 86 | 87 | async _handleApiCall(apiUrl: string, errorMessage: string): Promise { 88 | try { 89 | const response = await this.axios.get(encodeURI(apiUrl)); 90 | return response.data; 91 | } catch (error) { 92 | console.log(error); 93 | throw new Error(`Diablo 3 Game Data Error :: ${errorMessage}`); 94 | } 95 | } 96 | } 97 | 98 | export default Diablo3GameData; -------------------------------------------------------------------------------- /src/hearthstone/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Hearthstone Game Data 3 | In order to use these functions, you will need to have initialized the BattleNetWrapper class and then you can use these functions. 4 | 5 | ***Example implementation:*** 6 | 7 | ``` 8 | const battleNetWrapper = require('battlenet-api-wrapper'); 9 | 10 | const clientId = 'YOUR_CLIENT_ID'; 11 | const clientSecret = 'YOUR_CLIENT_SECRET'; 12 | 13 | (async function() { 14 | const bnw = new battleNetWrapper(); 15 | await bnw.init(clientId, clientSecret); 16 | const data = await bnw.HearthstoneGameData.searchCards({ class: 'mage', page: 1, pageSize: 3 }); 17 | }()); 18 | ``` 19 | 20 | **Available Functions** 21 | 22 | - [searchCards][36] 23 | - [getCard][37] 24 | - [getDeck][39] 25 | - [getMetadata][41] 26 | - [getSpecificMetadata][42] 27 | 28 | ### searchCards 29 | 30 | Returns all of the cards that match the passed parameters. 31 | 32 | **IMPORTANT NOTE:** Please ensure that your parameters match the field name, otherwise the Blizzard API won't know 33 | what to do with that particular query parameter and will just ignore it as you will see in the data returned to you. 34 | 35 | #### Parameters 36 | 37 | - `searchParams` **[CardSearch][28]** 38 | 39 | Returns **[Promise][310]<[object][311]>** 40 | ### getCard 41 | Returns the card with an ID or slug that matches the one you specify. 42 | 43 | #### Parameters 44 | - `cardSlug` **[number][312]** An ID or slug that uniquely identifies a card. You can discover these values by using the `/hearthstone/cards` search endpoint. 45 | 46 | Returns **[Promise][310]<[object][311]>** 47 | ### getDeck 48 | Finds a deck by its deck code. 49 | 50 | #### Parameters 51 | - `deckCode` **[string][313]** A code that identifies a deck. You can copy one from the game or various Hearthstone websites. 52 | 53 | Returns **[Promise][310]<[object][311]>** 54 | ### getMetadata 55 | Returns information about the categorization of cards. Metadata includes the card set, 56 | set group (for example, Standard or Year of the Dragon), rarity, class, card type, minion type, and keywords. 57 | 58 | Returns **[Promise][310]<[object][311]>** 59 | ### getSpecificMetadata 60 | Returns information about just one type of metadata. 61 | 62 | #### Parameters 63 | - `type` **[string][313]** The type of the metadata to retrieve. Valid values include sets, setGroups, types, 64 | rarities, classes, minionTypes, and keywords. 65 | 66 | Returns **[Promise][310]<[object][311]>** 67 | 68 | ________________________________ 69 | 70 | ### CardSearch 71 | 72 | Object parameters used for the drilldown searching of hearthstone cards. 73 | 74 | #### set 75 | 76 | (OPTIONAL) The slug of the set the card belongs to. If you do not supply a value, cards from all sets will be returned. 77 | 78 | Type: [string][313] 79 | 80 | #### classSlug 81 | 82 | (OPTIONAL) The slug of the card's class. 83 | 84 | Type: [string][313] 85 | 86 | #### manaCost 87 | 88 | (OPTIONAL) The mana cost required to play the card. You can include multiple values in a comma-separated list of numeric values. 89 | 90 | Type: [string][313] 91 | 92 | #### attack 93 | 94 | (OPTIONAL) The attack power of the minion or weapon. You can include multiple values in a comma-separated list of numeric values. 95 | 96 | Type: [string][313] 97 | 98 | #### health 99 | 100 | (OPTIONAL) The health of a minion. You can include multiple values in a comma-separated list of numeric values. 101 | 102 | Type: [string][313] 103 | 104 | #### collectible 105 | 106 | (OPTIONAL) Whether a card is collectible. A value of 1 indicates that collectible cards should be returned; 0 indicates uncollectible cards. To return all cards, use a value of '0,1'. 107 | 108 | Type: [string][313] 109 | 110 | #### rarity 111 | 112 | (OPTIONAL) The type of card (for example, minion, spell, and so on). This value must match the type slugs found in metadata. 113 | 114 | Type: [string][313] 115 | 116 | #### type 117 | 118 | (OPTIONAL) The type of minion card (for example, beast, murloc, dragon, and so on). This value must match the minion type slugs found in metadata. 119 | 120 | Type: [string][26] 121 | 122 | #### minionType 123 | 124 | (OPTIONAL) The type of minion card (for example, beast, murloc, dragon, and so on). This value must match the minion type slugs found in metadata. 125 | 126 | Type: [string][313] 127 | 128 | #### keyword 129 | 130 | (OPTIONAL) A required keyword on the card (for example, battlecry, deathrattle, and so on). This value must match the keyword slugs found in metadata. 131 | 132 | Type: [string][313] 133 | 134 | #### textFilter 135 | 136 | (OPTIONAL) A text string used to filter cards. You must include a locale along with the textFilter parameter. 137 | 138 | Type: [string][313] 139 | 140 | #### page 141 | 142 | (OPTIONAL) A page number. 143 | 144 | Type: [number][312] 145 | 146 | #### pageSize 147 | 148 | (OPTIONAL) The number of results to choose per page. A value will be selected automatically if you do not supply a pageSize or if the pageSize is higher than the maximum allowed. 149 | 150 | Type: [number][312] 151 | 152 | #### sort 153 | 154 | (OPTIONAL) The field used to sort the results. Valid values include manaCost, attack, health, and name. Results are sorted by manaCost by default. Cards will also be sorted by class automatically in most cases. 155 | 156 | Type: [string][313] 157 | 158 | #### order 159 | 160 | (OPTIONAL) The order in which to sort the results. Valid values are asc or desc. The default value is asc. 161 | 162 | Type: [string][313] 163 | 164 | [28]: #CardSearch 165 | 166 | [36]: #searchcards 167 | [37]: #getcard 168 | [39]: #getdeck 169 | [41]: #getmetadata 170 | [42]: #getspecificmetadata 171 | [310]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise 172 | [311]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object 173 | [312]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number 174 | [313]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -------------------------------------------------------------------------------- /src/hearthstone/gameData.ts: -------------------------------------------------------------------------------- 1 | // Hearthstone Game Data API documentation: https://develop.battle.net/documentation/hearthstone/game-data-apis 2 | 3 | import {AxiosInstance} from "axios"; 4 | 5 | /** 6 | * Object parameters used for the drilldown searching of hearthstone cards. 7 | */ 8 | interface CardSearch { 9 | 10 | /** 11 | * (OPTIONAL) The slug of the set the card belongs to. If you do not supply a value, cards from all sets will be returned. 12 | */ 13 | set?: string, 14 | 15 | /** 16 | * (OPTIONAL) The slug of the card's class. 17 | */ 18 | classSlug?: string, 19 | 20 | /** 21 | * (OPTIONAL) The mana cost required to play the card. You can include multiple values in a comma-separated list of numeric values. 22 | */ 23 | manaCost?: string, 24 | 25 | /** 26 | * (OPTIONAL) The attack power of the minion or weapon. You can include multiple values in a comma-separated list of numeric values. 27 | */ 28 | attack?: string, 29 | 30 | /** 31 | * (OPTIONAL) The health of a minion. You can include multiple values in a comma-separated list of numeric values. 32 | */ 33 | health?: string, 34 | 35 | /** 36 | * (OPTIONAL) Whether a card is collectible. A value of 1 indicates that collectible cards should be returned; 0 indicates uncollectible cards. To return all cards, use a value of '0,1'. 37 | */ 38 | collectible?: string, 39 | 40 | /** 41 | * (OPTIONAL) The type of card (for example, minion, spell, and so on). This value must match the type slugs found in metadata. 42 | */ 43 | rarity?: string, 44 | 45 | /** 46 | * (OPTIONAL) The type of minion card (for example, beast, murloc, dragon, and so on). This value must match the minion type slugs found in metadata. 47 | */ 48 | type?: string, 49 | 50 | /** 51 | * (OPTIONAL) The type of minion card (for example, beast, murloc, dragon, and so on). This value must match the minion type slugs found in metadata. 52 | */ 53 | minionType?: string, 54 | 55 | /** 56 | * (OPTIONAL) A required keyword on the card (for example, battlecry, deathrattle, and so on). This value must match the keyword slugs found in metadata. 57 | */ 58 | keyword?: string, 59 | 60 | /** 61 | * (OPTIONAL) A text string used to filter cards. You must include a locale along with the textFilter parameter. 62 | */ 63 | textFilter?: string, 64 | 65 | /** 66 | * (OPTIONAL) A page number. 67 | */ 68 | page?: number, 69 | 70 | /** 71 | * (OPTIONAL) The number of results to choose per page. A value will be selected automatically if you do not supply a pageSize or if the pageSize is higher than the maximum allowed. 72 | */ 73 | pageSize?: number, 74 | 75 | /** 76 | * (OPTIONAL) The field used to sort the results. Valid values include manaCost, attack, health, and name. Results are sorted by manaCost by default. Cards will also be sorted by class automatically in most cases. 77 | */ 78 | sort?: string, 79 | 80 | /** 81 | * (OPTIONAL) The order in which to sort the results. Valid values are asc or desc. The default value is asc. 82 | */ 83 | order?: string 84 | } 85 | 86 | class HearthstoneGameData { 87 | private readonly axios: AxiosInstance; 88 | private readonly defaultAxiosParams: object; 89 | private readonly gameBaseUrlPath: string = '/hearthstone'; 90 | 91 | constructor(axiosInstance: AxiosInstance, defaultAxiosParams: object) { 92 | this.axios = axiosInstance; 93 | this.defaultAxiosParams = defaultAxiosParams; 94 | } 95 | 96 | /**************************** 97 | * Cards API 98 | ****************************/ 99 | 100 | /** 101 | * Returns all of the cards that match the passed parameters. 102 | * 103 | * @param searchParams 104 | */ 105 | async searchCards(searchParams: CardSearch): Promise { 106 | try { 107 | const response = await this.axios.get(`${this.gameBaseUrlPath}/cards`, { 108 | params: { 109 | ...searchParams, 110 | ...this.defaultAxiosParams, 111 | }}); 112 | return response.data; 113 | } catch (error) { 114 | console.log(error); 115 | throw new Error('Error fetching cards that matched the passed parameters.'); 116 | } 117 | } 118 | 119 | /** 120 | * Returns the card with an ID or slug that matches the one you specify. 121 | * 122 | * @param cardSlug An ID or slug that uniquely identifies a card. You can discover these values by using the `/hearthstone/cards` search endpoint. 123 | */ 124 | async getCard(cardSlug: number): Promise { 125 | return await this._handleApiCall( 126 | `${this.gameBaseUrlPath}/cards/${cardSlug}`, 127 | 'Error fetching the specified card.' 128 | ); 129 | } 130 | 131 | /**************************** 132 | * Decks API 133 | ****************************/ 134 | 135 | /** 136 | * Finds a deck by its deck code. 137 | * 138 | * @param deckCode A code that identifies a deck. You can copy one from the game or various Hearthstone websites. 139 | */ 140 | async getDeck(deckCode: string): Promise { 141 | return await this._handleApiCall( 142 | `${this.gameBaseUrlPath}/deck/${deckCode}`, 143 | 'Error fetching the specified deck.' 144 | ); 145 | } 146 | 147 | /**************************** 148 | * Metadata API 149 | ****************************/ 150 | 151 | /** 152 | * Returns information about the categorization of cards. Metadata includes the card set, 153 | * set group (for example, Standard or Year of the Dragon), rarity, class, card type, minion type, and keywords. 154 | */ 155 | async getMetadata(): Promise { 156 | return await this._handleApiCall( 157 | `${this.gameBaseUrlPath}/metadata`, 158 | 'Error fetching the metadata.' 159 | ); 160 | } 161 | 162 | /** 163 | * Returns information about just one type of metadata. 164 | * 165 | * @param type The type of the metadata to retrieve. Valid values include sets, setGroups, types, 166 | * rarities, classes, minionTypes, and keywords. 167 | */ 168 | async getSpecificMetadata(type: string): Promise { 169 | return await this._handleApiCall( 170 | `${this.gameBaseUrlPath}/metadata/${type}`, 171 | 'Error fetching the specified metadata.' 172 | ); 173 | } 174 | 175 | /******************************** 176 | * Private Class Helper Functions 177 | ********************************/ 178 | 179 | async _handleApiCall(apiUrl: string, errorMessage: string): Promise { 180 | try { 181 | const response = await this.axios.get(encodeURI(apiUrl)); 182 | return response.data; 183 | } catch (error) { 184 | console.log(error); 185 | throw new Error(`Hearthstone Game Data Error :: ${errorMessage}`); 186 | } 187 | } 188 | } 189 | 190 | export default HearthstoneGameData; -------------------------------------------------------------------------------- /src/sc2/README.md: -------------------------------------------------------------------------------- 1 | ## Starcraft 2 Community 2 | 3 | In order to use these functions, you will need to have initialized the BattleNetWrapper class and then you can use these functions. 4 | 5 | ***Example implementation:*** 6 | ``` 7 | const battleNetWrapper = require('battlenet-api-wrapper'); 8 | 9 | const clientId = 'YOUR_CLIENT_ID'; 10 | const clientSecret = 'YOUR_CLIENT_SECRET'; 11 | 12 | (async function() { 13 | const bnw = new battleNetWrapper(); 14 | await bnw.init(clientId, clientSecret); 15 | const data = await bnw.Starcraft2Community.getSeason(seasonId); 16 | }()); 17 | ``` 18 | 19 | **Available Functions** 20 | 21 | - [getStaticProfileData][44] 22 | - [getMetadata][46] 23 | - [getProfile][48] 24 | - [getLadderSummary][50] 25 | - [getLadder][52] 26 | - [getGrandmasterLeaderboard][54] 27 | - [getSeason][56] 28 | - [getPlayer][58] 29 | - [getLegacyProfile][60] 30 | - [getLegacyProfileLadders][62] 31 | - [getLegacyProfileMatches][64] 32 | - [getLegacyAchievements][66] 33 | - [getLegacyRewards][68] 34 | 35 | 36 | ### getStaticProfileData 37 | 38 | Returns all static SC2 profile data (achievements, categories, criteria, and rewards). 39 | 40 | #### Parameters 41 | 42 | - `regionId` **[number][312]** The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 43 | 44 | Returns **[Promise][310]<[object][311]>** 45 | 46 | ### getMetadata 47 | 48 | Returns metadata for an individual's profile. 49 | 50 | #### Parameters 51 | 52 | - `regionId` **[number][312]** The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 53 | - `realmId` **[number][312]** The region of the profile (`1` or `2`). 54 | - `profileId` **[number][312]** The profile ID. 55 | 56 | Returns **[Promise][310]<[object][311]>** 57 | 58 | 59 | ### getProfile 60 | 61 | Returns data about an individual SC2 profile. 62 | 63 | #### Parameters 64 | 65 | - `regionId` **[number][312]** The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 66 | - `realmId` **[number][312]** The region of the profile (`1` or `2`). 67 | - `profileId` **[number][312]** The profile ID. 68 | 69 | Returns **[Promise][310]<[object][311]>** 70 | 71 | ### getLadderSummary 72 | 73 | Returns a ladder summary for an individual SC2 profile. 74 | 75 | #### Parameters 76 | 77 | - `regionId` **[number][312]** The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 78 | - `realmId` **[number][312]** The region of the profile (`1` or `2`). 79 | - `profileId` **[number][312]** The profile ID. 80 | 81 | Returns **[Promise][310]<[object][311]>** 82 | 83 | ### getLadder 84 | 85 | Returns data about an individual profile's ladder. 86 | 87 | #### Parameters 88 | 89 | - `regionId` **[number][312]** The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 90 | - `realmId` **[number][312]** The region of the profile (`1` or `2`). 91 | - `profileId` **[number][312]** The profile ID. 92 | - `ladderId` **[number][312]** The ID of the ladder for which to retrieve data. 93 | 94 | Returns **[Promise][310]<[object][311]>** 95 | 96 | ### getGrandmasterLeaderboard 97 | 98 | Returns ladder data for the current season's grandmaster leaderboard. 99 | 100 | #### Parameters 101 | 102 | - `regionId` **[number][312]** The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 103 | 104 | Returns **[Promise][310]<[object][311]>** 105 | 106 | ### getSeason 107 | 108 | Returns data about the current season. 109 | 110 | #### Parameters 111 | 112 | - `regionId` **[number][312]** The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 113 | 114 | Returns **[Promise][310]<[object][311]>** 115 | 116 | ### getPlayer 117 | 118 | Returns metadata for an individual's account. 119 | 120 | #### Parameters 121 | 122 | - `accountId` **[number][312]** The ID of the account for which to retrieve data. 123 | 124 | Returns **[Promise][310]<[object][311]>** 125 | 126 | ### getLegacyProfile 127 | 128 | Retrieves data about an individual SC2 profile. 129 | 130 | #### Parameters 131 | 132 | - `regionId` **[number][312]** The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 133 | - `realmId` **[number][312]** The region of the profile (`1` or `2`). 134 | - `profileId` **[number][312]** The profile ID. 135 | 136 | Returns **[Promise][310]<[object][311]>** 137 | 138 | ### getLegacyProfileLadders 139 | 140 | Retrieves data about an individual SC2 profile's ladders. 141 | 142 | #### Parameters 143 | 144 | - `regionId` **[number][312]** The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 145 | - `realmId` **[number][312]** The region of the profile (`1` or `2`). 146 | - `profileId` **[number][312]** The profile ID. 147 | 148 | Returns **[Promise][310]<[object][311]>** 149 | 150 | ### getLegacyProfileMatches 151 | 152 | Returns data about an individual SC2 profile's match history. 153 | 154 | #### Parameters 155 | 156 | - `regionId` **[number][312]** The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 157 | - `realmId` **[number][312]** The region of the profile (`1` or `2`). 158 | - `profileId` **[number][312]** The profile ID. 159 | 160 | Returns **[Promise][310]<[object][311]>** 161 | 162 | ### getLegacyAchievements 163 | 164 | Returns data about the achievements available in SC2. 165 | 166 | #### Parameters 167 | 168 | - `regionId` **[number][312]** The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 169 | 170 | Returns **[Promise][310]<[object][311]>** 171 | 172 | ### getLegacyRewards 173 | 174 | Returns data about the rewards available in SC2. 175 | 176 | #### Parameters 177 | 178 | - `regionId` **[number][312]** The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 179 | 180 | Returns **[Promise][310]<[object][311]>** 181 | 182 | ## Starcraft 2 Game Data 183 | 184 | In order to use these functions, you will need to have initialized the BattleNetWrapper class and then you can use these functions. 185 | 186 | ***Example implementation:*** 187 | ``` 188 | const battleNetWrapper = require('battlenet-api-wrapper'); 189 | 190 | const clientId = 'YOUR_CLIENT_ID'; 191 | const clientSecret = 'YOUR_CLIENT_SECRET'; 192 | 193 | (async function() { 194 | const bnw = new battleNetWrapper(); 195 | await bnw.init(clientId, clientSecret); 196 | const data = await bnw.Starcraft2GameData.getLeagueData('seasonId', 'queueId', 'teamType', 'leagueId'); 197 | }()); 198 | ``` 199 | 200 | **Available Functions** 201 | 202 | - [getLeagueData][70] 203 | 204 | ### getLeagueData 205 | 206 | Returns data for the specified season, queue, team, and league. 207 | 208 | **queueId**: the standard available queueIds are: 209 | `1`=WoL 1v1, `2`=WoL 2v2, `3`=WoL 3v3, `4`=WoL 4v4, `101`=HotS 1v1, `102`=HotS 2v2, `103`=HotS 3v3, `104`=HotS 4v4, 210 | `201`=LotV 1v1, `202`=LotV 2v2, `203`=LotV 3v3, `204`=LotV 4v4, `206`=LotV Archon. 211 | 212 | Note that other available queues may not be listed here. 213 | 214 | **teamType**: there are two available teamTypes: `0`=arranged, `1`=random. 215 | 216 | **leagueId**: available leagueIds are: `0`=Bronze, `1`=Silver, `2`=Gold, `3`=Platinum, `4`=Diamond, `5`=Master, `6`=Grandmaster. 217 | 218 | #### Parameters 219 | 220 | - `seasonId` **[string][313]** The season ID of the data to retrieve. 221 | - `queueId` **[string][313]** The queue ID of the data to retrieve. 222 | - `teamType` **[string][313]** The team type of the data to retrieve. 223 | - `leagueId` **[string][313]** The league ID of the data to retrieve. 224 | 225 | Returns **[Promise][310]<[object][311]>** 226 | 227 | [44]: #getstaticprofiledata 228 | 229 | [45]: #parameters-19 230 | 231 | [46]: #getmetadata 232 | 233 | [47]: #parameters-20 234 | 235 | [48]: #getprofile 236 | 237 | [49]: #parameters-21 238 | 239 | [50]: #getladdersummary 240 | 241 | [51]: #parameters-22 242 | 243 | [52]: #getladder 244 | 245 | [53]: #parameters-23 246 | 247 | [54]: #getgrandmasterleaderboard 248 | 249 | [55]: #parameters-24 250 | 251 | [56]: #getseason-1 252 | 253 | [57]: #parameters-25 254 | 255 | [58]: #getplayer 256 | 257 | [59]: #parameters-26 258 | 259 | [60]: #getlegacyprofile 260 | 261 | [61]: #parameters-27 262 | 263 | [62]: #getlegacyprofileladders 264 | 265 | [63]: #parameters-28 266 | 267 | [64]: #getlegacyprofilematches 268 | 269 | [65]: #parameters-29 270 | 271 | [66]: #getlegacyachievements 272 | 273 | [67]: #parameters-30 274 | 275 | [68]: #getlegacyrewards 276 | 277 | [69]: #parameters-31 278 | 279 | [70]: #getleaguedata 280 | 281 | [71]: #parameters-32 282 | 283 | [310]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise 284 | 285 | [311]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object 286 | 287 | [312]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number 288 | 289 | [313]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -------------------------------------------------------------------------------- /src/sc2/community.ts: -------------------------------------------------------------------------------- 1 | // Starcraft 2 Community API documentation: https://develop.battle.net/documentation/starcraft-2/community-apis 2 | 3 | import {AxiosInstance} from "axios"; 4 | 5 | class Starcraft2Community { 6 | private readonly axios: AxiosInstance; 7 | private readonly gameBaseUrlPath: string = '/sc2'; 8 | 9 | constructor(axiosInstance: AxiosInstance) { 10 | this.axios = axiosInstance; 11 | } 12 | 13 | /**************************** 14 | * Profile API 15 | ****************************/ 16 | 17 | /** 18 | * Returns all static SC2 profile data (achievements, categories, criteria, and rewards). 19 | * 20 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 21 | */ 22 | async getStaticProfileData(regionId: number): Promise { 23 | return await this._handleApiCall( 24 | `${this.gameBaseUrlPath}/static/profile/${regionId}`, 25 | 'Error fetching static profile data for the specified region.' 26 | ); 27 | } 28 | 29 | /** 30 | * Returns metadata for an individual's profile. 31 | * 32 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 33 | * @param realmId The region of the profile (`1` or `2`). 34 | * @param profileId The profile ID. 35 | */ 36 | async getMetadata(regionId: number, realmId: number, profileId: number): Promise { 37 | return await this._handleApiCall( 38 | `${this.gameBaseUrlPath}/static/profile/${regionId}/${realmId}/${profileId}`, 39 | 'Error fetching profile data for the specified region.' 40 | ); 41 | } 42 | 43 | /** 44 | * Returns data about an individual SC2 profile. 45 | * 46 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 47 | * @param realmId The region of the profile (`1` or `2`). 48 | * @param profileId The profile ID. 49 | */ 50 | async getProfile(regionId: number, realmId: number, profileId: number): Promise { 51 | return await this._handleApiCall( 52 | `${this.gameBaseUrlPath}/profile/${regionId}/${realmId}/${profileId}`, 53 | 'Error fetching specified profile data.' 54 | ); 55 | } 56 | 57 | /** 58 | * Returns a ladder summary for an individual SC2 profile. 59 | * 60 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 61 | * @param realmId The region of the profile (`1` or `2`). 62 | * @param profileId The profile ID. 63 | */ 64 | async getLadderSummary(regionId: number, realmId: number, profileId: number): Promise { 65 | return await this._handleApiCall( 66 | `${this.gameBaseUrlPath}/profile/${regionId}/${realmId}/${profileId}/ladder/summary`, 67 | 'Error fetching specified ladder summary.' 68 | ); 69 | } 70 | 71 | /** 72 | * Returns data about an individual profile's ladder. 73 | * 74 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 75 | * @param realmId The region of the profile (`1` or `2`). 76 | * @param profileId The profile ID. 77 | * @param ladderId The ID of the ladder for which to retrieve data. 78 | */ 79 | async getLadder(regionId: number, realmId: number, profileId: number, ladderId: number): Promise { 80 | return await this._handleApiCall( 81 | `${this.gameBaseUrlPath}/profile/${regionId}/${realmId}/${profileId}/ladder/${ladderId}`, 82 | 'Error fetching specified ladder.' 83 | ); 84 | } 85 | 86 | /**************************** 87 | * Ladder API 88 | ****************************/ 89 | 90 | /** 91 | * Returns ladder data for the current season's grandmaster leaderboard. 92 | * 93 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 94 | */ 95 | async getGrandmasterLeaderboard(regionId: number): Promise { 96 | return await this._handleApiCall( 97 | `${this.gameBaseUrlPath}/ladder/grandmaster/${regionId}`, 98 | 'Error fetching static profile data for the specified region.' 99 | ); 100 | } 101 | 102 | /** 103 | * Returns data about the current season. 104 | * 105 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 106 | */ 107 | async getSeason(regionId: number): Promise { 108 | return await this._handleApiCall( 109 | `${this.gameBaseUrlPath}/ladder/season/${regionId}`, 110 | 'Error fetching static profile data for the specified region.' 111 | ); 112 | } 113 | 114 | /**************************** 115 | * Account API 116 | ****************************/ 117 | 118 | /** 119 | * Returns metadata for an individual's account. 120 | * 121 | * @param accountId The ID of the account for which to retrieve data. 122 | */ 123 | async getPlayer(accountId: number): Promise { 124 | return await this._handleApiCall( 125 | `${this.gameBaseUrlPath}/player/${accountId}`, 126 | 'Error fetching metadata for player account.' 127 | ); 128 | } 129 | 130 | /**************************** 131 | * Legacy API 132 | ****************************/ 133 | 134 | /** 135 | * Retrieves data about an individual SC2 profile. 136 | * 137 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 138 | * @param realmId The region of the profile (`1` or `2`). 139 | * @param profileId The profile ID. 140 | */ 141 | async getLegacyProfile(regionId: number, realmId: number, profileId: number): Promise { 142 | return await this._handleApiCall( 143 | `${this.gameBaseUrlPath}/legacy/profile/${regionId}/${realmId}/${profileId}`, 144 | 'Error fetching specified legacy profile data.' 145 | ); 146 | } 147 | 148 | /** 149 | * Retrieves data about an individual SC2 profile's ladders. 150 | * 151 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 152 | * @param realmId The region of the profile (`1` or `2`). 153 | * @param profileId The profile ID. 154 | */ 155 | async getLegacyProfileLadders(regionId: number, realmId: number, profileId: number): Promise { 156 | return await this._handleApiCall( 157 | `${this.gameBaseUrlPath}/legacy/profile/${regionId}/${realmId}/${profileId}/ladders`, 158 | 'Error fetching specified legacy profile ladder data.' 159 | ); 160 | } 161 | 162 | /** 163 | * Returns data about an individual SC2 profile's match history. 164 | * 165 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 166 | * @param realmId The region of the profile (`1` or `2`). 167 | * @param profileId The profile ID. 168 | */ 169 | async getLegacyProfileMatches(regionId: number, realmId: number, profileId: number): Promise { 170 | return await this._handleApiCall( 171 | `${this.gameBaseUrlPath}/legacy/profile/${regionId}/${realmId}/${profileId}/matches`, 172 | 'Error fetching specified legacy profile match data.' 173 | ); 174 | } 175 | 176 | /** 177 | * Returns data about the achievements available in SC2. 178 | * 179 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 180 | */ 181 | async getLegacyAchievements(regionId: number): Promise { 182 | return await this._handleApiCall( 183 | `${this.gameBaseUrlPath}/legacy/data/achievements/${regionId}`, 184 | 'Error fetching specified legacy achievement data.' 185 | ); 186 | } 187 | 188 | /** 189 | * Returns data about the rewards available in SC2. 190 | * 191 | * @param regionId The region for the profile (`1`=US, `2`=EU, `3`=KO and TW, `5`=CN). 192 | */ 193 | async getLegacyRewards(regionId: number): Promise { 194 | return await this._handleApiCall( 195 | `${this.gameBaseUrlPath}/legacy/data/rewards/${regionId}`, 196 | 'Error fetching specified legacy rewards data.' 197 | ); 198 | } 199 | 200 | /******************************** 201 | * Private Class Helper Functions 202 | ********************************/ 203 | 204 | async _handleApiCall(apiUrl: string, errorMessage: string): Promise { 205 | try { 206 | const response = await this.axios.get(encodeURI(apiUrl)); 207 | return response.data; 208 | } catch (error) { 209 | console.log(error); 210 | throw new Error(`Starcraft 2 Community Error :: ${errorMessage}`); 211 | } 212 | } 213 | } 214 | 215 | export default Starcraft2Community; -------------------------------------------------------------------------------- /src/sc2/gameData.ts: -------------------------------------------------------------------------------- 1 | // Starcraft 2 Game Data API documentation: https://develop.battle.net/documentation/starcraft-2/game-data-apis 2 | 3 | import {AxiosInstance} from "axios"; 4 | 5 | class Starcraft2GameData { 6 | private readonly axios: AxiosInstance; 7 | private readonly gameBaseUrlPath: string = '/data/sc2'; 8 | 9 | constructor(axiosInstance: AxiosInstance) { 10 | this.axios = axiosInstance; 11 | } 12 | 13 | /** 14 | * Returns data for the specified season, queue, team, and league. 15 | * 16 | * **queueId**: the standard available queueIds are: 17 | * `1`=WoL 1v1, `2`=WoL 2v2, `3`=WoL 3v3, `4`=WoL 4v4, `101`=HotS 1v1, `102`=HotS 2v2, `103`=HotS 3v3, `104`=HotS 4v4, 18 | * `201`=LotV 1v1, `202`=LotV 2v2, `203`=LotV 3v3, `204`=LotV 4v4, `206`=LotV Archon. 19 | * 20 | * Note that other available queues may not be listed here. 21 | * 22 | * **teamType**: there are two available teamTypes: `0`=arranged, `1`=random. **leagueId**: 23 | * available leagueIds are: `0`=Bronze, `1`=Silver, `2`=Gold, `3`=Platinum, `4`=Diamond, `5`=Master, `6`=Grandmaster. 24 | * 25 | * @param seasonId The season ID of the data to retrieve. 26 | * @param queueId The queue ID of the data to retrieve. 27 | * @param teamType The team type of the data to retrieve. 28 | * @param leagueId The league ID of the data to retrieve. 29 | */ 30 | async getLeagueData(seasonId: string, queueId: string, teamType: string, leagueId: string): Promise { 31 | return await this._handleApiCall( 32 | `${this.gameBaseUrlPath}/league/${seasonId}/${queueId}/${teamType}/${leagueId}`, 33 | 'Error fetching the league data.' 34 | ); 35 | } 36 | 37 | /******************************** 38 | * Private Class Helper Functions 39 | ********************************/ 40 | 41 | async _handleApiCall(apiUrl: string, errorMessage: string): Promise { 42 | try { 43 | const response = await this.axios.get(encodeURI(apiUrl)); 44 | return response.data; 45 | } catch (error) { 46 | console.log(error); 47 | throw new Error(`Starcraft 2 Game Data Error :: ${errorMessage}`); 48 | } 49 | } 50 | } 51 | 52 | export default Starcraft2GameData; -------------------------------------------------------------------------------- /src/utils.ts: -------------------------------------------------------------------------------- 1 | export async function formatBattleTag(battleTag: string): Promise { 2 | return battleTag.replace('#', '-'); 3 | } -------------------------------------------------------------------------------- /src/wow/community.ts: -------------------------------------------------------------------------------- 1 | // WoW Game Data API documentation: https://develop.battle.net/documentation/world-of-warcraft/game-data-apis 2 | 3 | import {AxiosInstance} from "axios"; 4 | 5 | class WowCommunity { 6 | private readonly axios: AxiosInstance; 7 | private readonly defaultAxiosParams: object; 8 | private readonly gameBaseUrlPath: string = '/wow'; 9 | 10 | constructor(axiosInstance: AxiosInstance, defaultAxiosParams: object) { 11 | this.axios = axiosInstance; 12 | this.defaultAxiosParams = defaultAxiosParams; 13 | } 14 | 15 | /**************************** 16 | * Achievement API 17 | ****************************/ 18 | 19 | /** 20 | * Returns data about an individual achievement. 21 | * 22 | * @param achievementId The ID of the achievement to retrieve. 23 | */ 24 | async getAchievement(achievementId: number): Promise { 25 | return await this._handleApiCall( 26 | `${this.gameBaseUrlPath}/achievement/${achievementId}`, 27 | 'Error fetching specified achievement.' 28 | ); 29 | } 30 | 31 | /**************************** 32 | * Boss API 33 | ****************************/ 34 | 35 | /** 36 | * Returns a list of all supported bosses. A "boss" in this context should be considered a boss encounter, 37 | * which may include more than one NPC. 38 | */ 39 | async getBossMasterList(): Promise { 40 | return await this._handleApiCall( 41 | `${this.gameBaseUrlPath}/boss`, 42 | 'Error fetching master boss list.' 43 | ); 44 | } 45 | 46 | /** 47 | * Returns information about the specified boss. A "boss" in this context should be considered a boss encounter, 48 | * which may include more than one NPC. 49 | * 50 | * @param bossId The ID of the boss to retrieve. 51 | */ 52 | async getBoss(bossId: number): Promise { 53 | return await this._handleApiCall( 54 | `${this.gameBaseUrlPath}/boss/${bossId}`, 55 | 'Error fetching specified boss.' 56 | ); 57 | } 58 | 59 | /**************************** 60 | * Challenge Mode API 61 | ****************************/ 62 | 63 | /** 64 | * The request returns data for all nine challenge mode maps (currently). The map field includes the current medal 65 | * times for each dungeon. Each ladder provides data about each character that was part of each run. The 66 | * character data includes the current cached specialization of the character while the member field includes the 67 | * specialization of the character during the challenge mode run. 68 | * 69 | * @param realmSlug The realm to request. 70 | */ 71 | async getChallengeModeRealmLeaderboard(realmSlug: string): Promise { 72 | return await this._handleApiCall( 73 | `${this.gameBaseUrlPath}/challenge/${realmSlug}`, 74 | 'Error fetching challenge mode realm leaderboard.' 75 | ); 76 | } 77 | 78 | /** 79 | * The region leaderboard has the exact same data format as the realm leaderboards except there is no `realm` field. 80 | * Instead, the response has the top 100 results gathered for each map for all of the available realm leaderboards 81 | * in a region. 82 | */ 83 | async getChallengeModeRegionLeaderboard(): Promise { 84 | return await this._handleApiCall( 85 | `${this.gameBaseUrlPath}/challenge/region`, 86 | 'Error fetching challenge mode region leaderboard.' 87 | ); 88 | } 89 | 90 | /**************************** 91 | * Character Profile API 92 | ****************************/ 93 | 94 | /** 95 | * Returns a character profile. In order to get additional fields, you have to specify them in the fields parameter 96 | * as comma-delimited list. 97 | * 98 | * Your options for the fields are: 99 | * 100 | * achievements, appearance, feed, guild, hunterPets, items, mounts, pets, petSlots, professions, progression, 101 | * pvp, quests, reputation, statistics, stats, talents, titles, audit. 102 | * 103 | * @param realm The character's realm. Can be provided as the proper realm name or the normalized realm name. 104 | * @param characterName The name of the character to retrieve. 105 | * @param fields Specifies the data to retrieve. 106 | */ 107 | async getCharacterProfile(realm: string, characterName: string, fields: string): Promise { 108 | try { 109 | const response = await this.axios.get( 110 | encodeURI(`${this.gameBaseUrlPath}/character/${realm}/${characterName}`), 111 | { 112 | params: { 113 | fields: fields, 114 | ...this.defaultAxiosParams 115 | } 116 | }); 117 | return response.data; 118 | } catch (error) { 119 | console.log(error); 120 | throw new Error(`WoW Community Error :: Error fetching character profile.`); 121 | } 122 | } 123 | 124 | /**************************** 125 | * Guild API 126 | ****************************/ 127 | 128 | /** 129 | * Returns a guild profile. In order to get additional fields, you have to specify them in the fields parameter 130 | * as comma-delimited list. 131 | * 132 | * Your options for the fields are: 133 | * 134 | * achievements, challenges, members, news 135 | * 136 | * @param realm The guild's realm. 137 | * @param guildName The name of the guild to query. 138 | * @param fields The optional data to retrieve about the guild. 139 | */ 140 | async getGuildProfile(realm: string, guildName: string, fields: string): Promise { 141 | try { 142 | const response = await this.axios.get( 143 | encodeURI(`${this.gameBaseUrlPath}/guild/${realm}/${guildName}`), 144 | { 145 | params: { 146 | fields: fields, 147 | ...this.defaultAxiosParams 148 | } 149 | }); 150 | return response.data; 151 | } catch (error) { 152 | console.log(error); 153 | throw new Error(`WoW Community Error :: Error fetching guild profile.`); 154 | } 155 | } 156 | 157 | /**************************** 158 | * Item API 159 | ****************************/ 160 | 161 | /** 162 | * Returns detailed information about the item. 163 | * 164 | * @param itemId The requested item's unique ID. 165 | */ 166 | async getItem(itemId: number): Promise { 167 | return await this._handleApiCall( 168 | `${this.gameBaseUrlPath}/item/${itemId}`, 169 | 'Error fetching specified item.' 170 | ); 171 | } 172 | 173 | /** 174 | * Returns detailed information about the item set. 175 | * 176 | * @param setId The requested set's unique ID. 177 | */ 178 | async getItemSet(setId: string): Promise { 179 | return await this._handleApiCall( 180 | `${this.gameBaseUrlPath}/item/set/${setId}`, 181 | 'Error fetching specified item set.' 182 | ); 183 | } 184 | 185 | /**************************** 186 | * Mount API 187 | ****************************/ 188 | 189 | /** 190 | * Returns a list of all supported mounts. 191 | */ 192 | async getMountMasterList(): Promise { 193 | return await this._handleApiCall( 194 | `${this.gameBaseUrlPath}/mount`, 195 | 'Error fetching mount master list' 196 | ); 197 | } 198 | 199 | /**************************** 200 | * Pet API 201 | ****************************/ 202 | 203 | /** 204 | * Returns a list of all supported battle and vanity pets. 205 | */ 206 | async getPetMasterList(): Promise { 207 | return await this._handleApiCall( 208 | `${this.gameBaseUrlPath}/pet`, 209 | 'Error fetching pet master list.' 210 | ); 211 | } 212 | 213 | /** 214 | * Returns data about a individual battle pet ability ID. This resource does not provide ability tooltips. 215 | * 216 | * @param abilityId The ID of the ability to retrieve. 217 | */ 218 | async getPetAbilities(abilityId: string): Promise { 219 | return await this._handleApiCall( 220 | `${this.gameBaseUrlPath}/pet/ability/${abilityId}`, 221 | 'Error fetching specified pet abilities.' 222 | ); 223 | } 224 | 225 | /** 226 | * Returns data about an individual pet species. Use pets as the `field` value in a 227 | * character profile request to get species IDs. Each species also has data about its six abilities. 228 | * 229 | * @param speciesId 230 | */ 231 | async getPetSpecies(speciesId: string): Promise { 232 | return await this._handleApiCall( 233 | `${this.gameBaseUrlPath}/pet/species/${speciesId}`, 234 | 'Error fetching specified pet species.' 235 | ); 236 | } 237 | 238 | /** 239 | * Returns detailed information about a given species of pet. 240 | * 241 | * @param speciesId The pet's species ID. This can be found by querying a user's list of pets via the Character Profile API. 242 | * @param level The pet's level. Pet levels max out at 25. If omitted, the API assumes a default value of 1. 243 | * @param breedId The pet's breed. Retrievable via the Character Profile API. If omitted the API assumes a default value of 3. 244 | * @param qualityId The pet's quality. Retrievable via the Character Profile API. Pet quality can range from 0 to 5 245 | * (0 is poor quality and 5 is legendary). If omitted, the API will assume a default value of 1. 246 | */ 247 | async getPetStats(speciesId: string, level: number = 1, breedId: number = 3, qualityId: number = 1): Promise { 248 | try { 249 | const response = await this.axios.get( 250 | encodeURI(`${this.gameBaseUrlPath}/pet/stats/${speciesId}`), 251 | { 252 | params: { 253 | level: level, 254 | breedId: breedId, 255 | qualityId: qualityId, 256 | ...this.defaultAxiosParams 257 | } 258 | }); 259 | return response.data; 260 | } catch (error) { 261 | console.log(error); 262 | throw new Error(`WoW Community Error :: Error fetching specified pet stats.`); 263 | } 264 | } 265 | 266 | /**************************** 267 | * PvP Leaderboard API 268 | ****************************/ 269 | 270 | /** 271 | * Returns leaderboard information for the 2v2, 3v3, 5v5, and Rated Battleground leaderboards. 272 | * 273 | * @param bracket The type of leaderboard to retrieve. Valid entries are `2v2`, `3v3`, `5v5`, and `rbg`. 274 | */ 275 | async getPvpLeaderboards(bracket: string): Promise { 276 | return await this._handleApiCall( 277 | `${this.gameBaseUrlPath}/leaderboard/${bracket}`, 278 | 'Error fetching specified bracket leaderboard.' 279 | ); 280 | } 281 | 282 | /**************************** 283 | * Quest API 284 | ****************************/ 285 | 286 | /** 287 | * Returns metadata for a specified quest. 288 | * 289 | * @param questId The ID of the quest to retrieve. 290 | */ 291 | async getQuest(questId: string): Promise { 292 | return await this._handleApiCall( 293 | `${this.gameBaseUrlPath}/quest/${questId}`, 294 | 'Error fetching specified quest.' 295 | ); 296 | } 297 | 298 | /**************************** 299 | * Realm Status API 300 | ****************************/ 301 | 302 | /** 303 | * Retrieves realm status information. This information is limited to whether or not the realm is up, the type 304 | * and state of the realm, and the current population. 305 | */ 306 | async getRealmStatusList(): Promise { 307 | return await this._handleApiCall( 308 | `${this.gameBaseUrlPath}/realm/status`, 309 | 'Error fetching realm status list.' 310 | ); 311 | } 312 | 313 | /**************************** 314 | * Recipe API 315 | ****************************/ 316 | 317 | /** 318 | * Returns basic recipe information. 319 | * 320 | * @param recipeId Unique ID for the desired recipe. 321 | */ 322 | async getRecipe(recipeId: string): Promise { 323 | return await this._handleApiCall( 324 | `${this.gameBaseUrlPath}/recipe/${recipeId}`, 325 | 'Error fetching specified recipe.' 326 | ); 327 | } 328 | 329 | /**************************** 330 | * Spell API 331 | ****************************/ 332 | 333 | /** 334 | * Returns information about spells. 335 | * 336 | * @param spellId The ID of the spell to retrieve. 337 | */ 338 | async getSpell(spellId: string): Promise { 339 | return await this._handleApiCall( 340 | `${this.gameBaseUrlPath}/spell/${spellId}`, 341 | 'Error fetching specified spell.' 342 | ); 343 | } 344 | 345 | /**************************** 346 | * Zone API 347 | ****************************/ 348 | 349 | /** 350 | * Returns a list of all supported zones and their bosses. A "zone" in this context should be considered a 351 | * dungeon or a raid, not a world zone. A "boss" in this context should be considered a boss encounter, 352 | * which may include more than one NPC. 353 | */ 354 | async getZoneMasterList(): Promise { 355 | return await this._handleApiCall( 356 | `${this.gameBaseUrlPath}/zone`, 357 | 'Error fetching zone master list.' 358 | ); 359 | } 360 | 361 | /** 362 | * Returns information about zones. 363 | * 364 | * @param zoneId The ID of the zone to retrieve. 365 | */ 366 | async getZone(zoneId: string): Promise { 367 | return await this._handleApiCall( 368 | `${this.gameBaseUrlPath}/zone`, 369 | 'Error fetching specified zone.' 370 | ); 371 | } 372 | 373 | /**************************** 374 | * Data Resources 375 | ****************************/ 376 | 377 | /** 378 | * Returns a list of battlegroups for the specified region. 379 | */ 380 | async getBattlegroups(): Promise { 381 | return await this._handleApiCall( 382 | `${this.gameBaseUrlPath}/data/battleground/`, 383 | 'Error fetching region battlegrounds.' 384 | ); 385 | } 386 | 387 | /** 388 | * Returns a list of races and their associated faction, name, unique ID, and skin. 389 | */ 390 | async getCharacterRaces(): Promise { 391 | return await this._handleApiCall( 392 | `${this.gameBaseUrlPath}/data/character/races`, 393 | 'Error fetching character race list.' 394 | ); 395 | } 396 | 397 | /** 398 | * Returns a list of character classes. 399 | */ 400 | async getCharacterClasses(): Promise { 401 | return await this._handleApiCall( 402 | `${this.gameBaseUrlPath}/data/character/classes`, 403 | 'Error fetching character class list.' 404 | ); 405 | } 406 | 407 | /** 408 | * Returns a list of all achievements that characters can earn as well as the category structure and hierarchy. 409 | */ 410 | async getCharacterAchievements(): Promise { 411 | return await this._handleApiCall( 412 | `${this.gameBaseUrlPath}/data/character/achievements`, 413 | 'Error fetching character achievement list.' 414 | ); 415 | } 416 | 417 | /** 418 | * The guild rewards data API provides a list of all guild rewards. 419 | */ 420 | async getGuildRewards(): Promise { 421 | return await this._handleApiCall( 422 | `${this.gameBaseUrlPath}/data/guild/rewards`, 423 | 'Error fetching guild reward list.' 424 | ); 425 | } 426 | 427 | /** 428 | * Returns a list of all guild perks. 429 | */ 430 | async getGuildPerks(): Promise { 431 | return await this._handleApiCall( 432 | `${this.gameBaseUrlPath}/data/guild/perks`, 433 | 'Error fetching guild perk list.' 434 | ); 435 | } 436 | 437 | /** 438 | * Returns a list of all guild achievements as well as the category structure and hierarchy. 439 | */ 440 | async getGuildAchievements(): Promise { 441 | return await this._handleApiCall( 442 | `${this.gameBaseUrlPath}/data/guild/achievements`, 443 | 'Error fetching guild achievement list.' 444 | ); 445 | } 446 | 447 | /** 448 | * Returns a list of item classes. 449 | */ 450 | async getItemClasses(): Promise { 451 | return await this._handleApiCall( 452 | `${this.gameBaseUrlPath}/data/item/classes`, 453 | 'Error fetching item classes.' 454 | ); 455 | } 456 | 457 | /** 458 | * Returns a list of talents, specs, and glyphs for each class. 459 | */ 460 | async getTalents(): Promise { 461 | return await this._handleApiCall( 462 | `${this.gameBaseUrlPath}/data/talents`, 463 | 'Error fetching talent list.' 464 | ); 465 | } 466 | 467 | /** 468 | * Returns a list of the different battle pet types, including what they are strong and weak against. 469 | */ 470 | async getPetTypes(): Promise { 471 | return await this._handleApiCall( 472 | `${this.gameBaseUrlPath}/data/pet/types`, 473 | 'Error fetching pet type list.' 474 | ); 475 | } 476 | 477 | /******************************** 478 | * Private Class Helper Functions 479 | ********************************/ 480 | 481 | async _handleApiCall(apiUrl: string, errorMessage: string): Promise { 482 | try { 483 | const response = await this.axios.get(encodeURI(apiUrl)); 484 | return response.data; 485 | } catch (error) { 486 | console.log(error); 487 | throw new Error(`WoW Community Error :: ${errorMessage}`); 488 | } 489 | } 490 | } 491 | 492 | export default WowCommunity; -------------------------------------------------------------------------------- /src/wow/profileData.ts: -------------------------------------------------------------------------------- 1 | // WoW Profile Data API documentation: https://develop.battle.net/documentation/world-of-warcraft/profile-apis 2 | 3 | import {AxiosInstance} from "axios"; 4 | 5 | class WowProfileData { 6 | private readonly axios: AxiosInstance; 7 | private readonly defaultAxiosParams: object; 8 | private readonly namespace: string; 9 | private readonly gameBaseUrlPath: string = '/profile/wow/character'; 10 | 11 | constructor(axiosInstance: AxiosInstance, defaultAxiosParams: object, origin: string) { 12 | this.axios = axiosInstance; 13 | this.defaultAxiosParams = defaultAxiosParams; 14 | this.namespace = `profile-${origin}`; 15 | } 16 | 17 | /** 18 | * Returns a summary of the achievements a character has completed. 19 | * 20 | * @param realmSlug The slug of the realm. 21 | * @param characterName The lowercase name of the character. 22 | * 23 | */ 24 | async getCharacterAchievements(realmSlug: string, characterName: string): Promise { 25 | return await this._handleApiCall( 26 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/achievements`, 27 | 'Error fetching character achievements.' 28 | ); 29 | } 30 | 31 | /** 32 | * Returns a summary of a character's appearance settings. 33 | * 34 | * @param realmSlug The slug of the realm. 35 | * @param characterName The lowercase name of the character. 36 | * 37 | */ 38 | async getCharacterAppearance(realmSlug: string, characterName: string): Promise { 39 | return await this._handleApiCall( 40 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/appearance`, 41 | 'Error fetching character appearance.' 42 | ); 43 | } 44 | 45 | /** 46 | * Returns an index of collection types for a character. 47 | * 48 | * @param realmSlug The slug of the realm. 49 | * @param characterName The lowercase name of the character. 50 | * 51 | */ 52 | async getCharacterCollectionsIndex(realmSlug: string, characterName: string): Promise { 53 | return await this._handleApiCall( 54 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/collections`, 55 | 'Error fetching character collections.' 56 | ); 57 | } 58 | 59 | /** 60 | * Returns a summary of the mounts a character has obtained. 61 | * 62 | * @param realmSlug The slug of the realm. 63 | * @param characterName The lowercase name of the character. 64 | * 65 | */ 66 | async getCharacterMountsCollection(realmSlug: string, characterName: string): Promise { 67 | return await this._handleApiCall( 68 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/collections/mounts`, 69 | 'Error fetching character mounts collection.' 70 | ); 71 | } 72 | 73 | /** 74 | * Returns a summary of the battle pets a character has obtained. 75 | * 76 | * @param realmSlug The slug of the realm. 77 | * @param characterName The lowercase name of the character. 78 | * 79 | */ 80 | async getCharacterPetsCollection(realmSlug: string, characterName: string): Promise { 81 | return await this._handleApiCall( 82 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/collections/pets`, 83 | 'Error fetching character pets collection.' 84 | ); 85 | } 86 | 87 | /** 88 | * Returns a summary of the items equipped by a character. 89 | * 90 | * @param realmSlug The slug of the realm. 91 | * @param characterName The lowercase name of the character. 92 | * 93 | */ 94 | async getCharacterEquipment(realmSlug: string, characterName: string): Promise { 95 | return await this._handleApiCall( 96 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/equipment`, 97 | 'Error fetching character equipment.' 98 | ); 99 | } 100 | 101 | /** 102 | * If the character is a hunter, returns a summary of the character's hunter pets. 103 | * Otherwise, returns an HTTP 404 Not Found error. 104 | * 105 | * @param realmSlug The slug of the realm. 106 | * @param characterName The lowercase name of the character. 107 | * 108 | */ 109 | async getCharacterHunterPets(realmSlug: string, characterName: string): Promise { 110 | return await this._handleApiCall( 111 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/hunter-pets`, 112 | 'Error fetching character hunter pets.' 113 | ); 114 | } 115 | 116 | /** 117 | * Returns a summary of the media assets available for a character (such as an avatar render). 118 | * 119 | * @param realmSlug The slug of the realm. 120 | * @param characterName The lowercase name of the character. 121 | * 122 | */ 123 | async getCharacterMedia(realmSlug: string, characterName: string): Promise { 124 | return await this._handleApiCall( 125 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/character-media`, 126 | 'Error fetching character media.' 127 | ); 128 | } 129 | 130 | /** 131 | * Returns the Mythic Keystone profile index for a character. 132 | * 133 | * @param realmSlug The slug of the realm. 134 | * @param characterName The lowercase name of the character. 135 | * 136 | */ 137 | async getCharacterMythicKeystoneProfile(realmSlug: string, characterName: string): Promise { 138 | return await this._handleApiCall( 139 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/mythic-keystone-profile`, 140 | 'Error fetching character mythic keystone profile.' 141 | ); 142 | } 143 | 144 | /** 145 | * Returns the Mythic Keystone season details for a character. 146 | * Returns a **404 Not Found** for characters that have not yet completed a Mythic Keystone dungeon for the specified season. 147 | * 148 | * @param realmSlug The slug of the realm. 149 | * @param characterName The lowercase name of the character. 150 | * 151 | */ 152 | async getCharacterMythicKeystoneSeasonDetails(realmSlug: string, characterName: string, seasonId: string): Promise { 153 | return await this._handleApiCall( 154 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/mythic-keystone-profile/season/${seasonId}`, 155 | 'Error fetching character mythic keystone profile for specified season.' 156 | ); 157 | } 158 | 159 | /** 160 | * Returns a profile summary for a character. 161 | * 162 | * @param realmSlug The slug of the realm. 163 | * @param characterName The lowercase name of the character. 164 | * 165 | */ 166 | async getCharacterSummary(realmSlug: string, characterName: string): Promise { 167 | return await this._handleApiCall( 168 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}`, 169 | 'Error fetching character summary.' 170 | ); 171 | } 172 | 173 | /** 174 | * Returns the PvP bracket statistics for a character. 175 | * 176 | * @param realmSlug The slug of the realm. 177 | * @param characterName The lowercase name of the character. 178 | * @param pvpBracket The PvP bracket type (1v1, 3v3, etc). 179 | * 180 | */ 181 | async getCharacterPvpBracketStatistics(realmSlug: string, characterName: string, pvpBracket: string): Promise { 182 | return await this._handleApiCall( 183 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/pvp-bracket/${pvpBracket}`, 184 | 'Error fetching character pvp bracket statistics.' 185 | ); 186 | } 187 | 188 | /** 189 | * Returns a PvP summary for a character. 190 | * 191 | * @param realmSlug The slug of the realm. 192 | * @param characterName The lowercase name of the character. 193 | * 194 | */ 195 | async getCharacterPvpSummary(realmSlug: string, characterName: string): Promise { 196 | return await this._handleApiCall( 197 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/pvp-summary`, 198 | 'Error fetching character pvp summary.' 199 | ); 200 | } 201 | 202 | /** 203 | * Returns a summary of a character's reputations. 204 | * 205 | * @param realmSlug The slug of the realm. 206 | * @param characterName The lowercase name of the character. 207 | * 208 | */ 209 | async getCharacterReputations(realmSlug: string, characterName: string): Promise { 210 | return await this._handleApiCall( 211 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/reputations`, 212 | 'Error fetching character reputations.' 213 | ); 214 | } 215 | 216 | /** 217 | * Returns a summary of a character's specializations. 218 | * 219 | * @param realmSlug The slug of the realm. 220 | * @param characterName The lowercase name of the character. 221 | * 222 | */ 223 | async getCharacterSpecializations(realmSlug: string, characterName: string): Promise { 224 | return await this._handleApiCall( 225 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/specializations`, 226 | 'Error fetching character specializations.' 227 | ); 228 | } 229 | 230 | /** 231 | * Returns a statistics summary for a character. 232 | * 233 | * @param realmSlug The slug of the realm. 234 | * @param characterName The lowercase name of the character. 235 | * 236 | */ 237 | async getCharacterStatistics(realmSlug: string, characterName: string): Promise { 238 | return await this._handleApiCall( 239 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/statistics`, 240 | 'Error fetching character statistics.' 241 | ); 242 | } 243 | 244 | /** 245 | * Returns a summary of titles a character has obtained. 246 | * 247 | * @param realmSlug The slug of the realm. 248 | * @param characterName The lowercase name of the character. 249 | * 250 | */ 251 | async getCharacterTitles(realmSlug: string, characterName: string): Promise { 252 | return await this._handleApiCall( 253 | `${this.gameBaseUrlPath}/${realmSlug}/${characterName}/titles`, 254 | 'Error fetching character titles.' 255 | ); 256 | } 257 | 258 | /** 259 | * Returns a single guild summary by its name and realm. 260 | * 261 | * @param realmSlug The slug of the realm. 262 | * @param guildName The slug of the guild. 263 | * 264 | */ 265 | async getGuildSummary(realmSlug: string, guildName: string): Promise { 266 | return await this._handleApiCall( 267 | `/data/wow/guild//${realmSlug}/${guildName}`, 268 | 'Error fetching guild summary.' 269 | ); 270 | } 271 | 272 | /** 273 | * Returns a single guild's achievements by name and realm. 274 | * 275 | * @param realmSlug The slug of the realm. 276 | * @param guildName The slug of the guild. 277 | * 278 | */ 279 | async getGuildAchievements(realmSlug: string, guildName: string): Promise { 280 | return await this._handleApiCall( 281 | `/data/wow/guild/${realmSlug}/${guildName}/achievements`, 282 | 'Error fetching guild achievements.' 283 | ); 284 | } 285 | 286 | /** 287 | * Returns a single guild's roster by its name and realm. 288 | * 289 | * @param realmSlug The slug of the realm. 290 | * @param guildName The slug of the guild. 291 | * 292 | */ 293 | async getGuildRoster(realmSlug: string, guildName: string): Promise { 294 | return await this._handleApiCall( 295 | `/data/wow/guild/${realmSlug}/${guildName}/roster`, 296 | 'Error fetching guild roster.' 297 | ); 298 | } 299 | 300 | /******************************** 301 | * Private Class Helper Functions 302 | ********************************/ 303 | 304 | async _handleApiCall(apiUrl: string, errorMessage: string): Promise { 305 | try { 306 | const response = await this.axios.get(encodeURI(apiUrl), { 307 | params: { 308 | namespace: this.namespace, 309 | ...this.defaultAxiosParams 310 | }}); 311 | return response.data; 312 | } catch (error) { 313 | console.log(error); 314 | throw new Error(`WoW Profile Error :: ${errorMessage}`); 315 | } 316 | } 317 | } 318 | 319 | export default WowProfileData; 320 | -------------------------------------------------------------------------------- /src/wowClassic/README.md: -------------------------------------------------------------------------------- 1 | ## WoW Classic Game Data 2 | 3 | In order to use these functions, you will need to have initialized the BattleNetWrapper class and then you can use these functions. 4 | 5 | ***Example implementation:*** 6 | ``` 7 | const battleNetWrapper = require('battlenet-api-wrapper'); 8 | 9 | const clientId = 'YOUR_CLIENT_ID'; 10 | const clientSecret = 'YOUR_CLIENT_SECRET'; 11 | 12 | (async function() { 13 | const bnw = new battleNetWrapper(); 14 | await bnw.init(clientId, clientSecret); 15 | const data = await bnw.WowClassicGameData.getCreatureFamiliesIndex(); 16 | }()); 17 | ``` 18 | 19 | **Available Functions** 20 | 21 | - [getCreatureFamiliesIndex][273] 22 | - [getCreatureFamily][274] 23 | - [getCreatureTypesIndex][276] 24 | - [getCreatureType][277] 25 | - [getCreature][279] 26 | - [getCreatureDisplayMedia][281] 27 | - [getCreatureFamilyMedia][283] 28 | - [getGuildCrestComponentsIndex][285] 29 | - [getGuildCrestBorderMedia][286] 30 | - [getGuildCrestEmblemMedia][288] 31 | - [getItemClassesIndex][290] 32 | - [getItemClass][291] 33 | - [getItemSubclass][293] 34 | - [getItem][295] 35 | - [getItemMedia][297] 36 | - [getPlayableClassIndex][299] 37 | - [getPlayableClass][300] 38 | - [getPlayableClassMedia][302] 39 | - [getPlayableRaceIndex][304] 40 | - [getPlayableRace][305] 41 | - [getPowerTypesIndex][307] 42 | - [getPowerType][308] 43 | 44 | ### getCreatureFamiliesIndex 45 | 46 | Returns an index of creature families. 47 | 48 | Returns **[Promise][310]<[object][311]>** 49 | 50 | ### getCreatureFamily 51 | 52 | Returns a creature family by ID. 53 | 54 | #### Parameters 55 | 56 | - `creatureFamilyId` **[number][312]** The ID of the creature family. 57 | 58 | Returns **[Promise][310]<[object][311]>** 59 | 60 | ### getCreatureTypesIndex 61 | 62 | Returns an index of creature types. 63 | 64 | Returns **[Promise][310]<[object][311]>** 65 | 66 | ### getCreatureType 67 | 68 | Returns a creature type by ID. 69 | 70 | #### Parameters 71 | 72 | - `creatureTypeId` **[number][312]** The ID of the creature type. 73 | 74 | Returns **[Promise][310]<[object][311]>** 75 | 76 | ### getCreature 77 | 78 | Returns a creature by ID. 79 | 80 | #### Parameters 81 | 82 | - `creatureId` **[number][312]** The ID of the creature. 83 | 84 | Returns **[Promise][310]<[object][311]>** 85 | 86 | ### getCreatureDisplayMedia 87 | 88 | Returns media for a creature display by ID. 89 | 90 | #### Parameters 91 | 92 | - `creatureDisplayId` **[number][312]** The ID of the creature display. 93 | 94 | Returns **[Promise][310]<[object][311]>** 95 | 96 | ### getCreatureFamilyMedia 97 | 98 | Returns media for a creature family by ID. 99 | 100 | #### Parameters 101 | 102 | - `creatureFamilyId` **[number][312]** The ID of the creature family. 103 | 104 | Returns **[Promise][310]<[object][311]>** 105 | 106 | ### getGuildCrestComponentsIndex 107 | 108 | Returns an index of guild crest media. 109 | 110 | Returns **[Promise][310]<[object][311]>** 111 | 112 | ### getGuildCrestBorderMedia 113 | 114 | Returns media for a guild crest border by ID. 115 | 116 | #### Parameters 117 | 118 | - `borderId` **[number][312]** The ID of the guild crest border. 119 | 120 | Returns **[Promise][310]<[object][311]>** 121 | 122 | ### getGuildCrestEmblemMedia 123 | 124 | Returns media for a guild crest emblem by ID. 125 | 126 | #### Parameters 127 | 128 | - `emblemId` **[number][312]** The ID of the guild crest emblem. 129 | 130 | Returns **[Promise][310]<[object][311]>** 131 | 132 | ### getItemClassesIndex 133 | 134 | Returns an index of item classes. 135 | 136 | Returns **[Promise][310]<[object][311]>** 137 | 138 | ### getItemClass 139 | 140 | Returns an item class by ID. 141 | 142 | #### Parameters 143 | 144 | - `itemClassId` **[string][313]** The ID of the item class. 145 | 146 | Returns **[Promise][310]<[object][311]>** 147 | 148 | ### getItemSubclass 149 | 150 | Returns an item subclass by ID. 151 | 152 | #### Parameters 153 | 154 | - `itemClassId` **[string][313]** The ID of the item class. 155 | - `itemSubclassId` **[string][313]** The ID of the item subclass. 156 | 157 | Returns **[Promise][310]<[object][311]>** 158 | 159 | ### getItem 160 | 161 | Returns an item by ID. 162 | 163 | #### Parameters 164 | 165 | - `itemId` **[string][313]** The ID of the item. 166 | 167 | Returns **[Promise][310]<[object][311]>** 168 | 169 | ### getItemMedia 170 | 171 | Returns media for an item by ID. 172 | 173 | #### Parameters 174 | 175 | - `itemId` **[string][313]** The ID of the item. 176 | 177 | Returns **[Promise][310]<[object][311]>** 178 | 179 | ### getPlayableClassIndex 180 | 181 | Returns an index of playable classes. 182 | 183 | Returns **[Promise][310]<[object][311]>** 184 | 185 | ### getPlayableClass 186 | 187 | Returns a playable class by ID. 188 | 189 | #### Parameters 190 | 191 | - `playableClassId` **[number][312]** The ID of the playable class. 192 | 193 | Returns **[Promise][310]<[object][311]>** 194 | 195 | ### getPlayableClassMedia 196 | 197 | Returns media for a playable class by ID. 198 | 199 | #### Parameters 200 | 201 | - `playableClassId` **[number][312]** The ID of the playable class. 202 | 203 | Returns **[Promise][310]<[object][311]>** 204 | 205 | ### getPlayableRaceIndex 206 | 207 | Returns an index of playable races. 208 | 209 | Returns **[Promise][310]<[object][311]>** 210 | 211 | ### getPlayableRace 212 | 213 | Returns a playable race by ID. 214 | 215 | #### Parameters 216 | 217 | - `playableRaceId` **[number][312]** The ID of the playable race. 218 | 219 | Returns **[Promise][310]<[object][311]>** 220 | 221 | ### getPowerTypesIndex 222 | 223 | Returns an index of power types. 224 | 225 | Returns **[Promise][310]<[object][311]>** 226 | 227 | ### getPowerType 228 | 229 | Returns a power type by ID. 230 | 231 | #### Parameters 232 | 233 | - `powerTypeId` **[number][312]** 234 | 235 | Returns **[Promise][310]<[object][311]>** 236 | 237 | [273]: #getcreaturefamiliesindex 238 | 239 | [274]: #getcreaturefamily 240 | 241 | [275]: #parameters-112 242 | 243 | [276]: #getcreaturetypesindex-1 244 | 245 | [277]: #getcreaturetype 246 | 247 | [278]: #parameters-113 248 | 249 | [279]: #getcreature 250 | 251 | [280]: #parameters-114 252 | 253 | [281]: #getcreaturedisplaymedia 254 | 255 | [282]: #parameters-115 256 | 257 | [283]: #getcreaturefamilymedia 258 | 259 | [284]: #parameters-116 260 | 261 | [285]: #getguildcrestcomponentsindex 262 | 263 | [286]: #getguildcrestbordermedia 264 | 265 | [287]: #parameters-117 266 | 267 | [288]: #getguildcrestemblemmedia 268 | 269 | [289]: #parameters-118 270 | 271 | [290]: #getitemclassesindex 272 | 273 | [291]: #getitemclass 274 | 275 | [292]: #parameters-119 276 | 277 | [293]: #getitemsubclass 278 | 279 | [294]: #parameters-120 280 | 281 | [295]: #getitem 282 | 283 | [296]: #parameters-121 284 | 285 | [297]: #getitemmedia 286 | 287 | [298]: #parameters-122 288 | 289 | [299]: #getplayableclassindex 290 | 291 | [300]: #getplayableclass 292 | 293 | [301]: #parameters-123 294 | 295 | [302]: #getplayableclassmedia 296 | 297 | [303]: #parameters-124 298 | 299 | [304]: #getplayableraceindex 300 | 301 | [305]: #getplayablerace 302 | 303 | [306]: #parameters-125 304 | 305 | [307]: #getpowertypesindex 306 | 307 | [308]: #getpowertype 308 | 309 | [310]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise 310 | 311 | [311]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object 312 | 313 | [312]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number 314 | 315 | [313]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -------------------------------------------------------------------------------- /src/wowClassic/gameData.ts: -------------------------------------------------------------------------------- 1 | // WoW Classic Game Data API documentation: https://develop.battle.net/documentation/world-of-warcraft-classic/game-data-apis 2 | 3 | import {AxiosInstance} from "axios"; 4 | 5 | class WowClassicGameData { 6 | private readonly axios: AxiosInstance; 7 | private readonly defaultAxiosParams: object; 8 | private readonly namespace: string; 9 | private readonly gameBaseUrlPath: string = '/data/wow'; 10 | 11 | constructor(axiosInstance: AxiosInstance, defaultAxiosParams: object, origin: string) { 12 | this.axios = axiosInstance; 13 | this.defaultAxiosParams = defaultAxiosParams; 14 | this.namespace = `static-classic-${origin}`; 15 | } 16 | 17 | /** 18 | * Returns an index of creature families. 19 | */ 20 | async getCreatureFamiliesIndex(): Promise { 21 | return await this._handleApiCall( 22 | `${this.gameBaseUrlPath}/creature-family/index`, 23 | 'Error fetching creature families index.' 24 | ); 25 | } 26 | 27 | /** 28 | * Returns a creature family by ID. 29 | * 30 | * @param creatureFamilyId The ID of the creature family. 31 | */ 32 | async getCreatureFamily(creatureFamilyId: number): Promise { 33 | return await this._handleApiCall( 34 | `${this.gameBaseUrlPath}/creature-family/${creatureFamilyId}`, 35 | 'Error fetching specified creature family.' 36 | ); 37 | } 38 | 39 | /** 40 | * Returns an index of creature types. 41 | */ 42 | async getCreatureTypesIndex(): Promise { 43 | return await this._handleApiCall( 44 | `${this.gameBaseUrlPath}/creature-type/index`, 45 | 'Error fetching creature types index.' 46 | ); 47 | } 48 | 49 | /** 50 | * Returns a creature type by ID. 51 | * 52 | * @param creatureTypeId The ID of the creature type. 53 | */ 54 | async getCreatureType(creatureTypeId: number): Promise { 55 | return await this._handleApiCall( 56 | `${this.gameBaseUrlPath}/creature-type/${creatureTypeId}`, 57 | 'Error fetching specified creature type.' 58 | ); 59 | } 60 | 61 | /** 62 | * Returns a creature by ID. 63 | * 64 | * @param creatureId The ID of the creature. 65 | */ 66 | async getCreature(creatureId: number): Promise { 67 | return await this._handleApiCall( 68 | `${this.gameBaseUrlPath}/creature/${creatureId}`, 69 | 'Error fetching specified creature.' 70 | ); 71 | } 72 | 73 | /** 74 | * Returns media for a creature display by ID. 75 | * 76 | * @param creatureDisplayId The ID of the creature display. 77 | */ 78 | async getCreatureDisplayMedia(creatureDisplayId: number): Promise { 79 | return await this._handleApiCall( 80 | `${this.gameBaseUrlPath}/media/creature-display/${creatureDisplayId}`, 81 | 'Error fetching specified creature display media.' 82 | ); 83 | } 84 | 85 | /** 86 | * Returns media for a creature family by ID. 87 | * 88 | * @param creatureFamilyId The ID of the creature family. 89 | */ 90 | async getCreatureFamilyMedia(creatureFamilyId: number): Promise { 91 | return await this._handleApiCall( 92 | `${this.gameBaseUrlPath}/media/creature-family/${creatureFamilyId}`, 93 | 'Error fetching specified creature family media.' 94 | ); 95 | } 96 | 97 | /**************************** 98 | * Guild Crest API 99 | ****************************/ 100 | 101 | /** 102 | * Returns an index of guild crest media. 103 | */ 104 | async getGuildCrestComponentsIndex(): Promise { 105 | return await this._handleApiCall( 106 | `${this.gameBaseUrlPath}/guild-crest/index`, 107 | 'Error fetching guild crest components index.' 108 | ); 109 | } 110 | 111 | /** 112 | * Returns media for a guild crest border by ID. 113 | * 114 | * @param borderId The ID of the guild crest border. 115 | */ 116 | async getGuildCrestBorderMedia(borderId: number): Promise { 117 | return await this._handleApiCall( 118 | `${this.gameBaseUrlPath}/guild-crest/border/${borderId}`, 119 | 'Error fetching guild crest border media.' 120 | ); 121 | } 122 | 123 | /** 124 | * Returns media for a guild crest emblem by ID. 125 | * 126 | * @param emblemId The ID of the guild crest emblem. 127 | */ 128 | async getGuildCrestEmblemMedia(emblemId: number): Promise { 129 | return await this._handleApiCall( 130 | `${this.gameBaseUrlPath}/guild-crest/emblem/${emblemId}`, 131 | 'Error fetching guild crest emblem media.' 132 | ); 133 | } 134 | 135 | /**************************** 136 | * Item API 137 | ****************************/ 138 | 139 | /** 140 | * Returns an index of item classes. 141 | */ 142 | async getItemClassesIndex(): Promise { 143 | return await this._handleApiCall( 144 | `${this.gameBaseUrlPath}/item-class/index`, 145 | 'Error fetching item class index.' 146 | ); 147 | } 148 | 149 | /** 150 | * Returns an item class by ID. 151 | * 152 | * @param itemClassId The ID of the item class. 153 | */ 154 | async getItemClass(itemClassId: string): Promise { 155 | return await this._handleApiCall( 156 | `${this.gameBaseUrlPath}/item-class/${itemClassId}`, 157 | 'Error fetching specified item class.' 158 | ); 159 | } 160 | 161 | /** 162 | * Returns an item subclass by ID. 163 | * 164 | * @param itemClassId The ID of the item class. 165 | * @param itemSubclassId The ID of the item subclass. 166 | */ 167 | async getItemSubclass(itemClassId: string, itemSubclassId: string): Promise { 168 | return await this._handleApiCall( 169 | `${this.gameBaseUrlPath}/item-class/${itemClassId}/item-subclass/${itemSubclassId}`, 170 | 'Error fetching specified item class subclass.' 171 | ); 172 | } 173 | 174 | /** 175 | * Returns an item by ID. 176 | * 177 | * @param itemId The ID of the item. 178 | */ 179 | async getItem(itemId: string): Promise { 180 | return await this._handleApiCall( 181 | `${this.gameBaseUrlPath}/item/${itemId}`, 182 | 'Error fetching specified item.' 183 | ); 184 | } 185 | 186 | /** 187 | * Returns media for an item by ID. 188 | * 189 | * @param itemId The ID of the item. 190 | */ 191 | async getItemMedia(itemId: string): Promise { 192 | return await this._handleApiCall( 193 | `${this.gameBaseUrlPath}/media/item/${itemId}`, 194 | 'Error fetching specified item media.' 195 | ); 196 | } 197 | 198 | /**************************** 199 | * Playable Class API 200 | ****************************/ 201 | 202 | /** 203 | * Returns an index of playable classes. 204 | */ 205 | async getPlayableClassIndex(): Promise { 206 | return await this._handleApiCall( 207 | `${this.gameBaseUrlPath}/playable-class/index`, 208 | 'Error fetching playable class index.' 209 | ); 210 | } 211 | 212 | /** 213 | * Returns a playable class by ID. 214 | * 215 | * @param playableClassId The ID of the playable class. 216 | */ 217 | async getPlayableClass(playableClassId: number): Promise { 218 | return await this._handleApiCall( 219 | `${this.gameBaseUrlPath}/playable-class/${playableClassId}`, 220 | 'Error fetching specified playable class.' 221 | ); 222 | } 223 | 224 | /** 225 | * Returns media for a playable class by ID. 226 | * 227 | * @param playableClassId The ID of the playable class. 228 | */ 229 | async getPlayableClassMedia(playableClassId: number): Promise { 230 | return await this._handleApiCall( 231 | `${this.gameBaseUrlPath}/media/playable-class/${playableClassId}`, 232 | 'Error fetching specified playable class media.' 233 | ); 234 | } 235 | 236 | /**************************** 237 | * Playable Race API 238 | ****************************/ 239 | 240 | /** 241 | * Returns an index of playable races. 242 | */ 243 | async getPlayableRaceIndex(): Promise { 244 | return await this._handleApiCall( 245 | `${this.gameBaseUrlPath}/playable-race/index`, 246 | 'Error fetching playable race index.' 247 | ); 248 | } 249 | 250 | /** 251 | * Returns a playable race by ID. 252 | * 253 | * @param playableRaceId The ID of the playable race. 254 | */ 255 | async getPlayableRace(playableRaceId: number): Promise { 256 | return await this._handleApiCall( 257 | `${this.gameBaseUrlPath}/playable-race/${playableRaceId}`, 258 | 'Error fetching specified playable race.' 259 | ); 260 | } 261 | 262 | /**************************** 263 | * Power Type API 264 | ****************************/ 265 | 266 | /** 267 | * Returns an index of power types. 268 | */ 269 | async getPowerTypesIndex(): Promise { 270 | return await this._handleApiCall( 271 | `${this.gameBaseUrlPath}/power-type/index`, 272 | 'Error fetching power type index.' 273 | ); 274 | } 275 | 276 | /** 277 | * Returns a power type by ID. 278 | * 279 | * @param powerTypeId 280 | */ 281 | async getPowerType(powerTypeId: number): Promise { 282 | return await this._handleApiCall( 283 | `${this.gameBaseUrlPath}/power-type/${powerTypeId}`, 284 | 'Error fetching specified power type.' 285 | ); 286 | } 287 | 288 | /******************************** 289 | * Private Class Helper Functions 290 | ********************************/ 291 | 292 | async _handleApiCall(apiUrl: string, errorMessage: string): Promise { 293 | try { 294 | const response = await this.axios.get(encodeURI(apiUrl), { 295 | params: { 296 | namespace: this.namespace, 297 | ...this.defaultAxiosParams 298 | } 299 | }); 300 | return response.data; 301 | } catch (error) { 302 | console.log(error); 303 | throw new Error(`WoW Classic Game Data Error :: ${errorMessage}`); 304 | } 305 | } 306 | } 307 | 308 | export default WowClassicGameData; -------------------------------------------------------------------------------- /tests/__mocks__/axios.js: -------------------------------------------------------------------------------- 1 | const axios = jest.fn(obj => new Promise(_ => _(obj))); 2 | 3 | axios.get = jest.fn(url => new Promise(_ => _(url))); 4 | axios.post = jest.fn(url => new Promise(_ => _(url))); 5 | axios.all = jest.fn(); 6 | 7 | const create = jest.fn(() => axios); 8 | 9 | module.exports = { create }; -------------------------------------------------------------------------------- /tests/battleNetWrapper.test.js: -------------------------------------------------------------------------------- 1 | const battleNetWrapper = require('../index'); 2 | 3 | const d3Community = require('../dist/d3/community'); 4 | const d3GameData = require('../dist/d3/gameData'); 5 | const hearthstoneGameData = require('../dist/hearthstone/gameData'); 6 | const sc2Community = require('../dist/sc2/community'); 7 | const sc2GameData = require('../dist/sc2/gameData'); 8 | const wowGameData = require('../dist/wow/gameData'); 9 | const wowCommunity = require('../dist/wow/community'); 10 | const wowProfileData = require('../dist/wow/profileData'); 11 | const wowClassicGameData = require('../dist/wowClassic/gameData'); 12 | 13 | let bnw; 14 | 15 | describe('/battleNetWrapper', () => { 16 | beforeEach(() => { 17 | bnw = new battleNetWrapper(); 18 | bnw.init('clientId', 'clientSecret'); 19 | bnw.axios.mockClear(); 20 | }); 21 | 22 | test('should have API properties', () => { 23 | 24 | 25 | 26 | expect(bnw).toEqual( 27 | expect(objectContaining({ 28 | diablo3Community: expect.any(d3Community), 29 | 30 | })) 31 | ) 32 | 33 | }); 34 | 35 | 36 | }); -------------------------------------------------------------------------------- /tests/d3Community.test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuadDamn/battlenet-api-wrapper/49809253a88eae07a363011d84723205a177fdd9/tests/d3Community.test.js -------------------------------------------------------------------------------- /tests/d3GameData.test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuadDamn/battlenet-api-wrapper/49809253a88eae07a363011d84723205a177fdd9/tests/d3GameData.test.js -------------------------------------------------------------------------------- /tests/hearthstoneGameData.test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuadDamn/battlenet-api-wrapper/49809253a88eae07a363011d84723205a177fdd9/tests/hearthstoneGameData.test.js -------------------------------------------------------------------------------- /tests/sc2Community.test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuadDamn/battlenet-api-wrapper/49809253a88eae07a363011d84723205a177fdd9/tests/sc2Community.test.js -------------------------------------------------------------------------------- /tests/sc2GameData.test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuadDamn/battlenet-api-wrapper/49809253a88eae07a363011d84723205a177fdd9/tests/sc2GameData.test.js -------------------------------------------------------------------------------- /tests/utils.test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuadDamn/battlenet-api-wrapper/49809253a88eae07a363011d84723205a177fdd9/tests/utils.test.js -------------------------------------------------------------------------------- /tests/wowClassicGameData.test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuadDamn/battlenet-api-wrapper/49809253a88eae07a363011d84723205a177fdd9/tests/wowClassicGameData.test.js -------------------------------------------------------------------------------- /tests/wowCommunity.test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuadDamn/battlenet-api-wrapper/49809253a88eae07a363011d84723205a177fdd9/tests/wowCommunity.test.js -------------------------------------------------------------------------------- /tests/wowGameData.test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuadDamn/battlenet-api-wrapper/49809253a88eae07a363011d84723205a177fdd9/tests/wowGameData.test.js -------------------------------------------------------------------------------- /tests/wowProfileData.test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuadDamn/battlenet-api-wrapper/49809253a88eae07a363011d84723205a177fdd9/tests/wowProfileData.test.js -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs", 5 | "outDir": "./dist", 6 | // "noImplicitAny": true 7 | }, 8 | "include": ["./src/**/*"], 9 | "exclude": [ 10 | "node_modules" 11 | ] 12 | } --------------------------------------------------------------------------------