A step toward using Poster in place of the retrieve* methods.

I was trying to add  the flavor of the retrieve method that reads into an existing instance, when I realized that there are just too many orthogonal axes here to rely on overloaded methods.

That calls for a builder pattern, which we already have --- it's called Poster, but it can actually already handle GET and other HTTP requests.

So I'm retiring the retrieveXYZ methods and moving the code into Poster. This is the first step.
This commit is contained in:
Kohsuke Kawaguchi
2012-09-05 18:52:37 -07:00
parent 3f1bb1a214
commit d6d73f5165
10 changed files with 105 additions and 58 deletions

View File

@@ -170,6 +170,10 @@ public class GitHub {
return new URL(tailApiUrl);
}
/*package*/ Poster retrieve() {
return new Poster(this).method("GET");
}
/*package*/ <T> T retrieve(String tailApiUrl, Class<T> type) throws IOException {
return _retrieve(tailApiUrl, type, "GET", false);
}
@@ -379,7 +383,7 @@ public class GitHub {
public GHUser getUser(String login) throws IOException {
GHUser u = users.get(login);
if (u == null) {
u = retrieve("/users/" + login, GHUser.class);
u = retrieve().to("/users/" + login, GHUser.class);
u.root = this;
users.put(u.getLogin(), u);
}
@@ -465,9 +469,10 @@ public class GitHub {
* Newly created repository.
*/
public GHRepository createRepository(String name, String description, String homepage, boolean isPublic) throws IOException {
return new Poster(this).withCredential()
Poster poster = new Poster(this).withCredential()
.with("name", name).with("description", description).with("homepage", homepage)
.with("public", isPublic ? 1 : 0).to("/user/repos", GHRepository.class,"POST").wrap(this);
.with("public", isPublic ? 1 : 0);
return poster.method("POST").to("/user/repos", GHRepository.class).wrap(this);
}
/**