Skip to content

Commit

Permalink
adding some wow endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinta365 committed Sep 12, 2023
1 parent d9a8ca2 commit 4a71e44
Show file tree
Hide file tree
Showing 12 changed files with 486 additions and 13 deletions.
76 changes: 75 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,82 @@
# BLIZZARD_API

## WORK IN PROGRESS
Start of what will hopefully cover the whole Blizzard Battle.net API when its done.

Built for Deno 🦕

## WORK IN PROGRESS

### World of Warcraft

| APIs | Status | Note |
| ----------------------------------- | ------ | -------------- |
| **Game Data APIs** | | |
| `Achievement` || |
| `Auction House` || |
| `Azerite Essence` || Search missing |
| `Connected Realm` || Search missing |
| `Covenant` | | |
| `Creature` | | |
| `Guild Crest` | | |
| `Heirloom` | | |
| `Item` | | |
| `Journal` | | |
| `Media Search` | | |
| `Modified Crafting` | | |
| `Mount` | | |
| `Mythic Keystone Affix` | | |
| `Mythic Keystone Dungeon` | | |
| `Mythic Keystone Leaderboard` | | |
| `Mythic Raid Leaderboard` | | |
| `Pet` | | |
| `Playable Class` | | |
| `Playable Race` | | |
| `Playable Specialization` | | |
| `Power Type` | | |
| `Profession` | | |
| `PvP Season` | | |
| `PvP Tier` | | |
| `Quest` | | |
| `Realm` | | |
| `Region` | | |
| `Reputations` | | |
| `Spell` | | |
| `Talent` | | |
| `Tech Talent` | | |
| `Title` | | |
| `Toy` | | |
| `Token` || |
| **Profile APIs** | | |
| `Account Profile` | | |
| `Character Achievements` | | |
| `Character Appearance` | | |
| `Character Collections` | | |
| `Character Encounters` | | |
| `Character Equipment` | | |
| `Character Hunter Pets` | | |
| `Character Media` | | |
| `Character Mythic Keystone Profile` | | |
| `Character Professions` | | |
| `Character Profile` | | |
| `Character PvP` | | |
| `Character Quests` | | |
| `Character Reputations` | | |
| `Character Soulbinds` | | |
| `Character Specializations` | | |
| `Character Statistics` | | |
| `Character Titles` | | |
| `Guild` | | |

### World of Warcraft Classic

### Diablo III

### Hearthstone

### Overwatch League

### StarCraft II

## Issues

Issues or questions concerning the library can be raised at the
Expand Down
2 changes: 1 addition & 1 deletion mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { authenticate, setup } from "./src/shared/index.ts";
import * as wow from "./src/wow/index.ts";
import * as wowClassic from "./src/wow-classic/index.ts";
import * as wowClassic from "./src/wow_classic/index.ts";

