Search in sources :

Example 1 with HttpRequestBuilder

use of com.badlogic.gdx.net.HttpRequestBuilder in project Mindustry by Anuken.

the class Net method http.

public static void http(String url, String method, Consumer<String> listener, Consumer<Throwable> failure) {
    HttpRequest req = new HttpRequestBuilder().newRequest().method(method).url(url).build();
    Gdx.net.sendHttpRequest(req, new HttpResponseListener() {

        @Override
        public void handleHttpResponse(HttpResponse httpResponse) {
            listener.accept(httpResponse.getResultAsString());
        }

        @Override
        public void failed(Throwable t) {
            failure.accept(t);
        }

        @Override
        public void cancelled() {
        }
    });
}
Also used : HttpRequest(com.badlogic.gdx.Net.HttpRequest) HttpResponse(com.badlogic.gdx.Net.HttpResponse) HttpRequestBuilder(com.badlogic.gdx.net.HttpRequestBuilder) HttpResponseListener(com.badlogic.gdx.Net.HttpResponseListener)

Example 2 with HttpRequestBuilder

use of com.badlogic.gdx.net.HttpRequestBuilder in project skin-composer by raeleus.

the class Main method checkForUpdates.

public static void checkForUpdates(Main main) {
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            HttpRequestBuilder requestBuilder = new HttpRequestBuilder();
            HttpRequest httpRequest = requestBuilder.newRequest().method(HttpMethods.GET).url("https://raw.githubusercontent.com/raeleus/skin-composer/master/version").build();
            Gdx.net.sendHttpRequest(httpRequest, new Net.HttpResponseListener() {

                @Override
                public void handleHttpResponse(Net.HttpResponse httpResponse) {
                    newVersion = httpResponse.getResultAsString();
                    Gdx.app.postRunnable(new Runnable() {

                        @Override
                        public void run() {
                            main.rootTable.fire(new RootTable.RootTableEvent(RootTable.RootTableEnum.CHECK_FOR_UPDATES_COMPLETE));
                        }
                    });
                }

                @Override
                public void failed(Throwable t) {
                    newVersion = VERSION;
                }

                @Override
                public void cancelled() {
                    newVersion = VERSION;
                }
            });
        }
    });
    thread.start();
}
Also used : HttpRequest(com.badlogic.gdx.Net.HttpRequest) HttpRequestBuilder(com.badlogic.gdx.net.HttpRequestBuilder)

Aggregations

HttpRequest (com.badlogic.gdx.Net.HttpRequest)2 HttpRequestBuilder (com.badlogic.gdx.net.HttpRequestBuilder)2 HttpResponse (com.badlogic.gdx.Net.HttpResponse)1 HttpResponseListener (com.badlogic.gdx.Net.HttpResponseListener)1