当前位置: 首页>>代码示例>>Java>>正文


Java MultipartBody.field方法代码示例

本文整理汇总了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;
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:25,代码来源:TelegramBot.java

示例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;
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:23,代码来源:TelegramBot.java

示例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;
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:22,代码来源:TelegramBot.java

示例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;
        }
    }
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:33,代码来源:Utils.java

示例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;
}
 
开发者ID:bingoohuang,项目名称:spring-rest-client,代码行数:19,代码来源:RestReq.java

示例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);
    }
}
 
开发者ID:enil,项目名称:gitlab-api-plugin,代码行数:26,代码来源:GitLabApiClient.java

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

示例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);
    }
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:18,代码来源:Utils.java

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

示例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());
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:11,代码来源:Utils.java


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