use of me.semx11.autotip.api.request.Request in project Hyperium by HyperiumClient.
the class RequestHandler method getReply.
public static Optional<Reply> getReply(Request request, URI uri) {
String json = null;
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) uri.toURL().openConnection();
conn.setRequestProperty("User-Agent", "Autotip v" + autotip.getVersion());
InputStream input = conn.getResponseCode() < HttpURLConnection.HTTP_BAD_REQUEST ? conn.getInputStream() : conn.getErrorStream();
json = IOUtils.toString(input, StandardCharsets.UTF_8);
Autotip.LOGGER.info(request.getType() + " JSON: " + json);
Reply reply = GSON.fromJson(json, (Type) request.getType().getReplyClass());
return Optional.ofNullable(reply);
} catch (IOException | JsonParseException e) {
ErrorReport.reportException(e);
Autotip.LOGGER.debug(request.getType() + " JSON: " + json);
return Optional.empty();
} finally {
if (conn != null)
conn.disconnect();
}
}
use of me.semx11.autotip.api.request.Request in project Hyperium by HyperiumClient.
the class KeepAliveRequest method execute.
@Override
public KeepAliveReply execute() {
HttpUriRequest request = GetBuilder.of(this).addParameter("key", sessionKey).build();
Optional<Reply> optional = RequestHandler.getReply(this, request.getURI());
return optional.map(reply -> (KeepAliveReply) reply).orElseGet(() -> new KeepAliveReply(false));
}
use of me.semx11.autotip.api.request.Request in project Hyperium by HyperiumClient.
the class SettingsRequest method execute.
@Override
public SettingsReply execute() {
HttpUriRequest request = GetBuilder.of(this).addParameter("v", version.get()).build();
Optional<Reply> optional = RequestHandler.getReply(this, request.getURI());
return optional.map(reply -> (SettingsReply) reply).orElseGet(() -> new SettingsReply(false));
}
use of me.semx11.autotip.api.request.Request in project Hyperium by HyperiumClient.
the class LocaleRequest method execute.
@Override
public LocaleReply execute() {
HttpUriRequest request = GetBuilder.of(this).addParameter("lang", locale.toLanguageTag()).addParameter("v", version.get()).build();
Optional<Reply> optional = RequestHandler.getReply(this, request.getURI());
return optional.map(reply -> (LocaleReply) reply).orElseGet(() -> new LocaleReply(false));
}
use of me.semx11.autotip.api.request.Request in project Hyperium by HyperiumClient.
the class LogoutRequest method execute.
@Override
public LogoutReply execute() {
HttpUriRequest request = GetBuilder.of(this).addParameter("key", sessionKey).build();
Optional<Reply> optional = RequestHandler.getReply(this, request.getURI());
return optional.map(reply -> (LogoutReply) reply).orElseGet(() -> new LogoutReply(false));
}
Aggregations