-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
60 lines (54 loc) · 1.49 KB
/
index.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import * as url from "url";
import UserAgent from "./lib/UserAgent";
import Api from "./lib/models/Api";
import Account from "./lib/models/Account";
export type AnkonnectOptions = {
baseUrl?: string;
userAgent?: string;
lang?: string;
proxy?: url.URL | string | null;
};
export type AnkonnectDefOptions = {
baseUrl: string;
userAgent: string;
lang: string;
proxy: url.URL | null;
};
export default class Ankonnect {
private options: AnkonnectDefOptions = {
baseUrl: "https://haapi.ankama.com/json/Ankama/v2",
userAgent: UserAgent.getRandomUserAgent(),
lang: "fr",
proxy: null
};
public Api: Api;
public Account: Account;
public constructor(options?: AnkonnectOptions) {
const opts = {
baseUrl:
options && options.baseUrl ? options.baseUrl : this.options.baseUrl,
userAgent:
options && options.userAgent
? options.userAgent
: this.options.userAgent,
lang: options && options.lang ? options.lang : this.options.lang,
proxy: this.initProxy(options ? options.proxy : null)
};
this.options = opts;
this.Api = new Api(this.options);
this.Account = new Account(this.options);
}
private initProxy(
proxy: string | url.URL | null | undefined
): url.URL | null {
if (typeof proxy === "string") {
return new url.URL(proxy);
} else if (proxy instanceof url.URL) {
return proxy;
}
return null;
}
public getOptions(): AnkonnectDefOptions {
return this.options;
}
}