本文整理汇总了Java中com.mashape.unirest.request.body.MultipartBody.field方法的典型用法代码示例。如果您正苦于以下问题:Java MultipartBody.field方法的具体用法?Java MultipartBody.field怎么用?Java MultipartBody.field使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mashape.unirest.request.body.MultipartBody
的用法示例。
在下文中一共展示了MultipartBody.field方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: processReplyContent
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
/**
* This does generic processing of ReplyingOptions objects when sending a request to the API
*
* @param multipartBody The MultipartBody that the ReplyingOptions content should be appended to
* @param replyingOptions The ReplyingOptions that were used in this request
*/
public static void processReplyContent(MultipartBody multipartBody, ReplyingOptions replyingOptions) {
if (replyingOptions.getReplyTo() != 0)
multipartBody.field("reply_to_message_id", String.valueOf(replyingOptions.getReplyTo()), "application/json; charset=utf8;");
if (replyingOptions.getReplyMarkup() != null) {
switch (replyingOptions.getReplyMarkup().getType()) {
case FORCE_REPLY:
multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ForceReply.class), "application/json; charset=utf8;");
break;
case KEYBOARD_HIDE:
multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ReplyKeyboardHide.class), "application/json; charset=utf8;");
break;
case KEYBOARD_REMOVE:
multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ReplyKeyboardRemove.class), "application/json; charset=utf8;");
break;
case KEYBOARD_MARKUP:
multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ReplyKeyboardMarkup.class), "application/json; charset=utf8;");
break;
case INLINE_KEYBOARD_MARKUP:
multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), InlineKeyboardMarkup.class), "application/json; charset=utf8;");
break;
}
}
}
示例5: fieldFileOrElse
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
private MultipartBody fieldFileOrElse(HttpRequestWithBody post,
MultipartBody field,
Map.Entry<String, Object> entry,
Object value) {
if (value instanceof File) {
if (field != null) field.field(entry.getKey(), (File) value);
else field = post.field(entry.getKey(), (File) value);
} else if (value instanceof MultipartFile) {
if (field != null)
field.field(entry.getKey(), (MultipartFile) value);
else field = post.field(entry.getKey(), (MultipartFile) value);
} else {
if (field != null) field.field(entry.getKey(), value);
else field = post.field(entry.getKey(), value);
}
return field;
}
示例6: post
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
/**
* Makes a POST request to the API.
*
* @param path the path relative to the API
* @param fields the fields for the request
* @param includePrivateToken if the private token should be added to the fields
* @return an HTTP response containing a JSON body
* @throws GitLabApiException if the request failed
*/
protected HttpResponse<JsonNode> post(String path, Map<String, Object> fields, boolean includePrivateToken)
throws GitLabApiException {
HttpRequestWithBody request = Unirest.post(getApiUrl() + path);
final MultipartBody body = request.fields(fields);
if (includePrivateToken) {
body.field("private_token", privateToken);
}
try {
// make request
return processPostResponse(request.asJson());
} catch (UnirestException e) {
throw new ApiConnectionFailureException("Could not connect to API", e);
}
}
示例7: fields
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
public MultipartBody fields(Map<String, Object> parameters) {
MultipartBody body = new MultipartBody(this);
if (parameters != null) {
for(Entry<String, Object> param : parameters.entrySet()) {
Object value = param.getValue();
if(null == value)
continue;
if (value instanceof File) {
body.field(param.getKey(), (File)value);
} else {
body.field(param.getKey(), value.toString());
}
}
}
this.body = body;
return body;
}
示例8: processInputFileField
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
/**
* Adds an input file to a request, with the given field name.
*
* @param request The request to be added to.
* @param fieldName The name of the field.
* @param inputFile The input file.
*/
public static void processInputFileField(MultipartBody request, String fieldName, InputFile inputFile) {
String fileId = inputFile.getFileID();
if (fileId != null) {
request.field(fieldName, fileId, false);
} else if (inputFile.getInputStream() != null) {
request.field(fieldName, new InputStreamBody(inputFile.getInputStream(), inputFile.getFileName()), true);
} else { // assume file is not null (this is existing behaviour as of 1.5.1)
request.field(fieldName, new FileContainer(inputFile), true);
}
}
示例9: field
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
public MultipartBody field(String name, Object value) {
MultipartBody body = new MultipartBody(this);
if(null != value)
body.field(name, value.toString());
this.body = body;
return body;
}
示例10: processNotificationContent
import com.mashape.unirest.request.body.MultipartBody; //导入方法依赖的package包/类
/**
* This does generic processing of NotificationOptions objects when sending a request to the API
*
* @param multipartBody The MultipartBody that the NotificationOptions content should be appended to
* @param notificationOptions The NotificationOptions that were used in this request
*/
public static void processNotificationContent(MultipartBody multipartBody, NotificationOptions notificationOptions) {
multipartBody.field("disable_notification", notificationOptions.isDisableNotification());
}