本文整理汇总了Java中com.mashape.unirest.request.body.MultipartBody.asString方法的典型用法代码示例。如果您正苦于以下问题:Java MultipartBody.asString方法的具体用法?Java MultipartBody.asString怎么用?Java MultipartBody.asString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mashape.unirest.request.body.MultipartBody
的用法示例。
在下文中一共展示了MultipartBody.asString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getChat
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
/**
* A method used to get a Chat object via the chats ID
*
* @param chatID The Chat ID of the chat you want a Chat object of
*
* @return A Chat object or null if the chat does not exist or you don't have permission to get this chat
*/
public Chat getChat(String chatID) {
try {
MultipartBody request = Unirest.post(getBotAPIUrl() + "getChat")
.field("chat_id", chatID, "application/json; charset=utf8;");
HttpResponse<String> response = request.asString();
JSONObject jsonResponse = Utils.processResponse(response);
if (jsonResponse != null && Utils.checkResponseStatus(jsonResponse)) {
JSONObject result = jsonResponse.getJSONObject("result");
return ChatImpl.createChat(result, this);
}
} catch (UnirestException e) {
e.printStackTrace();
}
return null;
}
示例2: editMessageText
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
private JSONObject editMessageText(String chatId, Long messageId, String inlineMessageId, String text, ParseMode parseMode, boolean disableWebPagePreview, InlineReplyMarkup inlineReplyMarkup) {
HttpResponse<String> response;
JSONObject jsonResponse = null;
try {
MultipartBody requests = Unirest.post(getBotAPIUrl() + "editMessageText")
.field("text", text, "application/json; charset=utf8;")
.field("disable_web_page_preview", disableWebPagePreview);
if(chatId != null) requests.field("chat_id", chatId, "application/json; charset=utf8;");
if(messageId != null) requests.field("message_id", messageId);
if(inlineMessageId != null) requests.field("inline_message_id", inlineMessageId, "application/json; charset=utf8;");
if(parseMode != null) requests.field("parse_mode", parseMode.getModeName(), "application/json; charset=utf8;");
if(inlineReplyMarkup != null) requests.field("reply_markup", GSON.toJson(inlineReplyMarkup, InlineKeyboardMarkup.class), "application/json; charset=utf8;");
response = requests.asString();
jsonResponse = Utils.processResponse(response);
} catch (UnirestException e) {
e.printStackTrace();
}
return jsonResponse;
}
示例3: editMessageCaption
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
private JSONObject editMessageCaption(String chatId, Long messageId, String inlineMessageId, String caption, InlineReplyMarkup inlineReplyMarkup) {
HttpResponse<String> response;
JSONObject jsonResponse = null;
try {
MultipartBody requests = Unirest.post(getBotAPIUrl() + "editMessageCaption")
.field("caption", caption, "application/json; charset=utf8;");
if(chatId != null) requests.field("chat_id", chatId, "application/json; charset=utf8;");
if(messageId != null) requests.field("message_id", messageId);
if(inlineMessageId != null) requests.field("inline_message_id", inlineMessageId, "application/json; charset=utf8;");
if(inlineReplyMarkup != null) requests.field("reply_markup", GSON.toJson(inlineReplyMarkup, InlineKeyboardMarkup.class), "application/json; charset=utf8;");
response = requests.asString();
jsonResponse = Utils.processResponse(response);
} catch (UnirestException e) {
e.printStackTrace();
}
return jsonResponse;
}
示例4: editMessageReplyMarkup
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
private JSONObject editMessageReplyMarkup(String chatId, Long messageId, String inlineMessageId, InlineReplyMarkup inlineReplyMarkup) {
HttpResponse<String> response;
JSONObject jsonResponse = null;
try {
MultipartBody requests = Unirest.post(getBotAPIUrl() + "editMessageReplyMarkup")
.field("reply_markup", GSON.toJson(inlineReplyMarkup, InlineKeyboardMarkup.class), "application/json; charset=utf8;");
if(chatId != null) requests.field("chat_id", chatId, "application/json; charset=utf8;");
if(messageId != null) requests.field("message_id", messageId);
if(inlineMessageId != null) requests.field("inline_message_id", inlineMessageId, "application/json; charset=utf8;");
response = requests.asString();
jsonResponse = Utils.processResponse(response);
} catch (UnirestException e) {
e.printStackTrace();
}
return jsonResponse;
}
示例5: kickChatMember
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
/**
* Use this method to kick a user from a group or a supergroup. In the case of supergroups, the user will not be
* able to return to the group on their own using invite links, etc., unless unbanned first. The bot must be
* an administrator in the group for this to work
*
* @param chatId The ID of the chat that you want to kick the user from
* @param userId The ID of the user that you want to kick from the chat
*
* @return True if the user was kicked successfully, otherwise False
*/
public boolean kickChatMember(String chatId, int userId) {
HttpResponse<String> response;
JSONObject jsonResponse;
try {
MultipartBody request = Unirest.post(getBotAPIUrl() + "kickChatMember")
.field("chat_id", chatId, "application/json; charset=utf8;")
.field("user_id", userId);
response = request.asString();
jsonResponse = Utils.processResponse(response);
if(jsonResponse != null) {
if(jsonResponse.getBoolean("result")) return true;
}
} catch (UnirestException e) {
e.printStackTrace();
}
return false;
}
示例6: unbanChatMember
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
/**
* Use this method to unban a previously kicked user in a supergroup. The user will not return to the group
* automatically, but will be able to join via link, etc. The bot must be an administrator in the group for
* this to work
*
* @param chatId The ID of the chat that you want to unban the user from
* @param userId The ID of the user that you want to unban from the chat
*
* @return True if the user was unbanned, otherwise False
*/
public boolean unbanChatMember(String chatId, int userId) {
HttpResponse<String> response;
JSONObject jsonResponse;
try {
MultipartBody request = Unirest.post(getBotAPIUrl() + "unbanChatMember")
.field("chat_id", chatId, "application/json; charset=utf8;")
.field("user_id", userId);
response = request.asString();
jsonResponse = Utils.processResponse(response);
if(jsonResponse != null) {
if(jsonResponse.getBoolean("result")) return true;
}
} catch (UnirestException e) {
e.printStackTrace();
}
return false;
}
示例7: getChatMembersCount
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
/**
* Gets the amount of people in the chat
*
* @return The amount of people in the chat
*/
default Integer getChatMembersCount() {
try {
MultipartBody request = Unirest.post(getBotInstance().getBotAPIUrl() + "getChatMembersCount")
.field("chat_id", getId(), "application/json; charset=utf8;");
HttpResponse<String> response = request.asString();
JSONObject jsonResponse = processResponse(response);
if (jsonResponse != null && Utils.checkResponseStatus(jsonResponse)) {
return jsonResponse.getInt("result");
}
} catch (UnirestException e) {
e.printStackTrace();
}
return null;
}
示例8: getChatMember
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
/**
* Gets the ChatMember object for a specific user based on their ID in respect to this chat
*
* @param userID The ID of the user that you want the ChatMember object for
*
* @return The ChatMember object for this user or Null if the request failed
*/
default ChatMember getChatMember(long userID) {
try {
MultipartBody request = Unirest.post(getBotInstance().getBotAPIUrl() + "getChatMember")
.field("chat_id", getId(), "application/json; charset=utf8;")
.field("user_id", userID);
HttpResponse<String> response = request.asString();
JSONObject jsonResponse = processResponse(response);
if (jsonResponse != null && Utils.checkResponseStatus(jsonResponse)) {
return createChatMember(jsonResponse.getJSONObject("result"));
}
} catch (UnirestException e) {
e.printStackTrace();
}
return null;
}
示例9: leaveChat
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
/**
* If you call this method then the bot will leave this Chat if it is currently in it
*
* @return True if leaving the chat succeeded, otherwise False
*/
default boolean leaveChat() {
try {
MultipartBody request = Unirest.post(getBotInstance().getBotAPIUrl() + "leaveChat")
.field("chat_id", getId(), "application/json; charset=utf8;");
HttpResponse<String> response = request.asString();
JSONObject jsonResponse = processResponse(response);
if (jsonResponse != null && Utils.checkResponseStatus(jsonResponse)) {
return jsonResponse.getBoolean("result");
}
} catch (UnirestException e) {
e.printStackTrace();
}
return false;
}
示例10: answerInlineQuery
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
/**
* This allows you to respond to an inline query with an InlineQueryResponse object
*
* @param inlineQueryId The ID of the inline query you are responding to
* @param inlineQueryResponse The InlineQueryResponse object that you want to send to the user
*
* @return True if the response was sent successfully, otherwise False
*/
public boolean answerInlineQuery(String inlineQueryId, InlineQueryResponse inlineQueryResponse) {
if (inlineQueryId != null && inlineQueryResponse != null) {
HttpResponse<String> response;
JSONObject jsonResponse;
try {
MultipartBody requests = Unirest.post(getBotAPIUrl() + "answerInlineQuery")
.field("inline_query_id", inlineQueryId)
.field("results", GSON.toJson(inlineQueryResponse.getResults()))
.field("cache_time", inlineQueryResponse.getCacheTime())
.field("is_personal", inlineQueryResponse.isPersonal())
.field("next_offset", inlineQueryResponse.getNextOffset())
.field("switch_pm_text", inlineQueryResponse.getSwitchPmText())
.field("switch_pm_parameter", inlineQueryResponse.getSwitchPmParameter());
response = requests.asString();
jsonResponse = Utils.processResponse(response);
if (jsonResponse != null) {
if (jsonResponse.getBoolean("result")) return true;
}
} catch (UnirestException e) {
e.printStackTrace();
}
}
return false;
}
示例11: answerCallbackQuery
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
/**
* This allows you to respond to a callback query with some text as a response. This will either show up as an
* alert or as a toast on the telegram client
*
* @param callbackQueryId The ID of the callback query you are responding to
* @param callbackQueryResponse The response that you would like to send in reply to this callback query
*
* @return True if the response was sent successfully, otherwise False
*/
public boolean answerCallbackQuery(String callbackQueryId, CallbackQueryResponse callbackQueryResponse) {
if(callbackQueryId != null && callbackQueryResponse.getText() != null) {
HttpResponse<String> response;
JSONObject jsonResponse;
try {
MultipartBody requests = Unirest.post(getBotAPIUrl() + "answerCallbackQuery")
.field("callback_query_id", callbackQueryId, "application/json; charset=utf8;")
.field("text", callbackQueryResponse.getText(), "application/json; charset=utf8;")
.field("show_alert", callbackQueryResponse.isShowAlert())
.field("cache_time", callbackQueryResponse.getCacheTime())
.field("url", callbackQueryResponse.getURL() != null ? callbackQueryResponse.getURL().toExternalForm() : null, "application/json; charset=utf8;");
response = requests.asString();
jsonResponse = Utils.processResponse(response);
if (jsonResponse != null) {
if (jsonResponse.getBoolean("result")) return true;
}
} catch (UnirestException e) {
e.printStackTrace();
}
}
return false;
}
示例12: setGameScore
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
public GameScoreEditResponse setGameScore(SendableGameScore sendableGameScore) {
HttpResponse<String> response;
JSONObject jsonResponse;
try {
MultipartBody request = Unirest.post(getBotAPIUrl() + "setGameScore")
.field("user_id", sendableGameScore.getUserId(), "application/json; charset=utf8;")
.field("score", sendableGameScore.getScore())
.field("force", sendableGameScore.isForce())
.field("disable_edit_message", sendableGameScore.isDisableEditMessage())
.field("chat_id", sendableGameScore.getChatId())
.field("message_id", sendableGameScore.getMessageId())
.field("inline_message_id", sendableGameScore.getInlineMessageId());
response = request.asString();
jsonResponse = Utils.processResponse(response);
if(jsonResponse != null) {
return GameScoreEditResponseImpl.createGameScoreEditResponse(jsonResponse.getJSONObject("result"), this);
}
} catch (UnirestException e) {
e.printStackTrace();
}
return null;
}
示例13: getGameHighScores
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
public List<GameHighScore> getGameHighScores(GameScoreRequest gameScoreRequest) {
HttpResponse<String> response;
JSONObject jsonResponse;
try {
MultipartBody request = Unirest.post(getBotAPIUrl() + "setGameScore")
.field("user_id", gameScoreRequest.getUserId(), "application/json; charset=utf8;")
.field("chat_id", gameScoreRequest.getChatId())
.field("message_id", gameScoreRequest.getMessageId())
.field("inline_message_id", gameScoreRequest.getInlineMessageId());
response = request.asString();
jsonResponse = Utils.processResponse(response);
if(jsonResponse != null) {
List<GameHighScore> highScores = new LinkedList<>();
for(Object object : jsonResponse.getJSONArray("result")) {
JSONObject jsonObject = (JSONObject) object;
highScores.add(GameHighScoreImpl.createGameHighscore(jsonObject));
}
return highScores;
}
} catch (UnirestException e) {
e.printStackTrace();
}
return null;
}
示例14: uploadTwo
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
@Test
public void uploadTwo() throws IOException {
// Create temp file.
File temp1 = File.createTempFile("myimage", ".image");
Files.write("Hello world1111", temp1, Charsets.UTF_8);
File temp2 = File.createTempFile("myimage", ".image");
Files.write("Hello world2222", temp2, Charsets.UTF_8);
File temp3 = File.createTempFile("myimage", ".image");
Files.write("Hello 33333", temp3, Charsets.UTF_8);
try {
MultipartBody field = Unirest.post("http://localhost:4849/upload/images")
.field("name", "bingoo.txt")
.field("files", temp1)
.field("files", temp2)
.field("files", temp3);
HttpResponse<String> file = field.asString();
System.out.println(file.getStatus());
} catch (Exception e) {
e.printStackTrace();
}
temp1.delete();
temp2.delete();
}
示例15: uploadComponent
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
public static boolean uploadComponent(String url, ComponentModel c, IProject project) {
try {
String name = c.getComponent().getName();
File temp = File.createTempFile("bento." + name, ".zip");
/*
java.util.zip.ZipOutputStream zos = new java.util.zip.ZipOutputStream(new FileOutputStream(temp));
ZipEntry entry = new ZipEntry("metamodels");
zos.a
zos.putNextEntry(entry);
*/
temp.delete();
/*
ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(temp));
ZipParameters parameters = new ZipParameters();
// set compression method to store compression
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
// Set the compression level. This value has to be in between 0 to 9
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
outputStream.putNextEntry(project.getFolder("META-INF").getLocation().toFile(), parameters);
outputStream.closeEntry();
outputStream.finish();
outputStream.close();
*/
ZipFile zipFile = new ZipFile(temp);
ZipParameters parameters = new ZipParameters();
// set compression method to store compression
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
// Set the compression level. This value has to be in between 0 to 9
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
ArrayList<File> filesToAdd = new ArrayList<File>();
// To add something, that seems to be compulsory!
filesToAdd.add(project.getFile(".project").getLocation().toFile());
zipFile.createZipFile(filesToAdd, parameters);
// Assume certain structure for the moment!
zipFile.addFolder(project.getFolder("META-INF").getLocation().toPortableString(), parameters);
zipFile.addFolder(project.getFolder("metamodels").getLocation().toPortableString(), parameters);
zipFile.addFolder(project.getFolder("transformation").getLocation().toPortableString(), parameters);
if ( project.getFolder("bindings").exists() )
zipFile.addFolder(project.getFolder("bindings").getLocation().toPortableString(), parameters);
temp.deleteOnExit();
MultipartBody mpart = Unirest.put(url + "/component/" + name).
field("zipped", temp).
field("metadata", asJson(c));
HttpResponse<String> x = mpart.asString();
System.out.println(x.getStatus());
} catch (IOException | ZipException | UnirestException e) {
// showError(e.getMessage());
e.printStackTrace();
return false;
}
return true;
}