Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
Added Licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBusyBiscuit committed Jun 12, 2019
1 parent dab39a4 commit 52d7050
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,26 @@ public Map<String, String> getParameters() {
return null;
}


protected boolean getBoolean(String attribute, boolean full) throws IllegalAccessException {
JsonElement element = getResponse(full);

if (element == null) {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}
JsonObject response = element.getAsJsonObject();

return isInvalid(response, attribute) ? false: response.get(attribute).getAsBoolean();
}

protected String getString(String attribute, boolean full) throws IllegalAccessException {
JsonElement element = getResponse(full);

if (element == null) {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}
JsonObject response = element.getAsJsonObject();

return isInvalid(response, attribute) ? null: response.get(attribute).getAsString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,11 @@ public int getSize() throws IllegalAccessException {

@GitHubAccessPoint(path = "@content", type = String.class, requiresAccessToken = false)
public String getFileContent() throws IllegalAccessException {
JsonElement element = getResponse(true);

if (element == null) {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}
JsonObject response = element.getAsJsonObject();

return isInvalid(response, "content") ? null: response.get("content").getAsString();
return getString("content", true);
}

@GitHubAccessPoint(path = "@encoding", type = String.class, requiresAccessToken = false)
public String getEncoding() throws IllegalAccessException {
JsonElement element = getResponse(true);

if (element == null) {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}
JsonObject response = element.getAsJsonObject();

return isInvalid(response, "encoding") ? null: response.get("encoding").getAsString();
return getString("encoding", true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,7 @@ public String getRawURL() {

@GitHubAccessPoint(path = "@name", type = String.class, requiresAccessToken = false)
public String getName() throws IllegalAccessException {
JsonElement element = getResponse(false);

if (element == null) {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}
JsonObject response = element.getAsJsonObject();

return isInvalid(response, "name") ? null: response.get("name").getAsString();
return getString("name", false);
}

@GitHubAccessPoint(path = "@commit", type = GitHubCommit.class, requiresAccessToken = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ public GitHubUser getUser() throws IllegalAccessException {

@GitHubAccessPoint(path = "@body", type = String.class, requiresAccessToken = false)
public String getMessageBody() throws IllegalAccessException {
JsonElement element = getResponse(false);

if (element == null) {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}
JsonObject response = element.getAsJsonObject();

return isInvalid(response, "body") ? null: response.get("body").getAsString();
return getString("body", false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public List<GitHubComment> getComments() throws IllegalAccessException {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}

List<GitHubComment> list = new ArrayList<GitHubComment>();
List<GitHubComment> list = new ArrayList<>();
JsonArray array = response.getAsJsonArray();

for (int i = 0; i < array.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,17 @@ public int getID() throws IllegalAccessException {

@GitHubAccessPoint(path = "@name", type = String.class, requiresAccessToken = false)
public String getName() throws IllegalAccessException {
JsonElement element = getResponse(false);

if (element == null) {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}
JsonObject response = element.getAsJsonObject();

return isInvalid(response, "name") ? null: response.get("name").getAsString();
return getString("name", false);
}

@GitHubAccessPoint(path = "@color", type = String.class, requiresAccessToken = false)
public String getColor() throws IllegalAccessException {
JsonElement element = getResponse(false);

if (element == null) {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}
JsonObject response = element.getAsJsonObject();

return isInvalid(response, "color") ? null: response.get("color").getAsString();
return getString("color", false);
}

@GitHubAccessPoint(path = "@default", type = Boolean.class, requiresAccessToken = false)
public boolean isDefaultLabel() throws IllegalAccessException {
JsonElement element = getResponse(false);

if (element == null) {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}
JsonObject response = element.getAsJsonObject();

return isInvalid(response, "default") ? false: response.get("default").getAsBoolean();
return getBoolean("default", false);
}

public String getURLEncodedParameter() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package io.github.TheBusyBiscuit.GitHubWebAPI4Java.objects.repositories;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import io.github.TheBusyBiscuit.GitHubWebAPI4Java.GitHubWebAPI;
import io.github.TheBusyBiscuit.GitHubWebAPI4Java.annotations.GitHubAccessPoint;
import io.github.TheBusyBiscuit.GitHubWebAPI4Java.objects.GitHubObject;

public class GitHubLicense extends GitHubObject {

private String param;

public GitHubLicense(GitHubWebAPI api, String key) throws UnsupportedEncodingException {
super(api, null, "/licenses/" + URLEncoder.encode(key, "utf-8"));

this.param = URLEncoder.encode(key, "utf-8");
}

public GitHubLicense(GitHubObject obj) {
super(obj);
}

@Override
public String getRawURL() {
return ".*licenses/.*";
}

@GitHubAccessPoint(path = "@key", type = String.class, requiresAccessToken = false)
public String getKey() throws IllegalAccessException {
return getString("key", false);
}

@GitHubAccessPoint(path = "@name", type = String.class, requiresAccessToken = false)
public String getName() throws IllegalAccessException {
return getString("name", false);
}

@GitHubAccessPoint(path = "@spdx_id", type = String.class, requiresAccessToken = false)
public String getSpdxID() throws IllegalAccessException {
return getString("spdx_id", false);
}

@GitHubAccessPoint(path = "@description", type = String.class, requiresAccessToken = false)
public String getDescription() throws IllegalAccessException {
return getString("description", true);
}

@GitHubAccessPoint(path = "@implementation", type = String.class, requiresAccessToken = false)
public String getImplementation() throws IllegalAccessException {
return getString("implementation", true);
}

@GitHubAccessPoint(path = "@body", type = String.class, requiresAccessToken = false)
public String getFullBody() throws IllegalAccessException {
return getString("body", true);
}

@GitHubAccessPoint(path = "@featured", type= Boolean.class, requiresAccessToken = false)
public boolean isFeatured() throws IllegalAccessException {
return getBoolean("featured", true);
}

public String getURLEncodedParameter() {
return this.param;
}

private List<String> getList(String path) throws IllegalAccessException {
JsonElement response = getResponse(true);

if (response == null) {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}

List<String> list = new ArrayList<>();
JsonArray array = response.getAsJsonArray();

for (int i = 0; i < array.size(); i++) {
list.add(array.get(i).getAsString());
}

return list;
}

@GitHubAccessPoint(path= "@permissions", type = String.class, requiresAccessToken = false)
public List<String> getPermissions() throws IllegalAccessException {
return getList("permissions");
}

@GitHubAccessPoint(path= "@conditions", type = String.class, requiresAccessToken = false)
public List<String> getConditions() throws IllegalAccessException {
return getList("conditions");
}

@GitHubAccessPoint(path= "@limitations", type = String.class, requiresAccessToken = false)
public List<String> getLimitations() throws IllegalAccessException {
return getList("limitations");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,7 @@ public GitHubUser getCreator() throws IllegalAccessException {

@GitHubAccessPoint(path = "@description", type = String.class, requiresAccessToken = false)
public String getDescription() throws IllegalAccessException {
JsonElement element = getResponse(false);

if (element == null) {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}
JsonObject response = element.getAsJsonObject();

return isInvalid(response, "description") ? null: response.get("description").getAsString();
return getString("description", false);
}

@GitHubAccessPoint(path = "/labels", type = GitHubLabel.class, requiresAccessToken = false)
Expand All @@ -79,7 +72,7 @@ public List<GitHubLabel> getLabels() throws IllegalAccessException, UnsupportedE
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}

List<GitHubLabel> list = new ArrayList<GitHubLabel>();
List<GitHubLabel> list = new ArrayList<>();
JsonArray array = response.getAsJsonArray();

for (int i = 0; i < array.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,7 @@ public GitHubUser getUser() throws IllegalAccessException {

@GitHubAccessPoint(path = "@locked", type = Boolean.class, requiresAccessToken = false)
public boolean isLocked() throws IllegalAccessException {
JsonElement element = getResponse(false);

if (element == null) {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}
JsonObject response = element.getAsJsonObject();

return isInvalid(response, "locked") ? false: response.get("locked").getAsBoolean();
return getBoolean("locked", false);
}

@GitHubAccessPoint(path = "@base/label", type = String.class, requiresAccessToken = false)
Expand Down Expand Up @@ -322,38 +315,17 @@ public GitHubMilestone getMilestone() throws IllegalAccessException {

@GitHubAccessPoint(path = "@merged", type = Boolean.class, requiresAccessToken = false)
public boolean isMerged() throws IllegalAccessException {
JsonElement element = getResponse(true);

if (element == null) {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}
JsonObject response = element.getAsJsonObject();

return isInvalid(response, "merged") ? false: response.get("merged").getAsBoolean();
return getBoolean("merged", true);
}

@GitHubAccessPoint(path = "@mergeable", type = Boolean.class, requiresAccessToken = false)
public boolean isMergeable() throws IllegalAccessException {
JsonElement element = getResponse(true);

if (element == null) {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}
JsonObject response = element.getAsJsonObject();

return isInvalid(response, "mergeable") ? false: response.get("mergeable").getAsBoolean();
return getBoolean("mergeable", true);
}

@GitHubAccessPoint(path = "@body", type = String.class, requiresAccessToken = false)
public String getMessageBody() throws IllegalAccessException {
JsonElement element = getResponse(false);

if (element == null) {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}
JsonObject response = element.getAsJsonObject();

return isInvalid(response, "body") ? null: response.get("body").getAsString();
return getString("body", false);
}

@GitHubAccessPoint(path = "@merged_at", type = Date.class, requiresAccessToken = false)
Expand Down Expand Up @@ -382,7 +354,7 @@ public List<GitHubUser> getAssignees() throws IllegalAccessException, Unsupporte
}
JsonObject response = element.getAsJsonObject();

List<GitHubUser> users = new ArrayList<GitHubUser>();
List<GitHubUser> users = new ArrayList<>();

JsonArray array = response.get("assignees").getAsJsonArray();

Expand Down Expand Up @@ -415,7 +387,7 @@ public List<GitHubComment> getComments() throws IllegalAccessException {
throw new IllegalAccessException("Could not connect to '" + getURL() + "'");
}

List<GitHubComment> list = new ArrayList<GitHubComment>();
List<GitHubComment> list = new ArrayList<>();
JsonArray array = response.getAsJsonArray();

for (int i = 0; i < array.size(); i++) {
Expand Down
Loading

0 comments on commit 52d7050

Please sign in to comment.