Skip to content

Commit

Permalink
[WoW] Add support for Character Encounters APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pewtro committed Aug 10, 2024
1 parent c202b50 commit f224581
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-crabs-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@blizzard-api/wow': minor
---

Add support for Character Encounters APIs
45 changes: 45 additions & 0 deletions packages/wow/src/character-encounters/character-encounters.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { describe, expect, it } from 'vitest';
import { characterDungeons, characterEncountersSummary, characterRaids } from './character-encounters';

describe('Character Encounters', () => {
it('should return the correct ProtectedResource object for character encounters', () => {
const realmSlug = 'realm';
const characterName = 'character';
const token = 'token';

const result = characterEncountersSummary(realmSlug, characterName, token);

expect(result).toEqual({
namespace: 'profile',
path: 'profile/wow/character/realm/character/encounters',
token,
});
});
it('should return the correct ProtectedResource object for character dungeons', () => {
const realmSlug = 'realm';
const characterName = 'character';
const token = 'token';

const result = characterDungeons(realmSlug, characterName, token);

expect(result).toEqual({
namespace: 'profile',
path: 'profile/wow/character/realm/character/encounters/dungeons',
token,
});
});

it('should return the correct ProtectedResource object for character raids', () => {
const realmSlug = 'realm';
const characterName = 'character';
const token = 'token';

const result = characterRaids(realmSlug, characterName, token);

expect(result).toEqual({
namespace: 'profile',
path: 'profile/wow/character/realm/character/encounters/raids',
token,
});
});
});
40 changes: 40 additions & 0 deletions packages/wow/src/character-encounters/character-encounters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { ProtectedResource } from '@blizzard-api/core';
import type { CharacterDungeonsResponse, CharacterEncountersSummaryResponse, CharacterRaidsResponse } from './types';

const bathPase = 'profile/wow/character';

export function characterEncountersSummary(
realmSlug: string,
characterName: string,
token: string,
): ProtectedResource<CharacterEncountersSummaryResponse> {
return {
namespace: 'profile',
path: `${bathPase}/${realmSlug}/${characterName.toLowerCase()}/encounters`,
token,
};
}

export function characterDungeons(
realmSlug: string,
characterName: string,
token: string,
): ProtectedResource<CharacterDungeonsResponse> {
return {
namespace: 'profile',
path: `${bathPase}/${realmSlug}/${characterName.toLowerCase()}/encounters/dungeons`,
token,
};
}

export function characterRaids(
realmSlug: string,
characterName: string,
token: string,
): ProtectedResource<CharacterRaidsResponse> {
return {
namespace: 'profile',
path: `${bathPase}/${realmSlug}/${characterName.toLowerCase()}/encounters/raids`,
token,
};
}
92 changes: 92 additions & 0 deletions packages/wow/src/character-encounters/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import type { Href, NameIdKey } from '../base';

export interface CharacterEncountersSummaryResponse {
_links: { self: Href };
character: Character;
dungeons: Href;
raids: Href;
}

interface Realm extends NameIdKey {
slug: string;
}

interface Character extends NameIdKey {
realm: Realm;
}

export interface CharacterDungeonsResponse {
_links: { self: Href };
expansions: Array<Expansion<DungeonMode>>;
}

interface Expansion<T> {
expansion: NameIdKey;
instances: Array<Instance<T>>;
}

interface Instance<T> {
instance: NameIdKey;
modes: Array<T>;
}

interface DungeonMode {
difficulty: DungeonDifficulties;
progress: Progress;
status: Status;
}

interface Status {
name: 'Complete' | 'In Progress';
type: 'COMPLETE' | 'IN_PROGRESS';
}

interface DungeonDifficulties {
name: 'Heroic' | 'Mythic' | 'Mythic+ Dungeons' | 'Normal';
type: 'HEROIC' | 'MYTHIC' | 'MYTHIC_KEYSTONE' | 'NORMAL';
}

interface Progress {
completed_count: number;
encounters: Array<Encounter>;
total_count: number;
}

interface Encounter {
completed_count: number;
encounter: NameIdKey;
last_kill_timestamp: number;
}

export interface CharacterRaidsResponse {
_links: { self: Href };
character: Character;
expansions: Array<Expansion<RaidMode>>;
}

interface RaidMode {
difficulty: RaidDifficulties;
progress: Progress;
status: Status;
}

interface RaidDifficulties {
name:
| '10 Player (Heroic)'
| '10 Player'
| '25 Player (Heroic)'
| '25 Player'
| 'Heroic'
| 'Mythic'
| 'Normal'
| 'Raid Finder';
type:
| 'HEROIC'
| 'LEGACY_10_MAN'
| 'LEGACY_10_MAN_HEROIC'
| 'LEGACY_25_MAN'
| 'LEGACY_25_MAN_HEROIC'
| 'LFR'
| 'MYTHIC'
| 'NORMAL';
}
12 changes: 12 additions & 0 deletions packages/wow/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ import {
characterToysCollectionSummary,
characterTransmogCollectionSummary,
} from './character-collections/character-collections';
import {
characterDungeons,
characterEncountersSummary,
characterRaids,
} from './character-encounters/character-encounters';
import { connectedRealm, connectedRealmIndex, connectedRealmSearch } from './connected-realm/connected-realm';
import {
conduit,
Expand Down Expand Up @@ -202,6 +207,10 @@ export const wow = {
characterPetsCollectionSummary,
characterToysCollectionSummary,
characterTransmogCollectionSummary,
//Character Encounters
characterDungeons,
characterEncountersSummary,
characterRaids,
//Connected Realm
connectedRealm,
connectedRealmIndex,
Expand Down Expand Up @@ -386,6 +395,9 @@ export * from './character-appearance/types';
//Character Collections
export * from './character-collections/character-collections';
export * from './character-collections/types';
//Character Encounters
export * from './character-encounters/character-encounters';
export * from './character-encounters/types';
//Connected Realm
export * from './connected-realm/connected-realm';
export * from './connected-realm/types';
Expand Down

0 comments on commit f224581

Please sign in to comment.