aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-14 16:27:32 (EDT)
committerChris Aniszczyk2011-04-14 16:46:09 (EDT)
commit22bde950af9baeac1eb5482645fdd3e830aa0620 (patch)
treebcdbf0ecb8d65a67463a8101cf35c972adbb2552
parent70ccb0fa02bcec80a4022d4205285e14b320b4f0 (diff)
downloadegit-github-22bde950af9baeac1eb5482645fdd3e830aa0620.zip
egit-github-22bde950af9baeac1eb5482645fdd3e830aa0620.tar.gz
egit-github-22bde950af9baeac1eb5482645fdd3e830aa0620.tar.bz2
Add service support for updating a gistrefs/changes/21/3121/2
Change-Id: I5c2cfcf78649d4410300a5539f0f7636b54fc1c7 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/Gist.java9
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistFile.java7
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java14
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java33
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 5eeeb6d..99e3450 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 ff56ae2..ade2eae 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 02fe9aa..9fcd1d6 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 3547d24..ffbe25b 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>