export const blizzardAPI = {
setup,
Expand Down
2 changes: 1 addition & 1 deletion src/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export { setup } from "./config.ts";
export { authenticate } from "./auth.ts";
export { request } from "./request.ts";

export type { LinkSelfHref } from "./types.ts";
export type { KeyId, KeyNameId, LinkSelfHref, LocalizedString } from "./types.ts";

/*
Expand Down
13 changes: 5 additions & 8 deletions src/shared/request.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { requestOptions } from "./types.ts";
import { getSetup } from "./config.ts";
import { apiBaseUrl, getSetup } from "./config.ts";
import { authenticate, getauthConfig } from "./auth.ts";

import { APIError } from "./errors.ts";

export async function request(requestOptions: requestOptions) {
if (
!getauthConfig().accessToken || (getauthConfig().accessToken && getauthConfig().tokenExpiration &&
Expand All @@ -14,10 +16,6 @@ export async function request(requestOptions: requestOptions) {

const params = new URLSearchParams(qs);

const host = getSetup().region == "cn"
? "https://gateway.battlenet.com.cn"
: `https://${getSetup().region}.api.blizzard.com`;

const headers: Record<string, string> = {
"Authorization": "Bearer " + getauthConfig().accessToken,
};
Expand All @@ -26,8 +24,7 @@ export async function request(requestOptions: requestOptions) {
headers["Battlenet-Namespace"] = `${namespace}-${getSetup().region}`;
}

console.log(headers);
const response = await fetch(host + encodeURI(url) + (qs ? "?" + params.toString() : ""), {
const response = await fetch(apiBaseUrl(getSetup().region) + encodeURI(url) + (qs ? "?" + params.toString() : ""), {
method: method,
headers: headers,
});
Expand All @@ -36,5 +33,5 @@ export async function request(requestOptions: requestOptions) {
return await response.json();
}

throw new Error(`Problem fetching data. ${response.status} - ${response.statusText}`);
throw new APIError("Problem fetching data from API", response.status, response.statusText);
}
132 changes: 132 additions & 0 deletions src/wow/achievement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* This module provides interfaces and API function definitions for fetching World of Warcraft achievement data using the Blizzard API.
*
* @author Pinta <https://github.com/Pinta365>
*/

import { KeyId, KeyNameId, LinkSelfHref, LocalizedString, request } from "../shared/index.ts";

interface AchievementCategories extends LinkSelfHref {
categories: KeyNameId[];
}

interface AggregatesByFaction {
alliance: {
quantity: number;
points: number;
};
horde: {
quantity: number;
points: number;
};
}

interface AchievementCategory extends LinkSelfHref {
id: number;
name: LocalizedString;
achievements: KeyNameId[];
parent_category: KeyNameId;
is_guild_category: boolean;
aggregates_by_faction: AggregatesByFaction;
display_order: number;
}

interface Achievements extends LinkSelfHref {
achievements: KeyNameId[];
}

interface Achievement extends LinkSelfHref {
id: number;
category: KeyNameId;
name: LocalizedString;
description: LocalizedString;
points: number;
is_account_wide: boolean;
criteria: {
id: number;
description: LocalizedString;
amount: number;
};
next_achievement: KeyNameId;
media: KeyId;
display_order: number;
}

interface Asset {
key: string;
value: string;
file_data_id: number;
}

interface AchievementMedia extends LinkSelfHref {
assets: Asset[];
id: number;
}

/**
* Fetches and returns an index of achievement categories.
*
* @returns A promise that resolves to an object representing the index of achievement categories.
*/
export async function achievementCategories(): Promise<AchievementCategories> {
return await request({
method: "GET",
url: "/data/wow/achievement-category/index",
namespace: "static",
});
}

/**
* Fetches and returns details of a specific achievement category identified by its ID.
*
* @param achievementCategoryId - The unique identifier of the achievement category to retrieve.
* @returns A promise that resolves to an object representing the achievement category details.
*/
export async function achievementCategory(achievementCategoryId: number): Promise<AchievementCategory> {
return await request({
method: "GET",
url: `/data/wow/achievement-category/${achievementCategoryId}`,
namespace: "static",
});
}

/**
* Fetches and returns an index of achievements.
*
* @returns A promise that resolves to an object representing the index of achievements.
*/
export async function achievements(): Promise<Achievements> {
return await request({
method: "GET",
url: "/data/wow/achievement/index",
namespace: "static",
});
}

/**
* Fetches and returns details of a specific achievement identified by its ID.
*
* @param achievementId - The unique identifier of the achievement to retrieve.
* @returns A promise that resolves to an object representing the achievement details.
*/
export async function achievement(achievementId: number): Promise<Achievement> {
return await request({
method: "GET",
url: `/data/wow/achievement/${achievementId}`,
namespace: "static",
});
}

/**
* Fetches and returns media details for a specific achievement identified by its ID.
*
* @param achievementId - The unique identifier of the achievement to retrieve media details for.
* @returns A promise that resolves to an object representing the achievement media details.
*/
export async function achievementMedia(achievementId: number): Promise<AchievementMedia> {
return await request({
method: "GET",
url: `/data/wow/media/achievement/${achievementId}`,
namespace: "static",
});
}
83 changes: 83 additions & 0 deletions src/wow/auction_house.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { LinkSelfHref, request } from "../shared/index.ts";

interface AuctionItem {
id: number;
modifiers?: [{
type: number;
value: number;
}];
pet_breed_id?: number;
pet_level?: number;
pet_quality_id?: number;
pet_species_id?: number;
bonus_lists?: number[];
context?: number;
}

interface AuctionListing {
id: number;
item: AuctionItem;
bid?: number;
buyout?: number;
quantity: number;
time_left: "SHORT" | "MEDIUM" | "LONG" | "VERY_LONG";
}

interface Auctions extends LinkSelfHref {
connected_realm: {
href: string;
};
auctions: AuctionListing[];
commodities: {
href: string;
};
}

interface commodity {
"id": number;
"item": {
"id": number;
};
"quantity": number;
"unit_price": number;
"time_left": "SHORT" | "MEDIUM" | "LONG" | "VERY_LONG";
}

interface Commodities extends LinkSelfHref {
auctions: commodity[];
}

/**
* Returns all active auctions for a connected realm.
*
* Auction house data updates at a set interval. The value was initially set at 1 hour; however, it might change over time without notice.
*
* NOTE: Depending on the number of active auctions on the specified connected realm, the response from this endpoint may be rather large.
*
* @param connectedRealmId - The id of the connected realm to return auctions from.
* @returns A promise that resolves to an object representing the auctions being listed.
*/
export async function auctions(connectedRealmId: number): Promise<Auctions> {
return await request({
method: "GET",
url: `/data/wow/connected-realm/${connectedRealmId}/auctions`,
namespace: "dynamic",
});
}

/**
* Returns all active auctions for commodity items for the entire game region.
*
* Auction house data updates at a set interval. The value was initially set at 1 hour; however, it might change over time without notice.
*
* NOTE: Depending on the number of active auctions on the specified region, the response from this endpoint may be rather large.
*
* @returns A promise that resolves to an object representing the commodities being listed.
*/
export async function commodities(): Promise<Commodities> {
return await request({
method: "GET",
url: "/data/wow/auctions/commodities",
namespace: "dynamic",
});
}
Loading

0 comments on commit 4a71e44

Please sign in to comment.