Skip to content

Commit b60b483

Browse files
committed
Add Annotations for Get and Post
1 parent f424df2 commit b60b483

File tree

6 files changed

+168
-3
lines changed

6 files changed

+168
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins{
99
id 'net.kyori.blossom' version '1.1.0'
1010
}
1111

12-
def ver = new Version(major: 6, minor: 2, patch: 2)
12+
def ver = new Version(major: 6, minor: 3, patch: 0)
1313

1414
allprojects {
1515
apply plugin: 'com.jfrog.bintray'

core/src/main/java/org/botblock/javabotblockapi/core/BotBlockAPI.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
package org.botblock.javabotblockapi.core;
2020

21+
import org.botblock.javabotblockapi.core.annotations.Post;
22+
2123
import javax.annotation.Nonnull;
24+
import java.lang.reflect.Field;
2225
import java.util.HashMap;
2326
import java.util.Map;
2427

@@ -77,8 +80,10 @@ public Builder(){}
7780
* The API token from the corresponding bot list. May not be null or empty.
7881
* <br>You may receive the API token from the bot list.
7982
*
80-
* @throws java.lang.NullPointerException
81-
* When the provided token is empty ({@code ""}).
83+
* <p>Following Exceptions can be thrown from the {@link org.botblock.javabotblockapi.core.CheckUtil CheckUtil}:
84+
* <ul>
85+
* <li>{@link java.lang.NullPointerException NullPointerException} - When the provided Token is empty.</li>
86+
* </ul>
8287
*
8388
* @return The Builder after the site and token were set. Useful for chaining.
8489
*
@@ -87,6 +92,16 @@ public Builder(){}
8792
public Builder addAuthToken(@Nonnull Site site, @Nonnull String token){
8893
CheckUtil.notEmpty(token, "Token");
8994

95+
Field field;
96+
try{
97+
field = site.getClass().getField(site.name());
98+
}catch(NoSuchFieldException ex){
99+
field = null;
100+
}
101+
102+
if(field == null || !field.isAnnotationPresent(Post.class))
103+
throw new IllegalStateException("The provided Site instance is not allowed for POST Actions!");
104+
90105
tokens.put(site.getSite(), token);
91106
return this;
92107
}

core/src/main/java/org/botblock/javabotblockapi/core/CheckUtil.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
package org.botblock.javabotblockapi.core;
2020

21+
import org.botblock.javabotblockapi.core.annotations.Get;
22+
import org.botblock.javabotblockapi.core.annotations.Post;
23+
24+
import java.lang.reflect.Field;
2125
import java.util.Map;
2226

2327
/**
@@ -63,4 +67,40 @@ public static void condition(boolean expression, String message){
6367
if(expression)
6468
throw new IllegalStateException(message);
6569
}
70+
71+
/**
72+
* Will throw a {@link java.lang.IllegalStateException IllegalStateException} when the provided
73+
* {@link org.botblock.javabotblockapi.core.Site Site instance} does not have the
74+
* {@link org.botblock.javabotblockapi.core.annotations.Post @Post annotation}.
75+
*
76+
* @param site
77+
* The Site instance to check.
78+
*/
79+
public static void supportsPost(Site site){
80+
Field field = getField(site);
81+
82+
condition(field == null || !field.isAnnotationPresent(Post.class), site.getSite() + " does not support POST!");
83+
}
84+
85+
/**
86+
* Will throw a {@link java.lang.IllegalStateException IllegalStateException} when the provided
87+
* {@link org.botblock.javabotblockapi.core.Site Site instance} does not have the
88+
* {@link org.botblock.javabotblockapi.core.annotations.Get @Post annotation}.
89+
*
90+
* @param site
91+
* The Site instance to check.
92+
*/
93+
public static void supportsGet(Site site){
94+
Field field = getField(site);
95+
96+
condition(field == null || !field.isAnnotationPresent(Get.class), site.getSite() + " does not support GET!");
97+
}
98+
99+
private static Field getField(Site site){
100+
try{
101+
return site.getClass().getField(site.name());
102+
}catch(NoSuchFieldException ex){
103+
return null;
104+
}
105+
}
66106
}

