This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
75 lines (63 loc) · 1.92 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import {ok} from 'assert';
import * as V1 from './services/v1';
import * as V2 from './services/v2';
import {resolve} from "path";
export interface ICredentials {
client:number;
key:string;
}
export interface IServiceOptions {
hostname:string;
clientId:number;
secretKey:string;
resources?: {
cities: string;
}
}
export interface IServiceResponse {
[key:string]:any;
}
export interface IServiceRequest {
[key:string]:any;
}
export class Credentials implements ICredentials {
public client:number;
public key:string;
constructor(client:number, key:string) {
this.client = client;
this.key = key;
}
}
export class DPD {
credentials: Credentials;
hostname:string;
resources = {
cities: resolve(__dirname, './resources/cities.csv')
};
geography:V1.Geography;
geography2:V2.Geography2;
calculator2:V2.Calculator2;
order2:V2.Order2;
tracing:V1.Tracing;
tracing2:V2.Tracing2;
label:V1.Label;
constructor(options:IServiceOptions) {
ok(options.secretKey, 'A "key" option is required');
ok(options.clientId, 'A "client" option is required');
ok(options.hostname, 'A "hostname" option is required');
if (options.resources && options.resources) {
this.resources = {
cities: options.resources.cities
};
}
this.hostname = options.hostname;
this.credentials = new Credentials(options.clientId, options.secretKey);
this.geography = new V1.Geography(this);
this.geography2 = new V2.Geography2(this);
this.calculator2 = new V2.Calculator2(this);
this.order2 = new V2.Order2(this);
this.tracing = new V1.Tracing(this);
this.tracing2 = new V2.Tracing2(this);
this.label = new V1.Label(this);
}
}