Skip to content

Commit

Permalink
Generify RequestService.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wertik committed Aug 29, 2020
1 parent 2bbe7e5 commit 598de13
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import org.asynchttpclient.ListenableFuture;
import org.asynchttpclient.Response;
import space.devport.wertik.czechcraftquery.QueryPlugin;
import space.devport.wertik.czechcraftquery.system.struct.RequestType;
import space.devport.wertik.czechcraftquery.system.struct.context.RequestContext;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -27,9 +25,9 @@ public RequestService(QueryPlugin plugin) {
this.plugin = plugin;
}

public CompletableFuture<JsonObject> sendRequest(RequestType type, RequestContext context) {
public CompletableFuture<JsonObject> sendRequest(String stringURL) {

ListenableFuture<Response> getFuture = asyncHttpClient.prepareGet(context.parse(type.getStringURL())).execute();
ListenableFuture<Response> getFuture = asyncHttpClient.prepareGet(stringURL).execute();

return getFuture.toCompletableFuture().thenApplyAsync((response) -> {
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getResponseBodyAsStream()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public CompletableFuture<T> sendRequest(RequestContext context) {

if (!requestType.verifyContext(context)) return null;

CompletableFuture<JsonObject> future = plugin.getService().sendRequest(requestType, context);
CompletableFuture<JsonObject> future = plugin.getService().sendRequest(context.parse(requestType.getStringURL()));

return future.thenApplyAsync((jsonResponse) -> {
T response = (T) requestType.getParser().parse(jsonResponse);
Expand Down

0 comments on commit 598de13

Please sign in to comment.