From 1dceb1b4e9ee7a53777b0db5e39fd23c2f669554 Mon Sep 17 00:00:00 2001 From: beanbeanjuice Date: Mon, 27 May 2024 23:06:03 -0700 Subject: [PATCH] The Optional Update --- pom.xml | 30 +- .../com/beanbeanjuice/cafeapi/CafeAPI.java | 32 +- .../beanbeanjuice/cafeapi/api/CafeAPI.java | 4 +- .../beancoins/users/DonationUsers.java | 28 +- .../cafeapi/cafebot/birthdays/Birthday.java | 18 +- .../cafebot/birthdays/BirthdayMonth.java | 14 +- .../cafeapi/cafebot/birthdays/Birthdays.java | 51 +-- .../cafeapi/cafebot/cafe/CafeType.java | 5 +- .../cafeapi/cafebot/cafe/CafeUser.java | 29 +- .../cafeapi/cafebot/cafe/CafeUsers.java | 34 +- .../cafeapi/cafebot/codes/GeneratedCodes.java | 29 +- .../cafebot/counting/CountingInformation.java | 17 +- .../counting/CountingInformations.java | 57 ++- .../counting/GlobalCountingInformation.java | 183 ++++++++ .../cafeapi/cafebot/goodbyes/Goodbyes.java | 64 +-- .../cafebot/goodbyes/GuildGoodbye.java | 27 +- .../guilds/GlobalGuildInformation.java | 208 +++++++++ .../cafebot/guilds/GuildInformation.java | 36 +- .../cafebot/guilds/GuildInformationType.java | 5 +- .../cafebot/guilds/GuildInformations.java | 54 +-- .../cafebot/interactions/InteractionType.java | 108 ++--- .../cafebot/interactions/Interactions.java | 149 +++---- .../pictures/InteractionPictures.java | 29 +- .../interactions/users/Interaction.java | 413 +++--------------- .../minigames/winstreaks/MinigameType.java | 5 +- .../minigames/winstreaks/WinStreak.java | 23 +- .../minigames/winstreaks/WinStreaks.java | 36 +- .../cafeapi/cafebot/polls/Poll.java | 23 +- .../cafeapi/cafebot/polls/Polls.java | 31 +- .../cafeapi/cafebot/raffles/Raffle.java | 33 +- .../cafeapi/cafebot/raffles/Raffles.java | 31 +- .../cafebot/twitches/GuildTwitches.java | 24 +- .../cafeapi/cafebot/version/Versions.java | 14 +- .../cafebot/voicebinds/VoiceChannelBind.java | 23 +- .../cafebot/voicebinds/VoiceChannelBinds.java | 24 +- .../cafebot/welcomes/GuildWelcome.java | 37 +- .../cafeapi/cafebot/welcomes/Welcomes.java | 64 +-- .../cafeapi/cafebot/words/Word.java | 23 +- .../cafeapi/cafebot/words/Words.java | 21 +- .../exception/api/AuthorizationException.java | 3 +- .../cafeapi/exception/api/CafeException.java | 37 +- .../exception/api/ConflictException.java | 3 +- .../exception/api/NotFoundException.java | 3 +- .../exception/api/ResponseException.java | 3 +- .../exception/api/TeaPotException.java | 5 +- .../api/UndefinedVariableException.java | 3 +- .../program/BirthdayOverfillException.java | 3 +- .../program/InvalidTimeZoneException.java | 4 +- .../cafeapi/generic/CafeGeneric.java | 33 +- .../cafeapi/requests/Request.java | 24 +- .../cafeapi/requests/RequestBuilder.java | 83 +--- .../cafeapi/requests/RequestLocation.java | 16 +- .../cafeapi/requests/RequestRoute.java | 13 +- .../com/beanbeanjuice/cafeapi/user/User.java | 36 +- .../com/beanbeanjuice/cafeapi/user/Users.java | 28 +- .../beanbeanjuice/cafeapi/utility/Time.java | 38 +- .../cafeapi/beta/CafeUserTest.java | 8 +- .../cafeapi/beta/DonationUsersTest.java | 4 +- .../cafeapi/beta/GuildGoodbyeTest.java | 8 +- .../cafeapi/beta/GuildWelcomeTest.java | 8 +- .../cafeapi/beta/InteractionPictureTest.java | 10 +- .../beanbeanjuice/cafeapi/beta/PollTest.java | 2 +- .../cafeapi/beta/RaffleTest.java | 2 +- .../cafeapi/utility/TimeTest.java | 2 +- 64 files changed, 1038 insertions(+), 1377 deletions(-) create mode 100644 src/main/java/com/beanbeanjuice/cafeapi/cafebot/counting/GlobalCountingInformation.java create mode 100644 src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GlobalGuildInformation.java diff --git a/pom.xml b/pom.xml index 79537c6..5c069bf 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ 16 UTF-8 UTF-8 - 1.4.0 + 1.5.0 @@ -162,7 +162,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.1.0 + 3.2.4 maven-plugin @@ -170,39 +170,31 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.13 - - - - - org.jetbrains - annotations - 23.0.0 - compile + 1.7.0 com.fasterxml.jackson.core jackson-core - 2.15.2 + 2.17.1 com.fasterxml.jackson.core jackson-databind - 2.15.2 + 2.17.1 com.fasterxml.jackson.core jackson-annotations - 2.15.2 + 2.17.1 org.apache.httpcomponents.client5 httpclient5 - 5.2.1 + 5.3.1 @@ -222,9 +214,15 @@ org.junit.jupiter junit-jupiter - 5.9.0 + 5.10.2 test + + org.projectlombok + lombok + 1.18.30 + provided + diff --git a/src/main/java/com/beanbeanjuice/cafeapi/CafeAPI.java b/src/main/java/com/beanbeanjuice/cafeapi/CafeAPI.java index 513c7ae..391f70d 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/CafeAPI.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/CafeAPI.java @@ -8,8 +8,8 @@ import com.beanbeanjuice.cafeapi.cafebot.birthdays.Birthdays; import com.beanbeanjuice.cafeapi.cafebot.cafe.CafeUsers; import com.beanbeanjuice.cafeapi.cafebot.codes.GeneratedCodes; -import com.beanbeanjuice.cafeapi.cafebot.counting.CountingInformations; -import com.beanbeanjuice.cafeapi.cafebot.guilds.GuildInformations; +import com.beanbeanjuice.cafeapi.cafebot.counting.GlobalCountingInformation; +import com.beanbeanjuice.cafeapi.cafebot.guilds.GlobalGuildInformation; import com.beanbeanjuice.cafeapi.cafebot.interactions.Interactions; import com.beanbeanjuice.cafeapi.cafebot.interactions.pictures.InteractionPictures; import com.beanbeanjuice.cafeapi.cafebot.minigames.winstreaks.WinStreaks; @@ -20,7 +20,7 @@ import com.beanbeanjuice.cafeapi.cafebot.voicebinds.VoiceChannelBinds; import com.beanbeanjuice.cafeapi.cafebot.welcomes.Welcomes; import com.beanbeanjuice.cafeapi.cafebot.words.Words; -import org.jetbrains.annotations.NotNull; +import lombok.Getter; import java.util.TimeZone; @@ -28,7 +28,7 @@ public class CafeAPI { private String apiKey; private String userAgent; - private static RequestLocation requestLocation; + @Getter private static RequestLocation requestLocation; public KawaiiAPI KAWAII_API; public Users USER; @@ -42,10 +42,10 @@ public class CafeAPI { public WinStreaks WIN_STREAK; public Interactions INTERACTION; public GuildTwitches TWITCH; - public GuildInformations GUILD; + public GlobalGuildInformation GUILD; public GeneratedCodes GENERATED_CODE; public Versions VERSION; - public CountingInformations COUNTING_INFORMATION; + public GlobalCountingInformation COUNTING_INFORMATION; public CafeUsers CAFE_USER; public Birthdays BIRTHDAY; public DonationUsers DONATION_USER; @@ -57,7 +57,7 @@ public class CafeAPI { * @param password The {@link String password}. * @param requestLocation The {@link RequestLocation requestLocation}. */ - public CafeAPI(@NotNull String username, @NotNull String password, @NotNull RequestLocation requestLocation) { + public CafeAPI(String username, String password, RequestLocation requestLocation) { TimeZone.setDefault(TimeZone.getTimeZone("UTC")); this.userAgent = username; CafeAPI.requestLocation = requestLocation; @@ -80,10 +80,10 @@ public CafeAPI(@NotNull String username, @NotNull String password, @NotNull Requ WIN_STREAK = new WinStreaks(apiKey); INTERACTION = new Interactions(apiKey); TWITCH = new GuildTwitches(apiKey); - GUILD = new GuildInformations(apiKey); + GUILD = new GlobalGuildInformation(apiKey); GENERATED_CODE = new GeneratedCodes(apiKey); VERSION = new Versions(apiKey); - COUNTING_INFORMATION = new CountingInformations(apiKey); + COUNTING_INFORMATION = new GlobalCountingInformation(apiKey); CAFE_USER = new CafeUsers(apiKey); BIRTHDAY = new Birthdays(apiKey); DONATION_USER = new DonationUsers(apiKey); @@ -92,28 +92,20 @@ public CafeAPI(@NotNull String username, @NotNull String password, @NotNull Requ KAWAII_API = new KawaiiAPI("anonymous"); } - /** - * @return The {@link RequestLocation} for the {@link CafeAPI}. - */ - @NotNull - public static RequestLocation getRequestLocation() { - return requestLocation; - } - /** * Sets the {@link KawaiiAPI} token. * @param token The {@link String} token for the {@link KawaiiAPI}. */ - public void setKawaiiAPI(@NotNull String token) { + public void setKawaiiAPI(String token) { KAWAII_API = new KawaiiAPI(token); } - private String getToken(@NotNull String username, @NotNull String password) { + private String getToken(String username, String password) { Request request = new RequestBuilder(RequestRoute.CAFE, RequestType.POST) .setRoute("/user/login") .addParameter("username", username) .addParameter("password", password) - .build(); + .build().orElseThrow(); return request.getData().get("api_key").textValue(); } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/api/CafeAPI.java b/src/main/java/com/beanbeanjuice/cafeapi/api/CafeAPI.java index c5328c1..78ae878 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/api/CafeAPI.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/api/CafeAPI.java @@ -1,7 +1,5 @@ package com.beanbeanjuice.cafeapi.api; -import org.jetbrains.annotations.NotNull; - /** * An interface used for {@link com.beanbeanjuice.cafeapi.CafeAPI CafeAPI} Requests. * @@ -13,6 +11,6 @@ public interface CafeAPI { * Updates the {@link String apiKey}. * @param apiKey The new {@link String apiKey}. */ - void updateAPIKey(@NotNull String apiKey); + void updateAPIKey(String apiKey); } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/beancoins/users/DonationUsers.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/beancoins/users/DonationUsers.java index 5183f00..8fda43e 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/beancoins/users/DonationUsers.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/beancoins/users/DonationUsers.java @@ -8,11 +8,10 @@ import com.beanbeanjuice.cafeapi.requests.RequestRoute; import com.beanbeanjuice.cafeapi.requests.RequestType; import com.fasterxml.jackson.databind.JsonNode; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.sql.Timestamp; import java.util.HashMap; +import java.util.Optional; /** * A class used to make {@link DonationUsers} requests to the {@link CafeAPI CafeAPI}. @@ -27,7 +26,7 @@ public class DonationUsers implements com.beanbeanjuice.cafeapi.api.CafeAPI { * Creates a new {@link DonationUsers} object. * @param apiKey The {@link String apiKey} used for authorization. */ - public DonationUsers(@NotNull String apiKey) { + public DonationUsers(String apiKey) { this.apiKey = apiKey; } @@ -37,7 +36,6 @@ public DonationUsers(@NotNull String apiKey) { * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull public HashMap getAllUserDonationTimes() throws AuthorizationException, ResponseException { HashMap donationUsers = new HashMap<>(); @@ -45,11 +43,11 @@ public HashMap getAllUserDonationTimes() Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/beanCoin/donation_users") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode user : request.getData().get("users")) { String userID = user.get("user_id").asText(); - Timestamp timeUntilNextDonation = CafeGeneric.parseTimestampFromAPI(user.get("time_until_next_donation").asText()); + Timestamp timeUntilNextDonation = CafeGeneric.parseTimestampFromAPI(user.get("time_until_next_donation").asText()).orElse(null); donationUsers.put(userID, timeUntilNextDonation); } @@ -65,13 +63,12 @@ public HashMap getAllUserDonationTimes() * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws NotFoundException Thrown when the {@link Timestamp timeUntilNextDonation} does not exist for the specified {@link String userID}. */ - @Nullable - public Timestamp getUserDonationTime(@NotNull String userID) + public Optional getUserDonationTime(String userID) throws AuthorizationException, ResponseException, NotFoundException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/beanCoin/donation_users/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return CafeGeneric.parseTimestampFromAPI(request.getData().get("user").get("time_until_next_donation").asText()); } @@ -86,14 +83,13 @@ public Timestamp getUserDonationTime(@NotNull String userID) * @throws ConflictException Thrown when the {@link Timestamp timeUntilNextDonation} already exists for the specified {@link String userID}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean addDonationUser(@NotNull String userID, @NotNull Timestamp timeUntilNextDonation) + public Boolean addDonationUser(String userID, Timestamp timeUntilNextDonation) throws AuthorizationException, ResponseException, ConflictException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) .setRoute("/beanCoin/donation_users/" + userID) .addParameter("time_stamp", timeUntilNextDonation.toString()) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -105,13 +101,12 @@ public Boolean addDonationUser(@NotNull String userID, @NotNull Timestamp timeUn * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull - public Boolean deleteDonationUser(@NotNull String userID) + public Boolean deleteDonationUser(String userID) throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) .setRoute("/beanCoin/donation_users/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -121,7 +116,8 @@ public Boolean deleteDonationUser(@NotNull String userID) * @param apiKey The new {@link String apiKey}. */ @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/birthdays/Birthday.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/birthdays/Birthday.java index 85aa3d2..217b0d6 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/birthdays/Birthday.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/birthdays/Birthday.java @@ -3,7 +3,6 @@ import com.beanbeanjuice.cafeapi.exception.program.BirthdayOverfillException; import com.beanbeanjuice.cafeapi.exception.program.InvalidTimeZoneException; import com.beanbeanjuice.cafeapi.utility.Time; -import org.jetbrains.annotations.NotNull; import java.text.ParseException; import java.util.Date; @@ -17,9 +16,9 @@ public class Birthday { private final BirthdayMonth month; - private final Integer day; + private final int day; private final TimeZone timeZone; - private final Boolean alreadyMentioned; + private final boolean alreadyMentioned; /** * Creates a new {@link Birthday} object. @@ -27,8 +26,8 @@ public class Birthday { * @param day The {@link Integer day} of the {@link Birthday}. * @param alreadyMentioned False, if the user's birthday has not been mentioned by cafeBot. */ - public Birthday(@NotNull BirthdayMonth month, @NotNull Integer day, @NotNull String timeZone, - @NotNull Boolean alreadyMentioned) throws InvalidTimeZoneException, BirthdayOverfillException { + public Birthday(BirthdayMonth month, int day, String timeZone, + boolean alreadyMentioned) throws InvalidTimeZoneException, BirthdayOverfillException { this.month = month; this.day = day; @@ -45,7 +44,6 @@ public Birthday(@NotNull BirthdayMonth month, @NotNull Integer day, @NotNull Str /** * @return The {@link BirthdayMonth month} of the {@link Birthday}. */ - @NotNull public BirthdayMonth getMonth() { return month; } @@ -53,16 +51,14 @@ public BirthdayMonth getMonth() { /** * @return The {@link Integer day} of the {@link Birthday}. */ - @NotNull - public Integer getDay() { + public int getDay() { return day; } /** * @return False, if the user's birthday has not been mentioned by cafeBot. */ - @NotNull - public Boolean alreadyMentioned() { + public boolean alreadyMentioned() { return alreadyMentioned; } @@ -70,7 +66,6 @@ public Boolean alreadyMentioned() { * @return The {@link Date} of the {@link Birthday} in {@link TimeZone UTC} time. * @throws ParseException Thrown when the {@link Birthday} was unable to be parsed. */ - @NotNull public Date getUTCDate() throws ParseException { return Time.getFullDate(month.getMonthNumber() + "-" + day + "-2020", timeZone); } @@ -78,7 +73,6 @@ public Date getUTCDate() throws ParseException { /** * @return The {@link TimeZone} for the {@link Birthday}. */ - @NotNull public TimeZone getTimeZone() { return timeZone; } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/birthdays/BirthdayMonth.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/birthdays/BirthdayMonth.java index d2c6b40..885839f 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/birthdays/BirthdayMonth.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/birthdays/BirthdayMonth.java @@ -1,7 +1,5 @@ package com.beanbeanjuice.cafeapi.cafebot.birthdays; -import org.jetbrains.annotations.NotNull; - /** * A static {@link BirthdayMonth} class used for {@link Birthday} months. * @@ -23,15 +21,15 @@ public enum BirthdayMonth { DECEMBER (12, 31), ERROR (13, 31); - private final Integer monthNumber; - private final Integer daysInMonth; + private final int monthNumber; + private final int daysInMonth; /** * Creates a new {@link BirthdayMonth} static class. * @param monthNumber The {@link Integer monthNumber}. * @param daysInMonth The amount of {@link Integer daysInMonth}. */ - BirthdayMonth(@NotNull Integer monthNumber, @NotNull Integer daysInMonth) { + BirthdayMonth(int monthNumber, int daysInMonth) { this.monthNumber = monthNumber; this.daysInMonth = daysInMonth; } @@ -39,16 +37,14 @@ public enum BirthdayMonth { /** * @return The {@link Integer monthNumber}. */ - @NotNull - public Integer getMonthNumber() { + public int getMonthNumber() { return monthNumber; } /** * @return The amount of {@link Integer daysInMonth}. */ - @NotNull - public Integer getDaysInMonth() { + public int getDaysInMonth() { return daysInMonth; } } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/birthdays/Birthdays.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/birthdays/Birthdays.java index 46798e0..cc4bd51 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/birthdays/Birthdays.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/birthdays/Birthdays.java @@ -8,7 +8,6 @@ import com.beanbeanjuice.cafeapi.requests.RequestType; import com.beanbeanjuice.cafeapi.utility.Time; import com.fasterxml.jackson.databind.JsonNode; -import org.jetbrains.annotations.NotNull; import java.text.ParseException; import java.util.Calendar; @@ -29,7 +28,7 @@ public class Birthdays implements com.beanbeanjuice.cafeapi.api.CafeAPI { * Creates a new {@link Birthdays} object. * @param apiKey The {@link String apiKey} used for authorization. */ - public Birthdays(@NotNull String apiKey) { + public Birthdays(String apiKey) { this.apiKey = apiKey; } @@ -40,7 +39,6 @@ public Birthdays(@NotNull String apiKey) { * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws ParseException Thrown when there is an error parsing the {@link Birthday}. */ - @NotNull public HashMap getAllBirthdays() throws AuthorizationException, ResponseException, ParseException { HashMap birthdays = new HashMap<>(); @@ -48,7 +46,7 @@ public HashMap getAllBirthdays() Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/birthdays") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode birthday : request.getData().get("birthdays")) { String userID = birthday.get("user_id").asText(); @@ -67,13 +65,12 @@ public HashMap getAllBirthdays() * @throws NotFoundException Thrown when the {@link Birthday} for the specified {@link String userID} does not exist. * @throws ParseException Thrown when there was an error parsing the {@link Birthday}. */ - @NotNull - public Birthday getUserBirthday(@NotNull String userID) + public Birthday getUserBirthday(String userID) throws AuthorizationException, ResponseException, NotFoundException, ParseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/birthdays/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return parseBirthday(request.getData().get("birthday")); } @@ -89,8 +86,7 @@ public Birthday getUserBirthday(@NotNull String userID) * @throws UndefinedVariableException Thrown when a variable is undefined. * @throws TeaPotException Thrown when the {@link BirthdayMonth month} or {@link Integer day} is invalid. */ - @NotNull - public Boolean updateUserBirthday(@NotNull String userID, @NotNull Birthday birthday) + public Boolean updateUserBirthday(String userID, Birthday birthday) throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException, TeaPotException { BirthdayMonth month = birthday.getMonth(); int day = birthday.getDay(); @@ -110,7 +106,7 @@ public Boolean updateUserBirthday(@NotNull String userID, @NotNull Birthday birt .addParameter("birthday", getBirthdayString(month, day)) .addParameter("time_zone", birthday.getTimeZone().getID()) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -125,14 +121,13 @@ public Boolean updateUserBirthday(@NotNull String userID, @NotNull Birthday birt * @throws NotFoundException Thrown when the {@link Birthday} does not exist for the specified {@link String userID}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean updateUserBirthdayMention(@NotNull String userID, @NotNull Boolean alreadyMentioned) + public Boolean updateUserBirthdayMention(String userID, boolean alreadyMentioned) throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.PATCH) .setRoute("/birthdays/" + userID + "/mention") - .addParameter("already_mentioned", alreadyMentioned.toString()) + .addParameter("already_mentioned", String.valueOf(alreadyMentioned)) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -148,8 +143,7 @@ public Boolean updateUserBirthdayMention(@NotNull String userID, @NotNull Boolea * @throws UndefinedVariableException Thrown when a variable is undefined. * @throws TeaPotException Thrown when the {@link BirthdayMonth month} or {@link Integer day} is invalid. */ - @NotNull - public Boolean createUserBirthday(@NotNull String userID, @NotNull Birthday birthday) + public Boolean createUserBirthday(String userID, Birthday birthday) throws AuthorizationException, ResponseException, ConflictException, UndefinedVariableException, TeaPotException { BirthdayMonth month = birthday.getMonth(); int day = birthday.getDay(); @@ -169,7 +163,7 @@ public Boolean createUserBirthday(@NotNull String userID, @NotNull Birthday birt .addParameter("birthday", getBirthdayString(month, day)) .addParameter("time_zone", birthday.getTimeZone().getID()) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -181,13 +175,12 @@ public Boolean createUserBirthday(@NotNull String userID, @NotNull Birthday birt * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull - public Boolean removeUserBirthday(@NotNull String userID) + public Boolean removeUserBirthday(String userID) throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) .setRoute("/birthdays/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -197,8 +190,7 @@ public Boolean removeUserBirthday(@NotNull String userID) * @param birthday The {@link JsonNode} to parse. * @return The parsed {@link Birthday}. */ - @NotNull - private Birthday parseBirthday(@NotNull JsonNode birthday) throws ParseException { + private Birthday parseBirthday(JsonNode birthday) throws ParseException { String unformattedDate = birthday.get("birth_date").asText(); String timeZoneString = birthday.get("time_zone").asText(); Boolean alreadyMentioned = birthday.get("already_mentioned").asBoolean(); @@ -217,10 +209,9 @@ private Birthday parseBirthday(@NotNull JsonNode birthday) throws ParseException * @param index The {@link Integer index} of the month. January is 0. * @return The {@link BirthdayMonth} from the {@link Integer index}. */ - @NotNull - private BirthdayMonth getBirthdayMonth(@NotNull Integer index) { + private BirthdayMonth getBirthdayMonth(int index) { for (BirthdayMonth month : BirthdayMonth.values()) { - if (month.getMonthNumber().equals(index)) + if (month.getMonthNumber() == index) return month; } @@ -232,13 +223,12 @@ private BirthdayMonth getBirthdayMonth(@NotNull Integer index) { * @param number The {@link Integer number} to parse. * @return The parsed {@link String number}. Double-digit numbers don't have a 0 added. */ - @NotNull - private String parseNumber(@NotNull Integer number) { + private String parseNumber(int number) { // TODO: There MUST be a better way to do this. if (number <= 9) { return "0" + number; } - return number.toString(); + return String.valueOf(number); } /** @@ -247,8 +237,7 @@ private String parseNumber(@NotNull Integer number) { * @param day The {@link Integer day} in the {@link BirthdayMonth month} of the {@link Birthday}. * @return The birthday {@link String} to send to the {@link CafeAPI CafeAPI}. */ - @NotNull - private String getBirthdayString(@NotNull BirthdayMonth month, @NotNull Integer day) { + private String getBirthdayString(BirthdayMonth month, int day) { return parseNumber(month.getMonthNumber()) + "-" + parseNumber(day); } @@ -257,7 +246,7 @@ private String getBirthdayString(@NotNull BirthdayMonth month, @NotNull Integer * @param apiKey The new {@link String apiKey}. */ @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/cafe/CafeType.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/cafe/CafeType.java index 557785c..2dd9c18 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/cafe/CafeType.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/cafe/CafeType.java @@ -2,7 +2,6 @@ import com.beanbeanjuice.cafeapi.CafeAPI; import com.beanbeanjuice.cafeapi.requests.Request; -import org.jetbrains.annotations.NotNull; /** * A static {@link CafeType} used for the {@link CafeUsers} API. @@ -22,15 +21,15 @@ public enum CafeType { * Creates a new {@link CafeType} static object. * @param type The {@link String type} used for the {@link CafeAPI CafeAPI}. */ - CafeType(@NotNull String type) { + CafeType(String type) { this.type = type; } /** * @return The {@link String type} used for {@link CafeAPI CafeAPI} {@link Request Requests}. */ - @NotNull public String getType() { return type; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/cafe/CafeUser.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/cafe/CafeUser.java index 2542c00..cd25d3a 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/cafe/CafeUser.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/cafe/CafeUser.java @@ -1,9 +1,8 @@ package com.beanbeanjuice.cafeapi.cafebot.cafe; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; - import java.sql.Timestamp; +import java.util.Optional; /** * A class used for {@link CafeUser} objects. @@ -13,10 +12,10 @@ public class CafeUser { private final String userID; - private final Double beanCoins; + private final double beanCoins; private final Timestamp lastServingTime; - private final Integer ordersBought; - private final Integer ordersReceived; + private final int ordersBought; + private final int ordersReceived; /** * Creates a new {@link CafeUser} object. @@ -26,8 +25,8 @@ public class CafeUser { * @param ordersBought The {@link Integer ordersBought}. * @param ordersReceived The {@link Integer ordersReceived}. */ - public CafeUser(@NotNull String userID, @NotNull Double beanCoins, @Nullable Timestamp lastServingTime, - @NotNull Integer ordersBought, @NotNull Integer ordersReceived) { + public CafeUser(String userID, double beanCoins, @Nullable Timestamp lastServingTime, + int ordersBought, int ordersReceived) { this.userID = userID; this.beanCoins = beanCoins; this.lastServingTime = lastServingTime; @@ -38,7 +37,6 @@ public CafeUser(@NotNull String userID, @NotNull Double beanCoins, @Nullable Tim /** * @return The {@link String lastUserID}. */ - @NotNull public String getUserID() { return userID; } @@ -46,32 +44,29 @@ public String getUserID() { /** * @return The {@link Double beanCoins}. */ - @NotNull - public Double getBeanCoins() { + public double getBeanCoins() { return beanCoins; } /** * @return The {@link Timestamp lastServingTime}. */ - @Nullable - public Timestamp getLastServingTime() { - return lastServingTime; + public Optional getLastServingTime() { + return Optional.ofNullable(lastServingTime); } /** * @return The {@link Integer ordersBought}. */ - @NotNull - public Integer getOrdersBought() { + public int getOrdersBought() { return ordersBought; } /** * @return The {@link Integer ordersReceived}. */ - @NotNull - public Integer getOrdersReceived() { + public int getOrdersReceived() { return ordersReceived; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/cafe/CafeUsers.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/cafe/CafeUsers.java index 4188183..d3100fa 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/cafe/CafeUsers.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/cafe/CafeUsers.java @@ -8,7 +8,6 @@ import com.beanbeanjuice.cafeapi.requests.RequestRoute; import com.beanbeanjuice.cafeapi.requests.RequestType; import com.fasterxml.jackson.databind.JsonNode; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.sql.Timestamp; @@ -27,7 +26,7 @@ public class CafeUsers implements com.beanbeanjuice.cafeapi.api.CafeAPI { * Creates a new {@link CafeUsers} object. * @param apiKey The {@link String apiKey} used for authorization. */ - public CafeUsers(@NotNull String apiKey) { + public CafeUsers(String apiKey) { this.apiKey = apiKey; } @@ -37,7 +36,6 @@ public CafeUsers(@NotNull String apiKey) { * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull public ArrayList getAllCafeUsers() throws AuthorizationException, ResponseException { ArrayList cafeUsers = new ArrayList<>(); @@ -45,7 +43,7 @@ public ArrayList getAllCafeUsers() Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/cafe/users") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode cafeUser : request.getData().get("users")) { cafeUsers.add(parseCafeUser(cafeUser)); @@ -62,13 +60,12 @@ public ArrayList getAllCafeUsers() * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws NotFoundException Thrown when the {@link CafeUser} does not exist for the specified {@link String userID}. */ - @NotNull - public CafeUser getCafeUser(@NotNull String userID) + public CafeUser getCafeUser(String userID) throws AuthorizationException, ResponseException, NotFoundException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/cafe/users/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return parseCafeUser(request.getData().get("cafe_user")); } @@ -85,8 +82,7 @@ public CafeUser getCafeUser(@NotNull String userID) * @throws TeaPotException Thrown when the {@link Object value} entered is not compatible with the specified {@link CafeType type}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean updateCafeUser(@NotNull String userID, @NotNull CafeType type, @Nullable Object value) + public boolean updateCafeUser(String userID, CafeType type, @Nullable Object value) throws AuthorizationException, ResponseException, NotFoundException, TeaPotException, UndefinedVariableException { if (!(type.equals(CafeType.LAST_SERVING_TIME) && value == null)) { @@ -122,7 +118,7 @@ public Boolean updateCafeUser(@NotNull String userID, @NotNull CafeType type, @N requestBuilder.addParameter("value", value.toString()); } - Request request = requestBuilder.build(); + Request request = requestBuilder.build().orElseThrow(); return request.getStatusCode() == 200; } @@ -135,13 +131,12 @@ public Boolean updateCafeUser(@NotNull String userID, @NotNull CafeType type, @N * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws ConflictException Thrown when the {@link CafeUser} already exists for the specified {@link String userID}. */ - @NotNull - public Boolean createCafeUser(@NotNull String userID) + public boolean createCafeUser(String userID) throws AuthorizationException, ResponseException, ConflictException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) .setRoute("/cafe/users/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -153,13 +148,12 @@ public Boolean createCafeUser(@NotNull String userID) * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull - public Boolean deleteCafeUser(@NotNull String userID) + public boolean deleteCafeUser(String userID) throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) .setRoute("/cafe/users/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -169,11 +163,10 @@ public Boolean deleteCafeUser(@NotNull String userID) * @param node The {@link JsonNode node} to parse. * @return The parsed {@link CafeUser}. */ - @NotNull - private CafeUser parseCafeUser(@NotNull JsonNode node) { + private CafeUser parseCafeUser(JsonNode node) { String userID = node.get("user_id").asText(); Double beanCoins = node.get("bean_coins").asDouble(); - Timestamp timestamp = CafeGeneric.parseTimestampFromAPI(node.get("last_serving_time").asText()); + Timestamp timestamp = CafeGeneric.parseTimestampFromAPI(node.get("last_serving_time").asText()).orElse(null); Integer ordersBought = node.get("orders_bought").asInt(); Integer ordersReceived = node.get("orders_received").asInt(); @@ -185,7 +178,8 @@ private CafeUser parseCafeUser(@NotNull JsonNode node) { * @param apiKey The new {@link String apiKey}. */ @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/codes/GeneratedCodes.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/codes/GeneratedCodes.java index ed7d3ec..57bad26 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/codes/GeneratedCodes.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/codes/GeneratedCodes.java @@ -7,7 +7,6 @@ import com.beanbeanjuice.cafeapi.requests.RequestRoute; import com.beanbeanjuice.cafeapi.requests.RequestType; import com.fasterxml.jackson.databind.JsonNode; -import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -24,7 +23,7 @@ public class GeneratedCodes implements com.beanbeanjuice.cafeapi.api.CafeAPI { * Creates a new {@link GeneratedCodes} object. * @param apiKey The {@link String apiKey} used for authorization. */ - public GeneratedCodes(@NotNull String apiKey) { + public GeneratedCodes(String apiKey) { this.apiKey = apiKey; } @@ -34,7 +33,6 @@ public GeneratedCodes(@NotNull String apiKey) { * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull public HashMap getAllGeneratedCodes() throws AuthorizationException, ResponseException { HashMap codes = new HashMap<>(); @@ -42,7 +40,7 @@ public HashMap getAllGeneratedCodes() Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/codes") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode user : request.getData().get("users")) { codes.put(user.get("user_id").asText(), user.get("generated_code").asText()); @@ -59,13 +57,12 @@ public HashMap getAllGeneratedCodes() * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws NotFoundException Thrown when a {@link String generatedCode} for the specified {@link String userID} does not exist. */ - @NotNull - public String getUserGeneratedCode(@NotNull String userID) + public String getUserGeneratedCode(String userID) throws AuthorizationException, ResponseException, NotFoundException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/codes/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getData().get("generated_code").asText(); } @@ -80,14 +77,13 @@ public String getUserGeneratedCode(@NotNull String userID) * @throws NotFoundException Thrown when a {@link String generatedCode} does not exist for the specified {@link String userID}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean updateUserGeneratedCode(@NotNull String userID, @NotNull String newCode) + public boolean updateUserGeneratedCode(String userID, String newCode) throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.PATCH) .setRoute("/codes/" + userID) .addParameter("generated_code", newCode) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -102,14 +98,13 @@ public Boolean updateUserGeneratedCode(@NotNull String userID, @NotNull String n * @throws ConflictException Thrown when the {@link String generatedCode} already exists for the specified {@link String userID}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean createUserGeneratedCode(@NotNull String userID, @NotNull String newCode) + public Boolean createUserGeneratedCode(String userID, String newCode) throws AuthorizationException, ResponseException, ConflictException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) .setRoute("/codes/" + userID) .addParameter("generated_code", newCode) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -121,13 +116,12 @@ public Boolean createUserGeneratedCode(@NotNull String userID, @NotNull String n * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull - public Boolean deleteUserGeneratedCode(@NotNull String userID) + public Boolean deleteUserGeneratedCode(String userID) throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) .setRoute("/codes/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -137,7 +131,8 @@ public Boolean deleteUserGeneratedCode(@NotNull String userID) * @param apiKey The new {@link String apiKey}. */ @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/counting/CountingInformation.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/counting/CountingInformation.java index 22490aa..b30cf64 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/counting/CountingInformation.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/counting/CountingInformation.java @@ -1,7 +1,5 @@ package com.beanbeanjuice.cafeapi.cafebot.counting; -import org.jetbrains.annotations.NotNull; - /** * A class used for {@link CountingInformation}. * @@ -9,8 +7,8 @@ */ public class CountingInformation { - private final Integer highestNumber; - private final Integer lastNumber; + private final int highestNumber; + private final int lastNumber; private final String lastUserID; private final String failureRoleID; @@ -21,8 +19,7 @@ public class CountingInformation { * @param lastUserID The {@link String lastUserID}. * @param failureRoleID The {@link String failureRoleID}. */ - public CountingInformation(@NotNull Integer highestNumber, @NotNull Integer lastNumber, @NotNull String lastUserID, - @NotNull String failureRoleID) { + public CountingInformation(int highestNumber, int lastNumber, String lastUserID, String failureRoleID) { this.highestNumber = highestNumber; this.lastNumber = lastNumber; this.lastUserID = lastUserID; @@ -32,23 +29,20 @@ public CountingInformation(@NotNull Integer highestNumber, @NotNull Integer last /** * @return The {@link Integer highestNumber}. */ - @NotNull - public Integer getHighestNumber() { + public int getHighestNumber() { return highestNumber; } /** * @return The {@link Integer lastNumber}. */ - @NotNull - public Integer getLastNumber() { + public int getLastNumber() { return lastNumber; } /** * @return The {@link String lastUserID}. */ - @NotNull public String getLastUserID() { return lastUserID; } @@ -56,7 +50,6 @@ public String getLastUserID() { /** * @return The {@link String failureRoleID}. */ - @NotNull public String getFailureRoleID() { return failureRoleID; } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/counting/CountingInformations.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/counting/CountingInformations.java index 57e9be6..faf0dca 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/counting/CountingInformations.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/counting/CountingInformations.java @@ -7,7 +7,6 @@ import com.beanbeanjuice.cafeapi.requests.RequestRoute; import com.beanbeanjuice.cafeapi.requests.RequestType; import com.fasterxml.jackson.databind.JsonNode; -import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -15,6 +14,7 @@ * A class used for {@link CountingInformation} requests for the {@link CafeAPI CafeAPI}. * * @author beanbeanjuice + * @deprecated Since v1.5.0. Replaced by {@link GlobalCountingInformation}. */ public class CountingInformations implements com.beanbeanjuice.cafeapi.api.CafeAPI { @@ -24,7 +24,7 @@ public class CountingInformations implements com.beanbeanjuice.cafeapi.api.CafeA * Creates a new {@link CountingInformations object}. * @param apiKey The {@link String apiKey} used for authorization. */ - public CountingInformations(@NotNull String apiKey) { + public CountingInformations(String apiKey) { this.apiKey = apiKey; } @@ -34,15 +34,14 @@ public CountingInformations(@NotNull String apiKey) { * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull public HashMap getAllCountingInformation() - throws AuthorizationException, ResponseException { + throws AuthorizationException, ResponseException { HashMap guilds = new HashMap<>(); Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/counting/guilds") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode guild : request.getData().get("guilds")) { String guildID = guild.get("guild_id").asText(); @@ -61,13 +60,12 @@ public HashMap getAllCountingInformation() * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws NotFoundException Thrown when the {@link CountingInformation} does not exist for the specified {@link String guildID}. */ - @NotNull - public CountingInformation getGuildCountingInformation(@NotNull String guildID) - throws AuthorizationException, ResponseException, NotFoundException { + public CountingInformation getGuildCountingInformation(String guildID) + throws AuthorizationException, ResponseException, NotFoundException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/counting/guilds/" + guildID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return parseCountingInformation(request.getData().get("counting_information")); } @@ -84,18 +82,17 @@ public CountingInformation getGuildCountingInformation(@NotNull String guildID) * @throws NotFoundException Thrown when the {@link CountingInformation} was not found for the specified {@link String guildID}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean updateGuildCountingInformation(@NotNull String guildID, @NotNull Integer highestNumber, @NotNull Integer lastNumber, - @NotNull String lastUserID, @NotNull String failureRoleID) - throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException { + public Boolean updateGuildCountingInformation(String guildID, int highestNumber, int lastNumber, + String lastUserID, String failureRoleID) + throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.PATCH) .setRoute("/counting/guilds/" + guildID) - .addParameter("highest_number", highestNumber.toString()) - .addParameter("last_number", lastNumber.toString()) + .addParameter("highest_number", String.valueOf(highestNumber)) + .addParameter("last_number", String.valueOf(lastNumber)) .addParameter("last_user_id", lastUserID) .addParameter("failure_role_id", failureRoleID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -110,9 +107,8 @@ public Boolean updateGuildCountingInformation(@NotNull String guildID, @NotNull * @throws NotFoundException Thrown when the {@link CountingInformation} was not found for the specified {@link String guildID}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean updateGuildCountingInformation(@NotNull String guildID, @NotNull CountingInformation countingInformation) - throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException { + public boolean updateGuildCountingInformation(String guildID, CountingInformation countingInformation) + throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException { return updateGuildCountingInformation( guildID, countingInformation.getHighestNumber(), @@ -130,13 +126,12 @@ public Boolean updateGuildCountingInformation(@NotNull String guildID, @NotNull * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws ConflictException Thrown when the {@link CountingInformation} already exists for the specified {@link String guildID}. */ - @NotNull - public Boolean createGuildCountingInformation(@NotNull String guildID) - throws AuthorizationException, ResponseException, ConflictException { + public boolean createGuildCountingInformation(String guildID) + throws AuthorizationException, ResponseException, ConflictException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) .setRoute("/counting/guilds/" + guildID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -148,13 +143,12 @@ public Boolean createGuildCountingInformation(@NotNull String guildID) * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull - public Boolean deleteGuildCountingInformation(@NotNull String guildID) - throws AuthorizationException, ResponseException { + public boolean deleteGuildCountingInformation(String guildID) + throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) .setRoute("/counting/guilds/" + guildID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -164,10 +158,9 @@ public Boolean deleteGuildCountingInformation(@NotNull String guildID) * @param node The {@link JsonNode node} to parse. * @return The parsed {@link CountingInformation}. */ - @NotNull - private CountingInformation parseCountingInformation(@NotNull JsonNode node) { - Integer highestNumber = node.get("highest_number").asInt(); - Integer lastNumber = node.get("last_number").asInt(); + private CountingInformation parseCountingInformation(JsonNode node) { + int highestNumber = node.get("highest_number").asInt(); + int lastNumber = node.get("last_number").asInt(); String lastUserID = node.get("last_user_id").asText(); String failureRoleID = node.get("failure_role_id").asText(); @@ -184,7 +177,7 @@ private CountingInformation parseCountingInformation(@NotNull JsonNode node) { * @param apiKey The new {@link String apiKey}. */ @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/counting/GlobalCountingInformation.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/counting/GlobalCountingInformation.java new file mode 100644 index 0000000..78b2135 --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/counting/GlobalCountingInformation.java @@ -0,0 +1,183 @@ +package com.beanbeanjuice.cafeapi.cafebot.counting; + +import com.beanbeanjuice.cafeapi.CafeAPI; +import com.beanbeanjuice.cafeapi.exception.api.*; +import com.beanbeanjuice.cafeapi.requests.Request; +import com.beanbeanjuice.cafeapi.requests.RequestBuilder; +import com.beanbeanjuice.cafeapi.requests.RequestRoute; +import com.beanbeanjuice.cafeapi.requests.RequestType; +import com.fasterxml.jackson.databind.JsonNode; + +import java.util.HashMap; + +/** + * A class used for {@link CountingInformation} requests for the {@link CafeAPI CafeAPI}. + * + * @author beanbeanjuice + */ +public class GlobalCountingInformation implements com.beanbeanjuice.cafeapi.api.CafeAPI { + + private String apiKey; + + /** + * Creates a new {@link GlobalCountingInformation object}. + * @param apiKey The {@link String apiKey} used for authorization. + */ + public GlobalCountingInformation(String apiKey) { + this.apiKey = apiKey; + } + + /** + * Retrieves all {@link CountingInformation} in the {@link CafeAPI CafeAPI}. + * @return A {@link HashMap} with keys of {@link String userID} and values of {@link CountingInformation guildCountingInformation}. + * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. + * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. + */ + public HashMap getAllCountingInformation() + throws AuthorizationException, ResponseException { + HashMap guilds = new HashMap<>(); + + Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) + .setRoute("/counting/guilds") + .setAuthorization(apiKey) + .build().orElseThrow(); + + for (JsonNode guild : request.getData().get("guilds")) { + String guildID = guild.get("guild_id").asText(); + + guilds.put(guildID, parseCountingInformation(guild)); + } + + return guilds; + } + + /** + * Retrieves the {@link CountingInformation} for a specified {@link String guildID}. + * @param guildID THe specified {@link String guildID}. + * @return The {@link CountingInformation} for the specified {@link String guildID}. + * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. + * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. + * @throws NotFoundException Thrown when the {@link CountingInformation} does not exist for the specified {@link String guildID}. + */ + public CountingInformation getGuildCountingInformation(String guildID) + throws AuthorizationException, ResponseException, NotFoundException { + Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) + .setRoute("/counting/guilds/" + guildID) + .setAuthorization(apiKey) + .build().orElseThrow(); + + return parseCountingInformation(request.getData().get("counting_information")); + } + + /** + * Updates the {@link CountingInformation} for a specified {@link String guildID}. + * @param guildID The specified {@link String guildID}. + * @param highestNumber The new {@link Integer highestNumber}. + * @param lastNumber The new {@link Integer lastNumber}. + * @param lastUserID The new {@link String lastuserID}. + * @return True, if the {@link CountingInformation} was successfully updated for the specified {@link String guildID}. + * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. + * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. + * @throws NotFoundException Thrown when the {@link CountingInformation} was not found for the specified {@link String guildID}. + * @throws UndefinedVariableException Thrown when a variable is undefined. + */ + public Boolean updateGuildCountingInformation(String guildID, int highestNumber, int lastNumber, + String lastUserID, String failureRoleID) + throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException { + Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.PATCH) + .setRoute("/counting/guilds/" + guildID) + .addParameter("highest_number", String.valueOf(highestNumber)) + .addParameter("last_number", String.valueOf(lastNumber)) + .addParameter("last_user_id", lastUserID) + .addParameter("failure_role_id", failureRoleID) + .setAuthorization(apiKey) + .build().orElseThrow(); + + return request.getStatusCode() == 200; + } + + /** + * Updated the {@link CountingInformation} for a specified {@link String guildID}. + * @param guildID The specified {@link String guildID}. + * @param countingInformation The new {@link CountingInformation}. + * @return True, if the {@link CountingInformation} was successfully updated for the specified {@link String guildID}. + * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. + * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. + * @throws NotFoundException Thrown when the {@link CountingInformation} was not found for the specified {@link String guildID}. + * @throws UndefinedVariableException Thrown when a variable is undefined. + */ + public boolean updateGuildCountingInformation(String guildID, CountingInformation countingInformation) + throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException { + return updateGuildCountingInformation( + guildID, + countingInformation.getHighestNumber(), + countingInformation.getLastNumber(), + countingInformation.getLastUserID(), + countingInformation.getFailureRoleID() + ); + } + + /** + * Creates a new {@link CountingInformation} for the specified {@link String guildID}. + * @param guildID The specified {@link String guildID}. + * @return True, if the {@link CountingInformation} was successfully created for the specified {@link String guildID}. + * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. + * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. + * @throws ConflictException Thrown when the {@link CountingInformation} already exists for the specified {@link String guildID}. + */ + public boolean createGuildCountingInformation(String guildID) + throws AuthorizationException, ResponseException, ConflictException { + Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) + .setRoute("/counting/guilds/" + guildID) + .setAuthorization(apiKey) + .build().orElseThrow(); + + return request.getStatusCode() == 201; + } + + /** + * Deletes the {@link CountingInformation} for a specified {@link String guildID}. + * @param guildID The specified {@link String guildID}. + * @return True, if the {@link CountingInformation} was successfully deleted for the specified {@link String guildID}. + * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. + * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. + */ + public boolean deleteGuildCountingInformation(String guildID) + throws AuthorizationException, ResponseException { + Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) + .setRoute("/counting/guilds/" + guildID) + .setAuthorization(apiKey) + .build().orElseThrow(); + + return request.getStatusCode() == 200; + } + + /** + * Parses a {@link JsonNode} for its {@link CountingInformation}. + * @param node The {@link JsonNode node} to parse. + * @return The parsed {@link CountingInformation}. + */ + private CountingInformation parseCountingInformation(JsonNode node) { + int highestNumber = node.get("highest_number").asInt(); + int lastNumber = node.get("last_number").asInt(); + String lastUserID = node.get("last_user_id").asText(); + String failureRoleID = node.get("failure_role_id").asText(); + + return new CountingInformation( + highestNumber, + lastNumber, + lastUserID, + failureRoleID + ); + } + + /** + * Updates the {@link String apiKey}. + * @param apiKey The new {@link String apiKey}. + */ + @Override + public void updateAPIKey(String apiKey) { + this.apiKey = apiKey; + } + +} diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/goodbyes/Goodbyes.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/goodbyes/Goodbyes.java index 57ea8d5..89b6318 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/goodbyes/Goodbyes.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/goodbyes/Goodbyes.java @@ -7,7 +7,6 @@ import com.beanbeanjuice.cafeapi.requests.RequestRoute; import com.beanbeanjuice.cafeapi.requests.RequestType; import com.fasterxml.jackson.databind.JsonNode; -import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -22,7 +21,7 @@ public class Goodbyes { * Creates a new class used for {@link Goodbyes} API requests. * @param apiKey The API key used for authorization. */ - public Goodbyes(@NotNull String apiKey) { + public Goodbyes(String apiKey) { this.apiKey = apiKey; } @@ -32,14 +31,13 @@ public Goodbyes(@NotNull String apiKey) { * @throws AuthorizationException Thrown when the api key is unauthorized. * @throws ResponseException Thrown when there is a generic server-side exception. */ - @NotNull public ArrayList getAllGuildGoodbyes() throws AuthorizationException, ResponseException { ArrayList guildGoodbyes = new ArrayList<>(); Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/goodbyes") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode guildGoodbye : request.getData().get("goodbyes")) { guildGoodbyes.add(parseGuildGoodbye(guildGoodbye)); @@ -56,13 +54,12 @@ public ArrayList getAllGuildGoodbyes() throws AuthorizationExcepti * @throws ResponseException Thrown when there is a generic server-side exception. * @throws NotFoundException Thrown when the guild ID is not found. */ - @NotNull - public GuildGoodbye getGuildGoodbye(@NotNull String guildID) + public GuildGoodbye getGuildGoodbye(String guildID) throws AuthorizationException, ResponseException, NotFoundException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/goodbyes/" + guildID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); JsonNode guildGoodbye = request.getData().get("goodbye"); @@ -77,17 +74,16 @@ public GuildGoodbye getGuildGoodbye(@NotNull String guildID) * @throws NotFoundException Thrown when the guild ID is not found. * @throws ResponseException Thrown when there is a generic server-side exception. */ - @NotNull - public Boolean updateGuildGoodbye(@NotNull GuildGoodbye guildGoodbye) + public Boolean updateGuildGoodbye(GuildGoodbye guildGoodbye) throws AuthorizationException, NotFoundException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.PATCH) .setRoute("/goodbyes/" + guildGoodbye.getGuildID()) - .addParameter("description", guildGoodbye.getDescription()) - .addParameter("thumbnail_url", guildGoodbye.getThumbnailURL()) - .addParameter("image_url", guildGoodbye.getImageURL()) - .addParameter("message", guildGoodbye.getMessage()) + .addParameter("description", guildGoodbye.getDescription().orElse(null)) + .addParameter("thumbnail_url", guildGoodbye.getThumbnailURL().orElse(null)) + .addParameter("image_url", guildGoodbye.getImageURL().orElse(null)) + .addParameter("message", guildGoodbye.getMessage().orElse(null)) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -101,17 +97,16 @@ public Boolean updateGuildGoodbye(@NotNull GuildGoodbye guildGoodbye) * @throws ResponseException Thrown when there is a generic server-side exception. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean createGuildGoodbye(@NotNull GuildGoodbye guildGoodbye) + public Boolean createGuildGoodbye(GuildGoodbye guildGoodbye) throws AuthorizationException, ConflictException, ResponseException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) .setRoute("/goodbyes/" + guildGoodbye.getGuildID()) - .addParameter("description", guildGoodbye.getDescription()) - .addParameter("thumbnail_url", guildGoodbye.getThumbnailURL()) - .addParameter("image_url", guildGoodbye.getImageURL()) - .addParameter("message", guildGoodbye.getMessage()) + .addParameter("description", guildGoodbye.getDescription().orElse(null)) + .addParameter("thumbnail_url", guildGoodbye.getThumbnailURL().orElse(null)) + .addParameter("image_url", guildGoodbye.getImageURL().orElse(null)) + .addParameter("message", guildGoodbye.getMessage().orElse(null)) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -123,13 +118,12 @@ public Boolean createGuildGoodbye(@NotNull GuildGoodbye guildGoodbye) * @throws AuthorizationException Thrown when the API key is invalid. * @throws ResponseException Thrown when there is a generic server-side exception. */ - @NotNull - public Boolean deleteGuildGoodbye(@NotNull String guildID) + public Boolean deleteGuildGoodbye(String guildID) throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) .setRoute("/goodbyes/" + guildID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -139,8 +133,7 @@ public Boolean deleteGuildGoodbye(@NotNull String guildID) * @param node The {@link JsonNode} to parse. * @return The parsed {@link GuildGoodbye}. */ - @NotNull - private GuildGoodbye parseGuildGoodbye(@NotNull JsonNode node) { + private GuildGoodbye parseGuildGoodbye(JsonNode node) { String guildID = node.get("guild_id").asText(); String description = node.get("description").asText(); @@ -148,21 +141,10 @@ private GuildGoodbye parseGuildGoodbye(@NotNull JsonNode node) { String imageURL = node.get("image_url").asText(); String message = node.get("message").asText(); - if (description.equals("null")) { - description = null; - } - - if (thumbnailURL.equals("null")) { - thumbnailURL = null; - } - - if (imageURL.equals("null")) { - imageURL = null; - } - - if (message.equals("null")) { - message = null; - } + if (description.equals("null")) description = null; + if (thumbnailURL.equals("null")) thumbnailURL = null; + if (imageURL.equals("null")) imageURL = null; + if (message.equals("null")) message = null; return new GuildGoodbye( guildID, diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/goodbyes/GuildGoodbye.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/goodbyes/GuildGoodbye.java index c8d9c50..b367e84 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/goodbyes/GuildGoodbye.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/goodbyes/GuildGoodbye.java @@ -1,8 +1,9 @@ package com.beanbeanjuice.cafeapi.cafebot.goodbyes; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Optional; + /** * A class used for Goodbye Information for a Discord Guild. * @@ -24,7 +25,7 @@ public class GuildGoodbye { * @param imageURL The {@link String imageURL} of the {@link GuildGoodbye}. * @param message The {@link String message} of the {@link GuildGoodbye}. */ - public GuildGoodbye(@NotNull String guildID, @Nullable String description, @Nullable String thumbnailURL, + public GuildGoodbye(String guildID, @Nullable String description, @Nullable String thumbnailURL, @Nullable String imageURL, @Nullable String message) { this.guildID = guildID; this.description = description; @@ -36,7 +37,6 @@ public GuildGoodbye(@NotNull String guildID, @Nullable String description, @Null /** * @return The {@link String guildID} of the {@link GuildGoodbye}. */ - @NotNull public String getGuildID() { return guildID; } @@ -44,32 +44,29 @@ public String getGuildID() { /** * @return The {@link String description} of the {@link GuildGoodbye}. */ - @Nullable - public String getDescription() { - return description; + public Optional getDescription() { + return Optional.ofNullable(description); } /** * @return The {@link String thumbnailURL} of the {@link GuildGoodbye}. */ - @Nullable - public String getThumbnailURL() { - return thumbnailURL; + public Optional getThumbnailURL() { + return Optional.ofNullable(thumbnailURL); } /** * @return The {@link String imageURL} of the {@link GuildGoodbye}. */ - @Nullable - public String getImageURL() { - return imageURL; + public Optional getImageURL() { + return Optional.ofNullable(imageURL); } /** * @return The {@link String message} of the {@link GuildGoodbye}. */ - @Nullable - public String getMessage() { - return message; + public Optional getMessage() { + return Optional.ofNullable(message); } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GlobalGuildInformation.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GlobalGuildInformation.java new file mode 100644 index 0000000..bfe448c --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GlobalGuildInformation.java @@ -0,0 +1,208 @@ +package com.beanbeanjuice.cafeapi.cafebot.guilds; + +import com.beanbeanjuice.cafeapi.CafeAPI; +import com.beanbeanjuice.cafeapi.exception.api.*; +import com.beanbeanjuice.cafeapi.requests.Request; +import com.beanbeanjuice.cafeapi.requests.RequestBuilder; +import com.beanbeanjuice.cafeapi.requests.RequestRoute; +import com.beanbeanjuice.cafeapi.requests.RequestType; +import com.fasterxml.jackson.databind.JsonNode; + +import java.util.HashMap; + +/** + * A class used for {@link GlobalGuildInformation} requests to the {@link CafeAPI CafeAPI}. + * + * @author beanbeanjuice + */ +public class GlobalGuildInformation implements com.beanbeanjuice.cafeapi.api.CafeAPI { + + private String apiKey; + + /** + * Creates a new {@link GlobalGuildInformation} object. + * @param apiKey The {@link String apiKey} used for authorization. + */ + public GlobalGuildInformation(String apiKey) { + this.apiKey = apiKey; + } + + /** + * Retrieves all {@link GuildInformation} from the {@link CafeAPI CafeAPI}. + * @return A {@link HashMap} with keys of {@link String guildID} with a value of {@link GuildInformation guildInformation}. + * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. + * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. + */ + public HashMap getAllGuildInformation() + throws AuthorizationException, ResponseException { + HashMap guilds = new HashMap<>(); + + Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) + .setRoute("/guilds") + .setAuthorization(apiKey) + .build().orElseThrow(); + + for (JsonNode guild : request.getData().get("guilds")) { + String guildID = guild.get("guild_id").asText(); + guilds.put(guildID, parseGuildInformation(guild)); + } + + return guilds; + } + + /** + * Retrieves the {@link GuildInformation} for a specified {@link String guildID}. + * @param guildID The specified {@link String guildID}. + * @return The {@link GuildInformation} associated with the {@link String guildID}. + * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. + * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. + * @throws NotFoundException Thrown then the specified {@link String guildID} does not exist in the {@link CafeAPI CafeAPI}. + */ + public GuildInformation getGuildInformation(String guildID) + throws AuthorizationException, ResponseException, NotFoundException { + Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) + .setRoute("/guilds/" + guildID) + .setAuthorization(apiKey) + .build().orElseThrow(); + + return parseGuildInformation(request.getData().get("guild")); + } + + /** + * Creates a new {@link GuildInformation} in the {@link CafeAPI CafeAPI}. + * @param guildID The {@link String guildID} to create. + * @return True, if the {@link GlobalGuildInformation} was successfully created for the specified {@link String guildID}. + * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. + * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. + * @throws ConflictException Thrown when the specified {@link String guildID} already exists in the {@link CafeAPI CafeAPI}. + */ + public boolean createGuildInformation(String guildID) + throws AuthorizationException, ResponseException, ConflictException { + Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) + .setRoute("/guilds/" + guildID) + .setAuthorization(apiKey) + .build().orElseThrow(); + + return request.getStatusCode() == 201; + } + + /** + * Updates the {@link GuildInformation} for a specified {@link String guildID}. + * @param guildID The specified {@link String guildID}. + * @param type The {@link GuildInformationType type} of value. + * @param value The {@link String value} to update. + * @return True, if the {@link GuildInformationType type} was successfully updated to the specified {@link String value} for the {@link String guildID}. + * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. + * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. + * @throws NotFoundException Thrown when the specified {@link String guildID} was not found in the {@link CafeAPI CafeAPI}. + * @throws UndefinedVariableException Thrown when a variable is undefined. + * @throws TeaPotException Thrown when a variable is mismatched with its actual value. I.E. - Setting a boolean to "falfse" instead of "false" + */ + public boolean updateGuildInformation(String guildID, GuildInformationType type, Object value) + throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException, TeaPotException { + + switch (type){ + case PREFIX, MODERATOR_ROLE_ID, TWITCH_CHANNEL_ID, + MUTED_ROLE_ID, LIVE_NOTIFICATIONS_ROLE_ID, UPDATE_CHANNEL_ID, + COUNTING_CHANNEL_ID, POLL_CHANNEL_ID, RAFFLE_CHANNEL_ID, + BIRTHDAY_CHANNEL_ID, WELCOME_CHANNEL_ID, LOG_CHANNEL_ID, + VENTING_CHANNEL_ID, DAILY_CHANNEL_ID -> { + if (!value.getClass().equals(String.class)) { + throw new TeaPotException(value + " is invalid for " + type); + } + } + + case NOTIFY_ON_UPDATE, AI_RESPONSE -> { + if (!value.getClass().equals(Boolean.class)) { + throw new TeaPotException(value + " is invalid for " + type); + } + + if ((Boolean) value) { + value = "1"; + } else { + value = "0"; + } + } + + } + + Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.PATCH) + .setRoute("/guilds/" + guildID) + .addParameter("type", type.getType()) + .addParameter("value", value.toString()) + .setAuthorization(apiKey) + .build().orElseThrow(); + + return request.getStatusCode() == 200; + } + + /** + * Deletes a {@link GuildInformation} for a specified {@link String guildID} in the {@link CafeAPI CafeAPI}. + * @param guildID The specified {@link String guildID}. + * @return True, if the {@link GuildInformation} was successfully deleted for the specified {@link String guildID}. + * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. + * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. + */ + public boolean deleteGuildInformation(String guildID) + throws AuthorizationException, ResponseException { + Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) + .setRoute("/guilds/" + guildID) + .setAuthorization(apiKey) + .build().orElseThrow(); + + return request.getStatusCode() == 200; + } + + /** + * Parses a {@link JsonNode} for its {@link GuildInformation}. + * @param guild The {@link JsonNode} to parse. + * @return The parsed {@link GuildInformation}. + */ + private GuildInformation parseGuildInformation(JsonNode guild) { + String prefix = guild.get(GuildInformationType.PREFIX.getType()).asText(); + String moderatorRoleID = guild.get(GuildInformationType.MODERATOR_ROLE_ID.getType()).asText(); + String twitchChannelID = guild.get(GuildInformationType.TWITCH_CHANNEL_ID.getType()).asText(); + String mutedRoleID = guild.get(GuildInformationType.MUTED_ROLE_ID.getType()).asText(); + String liveNotificationsRoleID = guild.get(GuildInformationType.LIVE_NOTIFICATIONS_ROLE_ID.getType()).asText(); + boolean notifyOnUpdate = convertToBoolean(guild.get(GuildInformationType.NOTIFY_ON_UPDATE.getType()).asText()); + String updateChannelID = guild.get(GuildInformationType.UPDATE_CHANNEL_ID.getType()).asText(); + String countingChannelID = guild.get(GuildInformationType.COUNTING_CHANNEL_ID.getType()).asText(); + String pollChannelID = guild.get(GuildInformationType.POLL_CHANNEL_ID.getType()).asText(); + String raffleChannelID = guild.get(GuildInformationType.RAFFLE_CHANNEL_ID.getType()).asText(); + String birthdayChannelID = guild.get(GuildInformationType.BIRTHDAY_CHANNEL_ID.getType()).asText(); + String welcomeChannelID = guild.get(GuildInformationType.WELCOME_CHANNEL_ID.getType()).asText(); + String goodbyeChannelID = guild.get(GuildInformationType.GOODBYE_CHANNEL_ID.getType()).asText(); + String logChannelID = guild.get(GuildInformationType.LOG_CHANNEL_ID.getType()).asText(); + String ventingChannelID = guild.get(GuildInformationType.VENTING_CHANNEL_ID.getType()).asText(); + boolean aiResponseStatus = convertToBoolean(guild.get(GuildInformationType.AI_RESPONSE.getType()).asText()); + String dailyChannelID = guild.get(GuildInformationType.DAILY_CHANNEL_ID.getType()).asText(); + + return new GuildInformation( + prefix, moderatorRoleID, twitchChannelID, + mutedRoleID, liveNotificationsRoleID, notifyOnUpdate, + updateChannelID, countingChannelID, pollChannelID, + raffleChannelID, birthdayChannelID, welcomeChannelID, + goodbyeChannelID, logChannelID, ventingChannelID, + aiResponseStatus, dailyChannelID + ); + } + + /** + * Converts a specified {@link String} to a {@link Boolean}. + * @param string The specified {@link String}. + * @return The parsed {@link Boolean}. False, by default, if there was an error. + */ + private boolean convertToBoolean(String string) { + return string.equalsIgnoreCase("true") || string.equalsIgnoreCase("1"); + } + + /** + * Updates the {@link String apiKey}. + * @param apiKey The new {@link String apiKey}. + */ + @Override + public void updateAPIKey(String apiKey) { + this.apiKey = apiKey; + } + +} diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GuildInformation.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GuildInformation.java index b8dfc62..c782b89 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GuildInformation.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GuildInformation.java @@ -1,7 +1,5 @@ package com.beanbeanjuice.cafeapi.cafebot.guilds; -import org.jetbrains.annotations.NotNull; - /** * A class used for {@link GuildInformation}. * @@ -14,7 +12,7 @@ public class GuildInformation { private final String twitchChannelID; private final String mutedRoleID; private final String liveNotificationsRoleID; - private final Boolean notifyOnUpdate; + private final boolean notifyOnUpdate; private final String updateChannelID; private final String countingChannelID; private final String pollChannelID; @@ -24,7 +22,7 @@ public class GuildInformation { private final String goodbyeChannelID; private final String logChannelID; private final String ventingChannelID; - private final Boolean aiResponseStatus; + private final boolean aiResponseStatus; private final String dailyChannelID; /** @@ -47,12 +45,12 @@ public class GuildInformation { * @param aiResponseStatus The {@link Boolean aiResponseStatus} for the {@link String guildID}. * @param dailyChannelID The {@link String dailyChannelID} for the {@link String guildID}. */ - public GuildInformation(@NotNull String prefix, @NotNull String moderatorRoleID, @NotNull String twitchChannelID, - @NotNull String mutedRoleID, @NotNull String liveNotificationsRoleID, @NotNull Boolean notifyOnUpdate, - @NotNull String updateChannelID, @NotNull String countingChannelID, @NotNull String pollChannelID, - @NotNull String raffleChannelID, @NotNull String birthdayChannelID, @NotNull String welcomeChannelID, - @NotNull String goodbyeChannelID, @NotNull String logChannelID, @NotNull String ventingChannelID, - @NotNull Boolean aiResponseStatus, @NotNull String dailyChannelID) { + public GuildInformation(String prefix, String moderatorRoleID, String twitchChannelID, + String mutedRoleID, String liveNotificationsRoleID, Boolean notifyOnUpdate, + String updateChannelID, String countingChannelID, String pollChannelID, + String raffleChannelID, String birthdayChannelID, String welcomeChannelID, + String goodbyeChannelID, String logChannelID, String ventingChannelID, + boolean aiResponseStatus, String dailyChannelID) { this.prefix = prefix; this.moderatorRoleID = moderatorRoleID; this.twitchChannelID = twitchChannelID; @@ -75,7 +73,6 @@ public GuildInformation(@NotNull String prefix, @NotNull String moderatorRoleID, /** * @return The {@link String prefix} for the {@link GuildInformation}. */ - @NotNull public String getPrefix() { return prefix; } @@ -83,7 +80,6 @@ public String getPrefix() { /** * @return The {@link String moderatorRoleID} for the {@link GuildInformation}. */ - @NotNull public String getModeratorRoleID() { return moderatorRoleID; } @@ -91,7 +87,6 @@ public String getModeratorRoleID() { /** * @return The {@link String twitchChannelID} for the {@link GuildInformation}. */ - @NotNull public String getTwitchChannelID() { return twitchChannelID; } @@ -99,7 +94,6 @@ public String getTwitchChannelID() { /** * @return The {@link String mutedRoleID} for the {@link GuildInformation}. */ - @NotNull public String getMutedRoleID() { return mutedRoleID; } @@ -107,7 +101,6 @@ public String getMutedRoleID() { /** * @return The {@link String liveNotificationsRoleID} for the {@link GuildInformation}. */ - @NotNull public String getLiveNotificationsRoleID() { return liveNotificationsRoleID; } @@ -115,7 +108,6 @@ public String getLiveNotificationsRoleID() { /** * @return The {@link Boolean notifyOnUpdate} for the {@link GuildInformation}. */ - @NotNull public Boolean getNotifyOnUpdate() { return notifyOnUpdate; } @@ -123,7 +115,6 @@ public Boolean getNotifyOnUpdate() { /** * @return The {@link String updateChannelID} for the {@link GuildInformation}. */ - @NotNull public String getUpdateChannelID() { return updateChannelID; } @@ -131,7 +122,6 @@ public String getUpdateChannelID() { /** * @return The {@link String countingChannelID} for the {@link GuildInformation}. */ - @NotNull public String getCountingChannelID() { return countingChannelID; } @@ -139,7 +129,6 @@ public String getCountingChannelID() { /** * @return The {@link String pollChannelID} for the {@link GuildInformation}. */ - @NotNull public String getPollChannelID() { return pollChannelID; } @@ -147,7 +136,6 @@ public String getPollChannelID() { /** * @return The {@link String raffleChannelID} for the {@link GuildInformation}. */ - @NotNull public String getRaffleChannelID() { return raffleChannelID; } @@ -155,7 +143,6 @@ public String getRaffleChannelID() { /** * @return The {@link String birthdayChannelID} for the {@link GuildInformation}. */ - @NotNull public String getBirthdayChannelID() { return birthdayChannelID; } @@ -163,7 +150,6 @@ public String getBirthdayChannelID() { /** * @return The {@link String welcomeChannelID} for the {@link GuildInformation}. */ - @NotNull public String getWelcomeChannelID() { return welcomeChannelID; } @@ -171,7 +157,6 @@ public String getWelcomeChannelID() { /** * @return The {@link String goodbyeChannelID} for the {@link GuildInformation}. */ - @NotNull public String getGoodbyeChannelID() { return goodbyeChannelID; } @@ -179,7 +164,6 @@ public String getGoodbyeChannelID() { /** * @return The {@link String logChannelID} for the {@link GuildInformation}. */ - @NotNull public String getLogChannelID() { return logChannelID; } @@ -187,7 +171,6 @@ public String getLogChannelID() { /** * @return The {@link String ventingChannelID} for the {@link GuildInformation}. */ - @NotNull public String getVentingChannelID() { return ventingChannelID; } @@ -195,7 +178,6 @@ public String getVentingChannelID() { /** * @return The {@link Boolean aiResponseStatus} for the {@link GuildInformation}. */ - @NotNull public Boolean getAiResponseStatus() { return aiResponseStatus; } @@ -203,8 +185,8 @@ public Boolean getAiResponseStatus() { /** * @return The {@link String dailyChannelID} for the {@link GuildInformation}. */ - @NotNull public String getDailyChannelID() { return dailyChannelID; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GuildInformationType.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GuildInformationType.java index a7691bf..609b389 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GuildInformationType.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GuildInformationType.java @@ -1,7 +1,5 @@ package com.beanbeanjuice.cafeapi.cafebot.guilds; -import org.jetbrains.annotations.NotNull; - /** * A static class for {@link GuildInformationType}. * @@ -33,14 +31,13 @@ public enum GuildInformationType { * Creates a new {@link GuildInformationType} static object. * @param type The {@link String type} of object. */ - GuildInformationType(@NotNull String type) { + GuildInformationType(String type) { this.type = type; } /** * @return The {@link GuildInformationType} as a {@link String}. */ - @NotNull public String getType() { return type; } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GuildInformations.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GuildInformations.java index 573b8c9..9fe6b0a 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GuildInformations.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/guilds/GuildInformations.java @@ -7,7 +7,6 @@ import com.beanbeanjuice.cafeapi.requests.RequestRoute; import com.beanbeanjuice.cafeapi.requests.RequestType; import com.fasterxml.jackson.databind.JsonNode; -import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -15,6 +14,7 @@ * A class used for {@link GuildInformations} requests to the {@link CafeAPI CafeAPI}. * * @author beanbeanjuice + * @deprecated Since v1.5.0. Replaced by {@link GlobalGuildInformation}. */ public class GuildInformations implements com.beanbeanjuice.cafeapi.api.CafeAPI { @@ -24,7 +24,7 @@ public class GuildInformations implements com.beanbeanjuice.cafeapi.api.CafeAPI * Creates a new {@link GuildInformations} object. * @param apiKey The {@link String apiKey} used for authorization. */ - public GuildInformations(@NotNull String apiKey) { + public GuildInformations(String apiKey) { this.apiKey = apiKey; } @@ -34,15 +34,14 @@ public GuildInformations(@NotNull String apiKey) { * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull public HashMap getAllGuildInformation() - throws AuthorizationException, ResponseException { + throws AuthorizationException, ResponseException { HashMap guilds = new HashMap<>(); Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/guilds") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode guild : request.getData().get("guilds")) { String guildID = guild.get("guild_id").asText(); @@ -60,13 +59,12 @@ public HashMap getAllGuildInformation() * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws NotFoundException Thrown then the specified {@link String guildID} does not exist in the {@link CafeAPI CafeAPI}. */ - @NotNull - public GuildInformation getGuildInformation(@NotNull String guildID) - throws AuthorizationException, ResponseException, NotFoundException { + public GuildInformation getGuildInformation(String guildID) + throws AuthorizationException, ResponseException, NotFoundException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/guilds/" + guildID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return parseGuildInformation(request.getData().get("guild")); } @@ -79,13 +77,12 @@ public GuildInformation getGuildInformation(@NotNull String guildID) * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws ConflictException Thrown when the specified {@link String guildID} already exists in the {@link CafeAPI CafeAPI}. */ - @NotNull - public Boolean createGuildInformation(@NotNull String guildID) - throws AuthorizationException, ResponseException, ConflictException { + public boolean createGuildInformation(String guildID) + throws AuthorizationException, ResponseException, ConflictException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) .setRoute("/guilds/" + guildID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -102,16 +99,15 @@ public Boolean createGuildInformation(@NotNull String guildID) * @throws UndefinedVariableException Thrown when a variable is undefined. * @throws TeaPotException Thrown when a variable is mismatched with its actual value. I.E. - Setting a boolean to "falfse" instead of "false" */ - @NotNull - public Boolean updateGuildInformation(@NotNull String guildID, @NotNull GuildInformationType type, @NotNull Object value) - throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException, TeaPotException { + public boolean updateGuildInformation(String guildID, GuildInformationType type, Object value) + throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException, TeaPotException { switch (type){ case PREFIX, MODERATOR_ROLE_ID, TWITCH_CHANNEL_ID, - MUTED_ROLE_ID, LIVE_NOTIFICATIONS_ROLE_ID, UPDATE_CHANNEL_ID, - COUNTING_CHANNEL_ID, POLL_CHANNEL_ID, RAFFLE_CHANNEL_ID, - BIRTHDAY_CHANNEL_ID, WELCOME_CHANNEL_ID, LOG_CHANNEL_ID, - VENTING_CHANNEL_ID, DAILY_CHANNEL_ID -> { + MUTED_ROLE_ID, LIVE_NOTIFICATIONS_ROLE_ID, UPDATE_CHANNEL_ID, + COUNTING_CHANNEL_ID, POLL_CHANNEL_ID, RAFFLE_CHANNEL_ID, + BIRTHDAY_CHANNEL_ID, WELCOME_CHANNEL_ID, LOG_CHANNEL_ID, + VENTING_CHANNEL_ID, DAILY_CHANNEL_ID -> { if (!value.getClass().equals(String.class)) { throw new TeaPotException(value + " is invalid for " + type); } @@ -136,7 +132,7 @@ public Boolean updateGuildInformation(@NotNull String guildID, @NotNull GuildInf .addParameter("type", type.getType()) .addParameter("value", value.toString()) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -148,13 +144,12 @@ public Boolean updateGuildInformation(@NotNull String guildID, @NotNull GuildInf * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull - public Boolean deleteGuildInformation(@NotNull String guildID) - throws AuthorizationException, ResponseException { + public boolean deleteGuildInformation(String guildID) + throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) .setRoute("/guilds/" + guildID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -164,8 +159,7 @@ public Boolean deleteGuildInformation(@NotNull String guildID) * @param guild The {@link JsonNode} to parse. * @return The parsed {@link GuildInformation}. */ - @NotNull - private GuildInformation parseGuildInformation(@NotNull JsonNode guild) { + private GuildInformation parseGuildInformation(JsonNode guild) { String prefix = guild.get(GuildInformationType.PREFIX.getType()).asText(); String moderatorRoleID = guild.get(GuildInformationType.MODERATOR_ROLE_ID.getType()).asText(); String twitchChannelID = guild.get(GuildInformationType.TWITCH_CHANNEL_ID.getType()).asText(); @@ -199,8 +193,7 @@ private GuildInformation parseGuildInformation(@NotNull JsonNode guild) { * @param string The specified {@link String}. * @return The parsed {@link Boolean}. False, by default, if there was an error. */ - @NotNull - private Boolean convertToBoolean(@NotNull String string) { + private boolean convertToBoolean(String string) { return string.equalsIgnoreCase("true") || string.equalsIgnoreCase("1"); } @@ -209,7 +202,8 @@ private Boolean convertToBoolean(@NotNull String string) { * @param apiKey The new {@link String apiKey}. */ @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/InteractionType.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/InteractionType.java index 1028231..9b55e6d 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/InteractionType.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/InteractionType.java @@ -1,9 +1,11 @@ package com.beanbeanjuice.cafeapi.cafebot.interactions; import com.beanbeanjuice.cafeapi.cafebot.interactions.users.Interaction; -import org.jetbrains.annotations.NotNull; +import lombok.Getter; import org.jetbrains.annotations.Nullable; +import java.util.Optional; + /** * An enum used for {@link Interaction Interaction} types. * @@ -11,82 +13,62 @@ * @since 1.3.1 */ public enum InteractionType { + HUG ("hug_amount", "hug"), + PUNCH ("punch_amount", "punch"), + KISS ("kiss_amount", "kiss"), + BITE ("bite_amount", "bite"), + BLUSH ("blush_amount", "blush"), + CUDDLE ("cuddle_amount", "cuddle"), + NOM ("nom_amount", "nom"), + POKE ("poke_amount", "poke"), + SLAP ("slap_amount", "slap"), + STAB ("stab_amount", null), + HMPH ("hmph_amount", null), + POUT ("pout_amount", "pout"), + THROW ("throw_amount", null), + SMILE ("smile_amount", "smile"), + STARE ("stare_amount", "stare"), + TICKLE ("tickle_amount", "tickle"), + RAGE ("rage_amount", null), + YELL ("yell_amount", "scream"), + HEADPAT ("headpat_amount", "pat"), + CRY ("cry_amount", "cry"), + DANCE ("dance_amount", "dance"), + DAB ("dab_amount", null), + BONK ("bonk_amount", null), + SLEEP ("sleep_amount", "sleepy"), + DIE ("die_amount", "die"), + WELCOME ("welcome_amount", null), + LICK ("lick_amount", "lick"), + SHUSH ("shush_amount", null), + WAVE ("wave_amount", "wave"), + SHOOT ("shoot_amount", "shoot"), + AMAZED ("amazed_amount", "amazing"), + ASK ("ask_amount", "ask"), + BOOP ("boop_amount", "boop"), + LOVE ("love_amount", "love"), + NOSEBLEED ("nosebleed_amount", "nosebleed"), + OK ("ok_amount", "ok"), + UWU ("uwu_amount", "uwu"), + WINK ("wink_amount", "wink"); - HUG ("hug_amount", true, "hug"), - PUNCH ("punch_amount", true, "punch"), - KISS ("kiss_amount", true, "kiss"), - BITE ("bite_amount", true, "bite"), - BLUSH ("blush_amount", true, "blush"), - CUDDLE ("cuddle_amount", true, "cuddle"), - NOM ("nom_amount", true, "nom"), - POKE ("poke_amount", true, "poke"), - SLAP ("slap_amount", true, "slap"), - STAB ("stab_amount", false, null), - HMPH ("hmph_amount", false, null), - POUT ("pout_amount", true, "pout"), - THROW ("throw_amount", false, null), - SMILE ("smile_amount", true, "smile"), - STARE ("stare_amount", true, "stare"), - TICKLE ("tickle_amount", true, "tickle"), - RAGE ("rage_amount", false, null), - YELL ("yell_amount", true, "scream"), - HEADPAT ("headpat_amount", true, "pat"), - CRY ("cry_amount", true, "cry"), - DANCE ("dance_amount", true, "dance"), - DAB ("dab_amount", false, null), - BONK ("bonk_amount", false, null), - SLEEP ("sleep_amount", true, "sleepy"), - DIE ("die_amount", false, null), - WELCOME ("welcome_amount", false, null), - LICK ("lick_amount", true, "lick"), - SHUSH ("shush_amount", false, null), - WAVE ("wave_amount", true, "wave"), - SHOOT ("shoot_amount", true, "shoot"), - AMAZED ("amazed_amount", true, "amazing"), - ASK ("ask_amount", true, "ask"), - BOOP ("boop_amount", true, "boop"), - LOVE ("love_amount", true, "love"), - NOSEBLEED ("nosebleed_amount", true, "nosebleed"), - OK ("ok_amount", true, "ok"), - UWU ("uwu_amount", true, "uwu"), - WINK ("wink_amount", true, "wink"); - - private final String type; - private final Boolean isKawaiiAPI; + @Getter private final String type; private final String kawaiiAPIString; /** * Creates a new {@link InteractionType} static object. * @param type The {@link String type} of {@link Interaction Interaction}. */ - InteractionType(@NotNull String type, @NotNull Boolean isKawaiiAPI, @Nullable String kawaiiAPIString) { + InteractionType(String type, @Nullable String kawaiiAPIString) { this.type = type; - this.isKawaiiAPI = isKawaiiAPI; this.kawaiiAPIString = kawaiiAPIString; } - /** - * @return Retrieves the {@link Interaction Interaction} type as a {@link String}. - */ - @NotNull - public String getType() { - return type; - } - - /** - * @return True, if the image should be returned from the {@link com.beanbeanjuice.KawaiiAPI KawaiiAPI}. - */ - @NotNull - public Boolean isKawaiiAPI() { - return isKawaiiAPI; - } - /** * @return The {@link String} for retrieving the {@link com.beanbeanjuice.KawaiiAPI KawaiiAPI} image. */ - @Nullable - public String getKawaiiAPIString() { - return kawaiiAPIString; + public Optional getKawaiiAPIString() { + return Optional.ofNullable(kawaiiAPIString); } } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/Interactions.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/Interactions.java index b1036a4..9438387 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/Interactions.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/Interactions.java @@ -8,7 +8,6 @@ import com.beanbeanjuice.cafeapi.requests.RequestRoute; import com.beanbeanjuice.cafeapi.requests.RequestType; import com.fasterxml.jackson.databind.JsonNode; -import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -25,7 +24,7 @@ public class Interactions implements com.beanbeanjuice.cafeapi.api.CafeAPI { * Creates a new {@link Interactions} API module. * @param apiKey The {@link String apiKey} used for authorization. */ - public Interactions(@NotNull String apiKey) { + public Interactions(String apiKey) { this.apiKey = apiKey; } @@ -35,7 +34,6 @@ public Interactions(@NotNull String apiKey) { * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull public HashMap getAllInteractionSenders() throws AuthorizationException, ResponseException { HashMap senders = new HashMap<>(); @@ -43,7 +41,7 @@ public HashMap getAllInteractionSenders() Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/interactions/senders") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode interactionSender : request.getData().get("interactions_sent")) { String userID = interactionSender.get("user_id").asText(); @@ -61,13 +59,12 @@ public HashMap getAllInteractionSenders() * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws NotFoundException Thrown when the specified {@link String userID} is not found in the {@link CafeAPI CafeAPI}. */ - @NotNull - public Interaction getUserInteractionsSent(@NotNull String userID) + public Interaction getUserInteractionsSent(String userID) throws AuthorizationException, ResponseException, NotFoundException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/interactions/senders/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return parseInteraction(request.getData().get("interactions_sent")); } @@ -82,14 +79,13 @@ public Interaction getUserInteractionsSent(@NotNull String userID) * @throws NotFoundException Thrown when the {@link String userID} is not found in the {@link CafeAPI CafeAPI}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Integer getSpecificUserInteractionSentAmount(@NotNull String userID, @NotNull InteractionType type) + public Integer getSpecificUserInteractionSentAmount(String userID, InteractionType type) throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/interactions/senders/" + userID) .addParameter("type", type.toString().toLowerCase()) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getData().get(type.getType()).asInt(); } @@ -98,22 +94,21 @@ public Integer getSpecificUserInteractionSentAmount(@NotNull String userID, @Not * Updates the {@link Interaction} sent amount of a specified {@link InteractionType} for a specified {@link String userID}. * @param userID The specified {@link String userID}. * @param type The specified {@link InteractionType type}. - * @param value The specified {@link Integer value} for the {@link InteractionType}. + * @param amount The specified {@link Integer amount} for the {@link InteractionType}. * @return True, if the {@link Interaction} was successfully updated for the {@link String userID}. * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws NotFoundException Thrown when the specified {@link String userID} is not found in the {@link CafeAPI CafeAPI}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean updateSpecificUserInteractionSentAmount(@NotNull String userID, @NotNull InteractionType type, @NotNull Integer value) + public Boolean updateSpecificUserInteractionSentAmount(String userID, InteractionType type, int amount) throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.PATCH) .setRoute("/interactions/senders/" + userID) .addParameter("type", type.toString().toLowerCase()) - .addParameter("value", value.toString()) + .addParameter("value", String.valueOf(amount)) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -126,13 +121,12 @@ public Boolean updateSpecificUserInteractionSentAmount(@NotNull String userID, @ * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws ConflictException Thrown when the specified {@link String userID} already exists in the {@link CafeAPI CafeAPI}. */ - @NotNull - public Boolean createUserInteractionsSent(@NotNull String userID) + public boolean createUserInteractionsSent(String userID) throws AuthorizationException, ResponseException, ConflictException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) .setRoute("/interactions/senders/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -144,13 +138,12 @@ public Boolean createUserInteractionsSent(@NotNull String userID) * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull - public Boolean deleteUserInteractionsSent(@NotNull String userID) + public boolean deleteUserInteractionsSent(String userID) throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) .setRoute("/interactions/senders/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -165,7 +158,6 @@ public Boolean deleteUserInteractionsSent(@NotNull String userID) * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull public HashMap getAllInteractionReceivers() throws AuthorizationException, ResponseException { HashMap receivers = new HashMap<>(); @@ -173,7 +165,7 @@ public HashMap getAllInteractionReceivers() Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/interactions/receivers") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode interactionReceiver : request.getData().get("interactions_received")) { String userID = interactionReceiver.get("user_id").asText(); @@ -191,13 +183,12 @@ public HashMap getAllInteractionReceivers() * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws NotFoundException Thrown when the specified {@link String userID} is not found in the {@link CafeAPI CafeAPI}. */ - @NotNull - public Interaction getUserInteractionsReceived(@NotNull String userID) + public Interaction getUserInteractionsReceived(String userID) throws AuthorizationException, ResponseException, NotFoundException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/interactions/receivers/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return parseInteraction(request.getData().get("interactions_received")); } @@ -212,14 +203,13 @@ public Interaction getUserInteractionsReceived(@NotNull String userID) * @throws NotFoundException Thrown when the {@link String userID} is not found in the {@link CafeAPI CafeAPI}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Integer getSpecificUserInteractionReceivedAmount(@NotNull String userID, @NotNull InteractionType type) + public Integer getSpecificUserInteractionReceivedAmount(String userID, InteractionType type) throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/interactions/receivers/" + userID) .addParameter("type", type.toString().toLowerCase()) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getData().get(type.getType()).asInt(); } @@ -228,22 +218,21 @@ public Integer getSpecificUserInteractionReceivedAmount(@NotNull String userID, * Updates the {@link Interaction} received amount of a specified {@link InteractionType} for a specified {@link String userID}. * @param userID The specified {@link String userID}. * @param type The specified {@link InteractionType type}. - * @param value The specified {@link Integer value} for the {@link InteractionType}. + * @param amount The specified {@link Integer amount} for the {@link InteractionType}. * @return True, if the {@link Interaction} was successfully updated for the {@link String userID}. * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws NotFoundException Thrown when the specified {@link String userID} is not found in the {@link CafeAPI CafeAPI}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean updateSpecificUserInteractionReceivedAmount(@NotNull String userID, @NotNull InteractionType type, @NotNull Integer value) + public Boolean updateSpecificUserInteractionReceivedAmount(String userID, InteractionType type, int amount) throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.PATCH) .setRoute("/interactions/receivers/" + userID) .addParameter("type", type.toString().toLowerCase()) - .addParameter("value", value.toString()) + .addParameter("value", String.valueOf(amount)) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -256,13 +245,12 @@ public Boolean updateSpecificUserInteractionReceivedAmount(@NotNull String userI * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws ConflictException Thrown when the specified {@link String userID} already exists in the {@link CafeAPI CafeAPI}. */ - @NotNull - public Boolean createUserInteractionsReceived(@NotNull String userID) + public boolean createUserInteractionsReceived(String userID) throws AuthorizationException, ResponseException, ConflictException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) .setRoute("/interactions/receivers/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -274,13 +262,12 @@ public Boolean createUserInteractionsReceived(@NotNull String userID) * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull - public Boolean deleteUserInteractionsReceived(@NotNull String userID) + public boolean deleteUserInteractionsReceived(String userID) throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) .setRoute("/interactions/receivers/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -290,46 +277,45 @@ public Boolean deleteUserInteractionsReceived(@NotNull String userID) * @param jsonNode The {@link JsonNode} to parse into an {@link Interaction}. * @return The parsed {@link Interaction}. */ - @NotNull - private Interaction parseInteraction(@NotNull JsonNode jsonNode) { - Integer hugAmount = jsonNode.get(InteractionType.HUG.getType()).asInt(); - Integer punchAmount = jsonNode.get(InteractionType.PUNCH.getType()).asInt(); - Integer kissAmount = jsonNode.get(InteractionType.KISS.getType()).asInt(); - Integer biteAmount = jsonNode.get(InteractionType.BITE.getType()).asInt(); - Integer blushAmount = jsonNode.get(InteractionType.BLUSH.getType()).asInt(); - Integer cuddleAmount = jsonNode.get(InteractionType.CUDDLE.getType()).asInt(); - Integer nomAmount = jsonNode.get(InteractionType.NOM.getType()).asInt(); - Integer pokeAmount = jsonNode.get(InteractionType.POKE.getType()).asInt(); - Integer slapAmount = jsonNode.get(InteractionType.SLAP.getType()).asInt(); - Integer stabAmount = jsonNode.get(InteractionType.STAB.getType()).asInt(); - Integer hmphAmount = jsonNode.get(InteractionType.HMPH.getType()).asInt(); - Integer poutAmount = jsonNode.get(InteractionType.POUT.getType()).asInt(); - Integer throwAmount = jsonNode.get(InteractionType.THROW.getType()).asInt(); - Integer smileAmount = jsonNode.get(InteractionType.SMILE.getType()).asInt(); - Integer stareAmount = jsonNode.get(InteractionType.STARE.getType()).asInt(); - Integer tickleAmount = jsonNode.get(InteractionType.TICKLE.getType()).asInt(); - Integer rageAmount = jsonNode.get(InteractionType.RAGE.getType()).asInt(); - Integer yellAmount = jsonNode.get(InteractionType.YELL.getType()).asInt(); - Integer headpatAmount = jsonNode.get(InteractionType.HEADPAT.getType()).asInt(); - Integer cryAmount = jsonNode.get(InteractionType.CRY.getType()).asInt(); - Integer danceAmount = jsonNode.get(InteractionType.DANCE.getType()).asInt(); - Integer dabAmount = jsonNode.get(InteractionType.DAB.getType()).asInt(); - Integer bonkAmount = jsonNode.get(InteractionType.BONK.getType()).asInt(); - Integer sleepAmount = jsonNode.get(InteractionType.SLEEP.getType()).asInt(); - Integer dieAmount = jsonNode.get(InteractionType.DIE.getType()).asInt(); - Integer welcomeAmount = jsonNode.get(InteractionType.WELCOME.getType()).asInt(); - Integer lickAmount = jsonNode.get(InteractionType.LICK.getType()).asInt(); - Integer shushAmount = jsonNode.get(InteractionType.SHUSH.getType()).asInt(); - Integer waveAmount = jsonNode.get(InteractionType.WAVE.getType()).asInt(); - Integer shootAmount = jsonNode.get(InteractionType.SHOOT.getType()).asInt(); - Integer amazedAmount = jsonNode.get(InteractionType.AMAZED.getType()).asInt(); - Integer askAmount = jsonNode.get(InteractionType.ASK.getType()).asInt(); - Integer boopAmount = jsonNode.get(InteractionType.BOOP.getType()).asInt(); - Integer loveAmount = jsonNode.get(InteractionType.LOVE.getType()).asInt(); - Integer nosebleedAmount = jsonNode.get(InteractionType.NOSEBLEED.getType()).asInt(); - Integer okAmount = jsonNode.get(InteractionType.OK.getType()).asInt(); - Integer uwuAmount = jsonNode.get(InteractionType.UWU.getType()).asInt(); - Integer winkAmount = jsonNode.get(InteractionType.WINK.getType()).asInt(); + private Interaction parseInteraction(JsonNode jsonNode) { + int hugAmount = jsonNode.get(InteractionType.HUG.getType()).asInt(); + int punchAmount = jsonNode.get(InteractionType.PUNCH.getType()).asInt(); + int kissAmount = jsonNode.get(InteractionType.KISS.getType()).asInt(); + int biteAmount = jsonNode.get(InteractionType.BITE.getType()).asInt(); + int blushAmount = jsonNode.get(InteractionType.BLUSH.getType()).asInt(); + int cuddleAmount = jsonNode.get(InteractionType.CUDDLE.getType()).asInt(); + int nomAmount = jsonNode.get(InteractionType.NOM.getType()).asInt(); + int pokeAmount = jsonNode.get(InteractionType.POKE.getType()).asInt(); + int slapAmount = jsonNode.get(InteractionType.SLAP.getType()).asInt(); + int stabAmount = jsonNode.get(InteractionType.STAB.getType()).asInt(); + int hmphAmount = jsonNode.get(InteractionType.HMPH.getType()).asInt(); + int poutAmount = jsonNode.get(InteractionType.POUT.getType()).asInt(); + int throwAmount = jsonNode.get(InteractionType.THROW.getType()).asInt(); + int smileAmount = jsonNode.get(InteractionType.SMILE.getType()).asInt(); + int stareAmount = jsonNode.get(InteractionType.STARE.getType()).asInt(); + int tickleAmount = jsonNode.get(InteractionType.TICKLE.getType()).asInt(); + int rageAmount = jsonNode.get(InteractionType.RAGE.getType()).asInt(); + int yellAmount = jsonNode.get(InteractionType.YELL.getType()).asInt(); + int headpatAmount = jsonNode.get(InteractionType.HEADPAT.getType()).asInt(); + int cryAmount = jsonNode.get(InteractionType.CRY.getType()).asInt(); + int danceAmount = jsonNode.get(InteractionType.DANCE.getType()).asInt(); + int dabAmount = jsonNode.get(InteractionType.DAB.getType()).asInt(); + int bonkAmount = jsonNode.get(InteractionType.BONK.getType()).asInt(); + int sleepAmount = jsonNode.get(InteractionType.SLEEP.getType()).asInt(); + int dieAmount = jsonNode.get(InteractionType.DIE.getType()).asInt(); + int welcomeAmount = jsonNode.get(InteractionType.WELCOME.getType()).asInt(); + int lickAmount = jsonNode.get(InteractionType.LICK.getType()).asInt(); + int shushAmount = jsonNode.get(InteractionType.SHUSH.getType()).asInt(); + int waveAmount = jsonNode.get(InteractionType.WAVE.getType()).asInt(); + int shootAmount = jsonNode.get(InteractionType.SHOOT.getType()).asInt(); + int amazedAmount = jsonNode.get(InteractionType.AMAZED.getType()).asInt(); + int askAmount = jsonNode.get(InteractionType.ASK.getType()).asInt(); + int boopAmount = jsonNode.get(InteractionType.BOOP.getType()).asInt(); + int loveAmount = jsonNode.get(InteractionType.LOVE.getType()).asInt(); + int nosebleedAmount = jsonNode.get(InteractionType.NOSEBLEED.getType()).asInt(); + int okAmount = jsonNode.get(InteractionType.OK.getType()).asInt(); + int uwuAmount = jsonNode.get(InteractionType.UWU.getType()).asInt(); + int winkAmount = jsonNode.get(InteractionType.WINK.getType()).asInt(); return new Interaction( hugAmount, punchAmount, kissAmount, @@ -353,7 +339,8 @@ private Interaction parseInteraction(@NotNull JsonNode jsonNode) { * @param apiKey The new {@link String apiKey}. */ @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/pictures/InteractionPictures.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/pictures/InteractionPictures.java index 60fc7af..6be1558 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/pictures/InteractionPictures.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/pictures/InteractionPictures.java @@ -11,7 +11,8 @@ import com.beanbeanjuice.cafeapi.exception.api.ResponseException; import com.beanbeanjuice.cafeapi.exception.api.TeaPotException; import com.beanbeanjuice.cafeapi.exception.api.CafeException; -import org.jetbrains.annotations.NotNull; + +import java.util.Optional; /** * A class used to retrieve random pictures from the {@link CafeAPI CafeAPI}. @@ -28,7 +29,7 @@ public class InteractionPictures implements com.beanbeanjuice.cafeapi.api.CafeAP * Creates a new {@link InteractionPictures} object. * @param apiKey The {@link String apiKey} used for authorization. */ - public InteractionPictures(@NotNull String apiKey, @NotNull CafeAPI cafeAPI) { + public InteractionPictures(String apiKey, CafeAPI cafeAPI) { this.apiKey = apiKey; this.cafeAPI = cafeAPI; } @@ -41,19 +42,18 @@ public InteractionPictures(@NotNull String apiKey, @NotNull CafeAPI cafeAPI) { * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. * @throws TeaPotException Thrown when an invalid {@link InteractionType} is entered. */ - @NotNull - public String getRandomInteractionPicture(@NotNull InteractionType type) + public String getRandomInteractionPicture(InteractionType type) throws AuthorizationException, ResponseException, TeaPotException { - if (type.isKawaiiAPI()) { - return cafeAPI.KAWAII_API.GIF.getGIF(type.getKawaiiAPIString()); - } else { - Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) - .setRoute("/interaction_pictures/" + type) - .setAuthorization(apiKey) - .build(); + Optional potentialString = type.getKawaiiAPIString(); + + if (potentialString.isPresent()) return cafeAPI.KAWAII_API.GIF.getGIF(potentialString.get()); - return request.getData().get("url").asText(); - } + Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) + .setRoute("/interaction_pictures/" + type) + .setAuthorization(apiKey) + .build().orElseThrow(); + + return request.getData().get("url").asText(); } /** @@ -61,7 +61,8 @@ public String getRandomInteractionPicture(@NotNull InteractionType type) * @param apiKey The new {@link String apiKey}. */ @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/users/Interaction.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/users/Interaction.java index 0ac091d..0ec5f2e 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/users/Interaction.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/interactions/users/Interaction.java @@ -1,52 +1,54 @@ package com.beanbeanjuice.cafeapi.cafebot.interactions.users; -import org.jetbrains.annotations.NotNull; +import lombok.Getter; /** * A class used to hold {@link Interaction} information. * * @author beanbeanjuice */ +@Getter public class Interaction { - private final Integer hugAmount; - private final Integer punchAmount; - private final Integer kissAmount; - private final Integer biteAmount; - private final Integer blushAmount; - private final Integer cuddleAmount; - private final Integer nomAmount; - private final Integer pokeAmount; - private final Integer slapAmount; - private final Integer stabAmount; - private final Integer hmphAmount; - private final Integer poutAmount; - private final Integer throwAmount; - private final Integer smileAmount; - private final Integer stareAmount; - private final Integer tickleAmount; - private final Integer rageAmount; - private final Integer yellAmount; - private final Integer headpatAmount; - private final Integer cryAmount; - private final Integer danceAmount; - private final Integer dabAmount; - private final Integer bonkAmount; - private final Integer sleepAmount; - private final Integer dieAmount; - private final Integer welcomeAmount; - private final Integer lickAmount; - private final Integer shushAmount; - private final Integer waveAmount; - private final Integer shootAmount; - private final Integer amazedAmount; - private final Integer askAmount; - private final Integer boopAmount; - private final Integer loveAmount; - private final Integer nosebleedAmount; - private final Integer okAmount; - private final Integer uwuAmount; - private final Integer winkAmount; + // TODO: Switch to a hash map jesus christ. + private final int hugAmount; + private final int punchAmount; + private final int kissAmount; + private final int biteAmount; + private final int blushAmount; + private final int cuddleAmount; + private final int nomAmount; + private final int pokeAmount; + private final int slapAmount; + private final int stabAmount; + private final int hmphAmount; + private final int poutAmount; + private final int throwAmount; + private final int smileAmount; + private final int stareAmount; + private final int tickleAmount; + private final int rageAmount; + private final int yellAmount; + private final int headpatAmount; + private final int cryAmount; + private final int danceAmount; + private final int dabAmount; + private final int bonkAmount; + private final int sleepAmount; + private final int dieAmount; + private final int welcomeAmount; + private final int lickAmount; + private final int shushAmount; + private final int waveAmount; + private final int shootAmount; + private final int amazedAmount; + private final int askAmount; + private final int boopAmount; + private final int loveAmount; + private final int nosebleedAmount; + private final int okAmount; + private final int UWUAmount; + private final int winkAmount; /** * Creates a new {@link Interaction object.} @@ -86,22 +88,22 @@ public class Interaction { * @param loveAmount The {@link Integer loveAmount}. * @param nosebleedAmount The {@link Integer nosebleedAmount}. * @param okAmount The {@link Integer okAmount}. - * @param uwuAmount The {@link Integer uwuAmount}. + * @param UWUAmount The {@link Integer uwuAmount}. * @param winkAmount The {@link Integer winkAmount}. */ - public Interaction(Integer hugAmount, Integer punchAmount, Integer kissAmount, - Integer biteAmount, Integer blushAmount, Integer cuddleAmount, - Integer nomAmount, Integer pokeAmount, Integer slapAmount, - Integer stabAmount, Integer hmphAmount, Integer poutAmount, - Integer throwAmount, Integer smileAmount, Integer stareAmount, - Integer tickleAmount, Integer rageAmount, Integer yellAmount, - Integer headpatAmount, Integer cryAmount, Integer danceAmount, - Integer dabAmount, Integer bonkAmount, Integer sleepAmount, - Integer dieAmount, Integer welcomeAmount, Integer lickAmount, - Integer shushAmount, Integer waveAmount, Integer shootAmount, - Integer amazedAmount, Integer askAmount, Integer boopAmount, - Integer loveAmount, Integer nosebleedAmount, Integer okAmount, - Integer uwuAmount, Integer winkAmount) { + public Interaction(int hugAmount, int punchAmount, int kissAmount, + int biteAmount, int blushAmount, int cuddleAmount, + int nomAmount, int pokeAmount, int slapAmount, + int stabAmount, int hmphAmount, int poutAmount, + int throwAmount, int smileAmount, int stareAmount, + int tickleAmount, int rageAmount, int yellAmount, + int headpatAmount, int cryAmount, int danceAmount, + int dabAmount, int bonkAmount, int sleepAmount, + int dieAmount, int welcomeAmount, int lickAmount, + int shushAmount, int waveAmount, int shootAmount, + int amazedAmount, int askAmount, int boopAmount, + int loveAmount, int nosebleedAmount, int okAmount, + int UWUAmount, int winkAmount) { this.hugAmount = hugAmount; this.punchAmount = punchAmount; this.kissAmount = kissAmount; @@ -138,311 +140,8 @@ public Interaction(Integer hugAmount, Integer punchAmount, Integer kissAmount, this.loveAmount = loveAmount; this.nosebleedAmount = nosebleedAmount; this.okAmount = okAmount; - this.uwuAmount = uwuAmount; + this.UWUAmount = UWUAmount; this.winkAmount = winkAmount; } - /** - * @return The {@link Interaction} {@link Integer hugAmount}. - */ - @NotNull - public Integer getHugAmount() { - return hugAmount; - } - - /** - * @return The {@link Interaction} {@link Integer punchAmount}. - */ - @NotNull - public Integer getPunchAmount() { - return punchAmount; - } - - /** - * @return The {@link Interaction} {@link Integer kissAmount}. - */ - @NotNull - public Integer getKissAmount() { - return kissAmount; - } - - /** - * @return The {@link Interaction} {@link Integer biteAmount}. - */ - @NotNull - public Integer getBiteAmount() { - return biteAmount; - } - - /** - * @return The {@link Interaction} {@link Integer blushAmount}. - */ - @NotNull - public Integer getBlushAmount() { - return blushAmount; - } - - /** - * @return The {@link Interaction} {@link Integer cuddleAmount}. - */ - @NotNull - public Integer getCuddleAmount() { - return cuddleAmount; - } - - /** - * @return The {@link Interaction} {@link Integer nomAmount}. - */ - @NotNull - public Integer getNomAmount() { - return nomAmount; - } - - /** - * @return The {@link Interaction} {@link Integer pokeAmount}. - */ - @NotNull - public Integer getPokeAmount() { - return pokeAmount; - } - - /** - * @return The {@link Interaction} {@link Integer slapAmount}. - */ - @NotNull - public Integer getSlapAmount() { - return slapAmount; - } - - /** - * @return The {@link Interaction} {@link Integer stabAmount}. - */ - @NotNull - public Integer getStabAmount() { - return stabAmount; - } - - /** - * @return The {@link Interaction} {@link Integer hmphAmount}. - */ - @NotNull - public Integer getHmphAmount() { - return hmphAmount; - } - - /** - * @return The {@link Interaction} {@link Integer poutAmount}. - */ - @NotNull - public Integer getPoutAmount() { - return poutAmount; - } - - /** - * @return The {@link Interaction} {@link Integer throwAmount}. - */ - @NotNull - public Integer getThrowAmount() { - return throwAmount; - } - - /** - * @return The {@link Interaction} {@link Integer smileAmount}. - */ - @NotNull - public Integer getSmileAmount() { - return smileAmount; - } - - /** - * @return The {@link Interaction} {@link Integer stareAmount}. - */ - @NotNull - public Integer getStareAmount() { - return stareAmount; - } - - /** - * @return The {@link Interaction} {@link Integer tickleAmount}. - */ - @NotNull - public Integer getTickleAmount() { - return tickleAmount; - } - - /** - * @return The {@link Interaction} {@link Integer rageAmount}. - */ - @NotNull - public Integer getRageAmount() { - return rageAmount; - } - - /** - * @return The {@link Interaction} {@link Integer yellAmount}. - */ - @NotNull - public Integer getYellAmount() { - return yellAmount; - } - - /** - * @return The {@link Interaction} {@link Integer headpatAmount}. - */ - @NotNull - public Integer getHeadpatAmount() { - return headpatAmount; - } - - /** - * @return The {@link Interaction} {@link Integer cryAmount}. - */ - @NotNull - public Integer getCryAmount() { - return cryAmount; - } - - /** - * @return The {@link Interaction} {@link Integer danceAmount}. - */ - @NotNull - public Integer getDanceAmount() { - return danceAmount; - } - - /** - * @return The {@link Interaction} {@link Integer dabAmount}. - */ - @NotNull - public Integer getDabAmount() { - return dabAmount; - } - - /** - * @return The {@link Interaction} {@link Integer bonkAmount}. - */ - @NotNull - public Integer getBonkAmount() { - return bonkAmount; - } - - /** - * @return The {@link Interaction} {@link Integer sleepAmount}. - */ - @NotNull - public Integer getSleepAmount() { - return sleepAmount; - } - - /** - * @return The {@link Interaction} {@link Integer dieAmount}. - */ - @NotNull - public Integer getDieAmount() { - return dieAmount; - } - - /** - * @return The {@link Interaction} {@link Integer welcomeAmount}. - */ - @NotNull - public Integer getWelcomeAmount() { - return welcomeAmount; - } - - /** - * @return The {@link Interaction} {@link Integer lickAmount}. - */ - @NotNull - public Integer getLickAmount() { - return lickAmount; - } - - /** - * @return The {@link Interaction} {@link Integer shushAmount}. - */ - @NotNull - public Integer getShushAmount() { - return shushAmount; - } - - /** - * @return The {@link Interaction} {@link Integer waveAmount}. - */ - @NotNull - public Integer getWaveAmount() { - return waveAmount; - } - - /** - * @return The {@link Interaction} {@link Integer shootAmount}. - */ - @NotNull - public Integer getShootAmount() { - return shootAmount; - } - - /** - * @return The {@link Interaction} {@link Integer amazedAmount}. - */ - @NotNull - public Integer getAmazedAmount() { - return amazedAmount; - } - - /** - * @return The {@link Interaction} {@link Integer askAmount}. - */ - @NotNull - public Integer getAskAmount() { - return askAmount; - } - - /** - * @return The {@link Interaction} {@link Integer boopAmount}. - */ - @NotNull - public Integer getBoopAmount() { - return boopAmount; - } - - /** - * @return The {@link Interaction} {@link Integer loveAmount}. - */ - @NotNull - public Integer getLoveAmount() { - return loveAmount; - } - - /** - * @return The {@link Interaction} {@link Integer nosebleedAmount}. - */ - @NotNull - public Integer getNosebleedAmount() { - return nosebleedAmount; - } - - /** - * @return The {@link Interaction} {@link Integer okAmount}. - */ - @NotNull - public Integer getOKAmount() { - return okAmount; - } - - /** - * @return The {@link Interaction} {@link Integer uwuAmount}. - */ - @NotNull - public Integer getUWUAmount() { - return uwuAmount; - } - - /** - * @return The {@link Interaction} {@link Integer winkAmount}. - */ - @NotNull - public Integer getWinkAmount() { - return winkAmount; - } } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/minigames/winstreaks/MinigameType.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/minigames/winstreaks/MinigameType.java index ecef92d..1140686 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/minigames/winstreaks/MinigameType.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/minigames/winstreaks/MinigameType.java @@ -1,7 +1,5 @@ package com.beanbeanjuice.cafeapi.cafebot.minigames.winstreaks; -import org.jetbrains.annotations.NotNull; - /** * An enum used for Minigame {@link WinStreak} types. * @@ -18,14 +16,13 @@ public enum MinigameType { * Creates a {@link MinigameType} enum. * @param type The {@link String type} of enum. */ - MinigameType(@NotNull String type) { + MinigameType(String type) { this.type = type; } /** * @return The {@link String type} of {@link MinigameType}. */ - @NotNull public String getType() { return type; } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/minigames/winstreaks/WinStreak.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/minigames/winstreaks/WinStreak.java index 483195b..0935c82 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/minigames/winstreaks/WinStreak.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/minigames/winstreaks/WinStreak.java @@ -1,6 +1,6 @@ package com.beanbeanjuice.cafeapi.cafebot.minigames.winstreaks; -import org.jetbrains.annotations.NotNull; +import lombok.Getter; /** * A class used for a user's {@link WinStreak}. @@ -9,32 +9,17 @@ */ public class WinStreak { - private final Integer ticTacToeWins; - private final Integer connectFourWins; + @Getter private final int ticTacToeWins; + @Getter private final int connectFourWins; /** * Creates a new {@link WinStreak}. * @param ticTacToeWins The {@link Integer amount} of {@link MinigameType TIC_TAC_TOE} wins. * @param connectFourWins The {@link Integer amount} of {@link MinigameType CONNECT_FOUR} wins. */ - public WinStreak(@NotNull Integer ticTacToeWins, @NotNull Integer connectFourWins) { + public WinStreak(int ticTacToeWins, int connectFourWins) { this.ticTacToeWins = ticTacToeWins; this.connectFourWins = connectFourWins; } - /** - * @return The {@link Integer amount} of {@link MinigameType TIC_TAC_TOE} wins. - */ - @NotNull - public Integer getTicTacToeWins() { - return ticTacToeWins; - } - - /** - * @return The {@link Integer amount} of {@link MinigameType CONNECT_FOUR} wins. - */ - @NotNull - public Integer getConnectFourWins() { - return connectFourWins; - } } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/minigames/winstreaks/WinStreaks.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/minigames/winstreaks/WinStreaks.java index 2caf673..85c3a19 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/minigames/winstreaks/WinStreaks.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/minigames/winstreaks/WinStreaks.java @@ -7,7 +7,6 @@ import com.beanbeanjuice.cafeapi.requests.RequestRoute; import com.beanbeanjuice.cafeapi.requests.RequestType; import com.fasterxml.jackson.databind.JsonNode; -import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -24,7 +23,7 @@ public class WinStreaks implements CafeAPI { * Creates a new {@link WinStreaks} object. * @param apiKey The {@link String apiKey} used for authorization. */ - public WinStreaks(@NotNull String apiKey) { + public WinStreaks(String apiKey) { this.apiKey = apiKey; } @@ -41,7 +40,7 @@ public HashMap getAllWinStreaks() Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/minigames/win_streaks") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode winStreak : request.getData().get("win_streaks")) { String userID = winStreak.get("user_id").asText(); @@ -61,17 +60,16 @@ public HashMap getAllWinStreaks() * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws NotFoundException Thrown when the specified {@link String userID}'s {@link WinStreak} does not exist. */ - @NotNull - public WinStreak getUserWinStreak(@NotNull String userID) + public WinStreak getUserWinStreak(String userID) throws AuthorizationException, ResponseException, NotFoundException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/minigames/win_streaks/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); JsonNode winStreak = request.getData().get("win_streaks"); - Integer ticTacToeWins = winStreak.get("tic_tac_toe").asInt(); - Integer connectFourWins = winStreak.get("connect_four").asInt(); + int ticTacToeWins = winStreak.get("tic_tac_toe").asInt(); + int connectFourWins = winStreak.get("connect_four").asInt(); return new WinStreak(ticTacToeWins, connectFourWins); } @@ -80,22 +78,21 @@ public WinStreak getUserWinStreak(@NotNull String userID) * Updates a Discord user's {@link WinStreak}. * @param userID The {@link String userID} of the Discord user. * @param type The {@link MinigameType type} of {@link WinStreak} to update. - * @param value The {@link Integer value} of {@link MinigameType type} to set the {@link WinStreak} to. + * @param winstreak The {@link Integer winstreak} of {@link MinigameType type} to set the {@link WinStreak} to. * @return True, if the {@link WinStreak} was successfully updated. * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. * @throws NotFoundException Thrown when the {@link WinStreak} for the specified {@link String userID} does not exist. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean updateUserWinStreak(@NotNull String userID, @NotNull MinigameType type, @NotNull Integer value) + public boolean updateUserWinStreak(String userID, MinigameType type, int winstreak) throws AuthorizationException, ResponseException, NotFoundException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.PATCH) .setRoute("/minigames/win_streaks/" + userID) .addParameter("type", type.getType()) - .addParameter("value", value.toString()) + .addParameter("value", String.valueOf(winstreak)) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -109,13 +106,12 @@ public Boolean updateUserWinStreak(@NotNull String userID, @NotNull MinigameType * @throws ConflictException Thrown when the specified {@link String userID} already exists. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean createUserWinStreak(@NotNull String userID) + public boolean createUserWinStreak(String userID) throws AuthorizationException, ResponseException, ConflictException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) .setRoute("/minigames/win_streaks/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -127,13 +123,12 @@ public Boolean createUserWinStreak(@NotNull String userID) * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException}. */ - @NotNull - public Boolean deleteUserWinStreak(@NotNull String userID) + public boolean deleteUserWinStreak(String userID) throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) .setRoute("/minigames/win_streaks/" + userID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -143,7 +138,8 @@ public Boolean deleteUserWinStreak(@NotNull String userID) * @param apiKey The new {@link String apikey}. */ @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/polls/Poll.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/polls/Poll.java index fe65080..8c06609 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/polls/Poll.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/polls/Poll.java @@ -1,6 +1,6 @@ package com.beanbeanjuice.cafeapi.cafebot.polls; -import org.jetbrains.annotations.NotNull; +import lombok.Getter; import java.sql.Timestamp; @@ -11,32 +11,17 @@ */ public class Poll { - private final String messageID; - private final Timestamp endingTime; + @Getter private final String messageID; + @Getter private final Timestamp endingTime; /** * Creates a new {@link Poll} object. * @param messageID The {@link String messageID} of the {@link Poll}. * @param endingTime The {@link Timestamp endingTime} of the {@link Poll}. UTC Timezone. */ - public Poll(@NotNull String messageID, @NotNull Timestamp endingTime) { + public Poll(String messageID, Timestamp endingTime) { this.messageID = messageID; this.endingTime = endingTime; } - /** - * @return The {@link String messageID} of the {@link Poll}. - */ - @NotNull - public String getMessageID() { - return messageID; - } - - /** - * @return The {@link Timestamp endingTime} of the {@link Poll}. UTC Timezone. - */ - @NotNull - public Timestamp getEndingTime() { - return endingTime; - } } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/polls/Polls.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/polls/Polls.java index fc2bdcd..90c04d5 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/polls/Polls.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/polls/Polls.java @@ -12,7 +12,6 @@ import com.beanbeanjuice.cafeapi.exception.api.ResponseException; import com.beanbeanjuice.cafeapi.exception.api.UndefinedVariableException; import com.beanbeanjuice.cafeapi.exception.api.CafeException; -import org.jetbrains.annotations.NotNull; import java.sql.Timestamp; import java.util.ArrayList; @@ -31,7 +30,7 @@ public class Polls implements com.beanbeanjuice.cafeapi.api.CafeAPI { * Creates a new {@link Polls} object. * @param apiKey The {@link String apiKey} used for authorization. */ - public Polls(@NotNull String apiKey) { + public Polls(String apiKey) { this.apiKey = apiKey; } @@ -41,7 +40,6 @@ public Polls(@NotNull String apiKey) { * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. */ - @NotNull public HashMap> getAllPolls() throws AuthorizationException, ResponseException { HashMap> polls = new HashMap<>(); @@ -49,12 +47,12 @@ public HashMap> getAllPolls() Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/polls") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode poll : request.getData().get("polls")) { String guildID = poll.get("guild_id").asText(); String messageID = poll.get("message_id").asText(); - Timestamp endingTime = CafeGeneric.parseTimestampFromAPI(poll.get("ending_time").asText()); + Timestamp endingTime = CafeGeneric.parseTimestampFromAPI(poll.get("ending_time").asText()).orElse(null); if (!polls.containsKey(guildID)) { polls.put(guildID, new ArrayList<>()); @@ -73,19 +71,18 @@ public HashMap> getAllPolls() * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. */ - @NotNull - public ArrayList getGuildPolls(@NotNull String guildID) + public ArrayList getGuildPolls(String guildID) throws AuthorizationException, ResponseException { ArrayList polls = new ArrayList<>(); Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/polls/" + guildID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode poll : request.getData().get("polls")) { String messageID = poll.get("message_id").asText(); - Timestamp endingTime = CafeGeneric.parseTimestampFromAPI(poll.get("ending_time").asText()); + Timestamp endingTime = CafeGeneric.parseTimestampFromAPI(poll.get("ending_time").asText()).orElse(null); polls.add(new Poll(messageID, endingTime)); } @@ -103,15 +100,14 @@ public ArrayList getGuildPolls(@NotNull String guildID) * @throws ConflictException Thrown when the {@link Poll} already exists for the specified {@link String guildID}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean createPoll(@NotNull String guildID, @NotNull Poll poll) + public boolean createPoll(String guildID, Poll poll) throws AuthorizationException, ResponseException, ConflictException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) .setRoute("/polls/" + guildID) .addParameter("message_id", poll.getMessageID()) .addParameter("ending_time", poll.getEndingTime().toString()) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -122,8 +118,7 @@ public Boolean createPoll(@NotNull String guildID, @NotNull Poll poll) * @param poll The {@link Poll} to remove from the {@link CafeAPI CafeAPI}. * @return True, if the {@link Poll} was successfully removed from the {@link CafeAPI CafeAPI}. */ - @NotNull - public Boolean deletePoll(@NotNull String guildID, @NotNull Poll poll) { + public boolean deletePoll(String guildID, Poll poll) { return deletePoll(guildID, poll.getMessageID()); } @@ -136,14 +131,13 @@ public Boolean deletePoll(@NotNull String guildID, @NotNull Poll poll) { * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean deletePoll(@NotNull String guildID, @NotNull String messageID) + public boolean deletePoll(String guildID, String messageID) throws AuthorizationException, ResponseException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) .setRoute("/polls/" + guildID) .addParameter("message_id", messageID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -153,7 +147,8 @@ public Boolean deletePoll(@NotNull String guildID, @NotNull String messageID) * @param apiKey The new {@link String apiKey}. */ @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/raffles/Raffle.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/raffles/Raffle.java index 8324a90..7cbb8b7 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/raffles/Raffle.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/raffles/Raffle.java @@ -1,7 +1,7 @@ package com.beanbeanjuice.cafeapi.cafebot.raffles; import com.beanbeanjuice.cafeapi.CafeAPI; -import org.jetbrains.annotations.NotNull; +import lombok.Getter; import java.sql.Timestamp; @@ -12,9 +12,9 @@ */ public class Raffle { - private final String messageID; - private final Timestamp endingTime; - private final Integer winnerAmount; + @Getter private final String messageID; + @Getter private final Timestamp endingTime; + @Getter private final Integer winnerAmount; /** * Creates a new {@link Raffle} object. @@ -22,33 +22,10 @@ public class Raffle { * @param endingTime The {@link Timestamp endingTime} of the {@link Raffle}. UTC timezone. * @param winnerAmount The {@link Integer winnerAmount} of the {@link Raffle}. */ - public Raffle(@NotNull String messageID, @NotNull Timestamp endingTime, @NotNull Integer winnerAmount) { + public Raffle(String messageID, Timestamp endingTime, Integer winnerAmount) { this.messageID = messageID; this.endingTime = endingTime; this.winnerAmount = winnerAmount; } - /** - * @return The {@link String messageID} of the {@link Raffle}. - */ - @NotNull - public String getMessageID() { - return messageID; - } - - /** - * @return The {@link Timestamp endingTime} of the {@link Raffle}. UTC timezone. - */ - @NotNull - public Timestamp getEndingTime() { - return endingTime; - } - - /** - * @return The {@link Integer winnerAmount} of the {@link Raffle}. - */ - @NotNull - public Integer getWinnerAmount() { - return winnerAmount; - } } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/raffles/Raffles.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/raffles/Raffles.java index 900f327..89b6516 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/raffles/Raffles.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/raffles/Raffles.java @@ -12,7 +12,6 @@ import com.beanbeanjuice.cafeapi.exception.api.ResponseException; import com.beanbeanjuice.cafeapi.exception.api.UndefinedVariableException; import com.beanbeanjuice.cafeapi.exception.api.CafeException; -import org.jetbrains.annotations.NotNull; import java.sql.Timestamp; import java.util.ArrayList; @@ -31,7 +30,7 @@ public class Raffles implements com.beanbeanjuice.cafeapi.api.CafeAPI { * Creates the {@link Raffles} module for the {@link CafeAPI CafeAPI}. * @param apiKey The authorization {@link String apiKey}. */ - public Raffles(@NotNull String apiKey) { + public Raffles(String apiKey) { this.apiKey = apiKey; } @@ -41,7 +40,6 @@ public Raffles(@NotNull String apiKey) { * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. */ - @NotNull public HashMap> getAllRaffles() throws AuthorizationException, ResponseException { HashMap> raffles = new HashMap<>(); @@ -49,12 +47,12 @@ public HashMap> getAllRaffles() Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/raffles") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode raffle : request.getData().get("raffles")) { String guildID = raffle.get("guild_id").asText(); String messageID = raffle.get("message_id").asText(); - Timestamp endingTime = CafeGeneric.parseTimestampFromAPI(raffle.get("ending_time").asText()); + Timestamp endingTime = CafeGeneric.parseTimestampFromAPI(raffle.get("ending_time").asText()).orElse(null); Integer winnerAmount = raffle.get("winner_amount").asInt(); if (!raffles.containsKey(guildID)) { @@ -74,19 +72,18 @@ public HashMap> getAllRaffles() * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. */ - @NotNull - public ArrayList getGuildRaffles(@NotNull String guildID) + public ArrayList getGuildRaffles(String guildID) throws AuthorizationException, ResponseException { ArrayList raffles = new ArrayList<>(); Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/raffles/" + guildID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode raffle : request.getData().get("raffles")) { String messageID = raffle.get("message_id").asText(); - Timestamp endingTime = CafeGeneric.parseTimestampFromAPI(raffle.get("ending_time").asText()); + Timestamp endingTime = CafeGeneric.parseTimestampFromAPI(raffle.get("ending_time").asText()).orElse(null); Integer winnerAmount = raffle.get("winner_amount").asInt(); raffles.add(new Raffle(messageID, endingTime, winnerAmount)); @@ -105,8 +102,7 @@ public ArrayList getGuildRaffles(@NotNull String guildID) * @throws UndefinedVariableException Thrown when a variable is undefined. * @throws ConflictException Thrown when the {@link Raffle} already exists for the specified {@link String guildID}. */ - @NotNull - public Boolean createRaffle(@NotNull String guildID, @NotNull Raffle raffle) + public boolean createRaffle(String guildID, Raffle raffle) throws AuthorizationException, ResponseException, UndefinedVariableException, ConflictException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) .setRoute("/raffles/" + guildID) @@ -114,7 +110,7 @@ public Boolean createRaffle(@NotNull String guildID, @NotNull Raffle raffle) .addParameter("ending_time", raffle.getEndingTime().toString()) .addParameter("winner_amount", raffle.getWinnerAmount().toString()) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -128,8 +124,7 @@ public Boolean createRaffle(@NotNull String guildID, @NotNull Raffle raffle) * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean deleteRaffle(@NotNull String guildID, @NotNull Raffle raffle) + public boolean deleteRaffle(String guildID, Raffle raffle) throws AuthorizationException, ResponseException, UndefinedVariableException { return deleteRaffle(guildID, raffle.getMessageID()); } @@ -143,14 +138,13 @@ public Boolean deleteRaffle(@NotNull String guildID, @NotNull Raffle raffle) * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean deleteRaffle(@NotNull String guildID, @NotNull String messageID) + public boolean deleteRaffle(String guildID, String messageID) throws AuthorizationException, ResponseException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) .setRoute("/raffles/" + guildID) .addParameter("message_id", messageID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -160,7 +154,8 @@ public Boolean deleteRaffle(@NotNull String guildID, @NotNull String messageID) * @param apiKey The {@link String apiKey} to update the current one to. */ @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/twitches/GuildTwitches.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/twitches/GuildTwitches.java index 41d6222..8cecc2c 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/twitches/GuildTwitches.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/twitches/GuildTwitches.java @@ -13,7 +13,6 @@ import com.beanbeanjuice.cafeapi.exception.api.ResponseException; import com.beanbeanjuice.cafeapi.exception.api.UndefinedVariableException; import com.beanbeanjuice.cafeapi.exception.api.CafeException; -import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.HashMap; @@ -31,7 +30,7 @@ public class GuildTwitches implements com.beanbeanjuice.cafeapi.api.CafeAPI { * Creates a new {@link GuildTwitches} object. * @param apiKey The {@link String apiKey} used for authorization. */ - public GuildTwitches(@NotNull String apiKey) { + public GuildTwitches(String apiKey) { this.apiKey = apiKey; } @@ -41,7 +40,6 @@ public GuildTwitches(@NotNull String apiKey) { * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. */ - @NotNull public HashMap> getAllTwitches() throws AuthorizationException, ResponseException { HashMap> twitches = new HashMap<>(); @@ -49,7 +47,7 @@ public HashMap> getAllTwitches() Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/guilds/twitch") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode guildTwitch : request.getData().get("guilds_twitch")) { String guildID = guildTwitch.get("guild_id").asText(); @@ -72,13 +70,12 @@ public HashMap> getAllTwitches() * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. */ - @NotNull - public ArrayList getGuildTwitches(@NotNull String guildID) + public ArrayList getGuildTwitches(String guildID) throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/guilds/twitch/" + guildID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); try { return new ObjectMapper().readValue(request.getData().get("twitch_channels").toString(), ArrayList.class); @@ -98,14 +95,13 @@ public ArrayList getGuildTwitches(@NotNull String guildID) * @throws ConflictException Thrown when the {@link String twitchChannelName} already exists for the specified {@link String guildID}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean addGuildTwitch(@NotNull String guildID, @NotNull String twitchChannelName) + public boolean addGuildTwitch(String guildID, String twitchChannelName) throws AuthorizationException, ResponseException, ConflictException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) .setRoute("/guilds/twitch/" + guildID) .addParameter("twitch_channel", twitchChannelName) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -119,14 +115,13 @@ public Boolean addGuildTwitch(@NotNull String guildID, @NotNull String twitchCha * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean removeGuildTwitch(@NotNull String guildID, @NotNull String twitchChannelName) + public boolean removeGuildTwitch(String guildID, String twitchChannelName) throws AuthorizationException, ResponseException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) .setRoute("/guilds/twitch/" + guildID) .addParameter("twitch_channel", twitchChannelName) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -136,7 +131,8 @@ public Boolean removeGuildTwitch(@NotNull String guildID, @NotNull String twitch * @param apiKey The new {@link String apiKey}. */ @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/version/Versions.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/version/Versions.java index 5da6b63..bdece6b 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/version/Versions.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/version/Versions.java @@ -10,7 +10,6 @@ import com.beanbeanjuice.cafeapi.exception.api.TeaPotException; import com.beanbeanjuice.cafeapi.exception.api.UndefinedVariableException; import com.beanbeanjuice.cafeapi.exception.api.CafeException; -import org.jetbrains.annotations.NotNull; /** * A class used for handling CafeBot {@link Versions} in the {@link CafeAPI CafeAPI}. @@ -25,7 +24,7 @@ public class Versions implements com.beanbeanjuice.cafeapi.api.CafeAPI { * Creates a new {@link Versions} object. * @param apiKey The {@link String apiKey} used for authorization. */ - public Versions(@NotNull String apiKey) { + public Versions(String apiKey) { this.apiKey = apiKey; } @@ -35,13 +34,12 @@ public Versions(@NotNull String apiKey) { * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. */ - @NotNull public String getCurrentCafeBotVersion() throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/cafeBot") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getData().get("bot_information").get("version").asText(); } @@ -55,8 +53,7 @@ public String getCurrentCafeBotVersion() * @throws UndefinedVariableException Thrown when a variable is undefined. * @throws TeaPotException Thrown when you forget to add "v" to the beginning of the version number. */ - @NotNull - public Boolean updateCurrentCafeBotVersion(@NotNull String versionNumber) + public boolean updateCurrentCafeBotVersion(String versionNumber) throws AuthorizationException, ResponseException, UndefinedVariableException, TeaPotException { if (!versionNumber.startsWith("v")) { throw new TeaPotException("Version Number Must Start with 'v'."); @@ -66,7 +63,7 @@ public Boolean updateCurrentCafeBotVersion(@NotNull String versionNumber) .setRoute("/cafeBot") .addParameter("version", versionNumber) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -76,7 +73,8 @@ public Boolean updateCurrentCafeBotVersion(@NotNull String versionNumber) * @param apiKey The new {@link String apiKey}. */ @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/voicebinds/VoiceChannelBind.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/voicebinds/VoiceChannelBind.java index af7ed2e..c058654 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/voicebinds/VoiceChannelBind.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/voicebinds/VoiceChannelBind.java @@ -1,6 +1,6 @@ package com.beanbeanjuice.cafeapi.cafebot.voicebinds; -import org.jetbrains.annotations.NotNull; +import lombok.Getter; /** * A class used for a {@link VoiceChannelBind} for a Discord Server. @@ -9,32 +9,17 @@ */ public class VoiceChannelBind { - private final String voiceChannelID; - private final String roleID; + @Getter private final String voiceChannelID; + @Getter private final String roleID; /** * Creates a new {@link VoiceChannelBind}. * @param voiceChannelID The {@link String voiceChannelID} of the {@link VoiceChannelBind}. * @param roleID The {@link String roleID} of the {@link VoiceChannelBind}. */ - public VoiceChannelBind(@NotNull String voiceChannelID, @NotNull String roleID) { + public VoiceChannelBind(String voiceChannelID, String roleID) { this.voiceChannelID = voiceChannelID; this.roleID = roleID; } - /** - * @return The {@link String voiceChannelID} for the {@link VoiceChannelBind}. - */ - @NotNull - public String getVoiceChannelID() { - return voiceChannelID; - } - - /** - * @return The {@link String roleID} for the {@link VoiceChannelBind}. - */ - @NotNull - public String getRoleID() { - return roleID; - } } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/voicebinds/VoiceChannelBinds.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/voicebinds/VoiceChannelBinds.java index 2bc1942..d28c51b 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/voicebinds/VoiceChannelBinds.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/voicebinds/VoiceChannelBinds.java @@ -11,7 +11,6 @@ import com.beanbeanjuice.cafeapi.requests.RequestType; import com.fasterxml.jackson.databind.JsonNode; import com.beanbeanjuice.cafeapi.exception.api.CafeException; -import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.HashMap; @@ -29,7 +28,7 @@ public class VoiceChannelBinds implements com.beanbeanjuice.cafeapi.api.CafeAPI * Creates a new {@link VoiceChannelBinds} object. * @param apiKey The {@link String apiKey} used for authorization. */ - public VoiceChannelBinds(@NotNull String apiKey) { + public VoiceChannelBinds(String apiKey) { this.apiKey = apiKey; } @@ -39,13 +38,12 @@ public VoiceChannelBinds(@NotNull String apiKey) { * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. */ - @NotNull public HashMap> getAllVoiceChannelBinds() throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/voice_binds") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); HashMap> voiceBinds = new HashMap<>(); @@ -71,13 +69,12 @@ public HashMap> getAllVoiceChannelBinds() * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. */ - @NotNull - public ArrayList getGuildVoiceChannelBinds(@NotNull String guildID) + public ArrayList getGuildVoiceChannelBinds(String guildID) throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/voice_binds/" + guildID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); ArrayList voiceChannelBinds = new ArrayList<>(); @@ -101,15 +98,14 @@ public ArrayList getGuildVoiceChannelBinds(@NotNull String gui * @throws ConflictException Thrown when the {@link VoiceChannelBind} already exists for that Discord server. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean addVoiceChannelBind(@NotNull String guildID, @NotNull VoiceChannelBind voiceChannelBind) + public boolean addVoiceChannelBind(String guildID, VoiceChannelBind voiceChannelBind) throws AuthorizationException, ResponseException, ConflictException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) .setRoute("/voice_binds/" + guildID) .addParameter("voice_channel_id", voiceChannelBind.getVoiceChannelID()) .addParameter("role_id", voiceChannelBind.getRoleID()) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -123,21 +119,21 @@ public Boolean addVoiceChannelBind(@NotNull String guildID, @NotNull VoiceChanne * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean deleteVoiceChannelBind(@NotNull String guildID, @NotNull VoiceChannelBind voiceChannelBind) + public boolean deleteVoiceChannelBind(String guildID, VoiceChannelBind voiceChannelBind) throws AuthorizationException, ResponseException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) .setRoute("/voice_binds/" + guildID) .addParameter("voice_channel_id", voiceChannelBind.getVoiceChannelID()) .addParameter("role_id", voiceChannelBind.getRoleID()) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/welcomes/GuildWelcome.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/welcomes/GuildWelcome.java index 88e35ee..dca114e 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/welcomes/GuildWelcome.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/welcomes/GuildWelcome.java @@ -1,8 +1,10 @@ package com.beanbeanjuice.cafeapi.cafebot.welcomes; -import org.jetbrains.annotations.NotNull; +import lombok.Getter; import org.jetbrains.annotations.Nullable; +import java.util.Optional; + /** * A class used for Welcome Information for a Discord Guild. * @@ -10,7 +12,7 @@ */ public class GuildWelcome { - private final String guildID; + @Getter private final String guildID; private final String description; private final String thumbnailURL; private final String imageURL; @@ -24,7 +26,7 @@ public class GuildWelcome { * @param imageURL The {@link String imageURL} of the {@link GuildWelcome}. * @param message The {@link String message} of the {@link GuildWelcome}. */ - public GuildWelcome(@NotNull String guildID, @Nullable String description, @Nullable String thumbnailURL, + public GuildWelcome(String guildID, @Nullable String description, @Nullable String thumbnailURL, @Nullable String imageURL, @Nullable String message) { this.guildID = guildID; this.description = description; @@ -33,43 +35,32 @@ public GuildWelcome(@NotNull String guildID, @Nullable String description, @Null this.message = message; } - /** - * @return The {@link String guildID} of the {@link GuildWelcome}. - */ - @NotNull - public String getGuildID() { - return guildID; - } - /** * @return The {@link String description} of the {@link GuildWelcome}. */ - @Nullable - public String getDescription() { - return description; + public Optional getDescription() { + return Optional.ofNullable(description); } /** * @return The {@link String thumbnailURL} of the {@link GuildWelcome}. */ - @Nullable - public String getThumbnailURL() { - return thumbnailURL; + public Optional getThumbnailURL() { + return Optional.ofNullable(thumbnailURL); } /** * @return The {@link String imageURL} of the {@link GuildWelcome}. */ - @Nullable - public String getImageURL() { - return imageURL; + public Optional getImageURL() { + return Optional.ofNullable(imageURL); } /** * @return The {@link String message} of the {@link GuildWelcome}. */ - @Nullable - public String getMessage() { - return message; + public Optional getMessage() { + return Optional.ofNullable(message); } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/welcomes/Welcomes.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/welcomes/Welcomes.java index 8864b14..0776933 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/welcomes/Welcomes.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/welcomes/Welcomes.java @@ -7,7 +7,6 @@ import com.beanbeanjuice.cafeapi.requests.RequestRoute; import com.beanbeanjuice.cafeapi.requests.RequestType; import com.fasterxml.jackson.databind.JsonNode; -import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -22,7 +21,7 @@ public class Welcomes { * Creates a new class used for {@link Welcomes} API requests. * @param apiKey The API key used for authorization. */ - public Welcomes(@NotNull String apiKey) { + public Welcomes(String apiKey) { this.apiKey = apiKey; } @@ -32,14 +31,13 @@ public Welcomes(@NotNull String apiKey) { * @throws AuthorizationException Thrown when the api key is unauthorized. * @throws ResponseException Thrown when there is a generic server-side exception. */ - @NotNull public ArrayList getAllGuildWelcomes() throws AuthorizationException, ResponseException { ArrayList guildWelcomes = new ArrayList<>(); Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/welcomes") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode guildWelcome : request.getData().get("welcomes")) { guildWelcomes.add(parseGuildWelcome(guildWelcome)); @@ -56,13 +54,12 @@ public ArrayList getAllGuildWelcomes() throws AuthorizationExcepti * @throws ResponseException Thrown when there is a generic server-side exception. * @throws NotFoundException Thrown when the guild ID is not found. */ - @NotNull - public GuildWelcome getGuildWelcome(@NotNull String guildID) + public GuildWelcome getGuildWelcome(String guildID) throws AuthorizationException, ResponseException, NotFoundException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/welcomes/" + guildID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); JsonNode guildWelcome = request.getData().get("welcome"); @@ -77,17 +74,16 @@ public GuildWelcome getGuildWelcome(@NotNull String guildID) * @throws NotFoundException Thrown when the guild ID is not found. * @throws ResponseException Thrown when there is a generic server-side exception. */ - @NotNull - public Boolean updateGuildWelcome(@NotNull GuildWelcome guildWelcome) + public boolean updateGuildWelcome(GuildWelcome guildWelcome) throws AuthorizationException, NotFoundException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.PATCH) .setRoute("/welcomes/" + guildWelcome.getGuildID()) - .addParameter("description", guildWelcome.getDescription()) - .addParameter("thumbnail_url", guildWelcome.getThumbnailURL()) - .addParameter("image_url", guildWelcome.getImageURL()) - .addParameter("message", guildWelcome.getMessage()) + .addParameter("description", guildWelcome.getDescription().orElse(null)) + .addParameter("thumbnail_url", guildWelcome.getThumbnailURL().orElse(null)) + .addParameter("image_url", guildWelcome.getImageURL().orElse(null)) + .addParameter("message", guildWelcome.getMessage().orElse(null)) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -101,17 +97,16 @@ public Boolean updateGuildWelcome(@NotNull GuildWelcome guildWelcome) * @throws ResponseException Thrown when there is a generic server-side exception. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean createGuildWelcome(@NotNull GuildWelcome guildWelcome) + public boolean createGuildWelcome(GuildWelcome guildWelcome) throws AuthorizationException, ConflictException, ResponseException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.POST) .setRoute("/welcomes/" + guildWelcome.getGuildID()) - .addParameter("description", guildWelcome.getDescription()) - .addParameter("thumbnail_url", guildWelcome.getThumbnailURL()) - .addParameter("image_url", guildWelcome.getImageURL()) - .addParameter("message", guildWelcome.getMessage()) + .addParameter("description", guildWelcome.getDescription().orElse(null)) + .addParameter("thumbnail_url", guildWelcome.getThumbnailURL().orElse(null)) + .addParameter("image_url", guildWelcome.getImageURL().orElse(null)) + .addParameter("message", guildWelcome.getMessage().orElse(null)) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -123,13 +118,12 @@ public Boolean createGuildWelcome(@NotNull GuildWelcome guildWelcome) * @throws AuthorizationException Thrown when the API key is invalid. * @throws ResponseException Thrown when there is a generic server-side exception. */ - @NotNull - public Boolean deleteGuildWelcome(@NotNull String guildID) + public boolean deleteGuildWelcome(String guildID) throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE) .setRoute("/welcomes/" + guildID) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @@ -139,8 +133,7 @@ public Boolean deleteGuildWelcome(@NotNull String guildID) * @param node The {@link JsonNode} to parse. * @return The parsed {@link GuildWelcome}. */ - @NotNull - private GuildWelcome parseGuildWelcome(@NotNull JsonNode node) { + private GuildWelcome parseGuildWelcome(JsonNode node) { String guildID = node.get("guild_id").asText(); String description = node.get("description").asText(); @@ -148,21 +141,10 @@ private GuildWelcome parseGuildWelcome(@NotNull JsonNode node) { String imageURL = node.get("image_url").asText(); String message = node.get("message").asText(); - if (description.equals("null")) { - description = null; - } - - if (thumbnailURL.equals("null")) { - thumbnailURL = null; - } - - if (imageURL.equals("null")) { - imageURL = null; - } - - if (message.equals("null")) { - message = null; - } + if (description.equals("null")) description = null; + if (thumbnailURL.equals("null")) thumbnailURL = null; + if (imageURL.equals("null")) imageURL = null; + if (message.equals("null")) message = null; return new GuildWelcome( guildID, diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/words/Word.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/words/Word.java index 19c2480..1e8d00c 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/words/Word.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/words/Word.java @@ -1,35 +1,20 @@ package com.beanbeanjuice.cafeapi.cafebot.words; -import org.jetbrains.annotations.NotNull; +import lombok.Getter; public class Word { - private final String word; - private final Integer uses; + @Getter private final String word; + @Getter private final int uses; /** * Creates a new {@link Word} object. * @param word The {@link String word}. * @param uses The amount of {@link Integer uses} the {@link Word} has. */ - public Word(@NotNull String word, @NotNull Integer uses) { + public Word(String word, int uses) { this.word = word; this.uses = uses; } - /** - * @return The {@link String word}. - */ - @NotNull - public String getWord() { - return word; - } - - /** - * @return The amount of {@link Integer uses} the {@link Word} has. - */ - @NotNull - public Integer getUses() { - return uses; - } } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/words/Words.java b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/words/Words.java index d97fb29..51adc5a 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/cafebot/words/Words.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/cafebot/words/Words.java @@ -10,7 +10,6 @@ import com.beanbeanjuice.cafeapi.requests.RequestRoute; import com.beanbeanjuice.cafeapi.requests.RequestType; import com.fasterxml.jackson.databind.JsonNode; -import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -27,7 +26,7 @@ public class Words implements CafeAPI { * Creates a new {@link Words} API. * @param apiKey The API key to use for connection and verification to the {@link com.beanbeanjuice.cafeapi.CafeAPI CafeAPI}. */ - public Words(@NotNull String apiKey) { + public Words(String apiKey) { this.apiKey = apiKey; } @@ -36,12 +35,11 @@ public Words(@NotNull String apiKey) { * @return The {@link ArrayList} of {@link Word} from the {@link com.beanbeanjuice.cafeapi.CafeAPI CafeAPI}. * @throws ResponseException Thrown when there is a generic server-side exception. */ - @NotNull public ArrayList getAllWords() throws ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/words") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); ArrayList wordList = new ArrayList<>(); @@ -59,12 +57,11 @@ public ArrayList getAllWords() throws ResponseException { * @throws NotFoundException Thrown when the word is not found. * @throws ResponseException Thrown when there is a generic server-side exception. */ - @NotNull - public Word getWord(@NotNull String word) throws NotFoundException, ResponseException { + public Word getWord(String word) throws NotFoundException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET) .setRoute("/words/" + word) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return new Word(word, request.getData().get("word").get("uses").asInt()); } @@ -79,20 +76,20 @@ public Word getWord(@NotNull String word) throws NotFoundException, ResponseExce * @throws AuthorizationException Thrown when the current API key is invalid. * @throws UndefinedVariableException Thrown when a variable is undefined. */ - @NotNull - public Boolean updateWord(@NotNull String word, @NotNull Integer uses) + public boolean updateWord(String word, int uses) throws NotFoundException, ResponseException, AuthorizationException, UndefinedVariableException { Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.PATCH) .setRoute("/words/" + word) - .addParameter("uses", uses.toString()) + .addParameter("uses", String.valueOf(uses)) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 200; } @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/exception/api/AuthorizationException.java b/src/main/java/com/beanbeanjuice/cafeapi/exception/api/AuthorizationException.java index 5ea5cf1..0b38f88 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/exception/api/AuthorizationException.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/exception/api/AuthorizationException.java @@ -1,7 +1,6 @@ package com.beanbeanjuice.cafeapi.exception.api; import com.beanbeanjuice.cafeapi.requests.Request; -import org.jetbrains.annotations.NotNull; /** * A {@link CafeException} used when a {@link Request Request} responds with a status code of 401. @@ -14,7 +13,7 @@ public class AuthorizationException extends CafeException { * Creates a new {@link AuthorizationException}. * @param request The {@link Request} that threw the {@link CafeException}. */ - public AuthorizationException(@NotNull Request request) { + public AuthorizationException(Request request) { super(request); } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/exception/api/CafeException.java b/src/main/java/com/beanbeanjuice/cafeapi/exception/api/CafeException.java index 034d8f3..8213e77 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/exception/api/CafeException.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/exception/api/CafeException.java @@ -2,8 +2,9 @@ import com.beanbeanjuice.cafeapi.CafeAPI; import com.beanbeanjuice.cafeapi.requests.Request; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import lombok.Getter; + +import java.util.Optional; /** * A generic {@link RuntimeException} used for {@link CafeAPI CafeAPI} exceptions. @@ -12,16 +13,15 @@ */ public class CafeException extends RuntimeException { - private final Integer statusCode; - private final String message; - + @Getter private final int statusCode; + @Getter private final String message; private final Request request; /** * Creates a new {@link CafeException}. * @param request The {@link Request} that threw the {@link Exception}. */ - public CafeException(@NotNull Request request) { + public CafeException(Request request) { super("Error " + request.getStatusCode() + ": " + request.getData().get("message").asText()); this.statusCode = request.getStatusCode(); @@ -34,7 +34,7 @@ public CafeException(@NotNull Request request) { * @param statusCode The {@link Integer statusCode} for the {@link Exception}. * @param message The {@link String message} for the {@link Exception}. */ - public CafeException(@NotNull Integer statusCode, @NotNull String message) { + public CafeException(int statusCode, String message) { super("Error " + statusCode + ": " + message); this.statusCode = statusCode; @@ -42,28 +42,11 @@ public CafeException(@NotNull Integer statusCode, @NotNull String message) { this.request = null; } - /** - * @return The {@link Integer statusCode} from the {@link Request} that threw the {@link CafeException}. - */ - @NotNull - public Integer getStatusCode() { - return statusCode; - } - - /** - * @return The {@link String message} from the {@link Request} that threw the {@link CafeException}. - */ - @NotNull - @Override - public String getMessage() { - return message; - } - /** * @return The {@link Request} that threw the {@link CafeException}. */ - @Nullable - public Request getRequest() { - return request; + public Optional getRequest() { + return Optional.ofNullable(request); } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/exception/api/ConflictException.java b/src/main/java/com/beanbeanjuice/cafeapi/exception/api/ConflictException.java index 69e7ea5..7f396da 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/exception/api/ConflictException.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/exception/api/ConflictException.java @@ -1,7 +1,6 @@ package com.beanbeanjuice.cafeapi.exception.api; import com.beanbeanjuice.cafeapi.requests.Request; -import org.jetbrains.annotations.NotNull; /** * A {@link CafeException} used when a {@link Request} responds with a status code of 409. @@ -14,7 +13,7 @@ public class ConflictException extends CafeException { * Creates a new {@link ConflictException}. * @param request The {@link Request} that threw the {@link CafeException}. */ - public ConflictException(@NotNull Request request) { + public ConflictException(Request request) { super(request); } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/exception/api/NotFoundException.java b/src/main/java/com/beanbeanjuice/cafeapi/exception/api/NotFoundException.java index 13e8dc8..d99d9ba 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/exception/api/NotFoundException.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/exception/api/NotFoundException.java @@ -1,7 +1,6 @@ package com.beanbeanjuice.cafeapi.exception.api; import com.beanbeanjuice.cafeapi.requests.Request; -import org.jetbrains.annotations.NotNull; /** * A {@link CafeException} used when a {@link Request} responds with a status code of 404. @@ -14,7 +13,7 @@ public class NotFoundException extends CafeException { * Creates a new {@link NotFoundException}. * @param request The {@link Request} that threw the {@link CafeException}. */ - public NotFoundException(@NotNull Request request) { + public NotFoundException(Request request) { super(request); } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/exception/api/ResponseException.java b/src/main/java/com/beanbeanjuice/cafeapi/exception/api/ResponseException.java index 4439879..b3abc2e 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/exception/api/ResponseException.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/exception/api/ResponseException.java @@ -1,7 +1,6 @@ package com.beanbeanjuice.cafeapi.exception.api; import com.beanbeanjuice.cafeapi.requests.Request; -import org.jetbrains.annotations.NotNull; /** * A {@link CafeException} used when a {@link Request} responds with a status code of 500. @@ -14,7 +13,7 @@ public class ResponseException extends CafeException { * Creates a new {@link ResponseException}. * @param request The {@link Request} that threw the {@link CafeException}. */ - public ResponseException(@NotNull Request request) { + public ResponseException(Request request) { super(request); } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/exception/api/TeaPotException.java b/src/main/java/com/beanbeanjuice/cafeapi/exception/api/TeaPotException.java index a932365..629628c 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/exception/api/TeaPotException.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/exception/api/TeaPotException.java @@ -1,7 +1,6 @@ package com.beanbeanjuice.cafeapi.exception.api; import com.beanbeanjuice.cafeapi.requests.Request; -import org.jetbrains.annotations.NotNull; /** * An {@link CafeException} that is thrown when mismatched variables are present. @@ -16,7 +15,7 @@ public class TeaPotException extends CafeException { * Creates a new {@link TeaPotException}. * @param request The {@link Request} that threw the {@link CafeException}. */ - public TeaPotException(@NotNull Request request) { + public TeaPotException(Request request) { super(request); } @@ -24,7 +23,7 @@ public TeaPotException(@NotNull Request request) { * Creates a new {@link TeaPotException}. * @param message The {@link String} message to send. */ - public TeaPotException(@NotNull String message) { + public TeaPotException(String message) { super(413, message); } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/exception/api/UndefinedVariableException.java b/src/main/java/com/beanbeanjuice/cafeapi/exception/api/UndefinedVariableException.java index 1a44825..0bfdb94 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/exception/api/UndefinedVariableException.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/exception/api/UndefinedVariableException.java @@ -1,7 +1,6 @@ package com.beanbeanjuice.cafeapi.exception.api; import com.beanbeanjuice.cafeapi.requests.Request; -import org.jetbrains.annotations.NotNull; /** * A {@link CafeException} used when a {@link Request} responds with a status code of 400. @@ -14,7 +13,7 @@ public class UndefinedVariableException extends CafeException { * Creates a new {@link UndefinedVariableException}. * @param request The {@link Request} that threw the {@link CafeException}. */ - public UndefinedVariableException(@NotNull Request request) { + public UndefinedVariableException(Request request) { super(request); } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/exception/program/BirthdayOverfillException.java b/src/main/java/com/beanbeanjuice/cafeapi/exception/program/BirthdayOverfillException.java index 5e5f1bc..e42d9e7 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/exception/program/BirthdayOverfillException.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/exception/program/BirthdayOverfillException.java @@ -1,7 +1,6 @@ package com.beanbeanjuice.cafeapi.exception.program; import com.beanbeanjuice.cafeapi.cafebot.birthdays.BirthdayMonth; -import org.jetbrains.annotations.NotNull; /** * A {@link RuntimeException} that deals with incorrect days in a {@link BirthdayMonth BirthdayMonth}. @@ -14,7 +13,7 @@ public class BirthdayOverfillException extends RuntimeException { * Creates a new {@link BirthdayOverfillException}. * @param message The message to send to the {@link RuntimeException}. */ - public BirthdayOverfillException(@NotNull String message) { + public BirthdayOverfillException(String message) { super(message); } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/exception/program/InvalidTimeZoneException.java b/src/main/java/com/beanbeanjuice/cafeapi/exception/program/InvalidTimeZoneException.java index cb0e0e3..d733aa5 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/exception/program/InvalidTimeZoneException.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/exception/program/InvalidTimeZoneException.java @@ -1,7 +1,5 @@ package com.beanbeanjuice.cafeapi.exception.program; -import org.jetbrains.annotations.NotNull; - /** * A {@link RuntimeException} for dealing with invalid {@link java.util.TimeZone TimeZone}. * @@ -13,7 +11,7 @@ public class InvalidTimeZoneException extends RuntimeException { * Creates a new {@link InvalidTimeZoneException}. * @param message The message to send to the {@link RuntimeException}. */ - public InvalidTimeZoneException(@NotNull String message) { + public InvalidTimeZoneException(String message) { super(message); } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/generic/CafeGeneric.java b/src/main/java/com/beanbeanjuice/cafeapi/generic/CafeGeneric.java index 4412283..eff7c7a 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/generic/CafeGeneric.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/generic/CafeGeneric.java @@ -1,13 +1,11 @@ package com.beanbeanjuice.cafeapi.generic; import com.beanbeanjuice.cafeapi.CafeAPI; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - import java.sql.Date; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Optional; import java.util.TimeZone; /** @@ -24,15 +22,14 @@ public class CafeGeneric { * Null if timestamp was incorrectly entered. * @throws IllegalArgumentException - Thrown when the pattern given is invalid. */ - @Nullable - public static Timestamp parseTimestamp(@NotNull String timestampString) throws IllegalArgumentException { + public static Optional parseTimestamp(String timestampString) throws IllegalArgumentException { timestampString = timestampString.replace("T", " ").replace("Z", ""); try { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); // Sets the timezone to UTC. - return new Timestamp(simpleDateFormat.parse(timestampString).getTime()); + return Optional.of(new Timestamp(simpleDateFormat.parse(timestampString).getTime())); } catch (ParseException e) { - return null; + return Optional.empty(); } } @@ -43,14 +40,13 @@ public static Timestamp parseTimestamp(@NotNull String timestampString) throws I * Null if timestamp was incorrectly entered. * @throws IllegalArgumentException - Thrown when the pattern given is invalid. */ - @Nullable - public static Timestamp parseTimestampFromAPI(@NotNull String timestampString) throws IllegalArgumentException { + public static Optional parseTimestampFromAPI(String timestampString) throws IllegalArgumentException { timestampString = timestampString.replace("T", " ").replace("Z", ""); try { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - return new Timestamp(simpleDateFormat.parse(timestampString).getTime()); + return Optional.of(new Timestamp(simpleDateFormat.parse(timestampString).getTime())); } catch (ParseException e) { - return null; + return Optional.empty(); } } @@ -61,14 +57,13 @@ public static Timestamp parseTimestampFromAPI(@NotNull String timestampString) t * Null if the date was incorrectly entered. * @throws IllegalArgumentException - Thrown when the pattern given is invalid. */ - @Nullable - public static Date parseDateFromAPI(@NotNull String dateString) throws IllegalArgumentException { + public static Optional parseDateFromAPI(String dateString) throws IllegalArgumentException { dateString = dateString.replace("T", " ").replace("Z", ""); try { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - return new Date(simpleDateFormat.parse(dateString).getTime()); + return Optional.of(new Date(simpleDateFormat.parse(dateString).getTime())); } catch (ParseException e) { - return null; + return Optional.empty(); } } @@ -77,12 +72,8 @@ public static Date parseDateFromAPI(@NotNull String dateString) throws IllegalAr * @param bool The {@link Boolean} to parse. * @return "1", if true. If there was an error, it will be "0" by default. */ - @NotNull - public static String parseBoolean(@NotNull Boolean bool) { - if (bool.equals(true)) { - return "1"; - } - return "0"; + public static String parseBoolean(boolean bool) { + return (bool) ? "1" : "0"; } } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/requests/Request.java b/src/main/java/com/beanbeanjuice/cafeapi/requests/Request.java index c4116b4..6e218d8 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/requests/Request.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/requests/Request.java @@ -1,7 +1,7 @@ package com.beanbeanjuice.cafeapi.requests; import com.fasterxml.jackson.databind.JsonNode; -import org.jetbrains.annotations.NotNull; +import lombok.Getter; /** * A class containing the request's {@link Integer status code} and resulting {@link JsonNode data}. @@ -10,33 +10,17 @@ */ public class Request { - private final Integer statusCode; - private final JsonNode data; + @Getter final int statusCode; + @Getter private final JsonNode data; /** * Creates a new {@link Request} object. * @param statusCode The resulting {@link Integer status code}. * @param data The {@link JsonNode data} retrieved from the {@link Request}. */ - public Request(@NotNull Integer statusCode, @NotNull JsonNode data) { + public Request(int statusCode, JsonNode data) { this.statusCode = statusCode; this.data = data; } - /** - * @return The {@link Request Request's} {@link Integer status code}. - */ - @NotNull - public Integer getStatusCode() { - return statusCode; - } - - /** - * @return The {@link Request Request's} {@link JsonNode data}. - */ - @NotNull - public JsonNode getData() { - return data; - } - } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/requests/RequestBuilder.java b/src/main/java/com/beanbeanjuice/cafeapi/requests/RequestBuilder.java index 0dba98c..c756f1e 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/requests/RequestBuilder.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/requests/RequestBuilder.java @@ -14,13 +14,13 @@ import org.apache.http.client.utils.URIBuilder; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicHeader; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.InputStream; import java.net.URISyntaxException; import java.util.HashMap; +import java.util.Optional; /** * A {@link RequestBuilder} used to build {@link Request} objects. @@ -46,7 +46,7 @@ public class RequestBuilder { * @param requestType The {@link RequestType type} of {@link Request}. * @param requestRoute The {@link RequestRoute} of the {@link Request}. */ - public RequestBuilder(@NotNull RequestRoute requestRoute, @NotNull RequestType requestType) { + public RequestBuilder(RequestRoute requestRoute, RequestType requestType) { this.requestType = requestType; parameters = new HashMap<>(); @@ -58,8 +58,7 @@ public RequestBuilder(@NotNull RequestRoute requestRoute, @NotNull RequestType r * @param route The {@link String route} for the {@link RequestBuilder}. * @return The new {@link RequestBuilder}. */ - @NotNull - public RequestBuilder setRoute(@NotNull String route) { + public RequestBuilder setRoute(String route) { this.route = route; return this; } @@ -70,8 +69,7 @@ public RequestBuilder setRoute(@NotNull String route) { * @param value The {@link String value} for the {@link String key} in the {@link RequestBuilder}. * @return The new {@link RequestBuilder}. */ - @NotNull - public RequestBuilder addParameter(@NotNull String key, @Nullable String value) { + public RequestBuilder addParameter(String key, @Nullable String value) { parameters.put(key, value); return this; } @@ -81,8 +79,7 @@ public RequestBuilder addParameter(@NotNull String key, @Nullable String value) * @param apiKey The {@link String api key} for the {@link RequestBuilder}. * @return The new {@link RequestBuilder}. */ - @NotNull - public RequestBuilder setAuthorization(@NotNull String apiKey) { + public RequestBuilder setAuthorization(String apiKey) { this.apiKey = apiKey; return this; } @@ -91,8 +88,7 @@ public RequestBuilder setAuthorization(@NotNull String apiKey) { * Builds the {@link RequestBuilder}. * @return Null, if there is an error with the route. The resulting {@link Request}. */ - @Nullable - public Request build() { + public Optional build() { try { httpClient = HttpClients.createDefault(); uriBuilder = new URIBuilder(apiURL + route); @@ -102,59 +98,29 @@ public Request build() { authorization = new BasicHeader("Authorization", apiKey); switch (requestType) { - case GET -> { - httpResponse = get(); - } - - case POST -> { - httpResponse = post(); - } - - case PATCH -> { - httpResponse = patch(); - } - - case DELETE -> { - httpResponse = delete(); - } + case GET -> httpResponse = get(); + case POST -> httpResponse = post(); + case PATCH -> httpResponse = patch(); + case DELETE -> httpResponse = delete(); } - Integer statusCode = httpResponse.getStatusLine().getStatusCode(); + int statusCode = httpResponse.getStatusLine().getStatusCode(); HttpEntity httpEntity = httpResponse.getEntity(); try (InputStream inputStream = httpEntity.getContent()) { Request request = new Request(statusCode, new ObjectMapper().readTree(inputStream)); // Catching Status Codes - if (request.getStatusCode() == 400) { - throw new UndefinedVariableException(request); - } - - if (request.getStatusCode() == 401) { - throw new AuthorizationException(request); - } - - if (request.getStatusCode() == 404) { - throw new NotFoundException(request); - } - - if (request.getStatusCode() == 409) { - throw new ConflictException(request); - } - - if (request.getStatusCode() == 418) { - throw new TeaPotException(request); - } - - if (request.getStatusCode() == 500) { - throw new ResponseException(request); - } - - - return request; + if (request.getStatusCode() == 400) throw new UndefinedVariableException(request); + if (request.getStatusCode() == 401) throw new AuthorizationException(request); + if (request.getStatusCode() == 404) throw new NotFoundException(request); + if (request.getStatusCode() == 409) throw new ConflictException(request); + if (request.getStatusCode() == 418) throw new TeaPotException(request); + if (request.getStatusCode() == 500) throw new ResponseException(request); + + return Optional.of(request); } } catch (URISyntaxException | IOException e) { - e.printStackTrace(); - return null; + return Optional.empty(); } } @@ -164,7 +130,6 @@ public Request build() { * @throws URISyntaxException Thrown if there is an issue with the route syntax. * @throws IOException Thrown if there is an issue with the data returned. */ - @NotNull private HttpResponse get() throws URISyntaxException, IOException { HttpGet httpGet = new HttpGet(uriBuilder.build()); httpGet.addHeader(authorization); @@ -178,7 +143,6 @@ private HttpResponse get() throws URISyntaxException, IOException { * @throws URISyntaxException Thrown if there is an issue with the route syntax. * @throws IOException Thrown if there is an issue with the data returned. */ - @NotNull private HttpResponse post() throws URISyntaxException, IOException { HttpPost httpPost = new HttpPost(uriBuilder.build()); httpPost.addHeader(authorization); @@ -192,7 +156,6 @@ private HttpResponse post() throws URISyntaxException, IOException { * @throws URISyntaxException Thrown if there is an issue with the route syntax. * @throws IOException Thrown if there is an issue with the data returned. */ - @NotNull private HttpResponse patch() throws URISyntaxException, IOException { HttpPatch httpPatch = new HttpPatch(uriBuilder.build()); httpPatch.addHeader(authorization); @@ -206,7 +169,6 @@ private HttpResponse patch() throws URISyntaxException, IOException { * @throws URISyntaxException Thrown if there is an issue with the route syntax. * @throws IOException Thrown if there is an issue with the data returned. */ - @NotNull private HttpResponse delete() throws URISyntaxException, IOException { HttpDelete httpDelete = new HttpDelete(uriBuilder.build()); httpDelete.addHeader(authorization); @@ -217,9 +179,8 @@ private HttpResponse delete() throws URISyntaxException, IOException { /** * @return The {@link String route} for the {@link RequestBuilder}. */ - @Nullable - public String getRoute() { - return route; + public Optional getRoute() { + return Optional.ofNullable(route); } } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/requests/RequestLocation.java b/src/main/java/com/beanbeanjuice/cafeapi/requests/RequestLocation.java index 4496c15..7c8fbd8 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/requests/RequestLocation.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/requests/RequestLocation.java @@ -1,6 +1,6 @@ package com.beanbeanjuice.cafeapi.requests; -import org.jetbrains.annotations.NotNull; +import lombok.Getter; public enum RequestLocation { @@ -8,22 +8,14 @@ public enum RequestLocation { BETA ("http://beanbeanjuice.com:5101"), LOCAL ("http://localhost:5101"); - private final String url; + @Getter private final String URL; /** * Creates a new static {@link RequestLocation}. * @param url The {@link String url} for the {@link RequestLocation}. */ - RequestLocation(@NotNull String url) { - this.url = url; - } - - /** - * @return The URL for the specified {@link RequestLocation}. - */ - @NotNull - public String getURL() { - return url; + RequestLocation(String url) { + this.URL = url; } } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/requests/RequestRoute.java b/src/main/java/com/beanbeanjuice/cafeapi/requests/RequestRoute.java index 809f96f..7b6cb99 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/requests/RequestRoute.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/requests/RequestRoute.java @@ -1,6 +1,6 @@ package com.beanbeanjuice.cafeapi.requests; -import org.jetbrains.annotations.NotNull; +import lombok.Getter; /** * A class used for {@link RequestRoute} objects. @@ -12,21 +12,14 @@ public enum RequestRoute { CAFE("/cafe/api/v1"), CAFEBOT("/cafeBot/api/v1"); - private final String route; + @Getter private final String route; /** * Creates a new {@link RequestRoute} static object. * @param route The {@link String route} of the {@link Request}. */ - RequestRoute(@NotNull String route) { + RequestRoute(String route) { this.route = route; } - /** - * @return The route {@link String url} for the {@link Request}. - */ - @NotNull - public String getRoute() { - return route; - } } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/user/User.java b/src/main/java/com/beanbeanjuice/cafeapi/user/User.java index 9d51e5d..b6438a2 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/user/User.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/user/User.java @@ -1,6 +1,6 @@ package com.beanbeanjuice.cafeapi.user; -import org.jetbrains.annotations.NotNull; +import lombok.Getter; /** * A {@link User} class used for contextualising users in the API database. @@ -9,9 +9,9 @@ */ public class User { - private final Integer id; - private final String username; - private final UserType userType; // TODO: Make something for updating the UserType + @Getter private final int ID; + @Getter private final String username; + @Getter private final UserType userType; // TODO: Make something for updating the UserType /** * Creates a new {@link User}. @@ -19,34 +19,10 @@ public class User { * @param username The {@link String username} of the {@link User}. * @param userType The {@link UserType user type} of the {@link User}. */ - public User(@NotNull Integer id, @NotNull String username, @NotNull UserType userType) { - this.id = id; + public User(int id, String username, UserType userType) { + this.ID = id; this.username = username; this.userType = userType; } - /** - * @return The {@link Integer ID} of the {@link User}. - */ - @NotNull - public Integer getID() { - return id; - } - - /** - * @return The {@link String username} of the {@link User}. - */ - @NotNull - public String getUsername() { - return username; - } - - /** - * @return The {@link UserType} of the {@link User}. - */ - @NotNull - public UserType getUserType() { - return userType; - } - } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/user/Users.java b/src/main/java/com/beanbeanjuice/cafeapi/user/Users.java index 1e11cf4..faac0c0 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/user/Users.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/user/Users.java @@ -9,7 +9,6 @@ import com.beanbeanjuice.cafeapi.requests.RequestBuilder; import com.beanbeanjuice.cafeapi.requests.RequestRoute; import com.beanbeanjuice.cafeapi.requests.RequestType; -import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -26,7 +25,7 @@ public class Users implements CafeAPI { * Creates a new {@link Users}. * @param apiKey The {@link String API key} used for making a {@link Request}. */ - public Users(@NotNull String apiKey) { + public Users(String apiKey) { this.apiKey = apiKey; } @@ -40,10 +39,10 @@ public ArrayList getUsers() throws AuthorizationException, ResponseExcepti Request request = new RequestBuilder(RequestRoute.CAFE, RequestType.GET) .setRoute("/users") .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); for (JsonNode user : request.getData().get("users")) { - Integer id = user.get("user_id").intValue(); + int id = user.get("user_id").intValue(); String username = user.get("username").textValue(); UserType userType = UserType.valueOf(user.get("user_type").textValue()); users.add(new User(id, username, userType)); @@ -57,12 +56,12 @@ public ArrayList getUsers() throws AuthorizationException, ResponseExcepti * @param password The {@link String password} of the {@link User}. * @return True, if successfully signed up. */ - public Boolean signUp(@NotNull String username, @NotNull String password) { + public boolean signUp(String username, String password) { Request request = new RequestBuilder(RequestRoute.CAFE, RequestType.POST) .setRoute("/user/signup") .addParameter("username", username) .addParameter("password", password) - .build(); + .build().orElseThrow(); return request.getStatusCode() == 201; } @@ -74,13 +73,13 @@ public Boolean signUp(@NotNull String username, @NotNull String password) { * @throws AuthorizationException Thrown when the {@link String apiKey} is invalid. * @throws ResponseException Thrown when there is a generic server-side {@link CafeException CafeException}. */ - public User getUser(@NotNull String username) throws AuthorizationException, ResponseException { + public User getUser(String username) throws AuthorizationException, ResponseException { Request request = new RequestBuilder(RequestRoute.CAFE, RequestType.GET) .setRoute("/user/" + username) .setAuthorization(apiKey) - .build(); + .build().orElseThrow(); - Integer ID = request.getData().get("user").get("user_id").intValue(); + int ID = request.getData().get("user").get("user_id").intValue(); UserType userType = UserType.valueOf(request.getData().get("user").get("user_type").textValue()); return new User(ID, username, userType); } @@ -90,11 +89,11 @@ public User getUser(@NotNull String username) throws AuthorizationException, Res * @param username The {@link String username} of the {@link User}. * @return True, if the {@link User} was successfully deleted. */ - public Boolean deleteUser(@NotNull String username) { - RequestBuilder requestBuilder = new RequestBuilder(RequestRoute.CAFE, RequestType.DELETE) + public boolean deleteUser(String username) { + Request request = new RequestBuilder(RequestRoute.CAFE, RequestType.DELETE) .setRoute("/user/" + username) - .setAuthorization(apiKey); - return requestBuilder.build().getStatusCode() == 200; + .setAuthorization(apiKey).build().orElseThrow(); + return request.getStatusCode() == 200; } /** @@ -102,7 +101,8 @@ public Boolean deleteUser(@NotNull String username) { * @param apiKey The new {@link String apiKey}. */ @Override - public void updateAPIKey(@NotNull String apiKey) { + public void updateAPIKey(String apiKey) { this.apiKey = apiKey; } + } diff --git a/src/main/java/com/beanbeanjuice/cafeapi/utility/Time.java b/src/main/java/com/beanbeanjuice/cafeapi/utility/Time.java index ab4a97d..1561a6c 100644 --- a/src/main/java/com/beanbeanjuice/cafeapi/utility/Time.java +++ b/src/main/java/com/beanbeanjuice/cafeapi/utility/Time.java @@ -1,7 +1,5 @@ package com.beanbeanjuice.cafeapi.utility; -import org.jetbrains.annotations.NotNull; - import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -26,7 +24,7 @@ public class Time { * @param timezone The {@link String} of the specified {@link TimeZone}. * @param defaultFormat The {@link String} for the specified default {@link String format}. */ - public Time(@NotNull String timezone, @NotNull String defaultFormat) { + public Time(String timezone, String defaultFormat) { TIME_ZONE = TimeZone.getTimeZone(timezone); setDefaultFormat(defaultFormat); } @@ -36,7 +34,7 @@ public Time(@NotNull String timezone, @NotNull String defaultFormat) { * {@link TimeZone}. * @param timezone The {@link String} of the specified {@link TimeZone}. */ - public Time(@NotNull String timezone) { + public Time(String timezone) { TIME_ZONE = TimeZone.getTimeZone(timezone); } @@ -52,7 +50,7 @@ public Time() { * Sets the default {@link String format} for the specified {@link Time} object. * @param format The {@link String format} to be set. */ - public void setDefaultFormat(@NotNull String format) { + public void setDefaultFormat(String format) { defaultFormat = format; } @@ -61,8 +59,7 @@ public void setDefaultFormat(@NotNull String format) { * @param format The {@link String format} to return. * @return The {@link String formatted} {@link Time}. */ - @NotNull - public String format(@NotNull String format) { + public String format(String format) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); simpleDateFormat.setTimeZone(TIME_ZONE); return simpleDateFormat.format(new Date()); @@ -73,7 +70,6 @@ public String format(@NotNull String format) { * @return The {@link String formatted} {@link Time}. * @throws NullPointerException Thrown when there is no default {@link String format}. */ - @NotNull public String format() throws NullPointerException { if (defaultFormat == null) throw new NullPointerException("Default format is not specified!"); @@ -90,8 +86,7 @@ public String format() throws NullPointerException { * @param timestampDifference The {@link TimestampDifference} to choose. * @return The difference in time as a {@link Long}. */ - @NotNull - public static Long compareTwoTimeStamps(@NotNull Timestamp oldTime, @NotNull Timestamp currentTime, @NotNull TimestampDifference timestampDifference) { + public static Long compareTwoTimeStamps(Timestamp oldTime, Timestamp currentTime, TimestampDifference timestampDifference) { long milliseconds1 = oldTime.getTime(); long milliseconds2 = currentTime.getTime(); long diff = milliseconds2 - milliseconds1; @@ -111,21 +106,19 @@ public static Long compareTwoTimeStamps(@NotNull Timestamp oldTime, @NotNull Tim * @param format The formatting {@link String}. * @return The formatted {@link String}. */ - @NotNull - public static String format(@NotNull Timestamp timestamp, @NotNull String format) { + public static String format(Timestamp timestamp, String format) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); return simpleDateFormat.format(timestamp); } /** * - * @param dateString The {@link String} of the {@link Date}. + * @param dateString The {@link String} of the {@link Date}. (MM-dd-yyyy) * @param timeZone The {@link TimeZone} of the {@link Date}. * @return The formatted {@link Date}. * @throws ParseException Thrown if there was an error parsing the {@link Date}. */ - @NotNull - public static Date getFullDate(@NotNull String dateString, @NotNull TimeZone timeZone) throws ParseException { + public static Date getFullDate(String dateString, TimeZone timeZone) throws ParseException { SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy"); format.setTimeZone(timeZone); return format.parse(dateString); @@ -136,8 +129,7 @@ public static Date getFullDate(@NotNull String dateString, @NotNull TimeZone tim * @param timezoneString The {@link String timeZoneString} to check. * @return True, if the specified {@link String timeZoneString} is a valid {@link TimeZone}. */ - @NotNull - public static Boolean isValidTimeZone(@NotNull String timezoneString) { + public static boolean isValidTimeZone(String timezoneString) { return Set.of(TimeZone.getAvailableIDs()).contains(timezoneString); } @@ -147,8 +139,7 @@ public static Boolean isValidTimeZone(@NotNull String timezoneString) { * @return True, if the {@link Date} has passed the current {@link Date}. * @throws ParseException Thrown if there was an error parsing the {@link Date}. */ - @NotNull - public static Boolean dateHasPassed(@NotNull Date date) throws ParseException { + public static boolean dateHasPassed(Date date) throws ParseException { Calendar checkCalendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance(); @@ -169,8 +160,7 @@ public static Boolean dateHasPassed(@NotNull Date date) throws ParseException { * @return True, if the input {@link String} of a {@link Date} has passed. * @throws ParseException Thrown if there was an error parsing the {@link String} of the {@link Date}. */ - @NotNull - public static Boolean dateHasPassed(@NotNull String dateString, @NotNull TimeZone timeZone) throws ParseException { + public static boolean dateHasPassed(String dateString, TimeZone timeZone) throws ParseException { return dateHasPassed(getFullDate(dateString, timeZone)); } @@ -180,8 +170,7 @@ public static Boolean dateHasPassed(@NotNull String dateString, @NotNull TimeZon * @return True, if the {@link Date} is the current {@link Date}. * @throws ParseException Thrown if there was an error parsing the {@link Date}. */ - @NotNull - public static Boolean isSameDay(@NotNull Date date) throws ParseException { + public static boolean isSameDay(Date date) throws ParseException { SimpleDateFormat format = new SimpleDateFormat("MM-dd"); SimpleDateFormat yearFormat = new SimpleDateFormat("MM-dd-yyyy"); Date currentDate = new Date(); @@ -201,8 +190,7 @@ public static Boolean isSameDay(@NotNull Date date) throws ParseException { * @return True, if the input {@link String} of a {@link Date} is the date. * @throws ParseException Thrown if there was an error parsing the {@link String} of the {@link Date}. */ - @NotNull - public static Boolean isSameDay(@NotNull String dateString, @NotNull TimeZone timeZone) throws ParseException { + public static boolean isSameDay(String dateString, TimeZone timeZone) throws ParseException { return isSameDay(getFullDate(dateString, timeZone)); } diff --git a/src/test/java/com/beanbeanjuice/cafeapi/beta/CafeUserTest.java b/src/test/java/com/beanbeanjuice/cafeapi/beta/CafeUserTest.java index 91b1ca3..686f5ca 100644 --- a/src/test/java/com/beanbeanjuice/cafeapi/beta/CafeUserTest.java +++ b/src/test/java/com/beanbeanjuice/cafeapi/beta/CafeUserTest.java @@ -48,7 +48,7 @@ public void testCafeUserAPI() { // Makes sure all settings are default when first created. Assertions.assertEquals(0, cafeAPI.CAFE_USER.getCafeUser("236654580300120064").getBeanCoins()); - Assertions.assertNull(cafeAPI.CAFE_USER.getCafeUser("236654580300120064").getLastServingTime()); + Assertions.assertNull(cafeAPI.CAFE_USER.getCafeUser("236654580300120064").getLastServingTime().orElse(null)); Assertions.assertEquals(0, cafeAPI.CAFE_USER.getCafeUser("236654580300120064").getOrdersBought()); Assertions.assertEquals(0, cafeAPI.CAFE_USER.getCafeUser("236654580300120064").getOrdersReceived()); @@ -57,13 +57,13 @@ public void testCafeUserAPI() { Assertions.assertEquals(100.0, cafeAPI.CAFE_USER.getCafeUser("236654580300120064").getBeanCoins()); // Makes sure the timestamp can be changed. - Timestamp currentTimeStamp = CafeGeneric.parseTimestamp(new Timestamp(System.currentTimeMillis()).toString()); + Timestamp currentTimeStamp = CafeGeneric.parseTimestamp(new Timestamp(System.currentTimeMillis()).toString()).orElse(null); Assertions.assertTrue(cafeAPI.CAFE_USER.updateCafeUser("236654580300120064", CafeType.LAST_SERVING_TIME, currentTimeStamp)); - Assertions.assertEquals(currentTimeStamp, cafeAPI.CAFE_USER.getCafeUser("236654580300120064").getLastServingTime()); + Assertions.assertEquals(currentTimeStamp, cafeAPI.CAFE_USER.getCafeUser("236654580300120064").getLastServingTime().orElse(null)); // Makes sure the timestamp can be changed to null. Assertions.assertTrue(cafeAPI.CAFE_USER.updateCafeUser("236654580300120064", CafeType.LAST_SERVING_TIME, null)); - Assertions.assertNull(cafeAPI.CAFE_USER.getCafeUser("236654580300120064").getLastServingTime()); + Assertions.assertNull(cafeAPI.CAFE_USER.getCafeUser("236654580300120064").getLastServingTime().orElse(null)); // Makes sure the orders bought can be updated. Assertions.assertTrue(cafeAPI.CAFE_USER.updateCafeUser("236654580300120064", CafeType.ORDERS_BOUGHT, 10)); diff --git a/src/test/java/com/beanbeanjuice/cafeapi/beta/DonationUsersTest.java b/src/test/java/com/beanbeanjuice/cafeapi/beta/DonationUsersTest.java index 0f5be3c..45582a2 100644 --- a/src/test/java/com/beanbeanjuice/cafeapi/beta/DonationUsersTest.java +++ b/src/test/java/com/beanbeanjuice/cafeapi/beta/DonationUsersTest.java @@ -20,11 +20,11 @@ public void testDonationUsersAPI() { Assertions.assertTrue(cafeAPI.DONATION_USER.deleteDonationUser("738590591767543921")); Assertions.assertThrows(NotFoundException.class, () -> cafeAPI.DONATION_USER.getUserDonationTime("738590591767543921")); - Timestamp currentTimestamp = CafeGeneric.parseTimestamp((new Timestamp(System.currentTimeMillis())).toString()); + Timestamp currentTimestamp = CafeGeneric.parseTimestamp((new Timestamp(System.currentTimeMillis())).toString()).orElse(null); Assertions.assertTrue(cafeAPI.DONATION_USER.addDonationUser("738590591767543921", currentTimestamp)); Assertions.assertThrows(ConflictException.class, () -> cafeAPI.DONATION_USER.addDonationUser("738590591767543921", currentTimestamp)); Assertions.assertEquals(currentTimestamp, cafeAPI.DONATION_USER.getAllUserDonationTimes().get("738590591767543921")); - Assertions.assertEquals(currentTimestamp, cafeAPI.DONATION_USER.getUserDonationTime("738590591767543921")); + Assertions.assertEquals(currentTimestamp, cafeAPI.DONATION_USER.getUserDonationTime("738590591767543921").orElse(null)); Assertions.assertTrue(cafeAPI.DONATION_USER.deleteDonationUser("738590591767543921")); Assertions.assertThrows(NotFoundException.class, () -> cafeAPI.DONATION_USER.getUserDonationTime("738590591767543921")); diff --git a/src/test/java/com/beanbeanjuice/cafeapi/beta/GuildGoodbyeTest.java b/src/test/java/com/beanbeanjuice/cafeapi/beta/GuildGoodbyeTest.java index eb63180..3724b33 100644 --- a/src/test/java/com/beanbeanjuice/cafeapi/beta/GuildGoodbyeTest.java +++ b/src/test/java/com/beanbeanjuice/cafeapi/beta/GuildGoodbyeTest.java @@ -39,7 +39,7 @@ public void guildGoodbyesAPITest() { // Makes sure that the description of the retrieved guild is "test description" Assertions.assertEquals( "Goodbye... {user}... thanks for joining!", - cafeAPI.GOODBYE.getGuildGoodbye("798830792938881024").getDescription()); + cafeAPI.GOODBYE.getGuildGoodbye("798830792938881024").getDescription().orElse(null)); // Makes sure that this throws a NotFoundException as the guild "bruhmoment" does not exist. Assertions.assertThrows(NotFoundException.class, () -> { @@ -52,9 +52,9 @@ public void guildGoodbyesAPITest() { GuildGoodbye newGuildGoodbye = new GuildGoodbye( currentGuildGoodbye.getGuildID(), - currentGuildGoodbye.getDescription(), - currentGuildGoodbye.getThumbnailURL(), - currentGuildGoodbye.getImageURL(), + currentGuildGoodbye.getDescription().orElse(null), + currentGuildGoodbye.getThumbnailURL().orElse(null), + currentGuildGoodbye.getImageURL().orElse(null), "cool message!!!!" ); diff --git a/src/test/java/com/beanbeanjuice/cafeapi/beta/GuildWelcomeTest.java b/src/test/java/com/beanbeanjuice/cafeapi/beta/GuildWelcomeTest.java index be0eac7..76b0d55 100644 --- a/src/test/java/com/beanbeanjuice/cafeapi/beta/GuildWelcomeTest.java +++ b/src/test/java/com/beanbeanjuice/cafeapi/beta/GuildWelcomeTest.java @@ -40,7 +40,7 @@ public void guildWelcomesAPITest() { // Makes sure that the description of the retrieved guild is "test description" Assertions.assertEquals( "Welcome, {user} to the bot testing server!\\nI hope you enjoy your stay! :heart:\\nMake sure to...\\n Check out #polls,\\nCheck out #logger,\\n and Check out #cafebot-beta-log!", - cafeAPI.WELCOME.getGuildWelcome("798830792938881024").getDescription()); + cafeAPI.WELCOME.getGuildWelcome("798830792938881024").getDescription().orElse(null)); // Makes sure that this throws a NotFoundException as the guild "bruhmoment" does not exist. Assertions.assertThrows(NotFoundException.class, () -> { @@ -53,9 +53,9 @@ public void guildWelcomesAPITest() { GuildWelcome newGuildWelcome = new GuildWelcome( currentGuildWelcome.getGuildID(), - currentGuildWelcome.getDescription(), - currentGuildWelcome.getThumbnailURL(), - currentGuildWelcome.getImageURL(), + currentGuildWelcome.getDescription().orElse(null), + currentGuildWelcome.getThumbnailURL().orElse(null), + currentGuildWelcome.getImageURL().orElse(null), "cool message!!!!" ); diff --git a/src/test/java/com/beanbeanjuice/cafeapi/beta/InteractionPictureTest.java b/src/test/java/com/beanbeanjuice/cafeapi/beta/InteractionPictureTest.java index f416660..599d5c8 100644 --- a/src/test/java/com/beanbeanjuice/cafeapi/beta/InteractionPictureTest.java +++ b/src/test/java/com/beanbeanjuice/cafeapi/beta/InteractionPictureTest.java @@ -24,12 +24,10 @@ public void testInteractionPicturesAPI() { // Goes through every interaction type. Assertions.assertDoesNotThrow(() -> { for (InteractionType type : InteractionType.values()) { - - if (type.isKawaiiAPI()) - Assertions.assertTrue(cafeAPI.INTERACTION_PICTURE.getRandomInteractionPicture(type).startsWith("https://api.kawaii.red/gif/")); - - else - Assertions.assertNotNull(cafeAPI.INTERACTION_PICTURE.getRandomInteractionPicture(type)); + type.getKawaiiAPIString().ifPresentOrElse( + (kawaiiAPIString) -> Assertions.assertTrue(cafeAPI.INTERACTION_PICTURE.getRandomInteractionPicture(type).startsWith("https://api.kawaii.red/gif/")), + () -> Assertions.assertNotNull(cafeAPI.INTERACTION_PICTURE.getRandomInteractionPicture(type)) + ); } }); } diff --git a/src/test/java/com/beanbeanjuice/cafeapi/beta/PollTest.java b/src/test/java/com/beanbeanjuice/cafeapi/beta/PollTest.java index 59203fc..fc4ad6e 100644 --- a/src/test/java/com/beanbeanjuice/cafeapi/beta/PollTest.java +++ b/src/test/java/com/beanbeanjuice/cafeapi/beta/PollTest.java @@ -20,7 +20,7 @@ public void pollsAPITest() { CafeAPI cafeAPI = new CafeAPI("beanbeanjuice", System.getenv("API_PASSWORD"), RequestLocation.BETA); long currentTime = System.currentTimeMillis(); - Timestamp currentTimestamp = CafeGeneric.parseTimestamp(new Timestamp(currentTime).toString()); + Timestamp currentTimestamp = CafeGeneric.parseTimestamp(new Timestamp(currentTime).toString()).orElse(null); // Makes sure the poll doesn't exist before starting the test. Assertions.assertTrue(() -> cafeAPI.POLL.deletePoll("798830792938881024", "879519824424890438")); diff --git a/src/test/java/com/beanbeanjuice/cafeapi/beta/RaffleTest.java b/src/test/java/com/beanbeanjuice/cafeapi/beta/RaffleTest.java index 1e46a00..d917046 100644 --- a/src/test/java/com/beanbeanjuice/cafeapi/beta/RaffleTest.java +++ b/src/test/java/com/beanbeanjuice/cafeapi/beta/RaffleTest.java @@ -20,7 +20,7 @@ public void rafflesAPITest() { CafeAPI cafeAPI = new CafeAPI("beanbeanjuice", System.getenv("API_PASSWORD"), RequestLocation.BETA); long currentTime = System.currentTimeMillis(); - Timestamp currentTimestamp = CafeGeneric.parseTimestamp(new Timestamp(currentTime).toString()); + Timestamp currentTimestamp = CafeGeneric.parseTimestamp(new Timestamp(currentTime).toString()).orElse(null); // Makes sure the raffle is deleted beforehand. Assertions.assertTrue(cafeAPI.RAFFLE.deleteRaffle("798830792938881024", "878895791081676831")); diff --git a/src/test/java/com/beanbeanjuice/cafeapi/utility/TimeTest.java b/src/test/java/com/beanbeanjuice/cafeapi/utility/TimeTest.java index 50c8514..ea45675 100644 --- a/src/test/java/com/beanbeanjuice/cafeapi/utility/TimeTest.java +++ b/src/test/java/com/beanbeanjuice/cafeapi/utility/TimeTest.java @@ -60,7 +60,7 @@ public void testDatePassing() throws ParseException { assertTrue(Time.isSameDay(new Date())); assertFalse(Time.dateHasPassed(new Date(System.currentTimeMillis() + 120))); - Date birthday = Time.getFullDate("07-6-2020", TimeZone.getTimeZone("EST")); + Date birthday = Time.getFullDate("01-6-2020", TimeZone.getTimeZone("EST")); assertTrue(Time.dateHasPassed(birthday)); assertFalse(Time.dateHasPassed(new Date()));