core/src/main/java/org/botblock/javabotblockapi/core/Site.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
*/
1818
package org.botblock.javabotblockapi.core;
1919

20+
import org.botblock.javabotblockapi.core.annotations.Get;
21+
import org.botblock.javabotblockapi.core.annotations.Post;
22+
2023
/**
2124
* Enum class containing all sites currently supported by BotBlock.org.
2225
*
@@ -27,138 +30,179 @@ public enum Site {
2730
/**
2831
* <a href="https://arcane-center.xyz" target="_blank">arcane-center.xyz</a>
2932
*/
33+
@Post
3034
ARCANE_CENTER_XYZ("arcane-center.xyz"),
3135

3236
/**
3337
* <a href="https://blist.xyz" target="_blank">blist.xyz</a>
3438
*/
39+
@Post
3540
BLIST_XYZ("blist.xyz"),
3641

3742
/**
3843
* <a href="https://botlist.space" target="_blank">botlist.space</a>
3944
*/
45+
@Post
4046
BOTLIST_SPACE("botlist.space"),
4147

4248
/**
4349
* <a href="https://botsdatabase.com" target="_blank">botsdatabase.com</a>
4450
*/
51+
@Post
4552
BOTSDATABASE_COM("botsdatabase.com"),
4653

4754
/**
4855
* <a href="https://bots.discordlabs.org" target="_blank">bots.discordlabs.org</a>
4956
*/
57+
@Post
5058
BOTS_DISCORDLABS_ORG("bots.discordlabs.org"),
5159

5260
/**
5361
* <a href="https://botsfordiscord.com" target="_blank">botsfordiscord.com</a>
5462
*/
63+
@Post
5564
BOTSFORDISCORD_COM("botsfordiscord.com"),
5665

5766
/**
5867
* <a href="https://bots.ondiscord.xyz" target="_blank">bots.ondiscord.xyz</a>
5968
*/
69+
@Post
6070
BOTS_ONDISCORD_XYZ("bots.ondiscord.xyz"),
6171

6272
/**
6373
* <a href="https://dblista.pl" target="_blank">dblista.pl</a>
6474
*/
75+
@Post
6576
DBLISTA_PL("dblista.pl"),
6677

6778
/**
6879
* <a href="https://discordapps.dev" target="_blank">discordapps.dev</a>
6980
*/
81+
@Post
7082
DISCORDAPPS_DEV("discordapps.dev"),
7183

7284
/**
7385
* <a href="https://discord.boats" target="_blank">discord.boats</a>
7486
*/
87+
@Post
7588
DISCORD_BOATS("discord.boats"),
7689

90+
/**
91+
* <a href="https://discordbotdirectory.net" target="_blank">discordbotdirectory.net</a>
92+
*
93+
* @since 6.3.0
94+
*/
95+
@Get
96+
DISCORDBOTDIRECTORY_NET("discordbotdirectory.net"),
97+
7798
/**
7899
* <a href="https://discordbotlist.com" target="_blank">discordbotlist.com</a>
79100
*/
101+
@Post
80102
DISCORDBOTLIST_COM("discordbotlist.com"),
81103

82104
/**
83105
* <a href="https://discordbots.co" target="_blank">discordbots.co</a>
84106
*
85107
* @since 5.2.3
86108
*/
109+
@Post
87110
DISCORDBOTS_CO("discordbots.co"),
88111

89112
/**
90113
* <a href="https://discord.bots.gg" target="_blank">discord.bots.gg</a>
91114
*/
115+
@Post
92116
DISCORD_BOTS_GG("discord.bots.gg"),
93117

94118
/**
95119
* <a href="https://discordbots.fun" target="_blank">discordbots.fun</a>
96120
*/
121+
@Post
97122
DISCORDBOTS_FUN("discordbots.fun"),
98123

99124
/**
100125
* <a href="https://discordextremelist.xyz" target="_blank">discordextremelist.xyz</a>
101126
*
102127
* @since 2.3.3
103128
*/
129+
@Post
104130
DISCORDEXTREMELIST_XYZ("discordextremelist.xyz"),
105131

