Search in sources :

Example 1 with Reply

use of me.semx11.autotip.api.reply.Reply in project Hyperium by HyperiumClient.

the class Autotip method reloadGlobalSettings.

public void reloadGlobalSettings() {
    SettingsReply reply = SettingsRequest.of(this).execute();
    if (!reply.isSuccess()) {
        throw new AssertionError("Connection error while fetching global settings");
    }
    globalSettings = reply.getSettings();
}
Also used : SettingsReply(me.semx11.autotip.api.reply.impl.SettingsReply)

Example 2 with Reply

use of me.semx11.autotip.api.reply.Reply 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();
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStream(java.io.InputStream) Reply(me.semx11.autotip.api.reply.Reply) IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException)

Example 3 with Reply

use of me.semx11.autotip.api.reply.Reply 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));
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) KeepAliveReply(me.semx11.autotip.api.reply.impl.KeepAliveReply) RequestHandler(me.semx11.autotip.api.RequestHandler) SessionKey(me.semx11.autotip.api.SessionKey) RequestType(me.semx11.autotip.api.RequestType) GetBuilder(me.semx11.autotip.api.GetBuilder) Reply(me.semx11.autotip.api.reply.Reply) Optional(java.util.Optional) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) Request(me.semx11.autotip.api.request.Request) KeepAliveReply(me.semx11.autotip.api.reply.impl.KeepAliveReply) Reply(me.semx11.autotip.api.reply.Reply) KeepAliveReply(me.semx11.autotip.api.reply.impl.KeepAliveReply)

Example 4 with Reply

use of me.semx11.autotip.api.reply.Reply 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));
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) Autotip(me.semx11.autotip.Autotip) RequestHandler(me.semx11.autotip.api.RequestHandler) SettingsReply(me.semx11.autotip.api.reply.impl.SettingsReply) RequestType(me.semx11.autotip.api.RequestType) GetBuilder(me.semx11.autotip.api.GetBuilder) Reply(me.semx11.autotip.api.reply.Reply) Version(me.semx11.autotip.util.Version) Optional(java.util.Optional) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) Request(me.semx11.autotip.api.request.Request) SettingsReply(me.semx11.autotip.api.reply.impl.SettingsReply) Reply(me.semx11.autotip.api.reply.Reply) SettingsReply(me.semx11.autotip.api.reply.impl.SettingsReply)

Example 5 with Reply

use of me.semx11.autotip.api.reply.Reply in project Hyperium by HyperiumClient.

the class Autotip method reloadLocale.

public void reloadLocale() {
    LocaleReply reply = LocaleRequest.of(this).execute();
    if (!reply.isSuccess()) {
        throw new IllegalStateException("Could not fetch locale");
    }
    localeHolder = reply.getLocaleHolder();
}
Also used : LocaleReply(me.semx11.autotip.api.reply.impl.LocaleReply)

Aggregations

Reply (me.semx11.autotip.api.reply.Reply)7 Optional (java.util.Optional)6 GetBuilder (me.semx11.autotip.api.GetBuilder)6 RequestHandler (me.semx11.autotip.api.RequestHandler)6 RequestType (me.semx11.autotip.api.RequestType)6 Request (me.semx11.autotip.api.request.Request)6 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)6 Autotip (me.semx11.autotip.Autotip)3 SessionKey (me.semx11.autotip.api.SessionKey)3 GameProfile (com.mojang.authlib.GameProfile)2 LocaleReply (me.semx11.autotip.api.reply.impl.LocaleReply)2 LogoutReply (me.semx11.autotip.api.reply.impl.LogoutReply)2 SettingsReply (me.semx11.autotip.api.reply.impl.SettingsReply)2 Version (me.semx11.autotip.util.Version)2 JsonParseException (com.google.gson.JsonParseException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 Locale (java.util.Locale)1 KeepAliveReply (me.semx11.autotip.api.reply.impl.KeepAliveReply)1