/
profile.ts
42 lines (35 loc) · 1.33 KB
/
profile.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/// <reference path="./haloapi.d.ts"/>
class Profile implements IProfile {
private title: string;
constructor(public api: IHaloAPI) {
this.title = "h5";
}
/** @inheritdoc */
emblemImage(params: string | IProfileParams): Promise<EmblemImage> {
var p: IProfileParams;
p = typeof params === "string" ? { player: params } : params;
let endpoint: string = `/profile/${this.title}/profiles/`
+ `${encodeURIComponent(p.player)}/emblem`;
return this.api.getImageURL(endpoint + this.constructQs(p));
}
/** @inheritdoc */
spartanImage(params: string | IProfileParams): Promise<SpartanImage> {
var p: IProfileParams;
p = typeof params === "string" ? { player: params } : params;
let endpoint: string = `/profile/${this.title}/profiles/`
+ `${encodeURIComponent(p.player)}/spartan`;
return this.api.getImageURL(endpoint + this.constructQs(p));
}
private constructQs(params: IProfileParams): string {
let qs: string[] = [];
for (let key in params) {
if (key !== "player")
qs.push(encodeURIComponent(key) + "="
+ encodeURIComponent(String(params[key])));
}
if (qs.length)
return `?${qs.join("&")}`;
return "";
}
};
export = Profile;