• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Callback类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.mashape.unirest.http.async.Callback的典型用法代码示例。如果您正苦于以下问题:Java Callback类的具体用法?Java Callback怎么用?Java Callback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Callback类属于com.mashape.unirest.http.async包,在下文中一共展示了Callback类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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() {

				}

			});
}
 
开发者ID:pyloque,项目名称:captain-java,代码行数:22,代码来源:CaptainClient.java


示例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);
			}
		});
}
 
开发者ID:chrisj42,项目名称:minicraft-plus-revived,代码行数:41,代码来源:MultiplayerMenu.java


示例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();
        }
    });
}
 
开发者ID:elgoupil,项目名称:GoupilBot,代码行数:36,代码来源:CatCommand.java


示例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();
        }
    });
}
 
开发者ID:elgoupil,项目名称:GoupilBot,代码行数:36,代码来源:DogCommand.java


示例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() {

                }
            });
}
 
开发者ID:xSke,项目名称:Pxls,代码行数:36,代码来源:PacketHandler.java


示例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();
        }
    });
}
 
开发者ID:jagrosh,项目名称:ExampleBot,代码行数:32,代码来源:CatCommand.java


示例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;
}
 
开发者ID:arpitgautam,项目名称:AsyncFBClient,代码行数:9,代码来源:OAuth2AsyncFBClient.java


示例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;
        }
    });
}
 
开发者ID:wandora-team,项目名称:wandora,代码行数:30,代码来源:Requester.java


示例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;
		}
	});
}
 
开发者ID:chrisj42,项目名称:minicraft-plus-revived,代码行数:64,代码来源:MultiplayerMenu.java


示例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);
}
 
开发者ID:arpitgautam,项目名称:AsyncFBClient,代码行数:7,代码来源:OAuth2AsyncFBClient.java


示例11: getUserDetails

import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
public void getUserDetails(String id,Callback<JsonNode> usercallBack) {
	//TODO- implement this
}
 
开发者ID:arpitgautam,项目名称:AsyncFBClient,代码行数:4,代码来源:OAuth2AsyncFBClient.java


示例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);
}
 
开发者ID:arpitgautam,项目名称:AsyncFBClient,代码行数:7,代码来源:OAuth2AsyncFBClient.java


示例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);
}
 
开发者ID:zeeshanejaz,项目名称:unirest-android,代码行数:4,代码来源:BaseRequest.java


示例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);
}
 
开发者ID:zeeshanejaz,项目名称:unirest-android,代码行数:4,代码来源:BaseRequest.java


示例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);
}
 
开发者ID:zeeshanejaz,项目名称:unirest-android,代码行数:4,代码来源:BaseRequest.java


示例16: pushToUrl

import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
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();
        }

    }
 
开发者ID:caricah,项目名称:iotracah,代码行数:47,代码来源:PushHandler.java


示例17: getMyDetails

import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
void getMyDetails(Callback<JsonNode> callBack); 
开发者ID:arpitgautam,项目名称:AsyncFBClient,代码行数:2,代码来源:AsyncFBClient.java


示例18: getFriendList

import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
void getFriendList(Callback<JsonNode> friendListCallBack); 
开发者ID:arpitgautam,项目名称:AsyncFBClient,代码行数:2,代码来源:AsyncFBClient.java


示例19: getNext

import com.mashape.unirest.http.async.Callback; //导入依赖的package包/类
void getNext(Callback<JsonNode> usercallBack); 
开发者ID:arpitgautam,项目名称:AsyncFBClient,代码行数:2,代码来源:AsyncFBClient.java



注:本文中的com.mashape.unirest.http.async.Callback类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CoreAnnotation类代码示例发布时间:2022-05-21
下一篇:
Java MapChangeListener类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap