Skip to content

Commit 8c70f8c

Browse files
committed
Update 2.0: Added all actions to cover recent updates in the api
Documentation and nullity annotations are to follow
1 parent 73ea6a4 commit 8c70f8c

File tree

13 files changed

+639
-719
lines changed

13 files changed

+639
-719
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>me.robertlit</groupId>
88
<artifactId>SpigotResourcesAPI</artifactId>
9-
<version>1.2</version>
9+
<version>2.0</version>
1010

1111
<properties>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/me/robertlit/spigotresources/api/Author.java

Lines changed: 47 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,45 @@
11
package me.robertlit.spigotresources.api;
22

3-
import com.google.gson.annotations.JsonAdapter;
4-
import me.robertlit.spigotresources.internal.AuthorJsonAdapter;
5-
import me.robertlit.spigotresources.internal.HttpRequester;
6-
import org.jetbrains.annotations.NotNull;
7-
import org.jetbrains.annotations.Nullable;
3+
import com.google.gson.annotations.SerializedName;
84

9-
import java.awt.image.BufferedImage;
105
import java.util.Objects;
116

127
/**
138
* Represents a resource author
149
*/
15-
@JsonAdapter(AuthorJsonAdapter.class)
1610
public class Author {
11+
1712
private final int id;
1813
private final String username;
14+
@SerializedName("resource_count")
1915
private final int resourceCount;
2016
private final Identities identities;
21-
private final BufferedImage avatar;
22-
23-
private static final String AVATAR_URL = "https://www.spigotmc.org/data/avatars/l/%d/%d.jpg";
24-
private static final String DEFAULT_AVATAR_URL = "https://static.spigotmc.org/styles/spigot/xenforo/avatars/avatar_male_l.png";
25-
private static final BufferedImage DEFAULT_AVATAR = HttpRequester.requestImage(DEFAULT_AVATAR_URL);
17+
@SerializedName("avatar")
18+
private final String avatarLink;
2619

2720
/**
2821
* Constructs an Author with the given parameters
2922
* <p>
3023
* This should only be used internally
3124
* </p>
32-
* @param id user id
33-
* @param username username
25+
*
26+
* @param id user id
27+
* @param username username
3428
* @param resourceCount amount of resources
35-
* @param identities social media identities
29+
* @param identities social media identities
30+
* @param avatarLink link to avatar
3631
*/
37-
public Author(int id, @NotNull String username, int resourceCount, @NotNull Identities identities) {
32+
private Author(int id, String username, int resourceCount, Identities identities, String avatarLink) {
3833
this.id = id;
3934
this.username = username;
4035
this.resourceCount = resourceCount;
4136
this.identities = identities;
42-
BufferedImage image = HttpRequester.requestImage(String.format(AVATAR_URL, id / 1000, id));
43-
if (image == null) {
44-
image = DEFAULT_AVATAR;
45-
}
46-
this.avatar = image;
37+
this.avatarLink = avatarLink;
4738
}
4839

4940
/**
5041
* Gets this author's id
42+
*
5143
* @return id
5244
*/
5345
public int getId() {
@@ -56,15 +48,17 @@ public int getId() {
5648

5749
/**
5850
* Gets this author's username
51+
*
5952
* @return username
6053
*/
61-
@NotNull
54+
6255
public String getUsername() {
6356
return username;
6457
}
6558

6659
/**
6760
* Gets the amount of resources this author has published
61+
*
6862
* @return amount of resources this author has published
6963
*/
7064
public int getResourceCount() {
@@ -73,36 +67,29 @@ public int getResourceCount() {
7367

7468
/**
7569
* Gets this author's social media identities
70+
*
7671
* @return social media identities
7772
*/
78-
@NotNull
73+
7974
public Identities getIdentities() {
8075
return identities;
8176
}
8277

83-
/**
84-
* Gets this author's avatar
85-
* @return author's avatar
86-
*/
87-
@NotNull
88-
public BufferedImage getAvatar() {
89-
return avatar;
78+
public String getAvatarLink() {
79+
return avatarLink;
9080
}
9181

9282
@Override
9383
public boolean equals(Object o) {
9484
if (this == o) return true;
9585
if (o == null || getClass() != o.getClass()) return false;
9686
Author author = (Author) o;
97-
return id == author.id &&
98-
resourceCount == author.resourceCount &&
99-
username.equals(author.username) &&
100-
identities.equals(author.identities);
87+
return id == author.id && resourceCount == author.resourceCount && username.equals(author.username) && identities.equals(author.identities) && avatarLink.equals(author.avatarLink);
10188
}
10289

10390
@Override
10491
public int hashCode() {
105-
return Objects.hash(id, username, resourceCount, identities);
92+
return Objects.hash(id, username, resourceCount, identities, avatarLink);
10693
}
10794

10895
@Override
@@ -112,33 +99,36 @@ public String toString() {
11299
", username='" + username + '\'' +
113100
", resourceCount=" + resourceCount +
114101
", identities=" + identities +
102+
", avatarLink='" + avatarLink + '\'' +
115103
'}';
116104
}
117105

118106
/**
119107
* Represents an Author's social media identities
120108
*/
121109
public static class Identities {
110+
122111
private final String discord, youtube, aim, icq, msn, yahoo, skype, gtalk, facebook, twitter, github;
123112

124113
/**
125114
* Constructs an Identities object with the given parameters
126115
* <p>
127116
* This should only be used internally
128117
* </p>
129-
* @param discord discord identity
130-
* @param youtube youtube identity
131-
* @param aim aim identity
132-
* @param icq icq identity
133-
* @param msn msn identity
134-
* @param yahoo yahoo identity
135-
* @param skype skype identity
136-
* @param gtalk google talk identity
118+
*
119+
* @param discord discord identity
120+
* @param youtube youtube identity
121+
* @param aim aim identity
122+
* @param icq icq identity
123+
* @param msn msn identity
124+
* @param yahoo yahoo identity
125+
* @param skype skype identity
126+
* @param gtalk google talk identity
137127
* @param facebook facebook identity
138-
* @param twitter twitter identity
139-
* @param github github identity
128+
* @param twitter twitter identity
129+
* @param github github identity
140130
*/
141-
public Identities(@Nullable String discord, @Nullable String youtube, @Nullable String aim, @Nullable String icq, @Nullable String msn, @Nullable String yahoo, @Nullable String skype, @Nullable String gtalk, @Nullable String facebook, @Nullable String twitter, @Nullable String github) {
131+
public Identities(String discord, String youtube, String aim, String icq, String msn, String yahoo, String skype, String gtalk, String facebook, String twitter, String github) {
142132
this.discord = discord;
143133
this.youtube = youtube;
144134
this.aim = aim;
@@ -155,87 +145,87 @@ public Identities(@Nullable String discord, @Nullable String youtube, @Nullable
155145
/**
156146
* @return discord identity
157147
*/
158-
@Nullable
148+
159149
public String getDiscord() {
160150
return discord;
161151
}
162152

163153
/**
164154
* @return youtube identity
165155
*/
166-
@Nullable
156+
167157
public String getYoutube() {
168158
return youtube;
169159
}
170160

171161
/**
172162
* @return AIM identity
173163
*/
174-
@Nullable
164+
175165
public String getAim() {
176166
return aim;
177167
}
178168

179169
/**
180170
* @return ICQ identity
181171
*/
182-
@Nullable
172+
183173
public String getIcq() {
184174
return icq;
185175
}
186176

187177
/**
188178
* @return MSN identity
189179
*/
190-
@Nullable
180+
191181
public String getMsn() {
192182
return msn;
193183
}
194184

195185
/**
196186
* @return yahoo identity
197187
*/
198-
@Nullable
188+
199189
public String getYahoo() {
200190
return yahoo;
201191
}
202192

203193
/**
204194
* @return skype identity
205195
*/
206-
@Nullable
196+
207197
public String getSkype() {
208198
return skype;
209199
}
210200

211201
/**
212202
* @return google talk identity
213203
*/
214-
@Nullable
204+
215205
public String getGoogleTalk() {
216206
return gtalk;
217207
}
218208

219209
/**
220210
* @return facebook identity
221211
*/
222-
@Nullable
212+
223213
public String getFacebook() {
224214
return facebook;
225215
}
226216

227217
/**
228218
* @return twitter identity
229219
*/
230-
@Nullable
220+
231221
public String getTwitter() {
232222
return twitter;
233223
}
234224

235225
/**
236226
* @return github identity
237227
*/
238-
@Nullable
228+
239229
public String getGithub() {
240230
return github;
241231
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package me.robertlit.spigotresources.api;
2+
3+
import java.util.Objects;
4+
5+
public class Category {
6+
7+
private final int id;
8+
private final String title, description;
9+
10+
private Category(int id, String title, String description) {
11+
this.id = id;
12+
this.title = title;
13+
this.description = description;
14+
}
15+
16+
public int getId() {
17+
return id;
18+
}
19+
20+
public String getTitle() {
21+
return title;
22+
}
23+
24+
public String getDescription() {
25+
return description;
26+
}
27+
28+
@Override
29+
public boolean equals(Object o) {
30+
if (this == o) return true;
31+
if (o == null || getClass() != o.getClass()) return false;
32+
Category category = (Category) o;
33+
return id == category.id && title.equals(category.title) && description.equals(category.description);
34+
}
35+
36+
@Override
37+
public int hashCode() {
38+
return Objects.hash(id, title, description);
39+
}
40+
41+
@Override
42+
public String toString() {
43+
return "Category{" +
44+
"id=" + id +
45+
", title='" + title + '\'' +
46+
", description='" + description + '\'' +
47+
'}';
48+
}
49+
}

0 commit comments

Comments
 (0)