本文整理汇总了Java中com.mashape.unirest.http.async.Callback类的典型用法代码示例。如果您正苦于以下问题:Java Callback类的具体用法?Java Callback怎么用?Java Callback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Callback类属于com.mashape.unirest.http.async包,在下文中一共展示了Callback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateKv
import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
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() {
}
});
}
示例2: login
import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
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);
}
});
}
示例3: execute
import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
@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();
}
});
}
示例4: execute
import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
@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();
}
});
}
示例5: handleCaptcha
import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
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() {
}
});
}
示例6: execute
import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
@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();
}
});
}
示例7: getNext
import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
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;
}
示例8: run
import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
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;
}
});
}
示例9: MultiplayerMenu
import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
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;
}
});
}
示例10: getMyDetails
import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
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);
}
示例11: getUserDetails
import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
public void getUserDetails(String id,Callback<JsonNode> usercallBack) {
//TODO- implement this
}
示例12: getFriendList
import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
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);
}
示例13: asStringAsync
import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
public Future<HttpResponse<String>> asStringAsync(Callback<String> callback) {
return HttpClientHelper.requestAsync(httpRequest, String.class, callback);
}
示例14: asJsonAsync
import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
public Future<HttpResponse<JsonNode>> asJsonAsync(Callback<JsonNode> callback) {
return HttpClientHelper.requestAsync(httpRequest, JsonNode.class, callback);
}
示例15: asBinaryAsync
import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
public Future<HttpResponse<InputStream>> asBinaryAsync(Callback<InputStream> callback) {
return HttpClientHelper.requestAsync(httpRequest, InputStream.class, callback);
}