diff options
| author | Kevin Sawicki | 2011-04-12 16:48:50 +0000 |
|---|---|---|
| committer | Chris Aniszczyk | 2011-04-12 18:09:00 +0000 |
| commit | 42903ba6de530176385170a0dc98e0054e981a31 (patch) | |
| tree | 9f10129051ea73d5075ebba830ee508823b26b39 | |
| parent | 5f60a4f9d8b13fc220b39d76f4683facdef0815f (diff) | |
| download | egit-github-42903ba6de530176385170a0dc98e0054e981a31.tar.gz egit-github-42903ba6de530176385170a0dc98e0054e981a31.tar.xz egit-github-42903ba6de530176385170a0dc98e0054e981a31.zip | |
Add PUT request support to GitHubClient
This will be used to update existing issues.
Change-Id: I056b72934056daf8dbe7bdf4d38a9ec13dce106e
Signed-off-by: Kevin Sawicki <kevin@github.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
| -rw-r--r-- | org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java | 62 |
1 files changed, 53 insertions, 9 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java index e9b17dac..3493d381 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java @@ -31,15 +31,15 @@ import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.auth.BasicScheme; +import org.apache.commons.httpclient.methods.EntityEnclosingMethod; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.commons.httpclient.protocol.Protocol; /** * Client class for interacting with GitHub HTTP/JSON API. - * - * @author Kevin Sawicki (kevin@github.com) */ public class GitHubClient { @@ -88,6 +88,18 @@ public class GitHubClient { } /** + * Create standard post method + * + * @param uri + * @return post + */ + protected PutMethod createPut(String uri) { + PutMethod method = new PutMethod(uri); + setMethodDefaults(method); + return method; + } + + /** * Set method defaults * * @param method @@ -213,18 +225,17 @@ public class GitHubClient { } /** - * Post data to uri - * + * Send json using specified method + * * @param <V> - * @param uri + * @param method * @param params * @param type - * @return response + * @return resource * @throws IOException */ - public <V> V post(String uri, Map<String, String> params, Type type) - throws IOException { - PostMethod method = createPost(uri); + protected <V> V sendJson(EntityEnclosingMethod method, + Map<String, String> params, Type type) throws IOException { if (params != null && !params.isEmpty()) { StringBuilder payload = new StringBuilder(); this.gson.toJson(params, payload); @@ -240,6 +251,7 @@ public class GitHubClient { case 201: if (type != null) return parseJson(method, type); + case 204: break; case 400: case 404: @@ -255,4 +267,36 @@ public class GitHubClient { return null; } + /** + * Post data to uri + * + * @param <V> + * @param uri + * @param params + * @param type + * @return response + * @throws IOException + */ + public <V> V post(String uri, Map<String, String> params, Type type) + throws IOException { + PostMethod method = createPost(uri); + return sendJson(method, params, type); + } + + /** + * Put data to uri + * + * @param <V> + * @param uri + * @param params + * @param type + * @return response + * @throws IOException + */ + public <V> V put(String uri, Map<String, String> params, Type type) + throws IOException { + PutMethod method = createPut(uri); + return sendJson(method, params, type); + } + } |
