diff options
| author | Kevin Sawicki | 2011-04-14 20:27:32 +0000 |
|---|---|---|
| committer | Chris Aniszczyk | 2011-04-14 20:46:09 +0000 |
| commit | 22bde950af9baeac1eb5482645fdd3e830aa0620 (patch) | |
| tree | bcdbf0ecb8d65a67463a8101cf35c972adbb2552 | |
| parent | 70ccb0fa02bcec80a4022d4205285e14b320b4f0 (diff) | |
| download | egit-github-22bde950af9baeac1eb5482645fdd3e830aa0620.tar.gz egit-github-22bde950af9baeac1eb5482645fdd3e830aa0620.tar.xz egit-github-22bde950af9baeac1eb5482645fdd3e830aa0620.zip | |
Add service support for updating a gist
Change-Id: I5c2cfcf78649d4410300a5539f0f7636b54fc1c7
Signed-off-by: Kevin Sawicki <kevin@github.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
4 files changed, 63 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java index 5eeeb6de..99e3450f 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Gist.java @@ -134,6 +134,15 @@ public class Gist { } /** + * @param repo + * @return this gist + */ + public Gist setRepo(String repo) { + this.repo = repo; + return this; + } + + /** * @return url */ public String getUrl() { diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistFile.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistFile.java index ff56ae2a..ade2eae2 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistFile.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistFile.java @@ -54,6 +54,13 @@ public class GistFile { } /** + * @param filename + */ + public void setFilename(String filename) { + this.filename = filename; + } + + /** * @return rawUrl */ public String getRawUrl() { diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java index 02fe9aa3..9fcd1d6b 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java @@ -86,6 +86,20 @@ public class GistService { } /** + * Update a gist + * + * @param gist + * @return updated gist + * @throws IOException + */ + public Gist updateGist(Gist gist) throws IOException { + StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_GISTS); + uri.append('/').append(gist.getRepo()) + .append(IGitHubConstants.SUFFIX_JSON); + return this.client.put(uri.toString(), gist, Gist.class); + } + + /** * Create comment on specified gist id * * @param gistId 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 3547d24f..ffbe25b1 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 @@ -190,6 +190,39 @@ public class GitHubClient { } /** + * Get response stream from uri. It is the responsibility of the calling + * method to close the returned stream. + * + * @param uri + * @param params + * @return V + * @throws IOException + */ + public InputStream getStream(String uri, Map<String, String> params) + throws IOException { + GetMethod method = createGet(uri); + if (params != null && !params.isEmpty()) + method.setQueryString(getPairs(params)); + + try { + int status = this.client.executeMethod(this.hostConfig, method); + switch (status) { + case 200: + return method.getResponseBodyAsStream(); + case 400: + case 404: + case 500: + RequestError error = parseJson(method, RequestError.class); + throw new RequestException(error); + default: + throw new IOException(method.getStatusText()); + } + } catch (JsonParseException jpe) { + throw new IOException(jpe); + } + } + + /** * Get response from uri and bind to specified type * * @param <V> |
