Skip to content

Commit

Permalink
feat: add base getListURL method
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabb-c committed Jun 22, 2023
1 parent 5398167 commit 1b387c6
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 67 deletions.
7 changes: 3 additions & 4 deletions src/clients/berry.client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ENDPOINTS } from "../constants";
import { Berry, BerryFirmness, BerryFlavor, NamedAPIResourceList } from "../models";
import { BaseClient } from "../structures/base";
import { getListURL } from "../utils/request-params";
import { AxiosError, AxiosResponse } from "axios";

/**
Expand Down Expand Up @@ -109,7 +108,7 @@ export class BerryClient extends BaseClient {
*/
public listBerries(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.BERRY, offset, limit);
const url = this.getListURL(ENDPOINTS.BERRY, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -125,7 +124,7 @@ export class BerryClient extends BaseClient {
*/
public listBerryFirmnesses(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.BERRY_FIRMNESS, offset, limit);
const url = this.getListURL(ENDPOINTS.BERRY_FIRMNESS, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -141,7 +140,7 @@ export class BerryClient extends BaseClient {
*/
public listBerryFlavors(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.BERRY_FLAVOR, offset, limit);
const url = this.getListURL(ENDPOINTS.BERRY_FLAVOR, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand Down
7 changes: 3 additions & 4 deletions src/clients/contest.client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ENDPOINTS } from "../constants";
import { ContestEffect, ContestType, NamedAPIResourceList, SuperContestEffect } from "../models";
import { BaseClient } from "../structures/base";
import { getListURL } from "../utils/request-params";
import { AxiosError, AxiosResponse } from "axios";

/**
Expand Down Expand Up @@ -79,7 +78,7 @@ export class ContestClient extends BaseClient {
*/
public async listContestTypes(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.CONTEST_TYPE, offset, limit);
const url = this.getListURL(ENDPOINTS.CONTEST_TYPE, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -95,7 +94,7 @@ export class ContestClient extends BaseClient {
*/
public async listContestEffects(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.CONTEST_EFFECT, offset, limit);
const url = this.getListURL(ENDPOINTS.CONTEST_EFFECT, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -114,7 +113,7 @@ export class ContestClient extends BaseClient {
limit?: number,
): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.SUPER_CONTEST_EFFECT, offset, limit);
const url = this.getListURL(ENDPOINTS.SUPER_CONTEST_EFFECT, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand Down
7 changes: 3 additions & 4 deletions src/clients/encounter.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
NamedAPIResourceList,
} from "../models";
import { BaseClient } from "../structures/base";
import { getListURL } from "../utils/request-params";
import { AxiosError, AxiosResponse } from "axios";

/**
Expand Down Expand Up @@ -115,7 +114,7 @@ export class EncounterClient extends BaseClient {
limit?: number,
): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.ENCOUNTER_METHOD, offset, limit);
const url = this.getListURL(ENDPOINTS.ENCOUNTER_METHOD, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -134,7 +133,7 @@ export class EncounterClient extends BaseClient {
limit?: number,
): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.ENCOUNTER_CONDITION, offset, limit);
const url = this.getListURL(ENDPOINTS.ENCOUNTER_CONDITION, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -153,7 +152,7 @@ export class EncounterClient extends BaseClient {
limit?: number,
): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.ENCOUNTER_CONDITION_VALUE, offset, limit);
const url = this.getListURL(ENDPOINTS.ENCOUNTER_CONDITION_VALUE, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand Down
5 changes: 2 additions & 3 deletions src/clients/evolution.client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ENDPOINTS } from "../constants";
import { EvolutionChain, EvolutionTrigger, NamedAPIResourceList } from "../models";
import { BaseClient } from "../structures/base";
import { getListURL } from "../utils/request-params";
import { AxiosError, AxiosResponse } from "axios";

/**
Expand Down Expand Up @@ -64,7 +63,7 @@ export class EvolutionClient extends BaseClient {
*/
public async listEvolutionChains(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.EVOLUTION_CHAIN, offset, limit);
const url = this.getListURL(ENDPOINTS.EVOLUTION_CHAIN, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -83,7 +82,7 @@ export class EvolutionClient extends BaseClient {
limit?: number,
): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.EVOLUTION_TRIGGER, offset, limit);
const url = this.getListURL(ENDPOINTS.EVOLUTION_TRIGGER, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand Down
9 changes: 4 additions & 5 deletions src/clients/game.client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ENDPOINTS } from "../constants";
import { Generation, NamedAPIResourceList, Pokedex, Version, VersionGroup } from "../models";
import { BaseClient } from "../structures/base";
import { getListURL } from "../utils/request-params";
import { AxiosError, AxiosResponse } from "axios";

/**
Expand Down Expand Up @@ -136,7 +135,7 @@ export class GameClient extends BaseClient {
*/
public async listGenerations(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.GENERATION, offset, limit);
const url = this.getListURL(ENDPOINTS.GENERATION, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -152,7 +151,7 @@ export class GameClient extends BaseClient {
*/
public async listPokedexes(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.POKEDEX, offset, limit);
const url = this.getListURL(ENDPOINTS.POKEDEX, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -168,7 +167,7 @@ export class GameClient extends BaseClient {
*/
public async listVersions(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.VERSION, offset, limit);
const url = this.getListURL(ENDPOINTS.VERSION, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -184,7 +183,7 @@ export class GameClient extends BaseClient {
*/
public async listVersionGroups(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.VERSION_GROUP, offset, limit);
const url = this.getListURL(ENDPOINTS.VERSION_GROUP, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand Down
11 changes: 5 additions & 6 deletions src/clients/item.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
NamedAPIResourceList,
} from "../models";
import { BaseClient } from "../structures/base";
import { getListURL } from "../utils/request-params";
import { AxiosError, AxiosResponse } from "axios";

/**
Expand Down Expand Up @@ -172,7 +171,7 @@ export class ItemClient extends BaseClient {
*/
public async listItems(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.ITEM, offset, limit);
const url = this.getListURL(ENDPOINTS.ITEM, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -188,7 +187,7 @@ export class ItemClient extends BaseClient {
*/
public async listItemAttributes(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.ITEM_ATTRIBUTE, offset, limit);
const url = this.getListURL(ENDPOINTS.ITEM_ATTRIBUTE, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -204,7 +203,7 @@ export class ItemClient extends BaseClient {
*/
public async listItemCategories(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.ITEM_CATEGORY, offset, limit);
const url = this.getListURL(ENDPOINTS.ITEM_CATEGORY, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -223,7 +222,7 @@ export class ItemClient extends BaseClient {
limit?: number,
): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.ITEM_FLING_EFFECT, offset, limit);
const url = this.getListURL(ENDPOINTS.ITEM_FLING_EFFECT, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -239,7 +238,7 @@ export class ItemClient extends BaseClient {
*/
public async listItemPockets(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.ITEM_POCKET, offset, limit);
const url = this.getListURL(ENDPOINTS.ITEM_POCKET, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand Down
9 changes: 4 additions & 5 deletions src/clients/location.client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ENDPOINTS } from "../constants";
import { Location, LocationArea, NamedAPIResourceList, PalParkArea, Region } from "../models";
import { BaseClient } from "../structures/base";
import { getListURL } from "../utils/request-params";
import { AxiosError, AxiosResponse } from "axios";

/**
Expand Down Expand Up @@ -136,7 +135,7 @@ export class LocationClient extends BaseClient {
*/
public async listLocations(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.LOCATION, offset, limit);
const url = this.getListURL(ENDPOINTS.LOCATION, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -152,7 +151,7 @@ export class LocationClient extends BaseClient {
*/
public async listLocationAreas(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.LOCATION_AREA, offset, limit);
const url = this.getListURL(ENDPOINTS.LOCATION_AREA, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -168,7 +167,7 @@ export class LocationClient extends BaseClient {
*/
public async listPalParkAreas(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.PALPARK_AREA, offset, limit);
const url = this.getListURL(ENDPOINTS.PALPARK_AREA, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -184,7 +183,7 @@ export class LocationClient extends BaseClient {
*/
public async listRegions(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.REGION, offset, limit);
const url = this.getListURL(ENDPOINTS.REGION, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand Down
3 changes: 1 addition & 2 deletions src/clients/machine.client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ENDPOINTS } from "../constants";
import { Machine, NamedAPIResourceList } from "../models";
import { BaseClient } from "../structures/base";
import { getListURL } from "../utils/request-params";
import { AxiosError, AxiosResponse } from "axios";

/**
Expand Down Expand Up @@ -35,7 +34,7 @@ export class MachineClient extends BaseClient {
*/
public async listMachines(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.MACHINE, offset, limit);
const url = this.getListURL(ENDPOINTS.MACHINE, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand Down
15 changes: 7 additions & 8 deletions src/clients/move.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
NamedAPIResourceList,
} from "../models";
import { BaseClient } from "../structures/base";
import { getListURL } from "../utils/request-params";
import { AxiosError, AxiosResponse } from "axios";

/**
Expand Down Expand Up @@ -232,7 +231,7 @@ export class MoveClient extends BaseClient {
*/
public async listMoves(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.MOVE, offset, limit);
const url = this.getListURL(ENDPOINTS.MOVE, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -248,7 +247,7 @@ export class MoveClient extends BaseClient {
*/
public async listMoveAilments(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.MOVE_AILMENT, offset, limit);
const url = this.getListURL(ENDPOINTS.MOVE_AILMENT, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -267,7 +266,7 @@ export class MoveClient extends BaseClient {
limit?: number,
): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.MOVE_BATTLE_STYLE, offset, limit);
const url = this.getListURL(ENDPOINTS.MOVE_BATTLE_STYLE, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -283,7 +282,7 @@ export class MoveClient extends BaseClient {
*/
public async listMoveCategories(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.MOVE_CATEGORY, offset, limit);
const url = this.getListURL(ENDPOINTS.MOVE_CATEGORY, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -302,7 +301,7 @@ export class MoveClient extends BaseClient {
limit?: number,
): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.MOVE_DAMAGE_CLASS, offset, limit);
const url = this.getListURL(ENDPOINTS.MOVE_DAMAGE_CLASS, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -321,7 +320,7 @@ export class MoveClient extends BaseClient {
limit?: number,
): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.MOVE_LEARN_METHOD, offset, limit);
const url = this.getListURL(ENDPOINTS.MOVE_LEARN_METHOD, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand All @@ -337,7 +336,7 @@ export class MoveClient extends BaseClient {
*/
public async listMoveTargets(offset?: number, limit?: number): Promise<NamedAPIResourceList> {
return new Promise<NamedAPIResourceList>((resolve, reject) => {
const url = getListURL(ENDPOINTS.MOVE_TARGET, offset, limit);
const url = this.getListURL(ENDPOINTS.MOVE_TARGET, offset, limit);
this.api
.get<NamedAPIResourceList>(url)
.then((response: AxiosResponse<NamedAPIResourceList>) => resolve(response.data))
Expand Down
Loading

0 comments on commit 1b387c6

Please sign in to comment.