Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-13 17:06:54 +0000
committerChris Aniszczyk2011-04-14 14:53:18 +0000
commitc7661f48402d24a0604dffa79aca0681aa64c0b6 (patch)
tree447574c99e74adccfeb3830dae854d675d72a95e
parent02c60b82615110aeada76e9446cfb3f10d38df96 (diff)
downloadegit-github-c7661f48402d24a0604dffa79aca0681aa64c0b6.tar.gz
egit-github-c7661f48402d24a0604dffa79aca0681aa64c0b6.tar.xz
egit-github-c7661f48402d24a0604dffa79aca0681aa64c0b6.zip
Add service class for getting gists by id and user
Change-Id: Iac5a3aeaf6b56979571b530702e0e1e2d74b55ea 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/GistService.java67
1 files changed, 67 insertions, 0 deletions
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
new file mode 100644
index 00000000..00cf2f3c
--- /dev/null
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GistService.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.github.internal;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+
+import com.google.gson.reflect.TypeToken;
+
+/**
+ * Service class for getting and list gists.
+ */
+public class GistService {
+
+ private GitHubClient client;
+
+ /**
+ * Create gist service
+ *
+ * @param client
+ */
+ public GistService(GitHubClient client) {
+ Assert.isNotNull(client, "Client cannot be null");
+ this.client = client;
+ }
+
+ /**
+ * Get gist
+ *
+ * @param id
+ * @return gist
+ * @throws IOException
+ */
+ public Gist getGist(String id) throws IOException {
+ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_GISTS);
+ uri.append('/').append(id).append(IGitHubConstants.SUFFIX_JSON);
+ return this.client.get(uri.toString(), Gist.class);
+ }
+
+ /**
+ * Get gists for specified user
+ *
+ * @param user
+ * @return list of gists
+ * @throws IOException
+ */
+ public List<Gist> getGists(String user) throws IOException {
+ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_USERS);
+ uri.append('/').append(user);
+ uri.append(IGitHubConstants.SEGMENT_GISTS).append(
+ IGitHubConstants.SUFFIX_JSON);
+ TypeToken<List<Gist>> gistToken = new TypeToken<List<Gist>>() {
+ };
+ return this.client.get(uri.toString(), gistToken.getType());
+ }
+
+}

Back to the top