Skip to content

Commit

Permalink
Refactored the Wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
beanbeanjuice committed Jun 23, 2024
1 parent 1858f72 commit 8b92a69
Show file tree
Hide file tree
Showing 54 changed files with 631 additions and 878 deletions.
4 changes: 2 additions & 2 deletions wrappers/cafe-api-wrapper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {
implementation("com.fasterxml.jackson.core", "jackson-databind", "2.17.1")
implementation("com.fasterxml.jackson.core", "jackson-annotations", "2.17.1")

implementation("org.apache.httpcomponents", "httpclient", "4.5.14")
implementation("org.apache.httpcomponents.client5:httpclient5:5.3.1")

testImplementation("junit", "junit", "4.13.2")
testImplementation("org.junit.jupiter", "junit-jupiter", "5.8.1")
Expand All @@ -20,6 +20,6 @@ dependencies {

tasks.withType<ShadowJar> {
relocate("com.fasterxml.jackson.core", "com.beanbeanjuice.cafeapi.wrapper.libs.com.fasterxml.jackson.core")
relocate("org.apache.httpcomponents", "com.beanbeanjuice.cafeapi.wrapper.libs.org.apache.httpcomponents")
relocate("org.apache.httpcomponents.client5:httpclient5", "com.beanbeanjuice.cafeapi.wrapper.libs.org.apache.httpcomponents.client5:httpclient5")
relocate("org.jetbrains", "com.beanbeanjuice.cafeapi.wrapper.libs.org.jetbrains")
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
package com.beanbeanjuice.cafeapi.wrapper;

import com.beanbeanjuice.cafeapi.wrapper.endpoints.CafeEndpoint;
import com.beanbeanjuice.kawaiiapi.wrapper.KawaiiAPI;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.goodbyes.Goodbyes;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.goodbyes.GoodbyesEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.requests.*;
import com.beanbeanjuice.cafeapi.wrapper.user.Users;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.beancoins.users.DonationUsers;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.birthdays.Birthdays;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.cafe.CafeUsers;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.codes.GeneratedCodes;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.counting.GlobalCountingInformation;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.guilds.GlobalGuildInformation;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.interactions.Interactions;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.interactions.pictures.InteractionPictures;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.minigames.winstreaks.WinStreaks;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.polls.Polls;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.raffles.Raffles;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.twitches.GuildTwitches;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.version.Versions;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.voicebinds.VoiceChannelBinds;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.welcomes.Welcomes;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.words.Words;
import com.beanbeanjuice.cafeapi.wrapper.user.UsersEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.beancoins.users.DonationUsersEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.birthdays.BirthdaysEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.cafe.CafeUsersEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.codes.GeneratedCodesEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.counting.CountingEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.guilds.GuildsEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.interactions.InteractionsEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.interactions.pictures.InteractionPicturesEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.minigames.winstreaks.WinStreaksEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.polls.PollsEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.raffles.RafflesEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.twitches.TwitchEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.version.VersionsEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.voicebinds.VoiceChannelBindsEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.welcomes.WelcomesEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.words.WordsEndpoint;
import lombok.Getter;

import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -33,25 +37,25 @@ public class CafeAPI {
@Getter private static RequestLocation requestLocation;
public KawaiiAPI KAWAII_API;

public Users USER;

public Words WORD;
public Welcomes WELCOME;
public Goodbyes GOODBYE;
public VoiceChannelBinds VOICE_CHANNEL_BIND;
public Raffles RAFFLE;
public Polls POLL;
public WinStreaks WIN_STREAK;
public Interactions INTERACTION;
public GuildTwitches TWITCH;
public GlobalGuildInformation GUILD;
public GeneratedCodes GENERATED_CODE;
public Versions VERSION;
public GlobalCountingInformation COUNTING_INFORMATION;
public CafeUsers CAFE_USER;
public Birthdays BIRTHDAY;
public DonationUsers DONATION_USER;
public InteractionPictures INTERACTION_PICTURE;
@Getter private final UsersEndpoint usersEndpoint;

@Getter private final WordsEndpoint wordsEndpoint;
@Getter private final WelcomesEndpoint welcomesEndpoint;
@Getter private final GoodbyesEndpoint goodbyesEndpoint;
@Getter private final VoiceChannelBindsEndpoint voiceChannelBindsEndpoint;
@Getter private final RafflesEndpoint rafflesEndpoint;
@Getter private final PollsEndpoint pollsEndpoint;
@Getter private final WinStreaksEndpoint winStreaksEndpoint;
@Getter private final InteractionsEndpoint interactionsEndpoint;
@Getter private final TwitchEndpoint twitchEndpoint;
@Getter private final GuildsEndpoint guildsEndpoint;
@Getter private final GeneratedCodesEndpoint generatedCodesEndpoint;
@Getter private final VersionsEndpoint versionsEndpoint;
@Getter private final CountingEndpoint countingEndpoint;
@Getter private final CafeUsersEndpoint cafeUsersEndpoint;
@Getter private final BirthdaysEndpoint birthdaysEndpoint;
@Getter private final DonationUsersEndpoint donationUsersEndpoint;
@Getter private final InteractionPicturesEndpoint interactionPicturesEndpoint;

/**
* Creates a new {@link CafeAPI} object.
Expand All @@ -64,34 +68,52 @@ public CafeAPI(String username, String password, RequestLocation requestLocation
this.userAgent = username;
CafeAPI.requestLocation = requestLocation;

setAPIKey(username, password);
startRefreshTimer(username, password);

usersEndpoint = new UsersEndpoint();

// cafeBot
wordsEndpoint = new WordsEndpoint();
welcomesEndpoint = new WelcomesEndpoint();
goodbyesEndpoint = new GoodbyesEndpoint();
voiceChannelBindsEndpoint = new VoiceChannelBindsEndpoint();
rafflesEndpoint = new RafflesEndpoint();
pollsEndpoint = new PollsEndpoint();
winStreaksEndpoint = new WinStreaksEndpoint();
interactionsEndpoint = new InteractionsEndpoint();
twitchEndpoint = new TwitchEndpoint();
guildsEndpoint = new GuildsEndpoint();
generatedCodesEndpoint = new GeneratedCodesEndpoint();
versionsEndpoint = new VersionsEndpoint();
countingEndpoint = new CountingEndpoint();
cafeUsersEndpoint = new CafeUsersEndpoint();
birthdaysEndpoint = new BirthdaysEndpoint();
donationUsersEndpoint = new DonationUsersEndpoint();
interactionPicturesEndpoint = new InteractionPicturesEndpoint(this);

KAWAII_API = new KawaiiAPI("anonymous");
}

private void setAPIKey(final String username, final String password) {
try {
apiKey = getToken(username, password);
} catch (Exception e) {
Logger.getLogger(CafeAPI.class.getName()).log(Level.SEVERE, "Unable to login. Could the username or password be incorrect?");
}
CafeEndpoint.updateAPIKey(apiKey);
}

USER = new Users(apiKey);

// cafeBot
WORD = new Words(apiKey);
WELCOME = new Welcomes(apiKey);
GOODBYE = new Goodbyes(apiKey);
VOICE_CHANNEL_BIND = new VoiceChannelBinds(apiKey);
RAFFLE = new Raffles(apiKey);
POLL = new Polls(apiKey);
WIN_STREAK = new WinStreaks(apiKey);
INTERACTION = new Interactions(apiKey);
TWITCH = new GuildTwitches(apiKey);
GUILD = new GlobalGuildInformation(apiKey);
GENERATED_CODE = new GeneratedCodes(apiKey);
VERSION = new Versions(apiKey);
COUNTING_INFORMATION = new GlobalCountingInformation(apiKey);
CAFE_USER = new CafeUsers(apiKey);
BIRTHDAY = new Birthdays(apiKey);
DONATION_USER = new DonationUsers(apiKey);
INTERACTION_PICTURE = new InteractionPictures(apiKey, this);
private void startRefreshTimer(String username, String password) {
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
setAPIKey(username, password);
}
};

KAWAII_API = new KawaiiAPI("anonymous");
Timer timer = new Timer();
timer.scheduleAtFixedRate(timerTask, TimeUnit.MINUTES.toMillis(55), TimeUnit.MINUTES.toMillis(55));
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.beanbeanjuice.cafeapi.wrapper.endpoints;

public abstract class CafeEndpoint {

protected static String apiKey;

public static void updateAPIKey(final String apiKey) {
CafeEndpoint.apiKey = apiKey;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.beanbeanjuice.cafeapi.wrapper.endpoints.beancoins.users;

import com.beanbeanjuice.cafeapi.wrapper.CafeAPI;
import com.beanbeanjuice.cafeapi.wrapper.api.ICafeAPI;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.CafeEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.generic.CafeGeneric;
import com.beanbeanjuice.cafeapi.wrapper.requests.Request;
import com.beanbeanjuice.cafeapi.wrapper.requests.RequestBuilder;
Expand All @@ -15,21 +15,11 @@
import java.util.Optional;

/**
* A class used to make {@link DonationUsers} requests to the {@link CafeAPI CafeAPI}.
* A class used to make {@link DonationUsersEndpoint} requests to the {@link CafeAPI CafeAPI}.
*
* @author beanbeanjuice
*/
public class DonationUsers implements ICafeAPI {

private String apiKey;

/**
* Creates a new {@link DonationUsers} object.
* @param apiKey The {@link String apiKey} used for authorization.
*/
public DonationUsers(final String apiKey) {
this.apiKey = apiKey;
}
public class DonationUsersEndpoint extends CafeEndpoint {

/**
* Retrieves all {@link Timestamp} from the {@link CafeAPI CafeAPI} containing when a specified {@link String userID} can be donated to again.
Expand Down Expand Up @@ -112,13 +102,4 @@ public Boolean deleteDonationUser(final String userID)
return request.getStatusCode() == 200;
}

/**
* Updates the {@link String apiKey}.
* @param apiKey The new {@link String apiKey}.
*/
@Override
public void updateAPIKey(final String apiKey) {
this.apiKey = apiKey;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.beanbeanjuice.cafeapi.wrapper.endpoints.birthdays;

import com.beanbeanjuice.cafeapi.wrapper.CafeAPI;
import com.beanbeanjuice.cafeapi.wrapper.api.ICafeAPI;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.CafeEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.requests.Request;
import com.beanbeanjuice.cafeapi.wrapper.requests.RequestBuilder;
import com.beanbeanjuice.cafeapi.wrapper.requests.RequestRoute;
Expand All @@ -21,17 +21,7 @@
*
* @author beanbeanjuice
*/
public class Birthdays implements ICafeAPI {

private String apiKey;

/**
* Creates a new {@link Birthdays} object.
* @param apiKey The {@link String apiKey} used for authorization.
*/
public Birthdays(final String apiKey) {
this.apiKey = apiKey;
}
public class BirthdaysEndpoint extends CafeEndpoint {

/**
* Retrieves all {@link Birthday} from the {@link CafeAPI CafeAPI}.
Expand Down Expand Up @@ -235,13 +225,4 @@ private String getBirthdayString(final BirthdayMonth month, final int day) {
return parseNumber(month.getMonthNumber()) + "-" + parseNumber(day);
}

/**
* Updates the {@link String apiKey}.
* @param apiKey The new {@link String apiKey}.
*/
@Override
public void updateAPIKey(final String apiKey) {
this.apiKey = apiKey;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.Getter;

/**
* A static {@link CafeType} used for the {@link CafeUsers} API.
* A static {@link CafeType} used for the {@link CafeUsersEndpoint} API.
*
* @author beanbeanjuice
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.beanbeanjuice.cafeapi.wrapper.endpoints.cafe;

import com.beanbeanjuice.cafeapi.wrapper.CafeAPI;
import com.beanbeanjuice.cafeapi.wrapper.api.ICafeAPI;
import com.beanbeanjuice.cafeapi.wrapper.endpoints.CafeEndpoint;
import com.beanbeanjuice.cafeapi.wrapper.generic.CafeGeneric;
import com.beanbeanjuice.cafeapi.wrapper.requests.Request;
import com.beanbeanjuice.cafeapi.wrapper.requests.RequestBuilder;
Expand All @@ -19,17 +19,7 @@
*
* @author beanbeanjuice
*/
public class CafeUsers implements ICafeAPI {

private String apiKey;

/**
* Creates a new {@link CafeUsers} object.
* @param apiKey The {@link String apiKey} used for authorization.
*/
public CafeUsers(final String apiKey) {
this.apiKey = apiKey;
}
public class CafeUsersEndpoint extends CafeEndpoint {

/**
* Retrieves all {@link CafeUser} from the {@link CafeAPI CafeAPI}.
Expand Down Expand Up @@ -166,13 +156,4 @@ private CafeUser parseCafeUser(JsonNode node) {
return new CafeUser(userID, beanCoins, timestamp, ordersBought, ordersReceived);
}

/**
* Updates the {@link String apiKey}.
* @param apiKey The new {@link String apiKey}.
*/
@Override
public void updateAPIKey(String apiKey) {
this.apiKey = apiKey;
}

}
Loading

0 comments on commit 8b92a69

Please sign in to comment.