Skip to content
This repository was archived by the owner on Apr 11, 2021. It is now read-only.

Commit 7e09934

Browse files
authored
Merge pull request #26 from GlitchLib/dev
Release v0.3.0
2 parents 571815e + b65befb commit 7e09934

File tree

103 files changed

+2686
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+2686
-101
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212
# Glitch
1313
A hybrid-reactive Java wrapper for the Twitch. Supports using:
1414

15-
* [OkHttpClient](http://square.github.io/okhttp) - a Retrofit alternatives
15+
* [OkHttpClient](http://square.github.io/okhttp) - http client
1616
* [Gson](https://github.com/google/gson) - JSON
1717
* [Project Reactor](http://projectreactor.io/)
1818

1919
# Module Supports
20-
| Name | JVM (Tested) | Android (Not Tested) |
20+
| Name | JVM | Android |
2121
|:---:|:---:|:---:|
22-
| [glitch-core](core) | 1.8+ |(unknown) |
23-
| [glitch-kraken](kraken) | 1.8+ |(unknown) |
24-
| [glitch-helix](helix) | 1.8+ |(unknown) |
25-
| [glitch-auth](auth) | 1.8+ |(unknown) |
22+
| [glitch-core](core) | 1.8+ |SDK 26 |
23+
| [glitch-kraken](kraken) | 1.8+ |SDK 26 |
24+
| [glitch-helix](helix) | 1.8+ |SDK 26 |
25+
| [glitch-auth](auth) | 1.8+ |SDK 26 |
2626
| [glitch-chat](chat) | 1.8+ ||
2727
| [glitch-pubsub](pubsub) | 1.8+ ||
2828

2929
# Getting started
3030

31-
check the [BOM](./BOM) dependency how to import versions. Then get some examples below.
31+
Please introduce the [wiki page](https://glitchlib.github.io/wiki/getting-started/welcome/)
3232

3333
## Examples
3434

35-
Examples has been on [wiki page](./wiki)
35+
All example are be in **Basic Tutorials** on [wiki page](https://glitchlib.github.io/wiki/basic-tutorials/client/)
3636

3737
# Licence
3838

build.gradle

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
plugins {
2-
id "net.ltgt.apt" version "0.18"
2+
id "net.ltgt.apt" version "0.19"
33
id "com.jfrog.bintray" version "1.8.4"
4-
id "com.jfrog.artifactory" version "4.7.5"
54
id "de.lukaskoerfer.gradle.delombok" version "0.2"
6-
id "io.spring.dependency-management" version "1.0.6.RELEASE"
75
}
86

97
allprojects {
10-
apply plugin: "io.spring.dependency-management"
11-
12-
dependencyManagement {
13-
imports {
14-
mavenBom "io.projectreactor:reactor-bom:Californium-SR2"
15-
}
16-
}
8+
apply plugin: "net.ltgt.apt"
9+
apply plugin: "net.ltgt.apt-idea"
10+
apply plugin: "net.ltgt.apt-eclipse"
11+
apply plugin: "de.lukaskoerfer.gradle.delombok"
1712

1813
repositories {
1914
jcenter()
@@ -22,11 +17,7 @@ allprojects {
2217

2318
subprojects {
2419
apply plugin: "java"
25-
apply plugin: "net.ltgt.apt"
2620
apply plugin: "maven-publish"
27-
apply plugin: "net.ltgt.apt-idea"
28-
apply plugin: "net.ltgt.apt-eclipse"
29-
apply plugin: "de.lukaskoerfer.gradle.delombok"
3021

3122
tasks.withType(JavaCompile) {
3223
options.incremental = true
@@ -40,6 +31,9 @@ subprojects {
4031

4132
dependencies {
4233
if (project.name != "BOM" && project.name != "docs") {
34+
// https://docs.gradle.org/5.0/userguide/managing_transitive_dependencies.html#sec:bom_import
35+
compile enforcedPlatform("io.projectreactor:reactor-bom:Californium-SR3")
36+
4337
compile "org.slf4j:slf4j-api:1.7.25"
4438

4539
compileOnly "org.projectlombok:lombok:1.18.4"
@@ -59,6 +53,6 @@ subprojects {
5953
}
6054

6155
wrapper {
62-
gradleVersion = "4.10.2"
56+
gradleVersion = "5.0"
6357
distributionType = Wrapper.DistributionType.ALL
6458
}

chat/src/main/java/glitch/chat/GlitchChat.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.time.Duration;
3131
import java.util.*;
3232
import java.util.concurrent.atomic.AtomicBoolean;
33-
import java.util.function.Consumer;
3433

3534
@Slf4j
3635
public class GlitchChat extends AbstractWebSocketService<GlitchChat> {
@@ -198,7 +197,7 @@ private Mono<Credential> createBotConfig() {
198197
return client.getCredentialManager().buildFromCredentials(botCredential);
199198
}
200199

201-
public Mono<GlitchChat> build() {
200+
public Mono<GlitchChat> buildAsync() {
202201
return createBotConfig().map(credential -> new GlitchChat(client, new Configuration(credential, forceQuery.get()), eventProcessor, secure.get(), getApi()))
203202
.doOnSuccess(client -> {
204203
channels.forEach(client::joinChannel);
@@ -220,12 +219,8 @@ private GlitchKraken getApi() {
220219
}
221220
}
222221

223-
public void buildConsume(Consumer<GlitchChat> chat) {
224-
build().subscribe(chat);
225-
}
226-
227-
public GlitchChat buildBlocking() {
228-
return build().block();
222+
public GlitchChat build() {
223+
return buildAsync().block();
229224
}
230225
}
231226
}

chat/src/main/java/glitch/chat/object/entities/ChannelEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class ChannelEntity implements AbstractEntity<Channel> {
3232

3333
public ChannelEntity(GlitchChat client, String channelName) {
3434
this.client = client;
35-
this.data = (client.getApi() != null) ? client.getApi().use(UserService.class).flatMap(service -> service.getUser(channelName).next())
35+
this.data = (client.getApi() != null) ? client.getApi().use(UserService.class).flatMap(service -> service.getUsers(channelName).next())
3636
.flatMap(u -> client.getApi().use(ChannelService.class).flatMap(service -> service.getChannel(u.getId()))).switchIfEmpty(Mono.empty()) : Mono.empty();
3737
this.channelName = channelName;
3838

chat/src/main/java/glitch/chat/object/entities/ChannelUserEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public GlitchChat getClient() {
5858
}
5959

6060
public Mono<User> getData() {
61-
return (getClient().getApi() != null) ? getClient().getApi().use(UserService.class).flatMap(service -> service.getUser(username).next()).switchIfEmpty(Mono.empty()) : Mono.empty();
61+
return (getClient().getApi() != null) ? getClient().getApi().use(UserService.class).flatMap(service -> service.getUsers(username).next()).switchIfEmpty(Mono.empty()) : Mono.empty();
6262
}
6363

6464
public Mono<Long> getFollowTime() {

chat/src/main/java/glitch/chat/object/entities/UserEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public UserEntity(GlitchChat client, String username) {
1717
this.client = client;
1818
this.username = username;
1919
this.data = (getClient().getApi() != null) ? getClient().getApi()
20-
.use(UserService.class).zipWhen(service -> service.getUser(username).next())
20+
.use(UserService.class).zipWhen(service -> service.getUsers(username).next())
2121
.flatMap(tuple -> tuple.getT1().getChatUserState(tuple.getT2())) :
2222
Mono.empty();
2323
}

core/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ plugins {
33
}
44

55
dependencies {
6-
compile "com.google.guava:guava:27.0-jre"
6+
compile "com.google.guava:guava:27.0.1-jre"
77

8-
compile "com.squareup.okhttp3:okhttp:3.11.0"
9-
compile "com.squareup.okhttp3:logging-interceptor:3.11.0"
8+
compile "com.squareup.okhttp3:okhttp:3.12.0"
9+
compile "com.squareup.okhttp3:logging-interceptor:3.12.0"
1010

1111
compile "com.google.code.gson:gson:2.8.5"
1212

core/src/main/java/glitch/api/AbstractHttpService.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import glitch.api.http.HttpRequest;
77
import glitch.api.http.HttpResponse;
88
import glitch.auth.Scope;
9+
import glitch.exceptions.http.ScopeIsMissingException;
910
import lombok.AccessLevel;
1011
import lombok.AllArgsConstructor;
1112
import lombok.Getter;
@@ -28,7 +29,7 @@ public abstract class AbstractHttpService {
2829
*/
2930
@Getter
3031
private final GlitchClient client;
31-
private final GlitchHttpClient http;
32+
protected final GlitchHttpClient http;
3233

3334
/**
3435
* Create {@link HttpMethod#GET GET} Request
@@ -109,7 +110,24 @@ protected final <T> HttpResponse<T> exchange(HttpRequest<T> request) {
109110
return http.exchange(request);
110111
}
111112

113+
/**
114+
* Checks Required scopes
115+
*
116+
* @param scopes list of {@link Scope}
117+
* @param requiredScope required {@link Scope}
118+
* @return scope is exist
119+
*/
112120
protected final boolean checkRequiredScope(Collection<Scope> scopes, Scope requiredScope) {
113121
return scopes.contains(requiredScope);
114122
}
123+
124+
/**
125+
* Handling {@link ScopeIsMissingException}
126+
*
127+
* @param requiredScope required {@link Scope}
128+
* @return throwable exception called {@link ScopeIsMissingException}
129+
*/
130+
protected ScopeIsMissingException handleScopeMissing(Scope requiredScope) {
131+
return new ScopeIsMissingException(requiredScope);
132+
}
115133
}

core/src/main/java/glitch/api/http/GlitchHttpClient.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.collect.ImmutableListMultimap;
44
import com.google.common.collect.LinkedListMultimap;
55
import com.google.common.collect.Multimap;
6+
import com.google.gson.FieldNamingPolicy;
67
import com.google.gson.Gson;
78
import com.google.gson.GsonBuilder;
89
import glitch.api.objects.adapters.ColorAdapter;
@@ -135,7 +136,7 @@ public static Builder builder() {
135136

136137
private Request doRequest(HttpRequest<?> httpRequest) {
137138
return new Request.Builder()
138-
.method(httpRequest.method.name(), getBody(httpRequest.body))
139+
.method(httpRequest.method.name(), getBody(httpRequest.body, httpRequest.serializeNullsBody.get()))
139140
.url(buildUrl(httpRequest.endpoint, httpRequest.queryParams))
140141
.headers(buildHeaders(httpRequest.headers)).build();
141142
}
@@ -163,14 +164,16 @@ private String buildUrl(String endpoint, Multimap<String, ? extends Serializable
163164
}
164165

165166
@Nullable
166-
private RequestBody getBody(@Nullable Object body) {
167+
private RequestBody getBody(@Nullable Object body, boolean serializeNulls) {
168+
String requestBody = (serializeNulls) ? gson.newBuilder().serializeNulls().create().toJson(body) : gson.toJson(body);
167169
if (body == null) return null;
168-
else return RequestBody.create(MediaType.get("application/json"), gson.toJson(body));
170+
else return RequestBody.create(MediaType.get("application/json"), requestBody);
169171
}
170172

171173
public static class Builder {
172174
private final Multimap<String, String> headers = LinkedListMultimap.create();
173-
private final GsonBuilder gsonBuilder = new GsonBuilder();
175+
private final GsonBuilder gsonBuilder = new GsonBuilder()
176+
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
174177
private String baseUrl;
175178

176179
@Nullable

core/src/main/java/glitch/api/http/HttpRequest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import javax.annotation.Nullable;
77
import java.io.Serializable;
88
import java.util.Map;
9+
import java.util.concurrent.atomic.AtomicBoolean;
910

1011
/**
1112
* HTTP Request created by {@code {@link GlitchHttpClient#create(HttpMethod, String, Class)}}.
@@ -19,6 +20,7 @@ public class HttpRequest<T> {
1920

2021
@Nullable
2122
Object body;
23+
final AtomicBoolean serializeNullsBody = new AtomicBoolean(false);
2224

2325
final Multimap<String, String> headers = HashMultimap.create();
2426
final Multimap<String, ? extends Serializable> queryParams = HashMultimap.create();
@@ -32,13 +34,25 @@ public class HttpRequest<T> {
3234
/**
3335
* Set Request Body
3436
* @param body body Object
37+
* @param serializeNulls serialize nulls
3538
* @return this
3639
*/
37-
public HttpRequest<T> body(Object body) {
40+
public HttpRequest<T> body(Object body, boolean serializeNulls) {
3841
this.body = body;
42+
this.serializeNullsBody.set(serializeNulls);
3943
return this;
4044
}
4145

46+
/**
47+
* Set Request Body without serializing nulls
48+
*
49+
* @param body body Object
50+
* @return this
51+
*/
52+
public HttpRequest<T> body(Object body) {
53+
return body(body, false);
54+
}
55+
4256
/**
4357
* Add Header to the Request
4458
* @param key Header Key
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package glitch.api.objects.json.interfaces;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
public interface CursorList<E> extends OrdinalList<E> {
6+
@SerializedName(value = "cursor", alternate = ("_cursor"))
7+
String getCursor();
8+
}

core/src/main/java/glitch/api/objects/json/interfaces/OrdinalList.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,30 @@
33
import com.google.common.collect.ImmutableList;
44
import com.google.gson.annotations.SerializedName;
55

6-
public interface OrdinalList<E extends IDObject<?>> {
6+
public interface OrdinalList<E> {
77
@SerializedName(value = "data", alternate = {
8-
"rooms"
8+
"rooms",
9+
"users",
10+
"follows",
11+
"teams",
12+
"subscriptions",
13+
"videos",
14+
"communities",
15+
"emoticons",
16+
"clips",
17+
"top",
18+
"ingests",
19+
"channels",
20+
"games",
21+
"streams",
22+
"teams",
23+
"vods",
24+
"featured"
925
})
1026
ImmutableList<E> getData();
1127

1228
@SerializedName("_total")
13-
int size();
29+
default int size() {
30+
return getData().size();
31+
}
1432
}

0 commit comments

Comments
 (0)