Skip to content

Commit

Permalink
Adding comments to team client
Browse files Browse the repository at this point in the history
  • Loading branch information
Flusaka committed Feb 12, 2022
1 parent 3488f4c commit e04e5d9
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/clients/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@ import IRequestClient, { IResponse } from '../interfaces/request';
import { ITeam, ITeamClient, ITeamMember } from '../interfaces/teams';
import { parse } from 'node-html-parser';

/**
* Client for retrieving Team data specifically
* @class TeamClient
*/
export class TeamClient implements ITeamClient {
private requestClient: IRequestClient;

/**
*
* @param requestClient Create a new TeamClient
* @param requestClient Instance of a type of IRequestClient this will use to retrieve data from Liquipedia
*/
constructor(requestClient: IRequestClient) {
this.requestClient = requestClient;
}

/**
* Get the details of a team by name
* @param teamName The name of the team as it would appear in a URL on Liquipedia
* @returns An object containing all team details from Liquipedia
*/
public getTeam(teamName: string): Promise<ITeam> {
return new Promise((resolve, reject) => {
const encodedTeamName = teamName.replace(/ /g, '_');
Expand All @@ -23,6 +37,11 @@ export class TeamClient implements ITeamClient {
});
}

/**
* Parses the HTML response from Liquipedia into an ITeam object
* @param response The response object from the Liquipedia server, containing the HTML to parse
* @returns An ITeam object populated with details parsed from the HTML
*/
private _parseTeam(response: IResponse): ITeam {
const htmlRoot = parse(response.parse.text['*']);

Expand Down Expand Up @@ -68,6 +87,11 @@ export class TeamClient implements ITeamClient {
};
}

/**
* Clean up the full name of a player to remove some parts that aren't needed
* @param fullName The full name value of the player
* @returns Cleaned up name with certain characters removed
*/
private _cleanupName(fullName: string): string {
const cleanedUp = /\((.+)\)/.exec(fullName);
return cleanedUp ? cleanedUp[1] : fullName;
Expand Down

0 comments on commit e04e5d9

Please sign in to comment.