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


Java MultipartBody类代码示例

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


MultipartBody类属于com.mashape.unirest.request.body包,在下文中一共展示了MultipartBody类的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;
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:29,代码来源:TelegramBot.java

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

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

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

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

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

示例7: 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

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

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

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

示例11: fields

import com.mashape.unirest.request.body.MultipartBody; //导入依赖的package包/类
private BaseRequest fields(
        HttpRequestWithBody post, Map<String, Object> requestParams) {
    MultipartBody field = null;

    for (val entry : requestParams.entrySet()) {
        val value = entry.getValue();
        boolean isFileCollection = false;
        if (value instanceof Collection) {
            isFileCollection = true;
            for (Object o : (Collection) value) {
                if (o instanceof File || o instanceof MultipartFile)
                    field = fieldFileOrElse(post, field, entry, o);
                else {
                    isFileCollection = false;
                    break;
                }
            }
        }

        if (!isFileCollection) {
            field = fieldFileOrElse(post, field, entry, value);
        }
    }

    return field == null ? post : field;
}
 
开发者ID:bingoohuang,项目名称:spring-rest-client,代码行数:27,代码来源:RestReq.java

示例12: 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

示例13: 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

示例14: 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

示例15: sendFile

import com.mashape.unirest.request.body.MultipartBody; //导入依赖的package包/类
@Override
public Future<Message> sendFile(final File file, final String comment, FutureCallback<Message> callback) {
    final MessageReceiver receiver = this;
    ListenableFuture<Message> future =
            api.getThreadPool().getListeningExecutorService().submit(new Callable<Message>() {
                @Override
                public Message call() throws Exception {
                    logger.debug("Trying to send a file to user {} (name: {}, comment: {})",
                            ImplUser.this, file.getName(), comment);
                    api.checkRateLimit(null, RateLimitType.PRIVATE_MESSAGE, null, null);
                    MultipartBody body = Unirest
                            .post("https://discordapp.com/api/v6/channels/" + getUserChannelIdBlocking() + "/messages")
                            .header("authorization", api.getToken())
                            .field("file", file);
                    if (comment != null) {
                        body.field("content", comment);
                    }
                    HttpResponse<JsonNode> response = body.asJson();
                    api.checkResponse(response);
                    api.checkRateLimit(response, RateLimitType.PRIVATE_MESSAGE, null, null);
                    logger.debug("Sent a file to user {} (name: {}, comment: {})",
                            ImplUser.this, file.getName(), comment);
                    return new ImplMessage(response.getBody().getObject(), api, receiver);
                }
            });
    if (callback != null) {
        Futures.addCallback(future, callback);
    }
    return future;
}
 
开发者ID:BtoBastian,项目名称:Javacord,代码行数:31,代码来源:ImplUser.java


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