Skip to content

Commit d26bf5c

Browse files
authored
🚀 Version 1.1 • Added getLast12HVotes() endpoint.
New update to include the new endpoint to retrieve the last 12 hours voters. Just use the function getLast12HVotes(). (Must have authorization token)
1 parent 2a33c03 commit d26bf5c

File tree

4 files changed

+77
-10
lines changed

4 files changed

+77
-10
lines changed

‎pom.xml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@
1717
<build>
1818
<plugins>
1919
<plugin>
20-
<groupId>org.apache.maven.plugins</groupId>
21-
<artifactId>maven-compiler-plugin</artifactId>
22-
<version>3.5.1</version>
20+
<artifactId>maven-assembly-plugin</artifactId>
2321
<configuration>
24-
<source>1.8</source>
25-
<target>1.8</target>
22+
<archive>
23+
<manifest>
24+
<mainClass>me.dorian349.bfdapi.BotsForDiscordAPI</mainClass>
25+
</manifest>
26+
</archive>
27+
<descriptorRefs>
28+
<descriptorRef>jar-with-dependencies</descriptorRef>
29+
</descriptorRefs>
2630
</configuration>
2731
</plugin>
28-
<plugin>
29-
<groupId>org.apache.maven.plugins</groupId>
30-
<artifactId>maven-surefire-plugin</artifactId>
31-
<version>2.12.4</version>
32-
</plugin>
3332
</plugins>
3433
</build>
3534

‎src/main/java/me/dorian349/bfdapi/BotsForDiscordAPI.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.mashape.unirest.http.Unirest;
77
import com.mashape.unirest.http.exceptions.UnirestException;
88
import me.dorian349.bfdapi.entities.bot.Bot;
9+
import me.dorian349.bfdapi.entities.bot.BotLastVotes;
910
import me.dorian349.bfdapi.entities.bot.BotVotes;
1011
import me.dorian349.bfdapi.entities.user.User;
1112
import me.dorian349.bfdapi.entities.user.UserBots;
@@ -139,6 +140,36 @@ public BotVotes getVotes(){
139140
}
140141
}
141142

143+
/**
144+
* Returns the {@link BotLastVotes} instance of this bot
145+
*
146+
* @throws java.lang.IllegalArgumentException
147+
* If the provided bot id cannot be found or no user
148+
* has voted in the last 12 hours.
149+
*
150+
* @return the corresponding BotLastVotes instance.
151+
*/
152+
public BotLastVotes getLast12HVotes(){
153+
HttpResponse<String> response;
154+
155+
if(this.botId == null) throw new IllegalArgumentException("The bot id cannot be null.");
156+
157+
try {
158+
response = Unirest.get("https://discords.com/bots/api/bot/" + this.botId + "/votes12h").header("Authorization", this.bfdToken).header("Content-Type", "application/json").asString();
159+
if(response.getStatus() == 200){
160+
if(new JSONObject(response.getBody()).get("entries") instanceof String){
161+
throw new IllegalArgumentException(new JSONObject(response.getBody()).getString("entries"));
162+
}
163+
return gson.fromJson(response.getBody(), BotLastVotes.class);
164+
}
165+
else {
166+
throw new IllegalArgumentException(new JSONObject(response.getBody()).getString("message"));
167+
}
168+
} catch (UnirestException e) {
169+
throw new IllegalArgumentException(e);
170+
}
171+
}
172+
142173
/**
143174
* Returns the bot widget as a {@link String}
144175
*
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package me.dorian349.bfdapi.entities.bot;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import me.dorian349.bfdapi.entities.user.UserEntry;
5+
6+
import java.util.List;
7+
8+
public class BotLastVotes {
9+
10+
@SerializedName("entries")
11+
private List<UserEntry> entries;
12+
13+
public List<UserEntry> getEntries() {
14+
return entries;
15+
}
16+
}
17+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package me.dorian349.bfdapi.entities.user;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
public class UserEntry {
6+
7+
@SerializedName("userid")
8+
private String userId;
9+
10+
@SerializedName("expires")
11+
private String expirationString;
12+
13+
public String getUserId() {
14+
return userId;
15+
}
16+
17+
public String getExpirationString() {
18+
return expirationString;
19+
}
20+
}

0 commit comments

Comments
 (0)