1
mirror of https://github.com/CarmJos/GithubReleases4J.git synced 2024-09-19 13:45:45 +00:00

[v1.0.0] 完成GithubUser信息的获取

This commit is contained in:
Carm Jos 2022-01-22 05:09:02 +08:00
parent 718aa584bd
commit c9409bc26c
6 changed files with 118 additions and 13 deletions

View File

@ -16,7 +16,6 @@ README LANGUAGES [ [ENGLISH](README_enUS.md) | [中文](README.md) ]
[![License](https://img.shields.io/github/license/CarmJos/GithubPM)](https://opensource.org/licenses/GPL-3.0) [![License](https://img.shields.io/github/license/CarmJos/GithubPM)](https://opensource.org/licenses/GPL-3.0)
[![workflow](https://github.com/CarmJos/GithubPM/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/CarmJos/GithubPM/actions/workflows/maven.yml) [![workflow](https://github.com/CarmJos/GithubPM/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/CarmJos/GithubPM/actions/workflows/maven.yml)
![CodeSize](https://img.shields.io/github/languages/code-size/CarmJos/GithubPM) ![CodeSize](https://img.shields.io/github/languages/code-size/CarmJos/GithubPM)
![Support](https://img.shields.io/badge/Minecraft-Java%201.16--Latest-green)
![](https://visitor-badge.glitch.me/badge?page_id=GithubPM.readme) ![](https://visitor-badge.glitch.me/badge?page_id=GithubPM.readme)
GitHub Releases for Java , 基于 [GitHub REST API](https://docs.github.com/cn/rest/reference/releases) 实现。 GitHub Releases for Java , 基于 [GitHub REST API](https://docs.github.com/cn/rest/reference/releases) 实现。

View File

@ -17,10 +17,6 @@ public class GithubAsset {
return new GithubAsset(source, contents); return new GithubAsset(source, contents);
} }
protected static GithubAsset of(@NotNull GithubRelease source, @NotNull String jsonString) {
return of(source, new JSONObject(jsonString));
}
private final @NotNull GithubRelease source; private final @NotNull GithubRelease source;
private final @NotNull JSONObject contents; private final @NotNull JSONObject contents;
@ -102,6 +98,6 @@ public class GithubAsset {
@Override @Override
public String toString() { public String toString() {
return getContents().toString(0); return getContents().toString();
} }
} }

View File

@ -147,7 +147,7 @@ public class GithubRelease {
@Override @Override
public String toString() { public String toString() {
return getContents().toString(0); return getContents().toString();
} }

View File

@ -1,6 +1,7 @@
package cc.carm.lib.githubreleases4j; package cc.carm.lib.githubreleases4j;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONObject; import org.json.JSONObject;
public class GithubUser { public class GithubUser {
@ -9,10 +10,6 @@ public class GithubUser {
return new GithubUser(contents); return new GithubUser(contents);
} }
protected static GithubUser of(@NotNull String jsonString) {
return of(new JSONObject(jsonString));
}
private final @NotNull JSONObject contents; private final @NotNull JSONObject contents;
private GithubUser(@NotNull JSONObject contents) { private GithubUser(@NotNull JSONObject contents) {
@ -23,8 +20,96 @@ public class GithubUser {
return contents; return contents;
} }
public int getID() {
return getContents().getInt("id");
}
public @NotNull String getLoginID() {
return getContents().getString("login");
}
public @NotNull String getNodeID() {
return getContents().getString("node_id");
}
public @Nullable String getAvatarURL() {
return getContents().getString("avatar_url");
}
public @Nullable String getGravatarID() {
return getContents().getString("gravatar_id");
}
public @NotNull String getURL() {
return getContents().getString("url");
}
public @NotNull String getProfileURL() {
return getContents().getString("html_url");
}
public @NotNull String getFollowersURL() {
return getContents().getString("followers_url");
}
public @NotNull String getFollowingURL() {
return getContents().getString("following_url");
}
public @NotNull String getFollowingURL(@NotNull String otherUsername) {
return getFollowingURL().replace("{/other_user}", "/" + otherUsername);
}
public @NotNull String getGistsURL() {
return getContents().getString("gists_url");
}
public @NotNull String getGistsURL(int gistID) {
return getGistsURL().replace("{/gist_id}", "/" + gistID);
}
public @NotNull String getStarredURL() {
return getContents().getString("starred_url");
}
public @NotNull String getStarredURL(@NotNull String owner, @NotNull String repo) {
return getStarredURL().replace("{/owner}{/repo}", "/" + owner + "/" + repo);
}
public @NotNull String getSubscriptionsURL() {
return getContents().getString("subscriptions_url");
}
public @NotNull String getOrganizationsURL() {
return getContents().getString("organizations_url");
}
public @NotNull String getReposURL() {
return getContents().getString("repos_url");
}
public @NotNull String getEventsURL() {
return getContents().getString("events_url");
}
public @NotNull String getEventsURL(String privacy) {
return getEventsURL().replace("{/privacy}", "/" + privacy);
}
public @NotNull String getReceivedEventsURL() {
return getContents().getString("received_events_url");
}
public @NotNull String getType() {
return getContents().getString("type");
}
public boolean isSiteAdmin() {
return getContents().getBoolean("site_admin");
}
@Override @Override
public String toString() { public String toString() {
return getContents().toString(0); return getContents().toString();
} }
} }

View File

@ -26,7 +26,6 @@ public class GithubReleasesTest {
release.getAssets().stream().findFirst().ifPresent(GithubReleasesTest::downloadAssets); release.getAssets().stream().findFirst().ifPresent(GithubReleasesTest::downloadAssets);
} }
} }
private static void printInfo(@Nullable GithubRelease release) { private static void printInfo(@Nullable GithubRelease release) {

View File

@ -0,0 +1,26 @@
import cc.carm.lib.githubreleases4j.GithubRelease;
import cc.carm.lib.githubreleases4j.GithubReleases4J;
import cc.carm.lib.githubreleases4j.GithubUser;
import org.junit.Test;
import java.text.SimpleDateFormat;
public class GithubUserTestTest {
public static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Test
public void onTest() {
GithubRelease release = GithubReleases4J.getLatestRelease("CarmJos", "UltraDepository");
if (release != null) {
System.out.println("# " + release.getName() + " [" + FORMAT.format(release.getCreateTime()) + "]");
GithubUser author = release.getAuthor();
System.out.println("- " + author.getStarredURL("LSeng", "Kar"));
}
}
}