java类com.mashape.unirest.http.async.Callback的实例源码

CaptainClient.java 文件源码 项目:captain-java 阅读 16 收藏 0 点赞 0 评论 0
public void updateKv(String key, JSONObject js) {
    Unirest.post(urlRoot() + "/api/kv/set").field("key", key).field("value", js.toString())
            .asJsonAsync(new Callback<JsonNode>() {

                @Override
                public void completed(HttpResponse<JsonNode> response) {

                }

                @Override
                public void failed(UnirestException e) {
                    e.printStackTrace();
                }

                @Override
                public void cancelled() {

                }

            });
}
MultiplayerMenu.java 文件源码 项目:minicraft-plus-revived 阅读 18 收藏 0 点赞 0 评论 0
private void login(String email, String password) {
    setWaitMessage("logging in");

    /// HTTP REQUEST - send username and password to server via HTTPS, expecting a UUID in return.
    Unirest.post(apiDomain+"/login")
        .field("email", email)
        .field("password", password)
        .asJsonAsync(new Callback<JsonNode>() {
            @Override
            public void completed(HttpResponse<JsonNode> response) {
                JSONObject json = response.getBody().getObject();
                if(Game.debug) System.out.println("received json from login attempt: " + json.toString());
                switch(json.getString("status")) {
                    case "error":
                        setError(json.getString("message"), false); // in case the user abandoned the menu, don't drag them back.
                        break;

                    case "success":
                        savedUUID = json.getString("uuid");
                        savedUsername = json.getString("name");
                        setWaitMessage("saving credentials");
                        new Save();
                        typing = savedIP;
                        curState = State.ENTERIP;
                        break;
                }
            }

            @Override
            public void failed(UnirestException e) {
                e.printStackTrace();
                cancelled();
            }

            @Override
            public void cancelled() {
                setError("login failed.", false);
            }
        });
}
CatCommand.java 文件源码 项目:GoupilBot 阅读 18 收藏 0 点赞 0 评论 0
@Override
protected void execute(CommandEvent event) {
    if (event.isFromType(ChannelType.TEXT)) {
        String id = Constant.getTextChannelConf().getProperty(event.getGuild().getId());
        if (id != null) {
            if (!event.getChannel().getId().equals(id)) {
                return;
            }
        }
    }
    // use Unirest to poll an API
    Unirest.get("http://random.cat/meow").asJsonAsync(new Callback<JsonNode>() {

        // The API call was successful
        @Override
        public void completed(HttpResponse<JsonNode> hr) {
            event.reply(new EmbedBuilder()
                    .setColor(event.isFromType(ChannelType.TEXT) ? event.getSelfMember().getColor() : Color.GREEN)
                    .setImage(hr.getBody().getObject().getString("file"))
                    .build());
        }

        // The API call failed
        @Override
        public void failed(UnirestException ue) {
            event.reactError();
        }

        // The API call was cancelled (this should never happen)
        @Override
        public void cancelled() {
            event.reactError();
        }
    });
}
DogCommand.java 文件源码 项目:GoupilBot 阅读 18 收藏 0 点赞 0 评论 0
@Override
protected void execute(CommandEvent event) {
    if (event.isFromType(ChannelType.TEXT)) {
        String id = Constant.getTextChannelConf().getProperty(event.getGuild().getId());
        if (id != null) {
            if (!event.getChannel().getId().equals(id)) {
                return;
            }
        }
    }
    // use Unirest to poll an API
    Unirest.get("https://random.dog/woof.json").asJsonAsync(new Callback<JsonNode>() {

        // The API call was successful
        @Override
        public void completed(HttpResponse<JsonNode> hr) {
            event.reply(new EmbedBuilder()
                    .setColor(event.isFromType(ChannelType.TEXT) ? event.getSelfMember().getColor() : Color.GREEN)
                    .setImage(hr.getBody().getObject().getString("url"))
                    .build());
        }

        // The API call failed
        @Override
        public void failed(UnirestException ue) {
            event.reactError();
        }

        // The API call was cancelled (this should never happen)
        @Override
        public void cancelled() {
            event.reactError();
        }
    });
}
PacketHandler.java 文件源码 项目:Pxls 阅读 27 收藏 0 点赞 0 评论 0
private void handleCaptcha(WebSocketChannel channel, User user, ClientCaptcha cc) {
    if (!user.isFlaggedForCaptcha()) return;
    if (user.isBanned()) return;

    Unirest
            .post("https://www.google.com/recaptcha/api/siteverify")
            .field("secret", App.getConfig().getString("captcha.secret"))
            .field("response", cc.getToken())
            //.field("remoteip", "null")
            .asJsonAsync(new Callback<JsonNode>() {
                @Override
                public void completed(HttpResponse<JsonNode> response) {
                    JsonNode body = response.getBody();

                    String hostname = App.getConfig().getString("host");

                    boolean success = body.getObject().getBoolean("success") && body.getObject().getString("hostname").equals(hostname);
                    if (success) {
                        user.validateCaptcha();
                    }

                    server.send(channel, new ServerCaptchaStatus(success));
                }

                @Override
                public void failed(UnirestException e) {

                }

                @Override
                public void cancelled() {

                }
            });
}
CatCommand.java 文件源码 项目:ExampleBot 阅读 20 收藏 0 点赞 0 评论 0
@Override
protected void execute(CommandEvent event)
{
    // use Unirest to poll an API
    Unirest.get("http://random.cat/meow").asJsonAsync(new Callback<JsonNode>(){

        // The API call was successful
        @Override
        public void completed(HttpResponse<JsonNode> hr)
        {
            event.reply(new EmbedBuilder()
                    .setColor(event.isFromType(ChannelType.TEXT) ? event.getSelfMember().getColor() : Color.GREEN)
                    .setImage(hr.getBody().getObject().getString("file"))
                    .build());
        }

        // The API call failed
        @Override
        public void failed(UnirestException ue)
        {
            event.reactError();
        }

        // The API call was cancelled (this should never happen)
        @Override
        public void cancelled()
        {
            event.reactError();
        }
    });
}
OAuth2AsyncFBClient.java 文件源码 项目:AsyncFBClient 阅读 21 收藏 0 点赞 0 评论 0
public void getNext(Callback<JsonNode> callBack) {
    this.callBack = (NotificationCallBack) callBack;
    this.callBack.init();
    wrapper.get(nextURL).header("Content-Type", "application/json")
            .header("Authorization", "Bearer " + access_token)
            .asJsonAsync(callBack);
    return;
}
Requester.java 文件源码 项目:wandora 阅读 27 收藏 0 点赞 0 评论 0
public void run() {
    this.request.asJsonAsync(new Callback<JsonNode>() {
        @Override
        public void completed(HttpResponse<JsonNode> response) {
            callback.run(response);
            runFinished = true;
            runCounter++;
        }

        @Override
        public void failed(UnirestException e) {
            try {
                HttpResponse<String> s = request.asString();
                callback.error(e, s.getBody());
            } 
            catch (Exception e2) {
                callback.error(e2);
            }
            runFinished = true;
            failCounter++;
        }

        @Override
        public void cancelled() {
            callback.error(new Exception("Request was cancelled"));
            runFinished = true;
        }
    });
}
MultiplayerMenu.java 文件源码 项目:minicraft-plus-revived 阅读 24 收藏 0 点赞 0 评论 0
public MultiplayerMenu() {
    Game.ISONLINE = true;
    Game.ISHOST = false;

    if(savedUUID == null) savedUUID = "";
    if(email == null) email = "";
    if(savedUsername == null) savedUsername = "";

    // HTTP REQUEST - determine if there is internet connectivity.
    //String url = "https://www.playminicraft.com"; // test request
    setWaitMessage("testing connection");

    Unirest.get(domain).asBinaryAsync(new Callback<InputStream>() {
        @Override
        public void completed(HttpResponse<InputStream> httpResponse) {
            if(httpResponse.getStatus() == 200)
                online = true;
            else
                System.out.println("warning: minicraft site ping returned status code " + httpResponse.getStatus());

            //if(Game.getMenu() != MultiplayerMenu.this) return; // don't continue if the player moved to a different menu. 

            if(savedUUID.length() > 0) {
                // there is a previous login that can be used; check that it's valid
                setWaitMessage("attempting log in");
                //if (Game.debug) System.out.println("fetching username for uuid");
                fetchName(savedUUID);
            }

            if(curState == State.ERROR)
                return;

            // at this point, the game is online, and either the player could log in automatically, or has to enter their
            // email and password.

            if(savedUsername.length() == 0 || savedUUID.length() == 0)
                curState = State.LOGIN; // the player must log in manually.
            else {
                typing = savedIP;
                curState = State.ENTERIP; // the user has sufficient credentials; skip login phase
            }
        }

        @Override
        public void failed(UnirestException e) {
            e.printStackTrace();
            cancelled();
        }

        @Override
        public void cancelled() {
            if(savedUsername.length() == 0 || savedUUID.length() == 0) {
                // couldn't validate username, and can't enter offline mode b/c there is no username
                setError("no internet connection, but no login data saved; cannot enter offline mode.", false);
                //setError("could not access "+url);
                return;
            }

            // there is a saved copy of the uuid and username of the last player; use it for offline mode.
            curState = State.ENTERIP;
        }
    });
}
OAuth2AsyncFBClient.java 文件源码 项目:AsyncFBClient 阅读 17 收藏 0 点赞 0 评论 0
public void getMyDetails(Callback<JsonNode> usercallBack) {
    this.callBack = (NotificationCallBack) usercallBack;
    wrapper.get(meURL).header("Content-Type", "application/json")
            .header("Authorization", "Bearer " + access_token)
            .asJsonAsync(usercallBack);
}
OAuth2AsyncFBClient.java 文件源码 项目:AsyncFBClient 阅读 19 收藏 0 点赞 0 评论 0
public void getUserDetails(String id,Callback<JsonNode> usercallBack) {
    //TODO- implement this
}
OAuth2AsyncFBClient.java 文件源码 项目:AsyncFBClient 阅读 17 收藏 0 点赞 0 评论 0
public void getFriendList(Callback<JsonNode> friendListCallBack) {
    this.callBack = (NotificationCallBack) friendListCallBack;
    wrapper.get(friendURL).header("Content-Type", "application/json")
            .header("Authorization", "Bearer " + access_token)
            .asJsonAsync(friendListCallBack);
}
BaseRequest.java 文件源码 项目:unirest-android 阅读 26 收藏 0 点赞 0 评论 0
public Future<HttpResponse<String>> asStringAsync(Callback<String> callback) {
    return HttpClientHelper.requestAsync(httpRequest, String.class, callback);
}
BaseRequest.java 文件源码 项目:unirest-android 阅读 18 收藏 0 点赞 0 评论 0
public Future<HttpResponse<JsonNode>> asJsonAsync(Callback<JsonNode> callback) {
    return HttpClientHelper.requestAsync(httpRequest, JsonNode.class, callback);
}
BaseRequest.java 文件源码 项目:unirest-android 阅读 22 收藏 0 点赞 0 评论 0
public Future<HttpResponse<InputStream>> asBinaryAsync(Callback<InputStream> callback) {
    return HttpClientHelper.requestAsync(httpRequest, InputStream.class, callback);
}
PushHandler.java 文件源码 项目:iotracah 阅读 21 收藏 0 点赞 0 评论 0
public void pushToUrl(PublishMessage publishMessage, OnPushSuccessListener onPushSuccessListener) {


        ByteBuffer payloadBuffer = ByteBuffer.wrap((byte[]) publishMessage.getPayload());

        String payload = UTF8.decode(payloadBuffer).toString();


        MultipartBody httpMessage = Unirest.post(publishMessage.getProtocolData())
                .header("accept", "application/json")
                .field("topic", publishMessage.getTopic())
                .field("message", payload);

        if (MqttQoS.AT_LEAST_ONCE.value() == publishMessage.getQos()) {

            httpMessage.asJsonAsync(new Callback<JsonNode>() {

                public void failed(UnirestException e) {
                    log.info(" httpPushToUrl failed : problems calling service", e);
                }

                public void completed(HttpResponse<JsonNode> response) {
                    int code = response.getStatus();

                    JsonNode responseBody = response.getBody();
                    log.info(" httpPushToUrl completed : external server responded with {}", responseBody);
                    if (200 == code) {

                        AcknowledgeMessage ackMessage = AcknowledgeMessage.from(publishMessage.getMessageId());
                        ackMessage.copyTransmissionData(publishMessage);

                        onPushSuccessListener.success(ackMessage);

                    }
                }

                public void cancelled() {
                    log.info(" httpPushToUrl cancelled : request cancelled.");
                }

            });
        } else {
            httpMessage.asJsonAsync();
        }

    }
AsyncFBClient.java 文件源码 项目:AsyncFBClient 阅读 19 收藏 0 点赞 0 评论 0
void getMyDetails(Callback<JsonNode> callBack);
AsyncFBClient.java 文件源码 项目:AsyncFBClient 阅读 21 收藏 0 点赞 0 评论 0
void getFriendList(Callback<JsonNode> friendListCallBack);
AsyncFBClient.java 文件源码 项目:AsyncFBClient 阅读 23 收藏 0 点赞 0 评论 0
void getNext(Callback<JsonNode> usercallBack);


问题


面经


文章

微信
公众号

扫码关注公众号