Skip to content
This repository was archived by the owner on Jul 27, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/maven-publish-snapshot-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches:
- integration
- master
push:
branches:
- integration

# https://stackoverflow.com/questions/61096521/how-to-use-gpg-key-in-github-actions
# https://github.com/actions/setup-java/issues/83
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![wakatime](https://wakatime.com/badge/user/beeb4317-977b-4b19-878a-21e9aa8e43ed/project/da9ac356-721a-40dd-a76a-19c3ff0d57d5.svg?style=for-the-badge)](https://wakatime.com/badge/user/beeb4317-977b-4b19-878a-21e9aa8e43ed/project/da9ac356-721a-40dd-a76a-19c3ff0d57d5)
[![wakatime](https://wakatime.com/badge/github/beanbeanjuice/Java-Cafe-API-Wrapper.svg?style=for-the-badge)](https://wakatime.com/badge/github/beanbeanjuice/Java-Cafe-API-Wrapper)
[![CodeFactor](https://www.codefactor.io/repository/github/beanbeanjuice/java-cafe-api-wrapper/badge?style=for-the-badge)](https://www.codefactor.io/repository/github/beanbeanjuice/java-cafe-api-wrapper)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/beanbeanjuice/Java-Cafe-API-Wrapper?style=for-the-badge)

Expand Down Expand Up @@ -60,10 +60,17 @@
<!-- GETTING STARTED -->
# Getting Started

To add this bot to your server, follow these steps.
## Usage

```Java
CafeAPI cafeAPI = new CafeAPI(USERNAME_HERE, PASSWORD_HERE, RequestLocation.RELEASE);
cafeAPI.BIRTHDAY.getUserBirthday(USER_ID_HERE);
```

## Installation

![Maven Central](https://img.shields.io/maven-central/v/com.beanbeanjuice/cafe-api-wrapper?color=%23CBC3E3)

For `Maven`, paste this into your `dependencies` section of your `pom.xml` file.
```XML
<!-- Cafe API -->
Expand Down
28 changes: 14 additions & 14 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.3.1</version.number>
<version.number>1.4.0</version.number>
</properties>

<profiles>
Expand Down Expand Up @@ -74,7 +74,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<version>3.1.2</version>
</plugin>

<plugin>
Expand All @@ -92,7 +92,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<version>3.3.0</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -105,7 +105,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<version>3.5.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -119,7 +119,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<version>3.1.0</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down Expand Up @@ -155,14 +155,14 @@
<dependency>
<groupId>com.beanbeanjuice</groupId>
<artifactId>kawaii-api-wrapper</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
</dependency>

<!-- GPG Plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<version>3.1.0</version>
<type>maven-plugin</type>
</dependency>

Expand All @@ -185,24 +185,24 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.3</version>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.3</version>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.3</version>
<version>2.15.2</version>
</dependency>

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

<!-- DOTENV for Environment Variable Support -->
Expand All @@ -222,7 +222,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<version>5.9.0</version>
<scope>test</scope>
</dependency>

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/beanbeanjuice/cafeapi/CafeAPI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.beanbeanjuice.cafeapi;

import com.beanbeanjuice.KawaiiAPI;
import com.beanbeanjuice.cafeapi.cafebot.goodbyes.Goodbyes;
import com.beanbeanjuice.cafeapi.requests.*;
import com.beanbeanjuice.cafeapi.user.Users;
import com.beanbeanjuice.cafeapi.cafebot.beancoins.users.DonationUsers;
Expand Down Expand Up @@ -34,6 +35,7 @@ public class CafeAPI {

public Words WORD;
public Welcomes WELCOME;
public Goodbyes GOODBYE;
public VoiceChannelBinds VOICE_CHANNEL_BIND;
public Raffles RAFFLE;
public Polls POLL;
Expand Down Expand Up @@ -71,6 +73,7 @@ public CafeAPI(@NotNull String username, @NotNull String password, @NotNull Requ
// 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);
Expand Down
176 changes: 176 additions & 0 deletions src/main/java/com/beanbeanjuice/cafeapi/cafebot/goodbyes/Goodbyes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package com.beanbeanjuice.cafeapi.cafebot.goodbyes;

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 org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

/**
* A class used for the {@link Goodbyes} API.
*/
public class Goodbyes {

private String apiKey;

/**
* Creates a new class used for {@link Goodbyes} API requests.
* @param apiKey The API key used for authorization.
*/
public Goodbyes(@NotNull String apiKey) {
this.apiKey = apiKey;
}

/**
* Retrieves an {@link ArrayList} of {@link GuildGoodbye} containing all Guild Goodbyes in the {@link CafeAPI CafeAPI}.
* @return The {@link ArrayList} of {@link GuildGoodbye}.
* @throws AuthorizationException Thrown when the api key is unauthorized.
* @throws ResponseException Thrown when there is a generic server-side exception.
*/
@NotNull
public ArrayList<GuildGoodbye> getAllGuildGoodbyes() throws AuthorizationException, ResponseException {
ArrayList<GuildGoodbye> guildGoodbyes = new ArrayList<>();

Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET)
.setRoute("/goodbyes")
.setAuthorization(apiKey)
.build();

for (JsonNode guildGoodbye : request.getData().get("goodbyes")) {
guildGoodbyes.add(parseGuildGoodbye(guildGoodbye));
}

return guildGoodbyes;
}

/**
* Retrieves a {@link GuildGoodbye} from the {@link CafeAPI CafeAPI}.
* @param guildID The {@link String guildID} to retrieve the {@link GuildGoodbye} for.
* @return The {@link GuildGoodbye} retrieved.
* @throws AuthorizationException Thrown when the API key is invalid.
* @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)
throws AuthorizationException, ResponseException, NotFoundException {
Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.GET)
.setRoute("/goodbyes/" + guildID)
.setAuthorization(apiKey)
.build();

JsonNode guildGoodbye = request.getData().get("goodbye");

return parseGuildGoodbye(guildGoodbye);
}

/**
* Updates a {@link GuildGoodbye} in the {@link CafeAPI CafeAPI}.
* @param guildGoodbye The new {@link GuildGoodbye}.
* @return True, if updating the {@link GuildGoodbye} was successful.
* @throws AuthorizationException Thrown when the API key is invalid.
* @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)
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())
.setAuthorization(apiKey)
.build();

return request.getStatusCode() == 200;
}

/**
* Creates a new {@link GuildGoodbye} for the {@link CafeAPI CafeAPI}.
* @param guildGoodbye The new {@link GuildGoodbye} to add.
* @return True if the {@link GuildGoodbye} was successfully added.
* @throws AuthorizationException Thrown when the API key is invalid.
* @throws ConflictException Thrown when the provided guild ID already exists.
* @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)
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())
.setAuthorization(apiKey)
.build();

return request.getStatusCode() == 201;
}

/**
* Deletes a {@link GuildGoodbye} from the {@link CafeAPI CafeAPI}.
* @param guildID The {@link String} ID of the {@link GuildGoodbye} to delete.
* @return True if successfully deleted.
* @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)
throws AuthorizationException, ResponseException {
Request request = new RequestBuilder(RequestRoute.CAFEBOT, RequestType.DELETE)
.setRoute("/goodbyes/" + guildID)
.setAuthorization(apiKey)
.build();

return request.getStatusCode() == 200;
}

/**
* Parses a {@link GuildGoodbye} from the {@link JsonNode}.
* @param node The {@link JsonNode} to parse.
* @return The parsed {@link GuildGoodbye}.
*/
@NotNull
private GuildGoodbye parseGuildGoodbye(@NotNull JsonNode node) {
String guildID = node.get("guild_id").asText();

String description = node.get("description").asText();
String thumbnailURL = node.get("thumbnail_url").asText();
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;
}

return new GuildGoodbye(
guildID,
description,
thumbnailURL,
imageURL,
message
);
}

}
Loading