Skip to content

Commit

Permalink
[ClassicWoW/WoW] Additionally export functionality from the root rath…
Browse files Browse the repository at this point in the history
…er than only from the named wow/classicWow export
  • Loading branch information
Pewtro committed May 19, 2024
1 parent 6b88e25 commit e4c8e16
Show file tree
Hide file tree
Showing 108 changed files with 2,803 additions and 2,521 deletions.
6 changes: 6 additions & 0 deletions .changeset/cold-clocks-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@blizzard-api/classic-wow': minor
'@blizzard-api/wow': minor
---

Additionally export functionality from the root rather than only from the named wow/classicWow export
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# @blizzard-api/\*

The @blizzard-api collection aims to help you connect to the Blizzard Battle.net API as easily and painlessly as possible.

## NOTE: STILL EARLY STAGES

I am still in very early stages of development and the API can and will break a few times during development. Once a package is v1 or above, they will follow semantic versioning, but until then they should be considered experimental at best.
The @blizzard-api collection aims to help you connect to the Blizzard Battle.net API as easily and painlessly as possible. The packages are split up by game, and will contain all the endpoints, parameters, and responses you need to get started.

## Installation

Expand All @@ -30,10 +26,13 @@ The core package gives you access to helper functions such as `getBlizzardApi` w
The game package will let you access paths, namespaces, parameters and more for each endpoint. This can imported like so:

```ts
import { wow } from "@blizzard-api/wow"
import { achievement, wow } from "@blizzard-api/wow"

const achievement = wow.achievement(123);
^ { path: string, namespace: string }
//OR LIKE SO
const achievement = achievement(123);
^ { path: string, namespace: string }
```

