Skip to content

Commit

Permalink
Update 2.0: Added all actions to cover recent updates in the api
Browse files Browse the repository at this point in the history
Documentation and nullity annotations are to follow
  • Loading branch information
robertlit committed Jul 9, 2021
1 parent 73ea6a4 commit 8c70f8c
Show file tree
Hide file tree
Showing 13 changed files with 639 additions and 719 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.robertlit</groupId>
<artifactId>SpigotResourcesAPI</artifactId>
<version>1.2</version>
<version>2.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
104 changes: 47 additions & 57 deletions src/main/java/me/robertlit/spigotresources/api/Author.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,45 @@
package me.robertlit.spigotresources.api;

import com.google.gson.annotations.JsonAdapter;
import me.robertlit.spigotresources.internal.AuthorJsonAdapter;
import me.robertlit.spigotresources.internal.HttpRequester;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.google.gson.annotations.SerializedName;

import java.awt.image.BufferedImage;
import java.util.Objects;

/**
* Represents a resource author
*/
@JsonAdapter(AuthorJsonAdapter.class)
public class Author {

private final int id;
private final String username;
@SerializedName("resource_count")
private final int resourceCount;
private final Identities identities;
private final BufferedImage avatar;

private static final String AVATAR_URL = "https://www.spigotmc.org/data/avatars/l/%d/%d.jpg";
private static final String DEFAULT_AVATAR_URL = "https://static.spigotmc.org/styles/spigot/xenforo/avatars/avatar_male_l.png";
private static final BufferedImage DEFAULT_AVATAR = HttpRequester.requestImage(DEFAULT_AVATAR_URL);
@SerializedName("avatar")
private final String avatarLink;

/**
* Constructs an Author with the given parameters
* <p>
* This should only be used internally
* </p>
* @param id user id
* @param username username
*
* @param id user id
* @param username username
* @param resourceCount amount of resources
* @param identities social media identities
* @param identities social media identities
* @param avatarLink link to avatar
*/
public Author(int id, @NotNull String username, int resourceCount, @NotNull Identities identities) {
private Author(int id, String username, int resourceCount, Identities identities, String avatarLink) {
this.id = id;
this.username = username;
this.resourceCount = resourceCount;
this.identities = identities;
BufferedImage image = HttpRequester.requestImage(String.format(AVATAR_URL, id / 1000, id));
if (image == null) {
image = DEFAULT_AVATAR;
}
this.avatar = image;
this.avatarLink = avatarLink;
}

/**
* Gets this author's id
*
* @return id
*/
public int getId() {
Expand All @@ -56,15 +48,17 @@ public int getId() {

/**
* Gets this author's username
*
* @return username
*/
@NotNull

public String getUsername() {
return username;
}

/**
* Gets the amount of resources this author has published
*
* @return amount of resources this author has published
*/
public int getResourceCount() {
Expand All @@ -73,36 +67,29 @@ public int getResourceCount() {

/**
* Gets this author's social media identities
*
* @return social media identities
*/
@NotNull

public Identities getIdentities() {
return identities;
}

/**
* Gets this author's avatar
* @return author's avatar
*/
@NotNull
public BufferedImage getAvatar() {
return avatar;
public String getAvatarLink() {
return avatarLink;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Author author = (Author) o;
return id == author.id &&
resourceCount == author.resourceCount &&
username.equals(author.username) &&
identities.equals(author.identities);
return id == author.id && resourceCount == author.resourceCount && username.equals(author.username) && identities.equals(author.identities) && avatarLink.equals(author.avatarLink);
}

@Override
public int hashCode() {
return Objects.hash(id, username, resourceCount, identities);
return Objects.hash(id, username, resourceCount, identities, avatarLink);
}

@Override
Expand All @@ -112,33 +99,36 @@ public String toString() {
", username='" + username + '\'' +
", resourceCount=" + resourceCount +
", identities=" + identities +
", avatarLink='" + avatarLink + '\'' +
'}';
}

/**
* Represents an Author's social media identities
*/
public static class Identities {

private final String discord, youtube, aim, icq, msn, yahoo, skype, gtalk, facebook, twitter, github;

/**
* Constructs an Identities object with the given parameters
* <p>
* This should only be used internally
* </p>
* @param discord discord identity
* @param youtube youtube identity
* @param aim aim identity
* @param icq icq identity
* @param msn msn identity
* @param yahoo yahoo identity
* @param skype skype identity
* @param gtalk google talk identity
*
* @param discord discord identity
* @param youtube youtube identity
* @param aim aim identity
* @param icq icq identity
* @param msn msn identity
* @param yahoo yahoo identity
* @param skype skype identity
* @param gtalk google talk identity
* @param facebook facebook identity
* @param twitter twitter identity
* @param github github identity
* @param twitter twitter identity
* @param github github identity
*/
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) {
public Identities(String discord, String youtube, String aim, String icq, String msn, String yahoo, String skype, String gtalk, String facebook, String twitter, String github) {
this.discord = discord;
this.youtube = youtube;
this.aim = aim;
Expand All @@ -155,87 +145,87 @@ public Identities(@Nullable String discord, @Nullable String youtube, @Nullable
/**
* @return discord identity
*/
@Nullable

public String getDiscord() {
return discord;
}

/**
* @return youtube identity
*/
@Nullable

public String getYoutube() {
return youtube;
}

/**
* @return AIM identity
*/
@Nullable

public String getAim() {
return aim;
}

/**
* @return ICQ identity
*/
@Nullable

public String getIcq() {
return icq;
}

/**
* @return MSN identity
*/
@Nullable

public String getMsn() {
return msn;
}

/**
* @return yahoo identity
*/
@Nullable

public String getYahoo() {
return yahoo;
}

/**
* @return skype identity
*/
@Nullable

public String getSkype() {
return skype;
}

/**
* @return google talk identity
*/
@Nullable

public String getGoogleTalk() {
return gtalk;
}

/**
* @return facebook identity
*/
@Nullable

public String getFacebook() {
return facebook;
}

/**
* @return twitter identity
*/
@Nullable

public String getTwitter() {
return twitter;
}

/**
* @return github identity
*/
@Nullable

public String getGithub() {
return github;
}
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/me/robertlit/spigotresources/api/Category.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package me.robertlit.spigotresources.api;

import java.util.Objects;

public class Category {

private final int id;
private final String title, description;

private Category(int id, String title, String description) {
this.id = id;
this.title = title;
this.description = description;
}

public int getId() {
return id;
}

public String getTitle() {
return title;
}

public String getDescription() {
return description;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Category category = (Category) o;
return id == category.id && title.equals(category.title) && description.equals(category.description);
}

@Override
public int hashCode() {
return Objects.hash(id, title, description);
}

@Override
public String toString() {
return "Category{" +
"id=" + id +
", title='" + title + '\'' +
", description='" + description + '\'' +
'}';
}
}
Loading

0 comments on commit 8c70f8c

Please sign in to comment.