-
Notifications
You must be signed in to change notification settings - Fork 104
/
client.ts
64 lines (57 loc) · 2.5 KB
/
client.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
import { IConfiguration } from './configuration/IConfiguration'
import { AutomationDiscovery } from './discovery/automation/AutomationDiscovery'
import { CmsDiscovery } from './discovery/cms/CmsDiscovery'
import { CommunicationPreferencesDiscovery } from './discovery/communicationPreferences/CommunicationPreferencesDiscovery'
import { ConversationsDiscovery } from './discovery/conversations/ConversationsDiscovery'
import { CrmDiscovery } from './discovery/crm/CrmDiscovery'
import { EventsDiscovery } from './discovery/events/EventsDiscovery'
import { MarketingDiscovery } from './discovery/marketing/MarketingDiscovery'
import { OauthDiscovery } from './discovery/oauth/OauthDiscovery'
import { WebhooksDiscovery } from './discovery/webhooks/WebhooksDiscovery'
export class Client {
public automation: AutomationDiscovery = new AutomationDiscovery()
public cms: CmsDiscovery = new CmsDiscovery()
public communicationPreferences: CommunicationPreferencesDiscovery = new CommunicationPreferencesDiscovery()
public conversations: ConversationsDiscovery = new ConversationsDiscovery()
public crm: CrmDiscovery = new CrmDiscovery()
public events: EventsDiscovery = new EventsDiscovery()
public marketing: MarketingDiscovery = new MarketingDiscovery()
public oauth: OauthDiscovery = new OauthDiscovery()
public webhooks: WebhooksDiscovery = new WebhooksDiscovery()
public config: IConfiguration
constructor(config: IConfiguration = {}) {
this.config = config
this.init()
}
public init() {
this.automation = new AutomationDiscovery(this.config)
this.cms = new CmsDiscovery(this.config)
this.communicationPreferences = new CommunicationPreferencesDiscovery(this.config)
this.conversations = new ConversationsDiscovery(this.config)
this.crm = new CrmDiscovery(this.config)
this.events = new EventsDiscovery(this.config)
this.marketing = new MarketingDiscovery(this.config)
this.oauth = new OauthDiscovery(this.config)
this.webhooks = new WebhooksDiscovery(this.config)
}
public setAccessToken(token: string) {
this.cleanAuth()
this.config.accessToken = token
this.init()
}
public setApiKey(apiKey: string) {
this.cleanAuth()
this.config.apiKey = apiKey
this.init()
}
public setDeveloperApiKey(developerApiKey: string) {
this.cleanAuth()
this.config.developerApiKey = developerApiKey
this.init()
}
protected cleanAuth() {
delete this.config.accessToken
delete this.config.apiKey
delete this.config.developerApiKey
}
}