Skip to content

Commit

Permalink
[WoW] Add Account Profile API responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Pewtro committed Aug 9, 2024
1 parent 23c193f commit 57f0f76
Show file tree
Hide file tree
Showing 11 changed files with 373 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-poets-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@blizzard-api/wow': minor
---

Add Account Profile API responses.
4 changes: 2 additions & 2 deletions packages/classic-wow/src/playable-class/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Gender, KeyBase, NameId, NameIdKey, ResponseBase } from '../../../wow/src/base';
import type { GenderName, KeyBase, NameId, NameIdKey, ResponseBase } from '../../../wow/src/base';

export type { PlayableClassIndexResponse, PlayableClassMediaResponse } from '../../../wow/src/playable-class/types';

Expand All @@ -7,7 +7,7 @@ export type { PlayableClassIndexResponse, PlayableClassMediaResponse } from '../
* @see {@link https://develop.battle.net/documentation/world-of-warcraft-classic/game-data-apis}
*/
export interface PlayableClassResponse extends ResponseBase, NameId {
gender_name: Gender;
gender_name: GenderName;
media: Media;
playable_races: Array<NameIdKey>;
power_type: NameIdKey;
Expand Down
73 changes: 73 additions & 0 deletions packages/wow/src/account-profile/account-profile.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { describe, expect, it } from 'vitest';
import {
accountCollectionsIndex,
accountHeirloomsCollectionSummary,
accountMountsCollectionSummary,
accountPetsCollectionSummary,
accountProfileSummary,
accountToysCollectionSummary,
accountTransmogsCollectionSummary,
protectedCharacterProfileSummary,
} from './account-profile';

describe('Account Profile', () => {
const token = 'your_token_here';
const realmId = 1;
const characterId = 2;

it('should return account profile summary', () => {
const result = accountProfileSummary(token);
expect(result.namespace).toBe('profile');
expect(result.path).toBe('/profile/user/wow');
expect(result.token).toBe(token);
});

it('should return protected character profile summary', () => {
const result = protectedCharacterProfileSummary(realmId, characterId, token);
expect(result.namespace).toBe('profile');
expect(result.path).toBe('/profile/user/wow/protected-character/1-2');
expect(result.token).toBe(token);
});

it('should return account collections index', () => {
const result = accountCollectionsIndex(token);
expect(result.namespace).toBe('profile');
expect(result.path).toBe('/profile/user/wow/collections');
expect(result.token).toBe(token);
});

it('should return account heirlooms collection summary', () => {
const result = accountHeirloomsCollectionSummary(token);
expect(result.namespace).toBe('profile');
expect(result.path).toBe('/profile/user/wow/collections/heirlooms');
expect(result.token).toBe(token);
});

it('should return account mounts collection summary', () => {
const result = accountMountsCollectionSummary(token);
expect(result.namespace).toBe('profile');
expect(result.path).toBe('/profile/user/wow/collections/mounts');
expect(result.token).toBe(token);
});

it('should return account pets collection summary', () => {
const result = accountPetsCollectionSummary(token);
expect(result.namespace).toBe('profile');
expect(result.path).toBe('/profile/user/wow/collections/pets');
expect(result.token).toBe(token);
});

it('should return account toys collection summary', () => {
const result = accountToysCollectionSummary(token);
expect(result.namespace).toBe('profile');
expect(result.path).toBe('/profile/user/wow/collections/toys');
expect(result.token).toBe(token);
});

it('should return account transmogs collection summary', () => {
const result = accountTransmogsCollectionSummary(token);
expect(result.namespace).toBe('profile');
expect(result.path).toBe('/profile/user/wow/collections/transmogs');
expect(result.token).toBe(token);
});
});
87 changes: 87 additions & 0 deletions packages/wow/src/account-profile/account-profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import type { ProtectedResource } from '@blizzard-api/core';
import type {
AccountCollectionsIndexResponse,
AccountHeirloomsCollectionSummaryResponse,
AccountMountsCollectionSummaryResponse,
AccountPetsCollectionSummaryResponse,
AccountProfileSummaryResponse,
AccountToysCollectionSummaryResponse,
AccountTransmogsCollectionSummaryResponse,
ProtectedCharacterProfileSummaryResponse,
} from './types';

const accountProfileBase = '/profile/user/wow';

export function accountProfileSummary(token: string): ProtectedResource<AccountProfileSummaryResponse> {
return {
namespace: 'profile',
path: `${accountProfileBase}`,
token,
};
}

export function protectedCharacterProfileSummary(
realmId: number,
characterId: number,
token: string,
): ProtectedResource<ProtectedCharacterProfileSummaryResponse> {
return {
namespace: 'profile',
path: `${accountProfileBase}/protected-character/${realmId}-${characterId}`,
token,
};
}

export function accountCollectionsIndex(token: string): ProtectedResource<AccountCollectionsIndexResponse> {
return {
namespace: 'profile',
path: `${accountProfileBase}/collections`,
token,
};
}

export function accountHeirloomsCollectionSummary(
token: string,
): ProtectedResource<AccountHeirloomsCollectionSummaryResponse> {
return {
namespace: 'profile',
path: `${accountProfileBase}/collections/heirlooms`,
token,
};
}

export function accountMountsCollectionSummary(
token: string,
): ProtectedResource<AccountMountsCollectionSummaryResponse> {
return {
namespace: 'profile',
path: `${accountProfileBase}/collections/mounts`,
token,
};
}

export function accountPetsCollectionSummary(token: string): ProtectedResource<AccountPetsCollectionSummaryResponse> {
return {
namespace: 'profile',
path: `${accountProfileBase}/collections/pets`,
token,
};
}

export function accountToysCollectionSummary(token: string): ProtectedResource<AccountToysCollectionSummaryResponse> {
return {
namespace: 'profile',
path: `${accountProfileBase}/collections/toys`,
token,
};
}

export function accountTransmogsCollectionSummary(
token: string,
): ProtectedResource<AccountTransmogsCollectionSummaryResponse> {
return {
namespace: 'profile',
path: `${accountProfileBase}/collections/transmogs`,
token,
};
}
158 changes: 158 additions & 0 deletions packages/wow/src/account-profile/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import type { Faction, Gender, KeyBase, NameId, NameIdKey } from '../base';

export interface AccountProfileSummaryResponse {
_links: Links;
collections: Href;
id: number;
wow_accounts?: Array<WowAccount>;
}

interface Links {
profile: Href;
self: Href;
user: Href;
}

interface Href {
href: string;
}

interface WowAccount {
characters: Array<Character>;
id: number;
}

interface Realm extends NameIdKey {
slug: string;
}

interface Character {
character: Href;
faction: Faction;
gender: Gender;
id: number;
level: number;
name: string;
playable_class: NameIdKey;
playable_race: NameIdKey;
protected_character: Href;
realm: Realm;
}

export interface ProtectedCharacterProfileSummaryResponse {
_links: Links;
bind_position: Position;
character: NameIdKey & Realm;
id: number;
money: number;
name: string;
position: Position;
protected_stats: ProtectedStats;
wow_account: number;
}

interface Position {
facing: number;
map: NameId;
x: number;
y: number;
z: number;
zone: NameId;
}

interface ProtectedStats {
level_gold_gained: number;
level_gold_lost: number;
level_item_value_gained: number;
level_number_deaths: number;
total_gold_gained: number;
total_gold_lost: number;
total_item_value_gained: number;
total_number_deaths: number;
}

export interface AccountCollectionsIndexResponse {
_links: Links;
heirlooms: Href;
mounts: Href;
pets: Href;
toys: Href;
transmogs: Href;
}

export interface AccountHeirloomsCollectionSummaryResponse {
_links: Links;
heirlooms: Array<Heirloom>;
}

interface Heirloom {
heirloom: NameIdKey;
upgrade: { level: number };
}

export interface AccountMountsCollectionSummaryResponse {
_links: Links;
mounts: Array<Mount>;
}

interface Mount {
is_favorite?: boolean;
mount: NameIdKey;
}

export interface AccountPetsCollectionSummaryResponse {
_links: Links;
pets: Array<Pet>;
unlocked_battle_pet_slots: number;
}

interface Pet {
active_slot?: number;
creature_display?: { id: number } & KeyBase;
id: number;
is_active?: boolean;
is_favorite?: boolean;
level: number;
name?: string;
quality: Quality;
species: NameIdKey;
stats: Stats;
}

interface Quality {
name: 'Common' | 'Poor' | 'Rare' | 'Uncommon';
type: 'COMMON' | 'POOR' | 'RARE' | 'UNCOMMON';
}

interface Stats {
breed_id: number;
health: number;
power: number;
speed: number;
}

export interface AccountToysCollectionSummaryResponse {
_links: Links;
toys: Array<Toy>;
}

interface Toy {
is_favorite?: boolean;
toy: NameIdKey;
}

export interface AccountTransmogsCollectionSummaryResponse {
_links: Links;
appearance_sets: Array<NameIdKey>;
slots: Array<Slot>;
}

interface Slot {
appearances: Array<{ id: number } & KeyBase>;
slot: Slot;
}

interface Slot {
name: string;
type: string;
}
20 changes: 18 additions & 2 deletions packages/wow/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,29 @@ export interface MediaAsset {
}

/**
* The playable genders in World of Warcraft.
* The playable gender names/descriptions in World of Warcraft.
*/
export interface Gender {
export interface GenderName {
female: string;
male: string;
}

/**
* The playable genders in World of Warcraft.
*/
export const Genders = {
FEMALE: 'FEMALE',
MALE: 'MALE',
} as const;

/**
* The gender associated with a character or entity in World of Warcraft.
*/
export interface Gender {
name: Capitalize<Lowercase<keyof typeof Genders>>;
type: keyof typeof Genders;
}

/**
* The playable factions in World of Warcraft.
*/
Expand Down
Loading

0 comments on commit 57f0f76

Please sign in to comment.