106132
/**
107133
* <a href="https://discordlist.co" target="_blank">discordlist.co</a>
108134
*/
135+
@Post
109136
DISCORDLIST_CO("discordlist.co"),
110137

111138
/**
112139
* <a href="https://discordlistology.com" target="_blank">discordlistology.com</a>
113140
*
114141
* @since 5.2.1
115142
*/
143+
@Post
116144
DISCORDLISTOLOGY_COM("discordlistology.com"),
117145

118146
/**
119147
* <a href="https://disforge.com/bots" target="_blank">disforge.com</a>
120148
*
121149
* @since 6.2.2
122150
*/
151+
@Post
123152
DISFORGE_COM("disforge.com"),
124153

125154
/**
126155
* <a href="https://glennbotlist.xyz" target="_blank">glennbotlist.xyz</a>
127156
*/
157+
@Post
128158
GLENNBOTLIST_XYZ("glennbotlist.xyz"),
129159

130160
/**
131161
* <a href="https://hydrogenbots.club" target="_blank">hydrogenbots.club</a>
132162
*
133163
* @since 6.2.1
134164
*/
165+
@Post
135166
HYDROGENBOTS_CLUB("hydrogenbots.club"),
136167

137168
/**
138169
* <a href="https://mythicalbots.xyz" target="_blank">mythicalbots.xyz</a>
139170
*/
171+
@Post
140172
MYTHICALBOTS_XYZ("mythicalbots.xyz"),
141173

142174
/**
143175
* <a href="https://space-bot-list.xyz" target="_blank">space-bot-list.xyz</a>
144176
*/
177+
@Post
145178
SPACE_BOT_LIST_XYZ("space-bot-list.xyz"),
146179

147180
/**
148181
* <a href="https://topcord.xyz" target="_blank">topcord.xyz</a>
149182
*/
183+
@Post
150184
TOPCORD_XYZ("topcord.xyz"),
151185

186+
/**
187+
* <a href="https://voidbots.net" target="_blank">voidbots.net</a>
188+
*
189+
* @since 6.3.0
190+
*/
191+
@Post
192+
VOIDBOTS_NET("voidbots.net"),
193+
152194
/**
153195
* <a href="https://wonderbotlist.com" target="_blank">wonderbotlist.com</a>
154196
*/
197+
@Post
155198
WONDERBOTLIST_COM("wonderbotlist.com"),
156199

157200
/**
158201
* <a href="https://yabl.xyz" target="_blank">yabl.xyz</a>
159202
*
160203
* @since 2.1.1
161204
*/
205+
@Post
162206
YABL_XYZ("yabl.xyz");
163207

164208
private final String site;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2019 - 2020 Andre601
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
6+
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7+
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial
10+
* portions of the Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
16+
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17+
*/
18+
19+
package org.botblock.javabotblockapi.core.annotations;
20+
21+
import java.lang.annotation.*;
22+
23+
/**
24+
* This annotation is used to mark all the {@link org.botblock.javabotblockapi.core.Site Sites} that support GET requests
25+
* with.
26+
* <br>It helps to determine whether a provided site instance supports this method or not and may result in this Wrapper
27+
* throwing an exception for it.
28+
*/
29+
@Documented
30+
@Retention(RetentionPolicy.RUNTIME)
31+
@Target(ElementType.FIELD)
32+
public @interface Get{
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2019 - 2020 Andre601
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
6+
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7+
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial
10+
* portions of the Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
16+
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17+
*/
18+
19+
package org.botblock.javabotblockapi.core.annotations;
20+
21+
import java.lang.annotation.*;
22+
23+
/**
24+
* This annotation is used to mark all the {@link org.botblock.javabotblockapi.core.Site Sites} that support POST requests
25+
* with.
26+
* <br>It helps to determine whether a provided site instance supports this method or not and may result in this Wrapper
27+
* throwing an exception for it.
28+
*/
29+
@Documented
30+
@Retention(RetentionPolicy.RUNTIME)
31+
@Target(ElementType.FIELD)
32+
public @interface Post{
33+
}

0 commit comments

Comments
 (0)