Skip to content

Commit

Permalink
Merge pull request #15 from beanbeanjuice/integration
Browse files Browse the repository at this point in the history
Added the KawaiiAPI
  • Loading branch information
beanbeanjuice authored Jul 16, 2022
2 parents 73ce342 + 17e83df commit e5ebcf2
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: CodeQL

on:
push:
branches: [ integration ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ integration ]
Expand Down
9 changes: 8 additions & 1 deletion 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.3.0</version.number>
<version.number>1.3.1</version.number>
</properties>

<profiles>
Expand Down Expand Up @@ -151,6 +151,13 @@
</distributionManagement>

<dependencies>
<!-- Kawaii API -->
<dependency>
<groupId>com.beanbeanjuice</groupId>
<artifactId>kawaii-api-wrapper</artifactId>
<version>1.1.0</version>
</dependency>

<!-- GPG Plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/com/beanbeanjuice/cafeapi/CafeAPI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.beanbeanjuice.cafeapi;

import com.beanbeanjuice.KawaiiAPI;
import com.beanbeanjuice.cafeapi.requests.*;
import com.beanbeanjuice.cafeapi.user.Users;
import com.beanbeanjuice.cafeapi.cafebot.beancoins.users.DonationUsers;
Expand Down Expand Up @@ -27,6 +28,7 @@ public class CafeAPI {
private String apiKey;
private String userAgent;
private static RequestLocation requestLocation;
public KawaiiAPI KAWAII_API;

public Users USER;

Expand Down Expand Up @@ -82,14 +84,27 @@ public CafeAPI(@NotNull String username, @NotNull String password, @NotNull Requ
CAFE_USER = new CafeUsers(apiKey);
BIRTHDAY = new Birthdays(apiKey);
DONATION_USER = new DonationUsers(apiKey);
INTERACTION_PICTURE = new InteractionPictures(apiKey);
INTERACTION_PICTURE = new InteractionPictures(apiKey, this);

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) {
KAWAII_API = new KawaiiAPI(token);
}

private String getToken(@NotNull String username, @NotNull String password) {
Request request = new RequestBuilder(RequestRoute.CAFE, RequestType.POST)
.setRoute("/user/login")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,57 @@

import com.beanbeanjuice.cafeapi.cafebot.interactions.users.Interaction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* An enum used for {@link Interaction Interaction} types.
*
* @author beanbeanjuice
* @since 1.3.1
*/
public enum InteractionType {

HUG ("hug_amount"),
PUNCH ("punch_amount"),
KISS ("kiss_amount"),
BITE ("bite_amount"),
BLUSH ("blush_amount"),
CUDDLE ("cuddle_amount"),
NOM ("nom_amount"),
POKE ("poke_amount"),
SLAP ("slap_amount"),
STAB ("stab_amount"),
HMPH ("hmph_amount"),
POUT ("pout_amount"),
THROW ("throw_amount"),
SMILE ("smile_amount"),
STARE ("stare_amount"),
TICKLE ("tickle_amount"),
RAGE ("rage_amount"),
YELL ("yell_amount"),
HEADPAT ("headpat_amount"),
CRY ("cry_amount"),
DANCE ("dance_amount"),
DAB ("dab_amount"),
BONK ("bonk_amount"),
SLEEP ("sleep_amount"),
DIE ("die_amount"),
WELCOME ("welcome_amount"),
LICK ("lick_amount"),
SHUSH ("shush_amount");
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);

private final String type;
private final Boolean isKawaiiAPI;
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) {
InteractionType(@NotNull String type, @NotNull Boolean isKawaiiAPI, @Nullable String kawaiiAPIString) {
this.type = type;
this.isKawaiiAPI = isKawaiiAPI;
this.kawaiiAPIString = kawaiiAPIString;
}

/**
Expand All @@ -56,4 +62,21 @@ public enum InteractionType {
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@
* A class used to retrieve random pictures from the {@link CafeAPI CafeAPI}.
*
* @author beanbeanjuice
* @since 1.3.1
*/
public class InteractionPictures implements com.beanbeanjuice.cafeapi.api.CafeAPI {

private String apiKey;
private final CafeAPI cafeAPI;

/**
* Creates a new {@link InteractionPictures} object.
* @param apiKey The {@link String apiKey} used for authorization.
*/
public InteractionPictures(@NotNull String apiKey) {
public InteractionPictures(@NotNull String apiKey, @NotNull CafeAPI cafeAPI) {
this.apiKey = apiKey;
this.cafeAPI = cafeAPI;
}

/**
Expand All @@ -41,12 +44,16 @@ public InteractionPictures(@NotNull String apiKey) {
@NotNull
public String getRandomInteractionPicture(@NotNull InteractionType type)
throws AuthorizationException, ResponseException, TeaPotException {
Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET)
.setRoute("/interaction_pictures/" + type)
.setAuthorization(apiKey)
.build();
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();

return request.getData().get("url").asText();
return request.getData().get("url").asText();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

/**
* Tests the {@link com.beanbeanjuice.cafeapi.cafebot.interactions.pictures.InteractionPictures InteractionPictures}.
* This confirms that the {@link CafeAPI} and {@link com.beanbeanjuice.KawaiiAPI KawaiiAPI} are both working.
*
* @author beanbeanjuice
* @since 1.3.1
*/
public class InteractionPictureTest {

@Test
Expand All @@ -17,7 +24,12 @@ public void testInteractionPicturesAPI() {
// Goes through every interaction type.
Assertions.assertDoesNotThrow(() -> {
for (InteractionType type : InteractionType.values()) {
Assertions.assertNotNull(cafeAPI.INTERACTION_PICTURE.getRandomInteractionPicture(type));

if (type.isKawaiiAPI())
Assertions.assertTrue(cafeAPI.INTERACTION_PICTURE.getRandomInteractionPicture(type).startsWith("https://api.kawaii.red/gif/"));

else
Assertions.assertNotNull(cafeAPI.INTERACTION_PICTURE.getRandomInteractionPicture(type));
}
});
}
Expand Down

0 comments on commit e5ebcf2

Please sign in to comment.