/
TwitchGraphQLBuilder.java
126 lines (105 loc) · 3.4 KB
/
TwitchGraphQLBuilder.java
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.github.twitch4j.graphql;
import com.github.philippheuer.credentialmanager.domain.OAuth2Credential;
import com.github.philippheuer.events4j.api.service.IEventHandler;
import com.github.philippheuer.events4j.core.EventManager;
import com.github.twitch4j.common.annotation.Unofficial;
import com.github.philippheuer.events4j.simple.SimpleEventHandler;
import com.github.twitch4j.common.config.ProxyConfig;
import com.github.twitch4j.common.util.EventManagerUtils;
import com.netflix.config.ConfigurationManager;
import lombok.*;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.Map;
/**
* Twitch GraphQL Builder
* <p>
* This is an unofficial API that is not intended for third-party use. Use at your own risk. Methods could change or stop working at any time.
*/
@Slf4j
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
@Unofficial
public class TwitchGraphQLBuilder {
/**
* Event Manager
*/
@With
private EventManager eventManager = null;
/**
* EventManager
*/
@With
private Class<? extends IEventHandler> defaultEventHandler = SimpleEventHandler.class;
/**
* Proxy Configuration
*/
@With
private ProxyConfig proxyConfig = null;
/**
* Client Id
*/
@With
private String clientId = "kimne78kx3ncx6brgo4mv6wki5h1ko";
/**
* Client Secret
*/
@With(onMethod_ = { @Deprecated })
private String clientSecret = "**SECRET**";
/**
* Default First-Party OAuth Token
*/
@With
private OAuth2Credential defaultFirstPartyToken = null;
/**
* Whether GraphQL Queries should be batched
*/
@With
private boolean enableBatching = false;
/**
* Default Timeout
*/
@With
private Integer timeout = 5000;
/**
* User Agent
*/
@With
private String userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36";
/**
* Additional headers to be applied to each outbound request
*/
@With
private Map<String, String> headers = new HashMap<>();
/**
* BaseUrl
*/
private String baseUrl = "https://gql.twitch.tv/gql";
/**
* Initialize the builder
*
* @return Twitch GraphQL Builder
*/
public static TwitchGraphQLBuilder builder() {
return new TwitchGraphQLBuilder();
}
/**
* Twitch API Client (GraphQL)
*
* @return TwitchGraphQL
*/
public TwitchGraphQL build() {
log.debug("GraphQL: Initializing Module ...");
log.warn("GraphQL: GraphQL is a experimental module not intended for third-party use, please take care as some features might break unannounced.");
// Hystrix
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds", timeout);
// GQL
TwitchGraphQL client = new TwitchGraphQL(baseUrl, userAgent, eventManager, clientId, defaultFirstPartyToken, proxyConfig, enableBatching, timeout, headers);
// Initialize/Check EventManager
eventManager = EventManagerUtils.validateOrInitializeEventManager(eventManager, defaultEventHandler);
// register with serviceMediator
this.eventManager.getServiceMediator().addService("twitch4j-graphql", client);
return client;
}
}