Skip to content

Commit

Permalink
feat(servers): get base url in a generic manner
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveVanOpstal committed Jun 2, 2016
1 parent 0af0e4f commit 2a22be0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/server/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ export class Match {
}

private getMatchList(region, summonerId, championKey, callback: CallBack) {
let baseUrl = this.server.config.protocol + this.server.getHostname(region) + '/api/lol';
let path = baseUrl + region + '/' + settings.apiVersions.matchlist + 'matchlist/by-summoner/' + summonerId;
let path = this.server.getBaseUrl(region) + '/' + settings.apiVersions.matchlist + 'matchlist/by-summoner/' + summonerId;
this.server.sendRequest(path, region, (res: HostResponse) => {
if (res.success && res.json.totalGames >= config.games.min) {
return callback(undefined, res.json);
Expand Down Expand Up @@ -174,8 +173,7 @@ export class Match {
}

private getMatch(region: string, summonerId: number, matchId: number, callback: CallBack) {
let baseUrl = this.server.config.protocol + this.server.getHostname(region) + '/api/lol';
let path = baseUrl + region + '/' + settings.apiVersions.match + 'match' + matchId + '?includeTimeline=true';
let path = this.server.getBaseUrl(region) + '/' + settings.apiVersions.match + 'match' + matchId + '?includeTimeline=true';
this.server.sendRequest(path, region, (res: HostResponse) => {
if (res.success) {
callback(undefined, res.json);
Expand Down
6 changes: 5 additions & 1 deletion src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ export class Server {
this.sendHttpsRequest(options, callback);
}

public getBaseUrl(region?: string) {
return this.config.protocol + this.getHostname(region) + '/api/lol' + (region ? region : '');
}

public getHostname(region?: string) {
return region ? region : 'global' + this.config.hostname;
return (region ? region : 'global') + this.config.hostname;
}

public setCache(url: string, data: any): void {
Expand Down
2 changes: 1 addition & 1 deletion src/server/static-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {settings} from '../../config/settings';

let server = new Server(settings.staticServer.host, settings.staticServer.port);

let baseUrl = server.config.protocol + server.getHostname() + '/api/lol';
let baseUrl = server.getBaseUrl();

server.run((request: IncomingMessage, response: ServerResponse) => {
let pathname = getPathname(request.url);
Expand Down
3 changes: 1 addition & 2 deletions src/server/summoner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export class Summoner {
}

public getData(region: string, name: string, callback: (response: HostResponse) => void) {
let baseUrl = this.server.config.protocol + this.server.getHostname(region) + '/api/lol';
let path = baseUrl + region + '/' + settings.apiVersions.summoner + '/summoner/by-name/' + name;
let path = this.server.getBaseUrl(region) + '/' + settings.apiVersions.summoner + '/summoner/by-name/' + name;
this.server.sendRequest(path, region, callback);
}
}

0 comments on commit 2a22be0

Please sign in to comment.