If you additionally want to have a axios client with built in helpers, you can install `@blizzard-api/client` which will let you easily connect to the API and begin consuming it.
Expand Down Expand Up @@ -67,10 +66,7 @@ Please refer to the [battle.net documentation](https://develop.battle.net/docume

This list is generally prioritized but no promises that things will be addressed in this order.

- Release 1.0.0 of `@blizzard-api/client`, `@blizzard-api/core`, and `@blizzard-api/wow`.
- Add a package for the following games/flavours
- World of Warcraft Classic
- Diablo III
- Hearthstone
- Overwatch League
- StarCraft II
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
"diablo",
"d3",
"hs",
"hearthstone",
"ow",
"overwatch"
"hearthstone"
],
"devDependencies": {
"@changesets/cli": "2.27.2",
Expand Down
18 changes: 14 additions & 4 deletions packages/classic-wow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,34 @@ You can get paths, namespaces, parameters and more for a specific endpoint by ca
```ts
import { classicWow } from "@blizzard-api/classic-wow"

const achievement = classicWow.achievement(123);
const powerType = classicWow.powerType("static-classic", 123);
^ { path: string, namespace: string }
```

If you need the response types, they are also exported with "Response" appended, so to get the response type from the above code, you can import it like this:

```ts
import type { AchievementResponse } from '@blizzard-api/classic-wow';
import type { PowerTypeResponse } from '@blizzard-api/classic-wow';
```

If you simply want to use the existing object, you can use the helper from `@blizzard-api/core` like so:

```ts
import { classicWow } from "@blizzard-api/classic-wow"

const achievement = classicWow.achievement(123);
const powerType = classicWow.powerType("static-classic", 123);
^ { path: string, namespace: string }
type AchievementResponse = ExtractResourceType<typeof achievement>;
type PowerTypeResponse = ExtractResourceType<typeof powerType>;
```

If you don't want to use the exported classicWow object, you can also access the functions directly:

```ts
import { powerType } from "@blizzard-api/wow"

const powerType = powerType("static-classic", 123);
^ { path: string, namespace: string }
type PowerTypeResponse = ExtractResourceType<typeof powerType>;
```

## Differences to @blizzard-api/wow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it } from 'vitest';
import { classicAuctionHouseApi } from './auction-house';
import * as classicAuctionHouseApi from './auction-house';

describe.concurrent('classicAuctionHouseApi', () => {
it('should return the correct resource for auctionHouseIndex', ({ expect }) => {
Expand Down
74 changes: 36 additions & 38 deletions packages/classic-wow/src/auction-house/auction-house.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,39 @@ import type { BlizzardNamespaces, Resource } from '@blizzard-api/core';
import { base } from '../../../wow/src/base';
import type { AuctionHouseIndexResponse, AuctionsResponse } from './types';

export const classicAuctionHouseApi = {
/**
* Returns an index of auction houses for a connected realm.
* @param namespace The namespace to use. See {@link BlizzardNamespaces}.
* @param connectedRealmId The ID of the connected realm.
* @returns The auction house index. See {@link AuctionHouseIndexResponse}.
*/
auctionHouseIndex: (
namespace: Extract<BlizzardNamespaces, 'dynamic-classic' | 'dynamic-classic1x'>,
connectedRealmId: number,
): Resource<AuctionHouseIndexResponse> => {
return {
path: `${base}/connected-realm/${connectedRealmId}/auctions/index`,
namespace,
};
},
/**
* Returns all active auctions for a specific auction house on 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.
*
* Depending on the number of active auctions on the specified connected realm, the response from this endpoint may be rather large, sometimes exceeding 10 MB.
* @param namespace The namespace to use. See {@link BlizzardNamespaces}.
* @param connectedRealmId The ID of the connected realm.
* @param auctionHouseId The ID of the auction house.
* @returns The auction house data. See {@link AuctionsResponse}.
*/
auctions: (
namespace: Extract<BlizzardNamespaces, 'dynamic-classic' | 'dynamic-classic1x'>,
connectedRealmId: number,
auctionHouseId: number,
): Resource<AuctionsResponse> => {
return {
path: `${base}/connected-realm/${connectedRealmId}/auctions/${auctionHouseId}`,
namespace,
};
},
};
/**
* Returns an index of auction houses for a connected realm.
* @param namespace The namespace to use. See {@link BlizzardNamespaces}.
* @param connectedRealmId The ID of the connected realm.
* @returns The auction house index. See {@link AuctionHouseIndexResponse}.
*/
export function auctionHouseIndex(
namespace: Extract<BlizzardNamespaces, 'dynamic-classic' | 'dynamic-classic1x'>,
connectedRealmId: number,
): Resource<AuctionHouseIndexResponse> {
return {
path: `${base}/connected-realm/${connectedRealmId}/auctions/index`,
namespace,
};
}
/**
* Returns all active auctions for a specific auction house on 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.
*
* Depending on the number of active auctions on the specified connected realm, the response from this endpoint may be rather large, sometimes exceeding 10 MB.
* @param namespace The namespace to use. See {@link BlizzardNamespaces}.
* @param connectedRealmId The ID of the connected realm.
* @param auctionHouseId The ID of the auction house.
* @returns The auction house data. See {@link AuctionsResponse}.
*/
export function auctions(
namespace: Extract<BlizzardNamespaces, 'dynamic-classic' | 'dynamic-classic1x'>,
connectedRealmId: number,
auctionHouseId: number,
): Resource<AuctionsResponse> {
return {
path: `${base}/connected-realm/${connectedRealmId}/auctions/${auctionHouseId}`,
namespace,
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BlizzardNamespaces } from '@blizzard-api/core';
import { describe, it } from 'vitest';
import { classicConnectedRealmApi } from '../connected-realm/connected-realm';
import * as classicConnectedRealmApi from '../connected-realm/connected-realm';

const namespace: BlizzardNamespaces = 'dynamic-classic';
const namespace1x: BlizzardNamespaces = 'dynamic-classic1x';
Expand Down
100 changes: 49 additions & 51 deletions packages/classic-wow/src/connected-realm/connected-realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,52 @@ import type {
ConnectedRealmSearchResponseItem,
} from './types';

export const classicConnectedRealmApi = {
/**
* Returns an index of connected realms.
* @param namespace The namespace to use. See {@link BlizzardNamespaces}.
* @returns The connected realm index. See {@link ConnectedRealmIndexResponse}.
*/
connectedRealmIndex: (
namespace: Extract<BlizzardNamespaces, 'dynamic-classic' | 'dynamic-classic1x'>,
): Resource<ConnectedRealmIndexResponse> => {
return {
path: `${base}/connected-realm/index`,
namespace,
};
},
/**
* Returns a connected realm by ID.
* @param namespace The namespace to use. See {@link BlizzardNamespaces}.
* @param connectedRealmId The connected realm ID.
* @returns The connected realm. See {@link ConnectedRealmResponse}.
*/
connectedRealm: (
namespace: Extract<BlizzardNamespaces, 'dynamic-classic' | 'dynamic-classic1x'>,
connectedRealmId: number,
): Resource<ConnectedRealmResponse> => {
return {
path: `${base}/connected-realm/${connectedRealmId}`,
namespace,
};
},
/**
* Performs a search of connected realms.
* @param namespace The namespace to use. See {@link BlizzardNamespaces}.
* @param options The search parameters. See {@link ConnectedRealmSearchParameters}.
* @returns The search results. See {@link SearchResponse} & {@link ConnectedRealmSearchResponseItem}.
*/
connectedRealmSearch: (
namespace: Extract<BlizzardNamespaces, 'dynamic-classic' | 'dynamic-classic1x'>,
options: ConnectedRealmSearchParameters,
): Resource<SearchResponse<ConnectedRealmSearchResponseItem>, ConnectedRealmSearchParameters> => {
return {
namespace,
parameters: {
_page: options._page,
orderby: Array.isArray(options.orderby) ? options.orderby.join(',') : options.orderby,
'status.type': options['status.type'],
'realms.timezone': options['realms.timezone'],
},
path: `${base}/search/connected-realm`,
};
},
};
/**
* Returns an index of connected realms.
* @param namespace The namespace to use. See {@link BlizzardNamespaces}.
* @returns The connected realm index. See {@link ConnectedRealmIndexResponse}.
*/
export function connectedRealmIndex(
namespace: Extract<BlizzardNamespaces, 'dynamic-classic' | 'dynamic-classic1x'>,
): Resource<ConnectedRealmIndexResponse> {
return {
path: `${base}/connected-realm/index`,
namespace,
};
}
/**
* Returns a connected realm by ID.
* @param namespace The namespace to use. See {@link BlizzardNamespaces}.
* @param connectedRealmId The connected realm ID.
* @returns The connected realm. See {@link ConnectedRealmResponse}.
*/
export function connectedRealm(
namespace: Extract<BlizzardNamespaces, 'dynamic-classic' | 'dynamic-classic1x'>,
connectedRealmId: number,
): Resource<ConnectedRealmResponse> {
return {
path: `${base}/connected-realm/${connectedRealmId}`,
namespace,
};
}
/**
* Performs a search of connected realms.
* @param namespace The namespace to use. See {@link BlizzardNamespaces}.
* @param options The search parameters. See {@link ConnectedRealmSearchParameters}.
* @returns The search results. See {@link SearchResponse} & {@link ConnectedRealmSearchResponseItem}.
*/
export function connectedRealmSearch(
namespace: Extract<BlizzardNamespaces, 'dynamic-classic' | 'dynamic-classic1x'>,
options: ConnectedRealmSearchParameters,
): Resource<SearchResponse<ConnectedRealmSearchResponseItem>, ConnectedRealmSearchParameters> {
return {
namespace,
parameters: {
_page: options._page,
orderby: Array.isArray(options.orderby) ? options.orderby.join(',') : options.orderby,
'status.type': options['status.type'],
'realms.timezone': options['realms.timezone'],
},
path: `${base}/search/connected-realm`,
};
}
2 changes: 1 addition & 1 deletion packages/classic-wow/src/connected-realm/types.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
//The classic version of the connected realm types are the same as the retail version.
export type * from '../../../wow/src/connected-realm/types.js';
export type * from '../../../wow/src/connected-realm/types';
2 changes: 1 addition & 1 deletion packages/classic-wow/src/creature/creature.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it } from 'vitest';
import { base, mediaBase, searchBase } from '../../../wow/src/base';
import { classicCreatureApi } from './creature';
import * as classicCreatureApi from './creature';

describe.concurrent('classicCreatureApi', () => {
const namespace = 'static-classic';
Expand Down
Loading

0 comments on commit e4c8e16

Please sign in to comment.