From 0189124080fd8f0c3d507cdc7779252b296c3d6e Mon Sep 17 00:00:00 2001 From: EXH3Y Date: Fri, 28 Oct 2016 15:10:15 +0200 Subject: [PATCH] Include all getter methods in TelegramChat --- .../java/exh3y/telebot/data/TelegramChat.java | 90 ++++++++++++++++--- 1 file changed, 80 insertions(+), 10 deletions(-) diff --git a/src/main/java/exh3y/telebot/data/TelegramChat.java b/src/main/java/exh3y/telebot/data/TelegramChat.java index 0370077..098eba1 100644 --- a/src/main/java/exh3y/telebot/data/TelegramChat.java +++ b/src/main/java/exh3y/telebot/data/TelegramChat.java @@ -1,5 +1,6 @@ package exh3y.telebot.data; +import org.json.JSONException; import org.json.JSONObject; import exh3y.telebot.data.enums.ETelegramChatType; @@ -7,7 +8,7 @@ public class TelegramChat extends JSONObject { private ETelegramChatType type; - + /** * Creates a new TelegramChat object from a given JSON-String * @@ -17,10 +18,10 @@ public class TelegramChat extends JSONObject { public TelegramChat(JSONObject chat) { super(chat.toString()); - + this.type = ETelegramChatType.getEnumByName(chat.getString("type")); } - + /** * Returns the chat's type * @@ -28,10 +29,10 @@ public TelegramChat(JSONObject chat) { * @since 0.0.6 */ public ETelegramChatType getType() { - + return type; } - + /** * Returns the chat's id * @@ -39,10 +40,10 @@ public ETelegramChatType getType() { * @since 0.0.6 */ public int getId() { - + return this.getInt("id"); } - + /** * Returns the chat's title * @@ -50,8 +51,77 @@ public int getId() { * @since 0.0.6 */ public String getTitle() { - - return this.getString("title"); + + try { + + return this.getString("title"); + } catch (JSONException e) { + return ""; + } + } + + /** + * Returns the user's username + * + * @return The user's username + * @since 0.0.6 + */ + public String getUsername() { + + try { + + return this.getString("username"); + } catch (JSONException e) { + return ""; + } + } + + /** + * Returns the user's first name + * + * @return The user's first name + * @since 0.0.6 + */ + public String getFirstName() { + + try { + + return this.getString("first_name"); + } catch (JSONException e) { + return ""; + } } - + + /** + * Returns the user's last name + * + * @return The user's last name + * @since 0.0.6 + */ + public String getLastName() { + + try { + + return this.getString("last_name"); + } catch (JSONException e) { + return ""; + } + } + + /** + * Are all users administrators? + * + * @return True if all users are administrators, false otherwise + * @since 0.0.6 + */ + public boolean getAllUsersAreAdmins() { + + try { + + return this.getBoolean("all_members_are_administrators"); + } catch (JSONException e) { + return false; + } + } + }