Renaming to better represent what it does.

This commit is contained in:
Kohsuke Kawaguchi
2012-09-05 19:13:10 -07:00
parent ea9f3eacbc
commit 8a95847b0a
10 changed files with 41 additions and 41 deletions

View File

@@ -203,7 +203,7 @@ public class GHCommit {
public PagedIterable<GHCommitComment> listComments() {
return new PagedIterable<GHCommitComment>() {
public PagedIterator<GHCommitComment> iterator() {
return new PagedIterator<GHCommitComment>(owner.root.retrieve().asIterator(String.format("/repos/%s/%s/commits/%s/comments",owner.getOwnerName(),owner.getName(),sha),GHCommitComment[].class)) {
return new PagedIterator<GHCommitComment>(owner.root.retrieve().asIterator(String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha), GHCommitComment[].class)) {
@Override
protected void wrapUp(GHCommitComment[] page) {
for (GHCommitComment c : page)
@@ -220,7 +220,7 @@ public class GHCommit {
* I'm not sure how path/line/position parameters interact with each other.
*/
public GHCommitComment createComment(String body, String path, Integer line, Integer position) throws IOException {
GHCommitComment r = new Poster(owner.root)
GHCommitComment r = new Requester(owner.root)
.with("body",body)
.with("path",path)
.with("line",line)

View File

@@ -97,7 +97,7 @@ public class GHCommitComment {
* Updates the body of the commit message.
*/
public void update(String body) throws IOException {
GHCommitComment r = new Poster(owner.root)
GHCommitComment r = new Requester(owner.root)
.with("body", body)
.withCredential().method("PATCH").to(getApiTail(), GHCommitComment.class);
this.body = body;
@@ -107,7 +107,7 @@ public class GHCommitComment {
* Deletes this comment.
*/
public void delete() throws IOException {
new Poster(owner.root).withCredential().method("DELETE").to(getApiTail());
new Requester(owner.root).withCredential().method("DELETE").to(getApiTail());
}
private String getApiTail() {

View File

@@ -54,6 +54,6 @@ public final class GHHook {
* Deletes this hook.
*/
public void delete() throws IOException {
new Poster(repository.root).withCredential().method("DELETE").to(String.format("/repos/%s/%s/hooks/%d", repository.getOwnerName(), repository.getName(), id));
new Requester(repository.root).withCredential().method("DELETE").to(String.format("/repos/%s/%s/hooks/%d", repository.getOwnerName(), repository.getName(), id));
}
}

View File

@@ -115,11 +115,11 @@ public class GHIssue {
* Updates the issue by adding a comment.
*/
public void comment(String message) throws IOException {
new Poster(root).withCredential().with("body",message).to(getApiRoute() + "/comments");
new Requester(root).withCredential().with("body",message).to(getApiRoute() + "/comments");
}
private void edit(String key, Object value) throws IOException {
new Poster(root).withCredential()._with(key, value).method("PATCH").to(getApiRoute());
new Requester(root).withCredential()._with(key, value).method("PATCH").to(getApiRoute());
}
/**
@@ -167,7 +167,7 @@ public class GHIssue {
public PagedIterable<GHIssueComment> listComments() throws IOException {
return new PagedIterable<GHIssueComment>() {
public PagedIterator<GHIssueComment> iterator() {
return new PagedIterator<GHIssueComment>(root.retrieve().asIterator(getApiRoute() + "/comments",GHIssueComment[].class)) {
return new PagedIterator<GHIssueComment>(root.retrieve().asIterator(getApiRoute() + "/comments", GHIssueComment[].class)) {
protected void wrapUp(GHIssueComment[] page) {
for (GHIssueComment c : page)
c.wrapUp(GHIssue.this);

View File

@@ -37,7 +37,7 @@ public class GHMyself extends GHUser {
}
// public void addEmails(Collection<String> emails) throws IOException {
//// new Poster(root,ApiVersion.V3).withCredential().to("/user/emails");
//// new Requester(root,ApiVersion.V3).withCredential().to("/user/emails");
// root.retrieveWithAuth3()
// }
}

View File

@@ -33,7 +33,7 @@ public class GHOrganization extends GHPerson {
public GHRepository createRepository(String name, String description, String homepage, GHTeam team, boolean isPublic) throws IOException {
// such API doesn't exist, so fall back to HTML scraping
return new Poster(root).withCredential()
return new Requester(root).withCredential()
.with("name", name).with("description", description).with("homepage", homepage)
.with("public", isPublic).with("team_id",team.getId()).to("/orgs/"+login+"/repos", GHRepository.class).wrap(root);
}
@@ -95,7 +95,7 @@ public class GHOrganization extends GHPerson {
* Creates a new team and assigns the repositories.
*/
public GHTeam createTeam(String name, Permission p, Collection<GHRepository> repositories) throws IOException {
Poster post = new Poster(root).withCredential().with("name", name).with("permission", p.name().toLowerCase());
Requester post = new Requester(root).withCredential().with("name", name).with("permission", p.name().toLowerCase());
List<String> repo_names = new ArrayList<String>();
for (GHRepository r : repositories) {
repo_names.add(r.getName());

View File

@@ -253,7 +253,7 @@ public class GHRepository {
private void modifyCollaborators(Collection<GHUser> users, String method) throws IOException {
verifyMine();
for (GHUser user : users) {
new Poster(root).withCredential().method(method).to("/repos/" + owner.login + "/" + name + "/collaborators/" + user.getLogin());
new Requester(root).withCredential().method(method).to("/repos/" + owner.login + "/" + name + "/collaborators/" + user.getLogin());
}
}
@@ -270,10 +270,10 @@ public class GHRepository {
}
private void edit(String key, String value) throws IOException {
Poster poster = new Poster(root).withCredential();
Requester requester = new Requester(root).withCredential();
if (!key.equals("name"))
poster.with("name", name); // even when we don't change the name, we need to send it in
poster.with(key, value).method("PATCH").to("/repos/" + owner.login + "/" + name);
requester.with("name", name); // even when we don't change the name, we need to send it in
requester.with(key, value).method("PATCH").to("/repos/" + owner.login + "/" + name);
}
/**
@@ -313,7 +313,7 @@ public class GHRepository {
* Deletes this repository.
*/
public void delete() throws IOException {
new Poster(root).withCredential().method("DELETE").to("/repos/" + owner.login + "/" + name);
new Requester(root).withCredential().method("DELETE").to("/repos/" + owner.login + "/" + name);
}
/**
@@ -323,7 +323,7 @@ public class GHRepository {
* Newly forked repository that belong to you.
*/
public GHRepository fork() throws IOException {
return new Poster(root).withCredential().method("POST").to("/repos/" + owner.login + "/" + name + "/forks", GHRepository.class).wrap(root);
return new Requester(root).withCredential().method("POST").to("/repos/" + owner.login + "/" + name + "/forks", GHRepository.class).wrap(root);
}
/**
@@ -333,7 +333,7 @@ public class GHRepository {
* Newly forked repository that belong to you.
*/
public GHRepository forkTo(GHOrganization org) throws IOException {
new Poster(root).withCredential().to(String.format("/repos/%s/%s/forks?org=%s",owner.login,name,org.getLogin()));
new Requester(root).withCredential().to(String.format("/repos/%s/%s/forks?org=%s",owner.login,name,org.getLogin()));
// this API is asynchronous. we need to wait for a bit
for (int i=0; i<10; i++) {
@@ -370,7 +370,7 @@ public class GHRepository {
public PagedIterable<GHPullRequest> listPullRequests(final GHIssueState state) {
return new PagedIterable<GHPullRequest>() {
public PagedIterator<GHPullRequest> iterator() {
return new PagedIterator<GHPullRequest>(root.retrieve().asIterator(String.format("/repos/%s/%s/pulls?state=%s", owner.login,name,state.name().toLowerCase(Locale.ENGLISH)), GHPullRequest[].class)) {
return new PagedIterator<GHPullRequest>(root.retrieve().asIterator(String.format("/repos/%s/%s/pulls?state=%s", owner.login, name, state.name().toLowerCase(Locale.ENGLISH)), GHPullRequest[].class)) {
@Override
protected void wrapUp(GHPullRequest[] page) {
for (GHPullRequest pr : page)
@@ -414,7 +414,7 @@ public class GHRepository {
public PagedIterable<GHCommit> listCommits() {
return new PagedIterable<GHCommit>() {
public PagedIterator<GHCommit> iterator() {
return new PagedIterator<GHCommit>(root.retrieve().asIterator(String.format("/repos/%s/%s/commits",owner.login,name),GHCommit[].class)) {
return new PagedIterator<GHCommit>(root.retrieve().asIterator(String.format("/repos/%s/%s/commits", owner.login, name), GHCommit[].class)) {
protected void wrapUp(GHCommit[] page) {
for (GHCommit c : page)
c.wrapUp(GHRepository.this);
@@ -430,7 +430,7 @@ public class GHRepository {
public PagedIterable<GHCommitComment> listCommitComments() {
return new PagedIterable<GHCommitComment>() {
public PagedIterator<GHCommitComment> iterator() {
return new PagedIterator<GHCommitComment>(root.retrieve().asIterator(String.format("/repos/%s/%s/comments",owner.login,name),GHCommitComment[].class)) {
return new PagedIterator<GHCommitComment>(root.retrieve().asIterator(String.format("/repos/%s/%s/comments", owner.login, name), GHCommitComment[].class)) {
@Override
protected void wrapUp(GHCommitComment[] page) {
for (GHCommitComment c : page)
@@ -447,7 +447,7 @@ public class GHRepository {
public PagedIterable<GHCommitStatus> listCommitStatuses(final String sha1) throws IOException {
return new PagedIterable<GHCommitStatus>() {
public PagedIterator<GHCommitStatus> iterator() {
return new PagedIterator<GHCommitStatus>(root.retrieve().asIterator(String.format("/repos/%s/%s/statuses/%s", owner.login, name, sha1),GHCommitStatus[].class)) {
return new PagedIterator<GHCommitStatus>(root.retrieve().asIterator(String.format("/repos/%s/%s/statuses/%s", owner.login, name, sha1), GHCommitStatus[].class)) {
@Override
protected void wrapUp(GHCommitStatus[] page) {
for (GHCommitStatus c : page)
@@ -475,7 +475,7 @@ public class GHRepository {
* Optional short description.
*/
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description) throws IOException {
return new Poster(root)
return new Requester(root)
.withCredential()
.with("state",state.name().toLowerCase(Locale.ENGLISH))
.with("target_url", targetUrl)
@@ -504,7 +504,7 @@ public class GHRepository {
ea.add(e.name().toLowerCase(Locale.ENGLISH));
}
return new Poster(root)
return new Requester(root)
.withCredential()
.with("name",name)
.with("active", active)
@@ -640,7 +640,7 @@ public class GHRepository {
}
public GHMilestone createMilestone(String title, String description) throws IOException {
return new Poster(root).withCredential()
return new Requester(root).withCredential()
.with("title", title).with("description", description).method("POST").to("/repos/" + owner.login + "/" + name + "/milestones", GHMilestone.class).wrap(this);
}

View File

@@ -41,14 +41,14 @@ public class GHUser extends GHPerson {
* Follow this user.
*/
public void follow() throws IOException {
new Poster(root).withCredential().method("PUT").to("/user/following/" + login);
new Requester(root).withCredential().method("PUT").to("/user/following/" + login);
}
/**
* Unfollow this user.
*/
public void unfollow() throws IOException {
new Poster(root).withCredential().method("DELETE").to("/user/following/" + login);
new Requester(root).withCredential().method("DELETE").to("/user/following/" + login);
}
/**

View File

@@ -159,8 +159,8 @@ public class GitHub {
return new URL(tailApiUrl);
}
/*package*/ Poster retrieve() {
return new Poster(this).method("GET");
/*package*/ Requester retrieve() {
return new Requester(this).method("GET");
}
/**
@@ -277,10 +277,10 @@ public class GitHub {
* Newly created repository.
*/
public GHRepository createRepository(String name, String description, String homepage, boolean isPublic) throws IOException {
Poster poster = new Poster(this).withCredential()
Requester requester = new Requester(this).withCredential()
.with("name", name).with("description", description).with("homepage", homepage)
.with("public", isPublic ? 1 : 0);
return poster.method("POST").to("/user/repos", GHRepository.class).wrap(this);
return requester.method("POST").to("/user/repos", GHRepository.class).wrap(this);
}
/**

View File

@@ -52,7 +52,7 @@ import static org.kohsuke.github.GitHub.*;
*
* @author Kohsuke Kawaguchi
*/
class Poster {
class Requester {
private final GitHub root;
private final List<Entry> args = new ArrayList<Entry>();
private boolean authenticate;
@@ -72,50 +72,50 @@ class Poster {
}
}
Poster(GitHub root) {
Requester(GitHub root) {
this.root = root;
}
/**
* Makes a request with authentication credential.
*/
public Poster withCredential() {
public Requester withCredential() {
// keeping it inline with retrieveWithAuth not to enforce the check
// root.requireCredential();
authenticate = true;
return this;
}
public Poster with(String key, int value) {
public Requester with(String key, int value) {
return _with(key, value);
}
public Poster with(String key, Integer value) {
public Requester with(String key, Integer value) {
if (value!=null)
_with(key, value.intValue());
return this;
}
public Poster with(String key, boolean value) {
public Requester with(String key, boolean value) {
return _with(key, value);
}
public Poster with(String key, String value) {
public Requester with(String key, String value) {
return _with(key, value);
}
public Poster with(String key, Collection<String> value) {
public Requester with(String key, Collection<String> value) {
return _with(key, value);
}
public Poster _with(String key, Object value) {
public Requester _with(String key, Object value) {
if (value!=null) {
args.add(new Entry(key,value));
}
return this;
}
public Poster method(String method) {
public Requester method(String method) {
this.method = method;
return this;
}