Clear CallbackGame

This commit is contained in:
Rubenlagus 2016-09-30 14:55:08 +02:00
parent 8fdad42297
commit 238125879a
3 changed files with 13 additions and 56 deletions

View File

@ -6,7 +6,7 @@
<packaging>jar</packaging>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>2.4.0.BETA3-SNAPSHOT</version>
<version>2.4.0.BETA4-SNAPSHOT</version>
<name>Telegram Bots</name>
<url>https://github.com/rubenlagus/TelegramBots</url>

View File

@ -17,80 +17,42 @@
package org.telegram.telegrambots.api.objects.games;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import org.json.JSONObject;
import org.telegram.telegrambots.api.interfaces.IBotApiObject;
import org.telegram.telegrambots.api.interfaces.Validable;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.io.IOException;
/**
* @author Ruben Bermudez
* @version 2.4
* @brief This object contains information about a game that will be returned as a response to a callback query.
* @brief This object contains information about a game that will be returned as a response to a
* callback query. It has no fields, use BotFather to setup your game,
* its short name will actt as an identifier.
* @date 16 of September of 2016
*/
public class CallbackGame implements IBotApiObject, Validable {
private static final String TITLE_FIELD = "title";
private static final String ID_FIELD = "game_id";
private static final String START_PARAMETER_FIELD = "start_parameter";
@JsonProperty(TITLE_FIELD)
private String title; ///< Game title, aim at 128 characters or lower
@JsonProperty(ID_FIELD)
private Integer gameId; ///< Game identifier
@JsonProperty(START_PARAMETER_FIELD)
private String startParameter; ///< Start parameter for the bot URL when users share the game with others. See deep linking for more info.
public CallbackGame() {
super();
}
public class CallbackGame implements IBotApiObject {
private final JSONObject content;
public CallbackGame(JSONObject object) {
super();
title = object.getString(TITLE_FIELD);
gameId = object.getInt(ID_FIELD);
startParameter = object.getString(START_PARAMETER_FIELD);
content = object;
}
public String getTitle() {
return title;
public JSONObject getContent() {
return content;
}
public Integer getGameId() {
return gameId;
}
public String getStartParameter() {
return startParameter;
}
@Override
public void validate() throws TelegramApiValidationException {
if (title == null || title.isEmpty()) {
throw new TelegramApiValidationException("Title parameter can't be empty", this);
}
if (gameId == null) {
throw new TelegramApiValidationException("Id parameter can't be empty", this);
}
if (startParameter == null || startParameter.isEmpty()) {
throw new TelegramApiValidationException("StartParameter parameter can't be empty", this);
}
public String getContentText() {
return content.toString();
}
@Override
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeStartObject();
gen.writeStringField(TITLE_FIELD, title);
gen.writeNumberField(ID_FIELD, gameId);
gen.writeStringField(START_PARAMETER_FIELD, startParameter);
gen.writeEndObject();
gen.flush();
gen.writeObject(content);
}
@Override
@ -101,9 +63,7 @@ public class CallbackGame implements IBotApiObject, Validable {
@Override
public String toString() {
return "CallbackGame{" +
"title='" + title + '\'' +
", gameId=" + gameId +
", startParameter='" + startParameter + '\'' +
"content=" + content +
'}';
}
}

View File

@ -147,9 +147,6 @@ public class InlineKeyboardButton implements IBotApiObject, IToJson, Validable {
if (text == null || text.isEmpty()) {
throw new TelegramApiValidationException("Text parameter can't be empty", this);
}
if (callbackGame != null) {
callbackGame.validate();
}
}
@Override