From ce05d68e81e45f0ebc22af83a07d2db9aac3b772 Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 7 Nov 2018 12:34:50 +0200 Subject: [PATCH] Fix wrong class and method names --- .../DeleteChatStickerSet.java | 91 +++++++++++++++++++ .../DeleteStickerSetName.java | 2 + .../GetChatMemberCount.java | 2 + .../GetChatMembersCount.java | 78 ++++++++++++++++ .../EditMessageLiveLocation.java | 35 +++++-- .../test/BotApiMethodHelperFactory.java | 6 +- .../telegrambots/test/TestRestApi.java | 6 +- 7 files changed, 206 insertions(+), 14 deletions(-) create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteChatStickerSet.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMembersCount.java diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteChatStickerSet.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteChatStickerSet.java new file mode 100644 index 00000000..609678d8 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteChatStickerSet.java @@ -0,0 +1,91 @@ +package org.telegram.telegrambots.meta.api.methods.groupadministration; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; +import java.io.IOException; +import java.util.Objects; +import org.telegram.telegrambots.meta.api.methods.BotApiMethod; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Ruben Bermudez + * @version 3.4 + * Use this method to delete a group sticker set from a supergroup. + * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + * Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. + * Returns True on success. + */ +public class DeleteChatStickerSet extends BotApiMethod { + public static final String PATH = "deleteChatStickerSet"; + + private static final String CHATID_FIELD = "chat_id"; + + @JsonProperty(CHATID_FIELD) + private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) + + public DeleteChatStickerSet() { + super(); + } + + public DeleteChatStickerSet(String chatId) { + super(); + this.chatId = checkNotNull(chatId); + } + + public DeleteChatStickerSet(Long chatId) { + super(); + this.chatId = checkNotNull(chatId).toString(); + } + + public String getChatId() { + return chatId; + } + + public DeleteChatStickerSet setChatId(String chatId) { + this.chatId = chatId; + return this; + } + + public DeleteChatStickerSet setChatId(Long chatId) { + Objects.requireNonNull(chatId); + this.chatId = chatId.toString(); + return this; + } + + @Override + public String getMethod() { + return PATH; + } + + @Override + public Boolean deserializeResponse(String answer) throws TelegramApiRequestException { + try { + ApiResponse result = OBJECT_MAPPER.readValue(answer, + new TypeReference>(){}); + if (result.getOk()) { + return result.getResult(); + } else { + throw new TelegramApiRequestException("Error deleting chat sticker set", result); + } + } catch (IOException e) { + throw new TelegramApiRequestException("Unable to deserialize response", e); + } + } + + @Override + public void validate() throws TelegramApiValidationException { + if (chatId == null || chatId.isEmpty()) { + throw new TelegramApiValidationException("ChatId can't be empty", this); + } + } + + @Override + public String toString() { + return "DeleteChatStickerSet{" + + "chatId='" + chatId + '\'' + + '}'; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteStickerSetName.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteStickerSetName.java index 4bda56ad..dcf72224 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteStickerSetName.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/DeleteStickerSetName.java @@ -19,7 +19,9 @@ import static com.google.common.base.Preconditions.checkNotNull; * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. * Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. * Returns True on success. + * @deprecated Replaced by {@link DeleteChatStickerSet} */ +@Deprecated public class DeleteStickerSetName extends BotApiMethod { public static final String PATH = "deleteChatStickerSet"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMemberCount.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMemberCount.java index d7691365..39fbb39f 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMemberCount.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMemberCount.java @@ -16,7 +16,9 @@ import java.util.Objects; * @version 1.0 * @brief Use this method to get the number of members in a chat. Returns Int on success. * @date 20 of May of 2016 + * @deprecated Replaced by {@link GetChatMembersCount} */ +@Deprecated public class GetChatMemberCount extends BotApiMethod { public static final String PATH = "getChatMembersCount"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMembersCount.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMembersCount.java new file mode 100644 index 00000000..be757c73 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/GetChatMembersCount.java @@ -0,0 +1,78 @@ +package org.telegram.telegrambots.meta.api.methods.groupadministration; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; +import java.io.IOException; +import java.util.Objects; +import org.telegram.telegrambots.meta.api.methods.BotApiMethod; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method to get the number of members in a chat. Returns Int on success. + * @date 20 of May of 2016 + */ +public class GetChatMembersCount extends BotApiMethod { + public static final String PATH = "getChatMembersCount"; + + private static final String CHATID_FIELD = "chat_id"; + + @JsonProperty(CHATID_FIELD) + private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) + + public GetChatMembersCount() { + super(); + } + + public String getChatId() { + return chatId; + } + + public GetChatMembersCount setChatId(String chatId) { + this.chatId = chatId; + return this; + } + + public GetChatMembersCount setChatId(Long chatId) { + Objects.requireNonNull(chatId); + this.chatId = chatId.toString(); + return this; + } + + @Override + public String getMethod() { + return PATH; + } + + @Override + public Integer deserializeResponse(String answer) throws TelegramApiRequestException { + try { + ApiResponse result = OBJECT_MAPPER.readValue(answer, + new TypeReference>(){}); + if (result.getOk()) { + return result.getResult(); + } else { + throw new TelegramApiRequestException("Error getting chat members count", result); + } + } catch (IOException e) { + throw new TelegramApiRequestException("Unable to deserialize response", e); + } + } + + @Override + public void validate() throws TelegramApiValidationException { + if (chatId == null || chatId.isEmpty()) { + throw new TelegramApiValidationException("ChatId can't be empty", this); + } + } + + @Override + public String toString() { + return "GetChatMembersCount{" + + "chatId='" + chatId + '\'' + + '}'; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java index df23324e..bb5c391c 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java @@ -1,5 +1,6 @@ package org.telegram.telegrambots.meta.api.methods.updatingmessages; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; @@ -50,7 +51,7 @@ public class EditMessageLiveLocation extends BotApiMethod { @JsonProperty(LATITUDE_FIELD) private Float latitude; ///< Latitude of new location @JsonProperty(LONGITUDE_FIELD) - private Float longitud; ///< Longitude of new location + private Float longitude; ///< Longitude of new location @JsonProperty(REPLYMARKUP_FIELD) private InlineKeyboardMarkup replyMarkup; ///< Optional. A JSON-serialized object for an inline keyboard. @@ -109,13 +110,31 @@ public class EditMessageLiveLocation extends BotApiMethod { return this; } + /** + * @deprecated Replaced by {@link #getLongitude()} + */ + @Deprecated + @JsonIgnore public Float getLongitud() { - return longitud; + return longitude; } - public EditMessageLiveLocation setLongitud(Float longitud) { - Objects.requireNonNull(longitud); - this.longitud = longitud; + public Float getLongitude() { + return longitude; + } + + /** + * @deprecated Replaced by {@link #setLongitude(Float)} + */ + @Deprecated + @JsonIgnore + public EditMessageLiveLocation setLongitud(Float longitude) { + return setLongitude(longitude); + } + + public EditMessageLiveLocation setLongitude(Float longitude) { + Objects.requireNonNull(longitude); + this.longitude = longitude; return this; } @@ -170,8 +189,8 @@ public class EditMessageLiveLocation extends BotApiMethod { if (latitude == null) { throw new TelegramApiValidationException("Latitude parameter can't be empty", this); } - if (longitud == null) { - throw new TelegramApiValidationException("Longitud parameter can't be empty", this); + if (longitude == null) { + throw new TelegramApiValidationException("Longitude parameter can't be empty", this); } if (replyMarkup != null) { replyMarkup.validate(); @@ -185,7 +204,7 @@ public class EditMessageLiveLocation extends BotApiMethod { ", messageId=" + messageId + ", inlineMessageId='" + inlineMessageId + '\'' + ", latitude=" + latitude + - ", longitud=" + longitud + + ", longitude=" + longitude + ", replyMarkup=" + replyMarkup + '}'; } diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java index 7cd9c3f2..2b43acaa 100644 --- a/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java +++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java @@ -14,7 +14,7 @@ import org.telegram.telegrambots.meta.api.methods.games.SetGameScore; import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChat; import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators; import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMember; -import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMemberCount; +import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMembersCount; import org.telegram.telegrambots.meta.api.methods.groupadministration.KickChatMember; import org.telegram.telegrambots.meta.api.methods.groupadministration.LeaveChat; import org.telegram.telegrambots.meta.api.methods.groupadministration.UnbanChatMember; @@ -123,8 +123,8 @@ public final class BotApiMethodHelperFactory { .setUserId(98765); } - public static BotApiMethod getChatMemberCount() { - return new GetChatMemberCount() + public static BotApiMethod getChatMembersCount() { + return new GetChatMembersCount() .setChatId("12345"); } diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java index 15123914..09228816 100644 --- a/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java +++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/TestRestApi.java @@ -196,14 +196,14 @@ public class TestRestApi extends JerseyTest { } @Test - public void TestGetChatMemberCount() { - webhookBot.setReturnValue(BotApiMethodHelperFactory.getChatMemberCount()); + public void TestGetChatMembersCount() { + webhookBot.setReturnValue(BotApiMethodHelperFactory.getChatMembersCount()); Entity entity = Entity.json(getUpdate()); BotApiMethod result = target("callback/testbot") .request(MediaType.APPLICATION_JSON) - .post(entity, GetChatMemberCount.class); + .post(entity, GetChatMembersCount.class); assertEquals("{\"chat_id\":\"12345\",\"method\":\"getChatMembersCount\"}", map(result)); }