Skip to content

Commit

Permalink
Merge pull request #27 from beanbeanjuice/major-update
Browse files Browse the repository at this point in the history
The Optional Update
  • Loading branch information
beanbeanjuice authored May 28, 2024
2 parents f495eba + 1dceb1b commit f61834b
Show file tree
Hide file tree
Showing 64 changed files with 1,038 additions and 1,377 deletions.
30 changes: 14 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<maven.compiler.target>16</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<version.number>1.4.0</version.number>
<version.number>1.5.0</version.number>
</properties>

<profiles>
Expand Down Expand Up @@ -162,47 +162,39 @@
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.4</version>
<type>maven-plugin</type>
</dependency>

<!-- Nexus Staging Maven Plugin -->
<dependency>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
</dependency>

<!-- Jetbrains Annotations -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<scope>compile</scope>
<version>1.7.0</version>
</dependency>

<!-- Faster XML for JSON Parsing -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.15.2</version>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.2</version>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.15.2</version>
<version>2.17.1</version>
</dependency>

<!-- HTTPComponents for REQUESTS to the API -->
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.1</version>
<version>5.3.1</version>
</dependency>

<!-- DOTENV for Environment Variable Support -->
Expand All @@ -222,9 +214,15 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.0</version>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>

</dependencies>

Expand Down
32 changes: 12 additions & 20 deletions src/main/java/com/beanbeanjuice/cafeapi/CafeAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,15 +20,15 @@
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;

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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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();
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/beanbeanjuice/cafeapi/api/CafeAPI.java
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -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;
}

Expand All @@ -37,19 +36,18 @@ 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<String, Timestamp> getAllUserDonationTimes()
throws AuthorizationException, ResponseException {
HashMap<String, Timestamp> donationUsers = new HashMap<>();

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);
}
Expand All @@ -65,13 +63,12 @@ public HashMap<String, Timestamp> 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<Timestamp> 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());
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,18 +16,18 @@
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.
* @param month The {@link BirthdayMonth month} of the {@link 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;

Expand All @@ -45,40 +44,35 @@ 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;
}

/**
* @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;
}

/**
* @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);
}

/**
* @return The {@link TimeZone} for the {@link Birthday}.
*/
@NotNull
public TimeZone getTimeZone() {
return timeZone;
}
Expand Down
Loading

0 comments on commit f61834b

Please sign in to comment.