/
PubSubListenResponseEvent.java
61 lines (48 loc) · 1.7 KB
/
PubSubListenResponseEvent.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
package com.github.twitch4j.pubsub.events;
import com.github.twitch4j.common.events.TwitchEvent;
import com.github.twitch4j.pubsub.domain.PubSubRequest;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.Value;
import java.util.Optional;
import java.util.function.Supplier;
@Value
@EqualsAndHashCode(callSuper = false)
public class PubSubListenResponseEvent extends TwitchEvent {
/**
* The nonce that was passed in the request, if one was provided there.
*/
String nonce;
/**
* The error message associated with the request, or an empty string if there is no error.
*/
String error;
@ToString.Exclude
@Getter(AccessLevel.PRIVATE)
Supplier<PubSubRequest> listenRequestSupplier;
/**
* @return the listen request associated with this response.
* @implNote The current implementation requires unique nonce's across requests (which is the default behavior for the listen methods provided by the library).
* @implSpec This method involves an O(n) operation where n <= 50, so it is best to only call it once when needed.
*/
public Optional<PubSubRequest> getListenRequest() {
return Optional.ofNullable(listenRequestSupplier.get());
}
public boolean hasError() {
return error != null && error.length() > 0;
}
public boolean isBadAuthentication() {
return "ERR_BADAUTH".equals(error);
}
public boolean isBadMessage() {
return "ERR_BADMESSAGE".equals(error);
}
public boolean isBadTopic() {
return "ERR_BADTOPIC".equals(error);
}
public boolean isServerError() {
return "ERR_SERVER".equals(error);
}
}