mirror of
https://github.com/jlengrand/github-api.git
synced 2026-04-14 00:11:23 +00:00
Remove fetchArray method
This commit is contained in:
@@ -69,7 +69,10 @@ public class GHMyself extends GHUser {
|
||||
* the io exception
|
||||
*/
|
||||
public List<GHEmail> getEmails2() throws IOException {
|
||||
GHEmail[] addresses = root.createRequest().withUrlPath("/user/emails").fetchArray(GHEmail[].class);
|
||||
GHEmail[] addresses = root.createRequest()
|
||||
.withUrlPath("/user/emails")
|
||||
.toIterable(GHEmail[].class, null)
|
||||
.toArray();
|
||||
return Collections.unmodifiableList(Arrays.asList(addresses));
|
||||
}
|
||||
|
||||
@@ -84,8 +87,8 @@ public class GHMyself extends GHUser {
|
||||
* the io exception
|
||||
*/
|
||||
public List<GHKey> getPublicKeys() throws IOException {
|
||||
return Collections.unmodifiableList(
|
||||
Arrays.asList(root.createRequest().withUrlPath("/user/keys").fetchArray(GHKey[].class)));
|
||||
return Collections.unmodifiableList(Arrays
|
||||
.asList(root.createRequest().withUrlPath("/user/keys").toIterable(GHKey[].class, null).toArray()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,8 +102,10 @@ public class GHMyself extends GHUser {
|
||||
* the io exception
|
||||
*/
|
||||
public List<GHVerifiedKey> getPublicVerifiedKeys() throws IOException {
|
||||
return Collections.unmodifiableList(Arrays.asList(
|
||||
root.createRequest().withUrlPath("/users/" + getLogin() + "/keys").fetchArray(GHVerifiedKey[].class)));
|
||||
return Collections.unmodifiableList(Arrays.asList(root.createRequest()
|
||||
.withUrlPath("/users/" + getLogin() + "/keys")
|
||||
.toIterable(GHVerifiedKey[].class, null)
|
||||
.toArray()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +118,10 @@ public class GHMyself extends GHUser {
|
||||
public GHPersonSet<GHOrganization> getAllOrganizations() throws IOException {
|
||||
GHPersonSet<GHOrganization> orgs = new GHPersonSet<GHOrganization>();
|
||||
Set<String> names = new HashSet<String>();
|
||||
for (GHOrganization o : root.createRequest().withUrlPath("/user/orgs").fetchArray(GHOrganization[].class)) {
|
||||
for (GHOrganization o : root.createRequest()
|
||||
.withUrlPath("/user/orgs")
|
||||
.toIterable(GHOrganization[].class, null)
|
||||
.toArray()) {
|
||||
if (names.add(o.getLogin())) // in case of rumoured duplicates in the data
|
||||
orgs.add(root.getOrganization(o.getLogin()));
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ public class GHRelease extends GHObject {
|
||||
public List<GHAsset> getAssets() throws IOException {
|
||||
Requester builder = owner.root.createRequest();
|
||||
|
||||
GHAsset[] assets = builder.withUrlPath(getApiTailUrl("assets")).fetchArray(GHAsset[].class);
|
||||
GHAsset[] assets = builder.withUrlPath(getApiTailUrl("assets")).toIterable(GHAsset[].class, null).toArray();
|
||||
return Arrays.asList(GHAsset.wrap(assets, this));
|
||||
}
|
||||
|
||||
|
||||
@@ -376,8 +376,9 @@ public class GHRepository extends GHObject {
|
||||
Requester requester = root.createRequest()
|
||||
.with("state", state)
|
||||
.with("milestone", milestone == null ? "none" : "" + milestone.getNumber());
|
||||
return Arrays
|
||||
.asList(GHIssue.wrap(requester.withUrlPath(getApiTailUrl("issues")).fetchArray(GHIssue[].class), this));
|
||||
return Arrays.asList(
|
||||
GHIssue.wrap(requester.withUrlPath(getApiTailUrl("issues")).toIterable(GHIssue[].class, null).toArray(),
|
||||
this));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -785,9 +786,10 @@ public class GHRepository extends GHObject {
|
||||
*/
|
||||
public Set<String> getCollaboratorNames() throws IOException {
|
||||
Set<String> r = new HashSet<String>();
|
||||
for (GHUser u : GHUser.wrap(
|
||||
root.createRequest().withUrlPath(getApiTailUrl("collaborators")).fetchArray(GHUser[].class),
|
||||
root))
|
||||
for (GHUser u : GHUser.wrap(root.createRequest()
|
||||
.withUrlPath(getApiTailUrl("collaborators"))
|
||||
.toIterable(GHUser[].class, null)
|
||||
.toArray(), root))
|
||||
r.add(u.login);
|
||||
return r;
|
||||
}
|
||||
@@ -830,9 +832,9 @@ public class GHRepository extends GHObject {
|
||||
* the io exception
|
||||
*/
|
||||
public Set<GHTeam> getTeams() throws IOException {
|
||||
return Collections.unmodifiableSet(new HashSet<GHTeam>(Arrays.asList(
|
||||
GHTeam.wrapUp(root.createRequest().withUrlPath(getApiTailUrl("teams")).fetchArray(GHTeam[].class),
|
||||
root.getOrganization(getOwnerName())))));
|
||||
return Collections.unmodifiableSet(new HashSet<GHTeam>(Arrays.asList(GHTeam.wrapUp(
|
||||
root.createRequest().withUrlPath(getApiTailUrl("teams")).toIterable(GHTeam[].class, null).toArray(),
|
||||
root.getOrganization(getOwnerName())))));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1451,7 +1453,8 @@ public class GHRepository extends GHObject {
|
||||
public GHRef[] getRefs() throws IOException {
|
||||
return GHRef.wrap(root.createRequest()
|
||||
.withUrlPath(String.format("/repos/%s/%s/git/refs", getOwnerName(), name))
|
||||
.fetchArray(GHRef[].class), root);
|
||||
.toIterable(GHRef[].class, null)
|
||||
.toArray(), root);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1478,7 +1481,8 @@ public class GHRepository extends GHObject {
|
||||
public GHRef[] getRefs(String refType) throws IOException {
|
||||
return GHRef.wrap(root.createRequest()
|
||||
.withUrlPath(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType))
|
||||
.fetchArray(GHRef[].class), root);
|
||||
.toIterable(GHRef[].class, null)
|
||||
.toArray(), root);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2071,7 +2075,10 @@ public class GHRepository extends GHObject {
|
||||
*/
|
||||
public Map<String, GHBranch> getBranches() throws IOException {
|
||||
Map<String, GHBranch> r = new TreeMap<String, GHBranch>();
|
||||
for (GHBranch p : root.createRequest().withUrlPath(getApiTailUrl("branches")).fetchArray(GHBranch[].class)) {
|
||||
for (GHBranch p : root.createRequest()
|
||||
.withUrlPath(getApiTailUrl("branches"))
|
||||
.toIterable(GHBranch[].class, null)
|
||||
.toArray()) {
|
||||
p.wrap(this);
|
||||
r.put(p.getName(), p);
|
||||
}
|
||||
@@ -2203,7 +2210,10 @@ public class GHRepository extends GHObject {
|
||||
}
|
||||
String target = getApiTailUrl("contents/" + path);
|
||||
|
||||
GHContent[] files = requester.with("ref", ref).withUrlPath(target).fetchArray(GHContent[].class);
|
||||
GHContent[] files = requester.with("ref", ref)
|
||||
.withUrlPath(target)
|
||||
.toIterable(GHContent[].class, null)
|
||||
.toArray();
|
||||
|
||||
GHContent.wrap(files, this);
|
||||
|
||||
@@ -2361,8 +2371,10 @@ public class GHRepository extends GHObject {
|
||||
* the io exception
|
||||
*/
|
||||
public List<GHDeployKey> getDeployKeys() throws IOException {
|
||||
List<GHDeployKey> list = new ArrayList<GHDeployKey>(
|
||||
Arrays.asList(root.createRequest().withUrlPath(getApiTailUrl("keys")).fetchArray(GHDeployKey[].class)));
|
||||
List<GHDeployKey> list = new ArrayList<GHDeployKey>(Arrays.asList(root.createRequest()
|
||||
.withUrlPath(getApiTailUrl("keys"))
|
||||
.toIterable(GHDeployKey[].class, null)
|
||||
.toArray()));
|
||||
for (GHDeployKey h : list)
|
||||
h.wrap(this);
|
||||
return list;
|
||||
|
||||
@@ -41,8 +41,8 @@ public class GHUser extends GHPerson {
|
||||
* the io exception
|
||||
*/
|
||||
public List<GHKey> getKeys() throws IOException {
|
||||
return Collections.unmodifiableList(
|
||||
Arrays.asList(root.createRequest().withUrlPath(getApiTailUrl("keys")).fetchArray(GHKey[].class)));
|
||||
return Collections.unmodifiableList(Arrays.asList(
|
||||
root.createRequest().withUrlPath(getApiTailUrl("keys")).toIterable(GHKey[].class, null).toArray()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,7 +191,8 @@ public class GHUser extends GHPerson {
|
||||
Set<String> names = new HashSet<String>();
|
||||
for (GHOrganization o : root.createRequest()
|
||||
.withUrlPath("/users/" + login + "/orgs")
|
||||
.fetchArray(GHOrganization[].class)) {
|
||||
.toIterable(GHOrganization[].class, null)
|
||||
.toArray()) {
|
||||
if (names.add(o.getLogin())) // I've seen some duplicates in the data
|
||||
orgs.add(root.getOrganization(o.getLogin()));
|
||||
}
|
||||
|
||||
@@ -600,7 +600,8 @@ public class GitHub {
|
||||
*/
|
||||
public List<GHInvitation> getMyInvitations() throws IOException {
|
||||
GHInvitation[] invitations = createRequest().withUrlPath("/user/repository_invitations")
|
||||
.fetchArray(GHInvitation[].class);
|
||||
.toIterable(GHInvitation[].class, null)
|
||||
.toArray();
|
||||
for (GHInvitation i : invitations) {
|
||||
i.wrapUp(this);
|
||||
}
|
||||
@@ -618,7 +619,9 @@ public class GitHub {
|
||||
* the io exception
|
||||
*/
|
||||
public Map<String, GHOrganization> getMyOrganizations() throws IOException {
|
||||
GHOrganization[] orgs = createRequest().withUrlPath("/user/orgs").fetchArray(GHOrganization[].class);
|
||||
GHOrganization[] orgs = createRequest().withUrlPath("/user/orgs")
|
||||
.toIterable(GHOrganization[].class, null)
|
||||
.toArray();
|
||||
Map<String, GHOrganization> r = new HashMap<String, GHOrganization>();
|
||||
for (GHOrganization o : orgs) {
|
||||
// don't put 'o' into orgs because they are shallow
|
||||
@@ -672,7 +675,8 @@ public class GitHub {
|
||||
*/
|
||||
public Map<String, GHOrganization> getUserPublicOrganizations(String login) throws IOException {
|
||||
GHOrganization[] orgs = createRequest().withUrlPath("/users/" + login + "/orgs")
|
||||
.fetchArray(GHOrganization[].class);
|
||||
.toIterable(GHOrganization[].class, null)
|
||||
.toArray();
|
||||
Map<String, GHOrganization> r = new HashMap<String, GHOrganization>();
|
||||
for (GHOrganization o : orgs) {
|
||||
// don't put 'o' into orgs because they are shallow
|
||||
@@ -693,7 +697,7 @@ public class GitHub {
|
||||
*/
|
||||
public Map<String, Set<GHTeam>> getMyTeams() throws IOException {
|
||||
Map<String, Set<GHTeam>> allMyTeams = new HashMap<String, Set<GHTeam>>();
|
||||
for (GHTeam team : createRequest().withUrlPath("/user/teams").fetchArray(GHTeam[].class)) {
|
||||
for (GHTeam team : createRequest().withUrlPath("/user/teams").toIterable(GHTeam[].class, null).toArray()) {
|
||||
team.wrapUp(this);
|
||||
String orgLogin = team.getOrganization().getLogin();
|
||||
Set<GHTeam> teamsPerOrg = allMyTeams.get(orgLogin);
|
||||
@@ -727,7 +731,7 @@ public class GitHub {
|
||||
* the io exception
|
||||
*/
|
||||
public List<GHEventInfo> getEvents() throws IOException {
|
||||
GHEventInfo[] events = createRequest().withUrlPath("/events").fetchArray(GHEventInfo[].class);
|
||||
GHEventInfo[] events = createRequest().withUrlPath("/events").toIterable(GHEventInfo[].class, null).toArray();
|
||||
for (GHEventInfo e : events)
|
||||
e.wrapUp(this);
|
||||
return Arrays.asList(events);
|
||||
|
||||
@@ -68,21 +68,6 @@ class Requester extends GitHubRequest.Builder<Requester> {
|
||||
return client.sendRequest(this, (responseInfo) -> GitHubResponse.parseBody(responseInfo, type)).body();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request and parses the response into an array of the given type via databinding.
|
||||
*
|
||||
* @param <T>
|
||||
* the type parameter
|
||||
* @param type
|
||||
* the type
|
||||
* @return an array of {@link T} elements
|
||||
* @throws IOException
|
||||
* if the server returns 4xx/5xx responses.
|
||||
*/
|
||||
public <T> T[] fetchArray(@Nonnull Class<T[]> type) throws IOException {
|
||||
return toIterable(client, type, null).toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@link #fetch(Class)} but updates an existing object instead of creating a new instance.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user