Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-25 19:05:59 +0000
committerKevin Sawicki2011-04-25 19:05:59 +0000
commitb663d6de6a261cf8b445fc1926dbd9a675aa6841 (patch)
tree18503755a04f7bf5a829224982e9a90a41785001
parent128aa1ca1417e52fcfc48f00c8b39cdef5cc9403 (diff)
downloadegit-github-b663d6de6a261cf8b445fc1926dbd9a675aa6841.tar.gz
egit-github-b663d6de6a261cf8b445fc1926dbd9a675aa6841.tar.xz
egit-github-b663d6de6a261cf8b445fc1926dbd9a675aa6841.zip
Add repository service support.
Change-Id: I617f98a70fff3b72c53950093cdac2c1b18fd4ca Signed-off-by: Kevin Sawicki <kevin@github.com>
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/DateFormatter.java29
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java30
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryService.java71
3 files changed, 120 insertions, 10 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/DateFormatter.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/DateFormatter.java
index aa00d910..72064a4f 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/DateFormatter.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/DateFormatter.java
@@ -20,24 +20,30 @@ import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
import java.util.TimeZone;
/**
* Date formatter for date format present in the GitHub v3 API.
- *
+ *
* @author Kevin Sawicki (kevin@github.com)
*/
public class DateFormatter implements JsonDeserializer<Date> {
- private DateFormat format;
+ private List<DateFormat> formats;
/**
* Create date formatter
*/
public DateFormatter() {
- this.format = new SimpleDateFormat(IGitHubConstants.DATE_FORMAT);
+ this.formats = new LinkedList<DateFormat>();
+ this.formats.add(new SimpleDateFormat(IGitHubConstants.DATE_FORMAT));
+ this.formats
+ .add(new SimpleDateFormat(IGitHubConstants.DATE_FORMAT_V2_1));
TimeZone timeZone = TimeZone.getTimeZone("Zulu"); //$NON-NLS-1$
- this.format.setTimeZone(timeZone);
+ for (DateFormat format : this.formats)
+ format.setTimeZone(timeZone);
}
/**
@@ -46,13 +52,16 @@ public class DateFormatter implements JsonDeserializer<Date> {
*/
public Date deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
- try {
- synchronized (this.format) {
- return this.format.parse(json.getAsString());
+ JsonParseException exception = null;
+ for (DateFormat format : this.formats)
+ try {
+ synchronized (format) {
+ return format.parse(json.getAsString());
+ }
+ } catch (ParseException e) {
+ exception = new JsonParseException(e);
}
- } catch (ParseException e) {
- throw new JsonParseException(e);
- }
+ throw exception;
}
}
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java
index 8b836a73..fb1420ae 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java
@@ -21,6 +21,21 @@ public interface IGitHubConstants {
String SEGMENT_REPOS = "/repos"; //$NON-NLS-1$
/**
+ * SEGMENT_SHOW
+ */
+ String SEGMENT_SHOW = "/show"; //$NON-NLS-1$
+
+ /**
+ * SEGMENT_ORGANIZATIONS
+ */
+ String SEGMENT_ORGANIZATIONS = "/organizations"; //$NON-NLS-1$
+
+ /**
+ * SEGMENT_REPOSITORIES
+ */
+ String SEGMENT_REPOSITORIES = "/repositories"; //$NON-NLS-1$
+
+ /**
* SEGMENT_ISSUES
*/
String SEGMENT_ISSUES = "/issues"; //$NON-NLS-1$
@@ -51,6 +66,11 @@ public interface IGitHubConstants {
String SEGMENT_USERS = "/users"; //$NON-NLS-1$
/**
+ * SEGMENT_V2_API
+ */
+ String SEGMENT_V2_API = "/api/v2/json"; //$NON-NLS-1$
+
+ /**
* SUFFIX_JSON
*/
String SUFFIX_JSON = ".json"; //$NON-NLS-1$
@@ -61,6 +81,11 @@ public interface IGitHubConstants {
String HOST_API = "api.github.com"; //$NON-NLS-1$
/**
+ * HOST_API_V2
+ */
+ String HOST_API_V2 = "github.com"; //$NON-NLS-1$
+
+ /**
* PROTOCOL_HTTPS
*/
String PROTOCOL_HTTPS = "https"; //$NON-NLS-1$
@@ -71,6 +96,11 @@ public interface IGitHubConstants {
String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$
/**
+ * DATE_FORMAT_V2_1
+ */
+ String DATE_FORMAT_V2_1 = "yyyy/MM/dd HH:mm:ss Z"; //$NON-NLS-N$
+
+ /**
* CONTENT_TYPE_JSON
*/
String CONTENT_TYPE_JSON = "application/json"; //$NON-NLS-1$
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryService.java
new file mode 100644
index 00000000..be8a5a30
--- /dev/null
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/RepositoryService.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Repository service class.
+ *
+ * @author Kevin Sawicki (kevin@github.com)
+ */
+public class RepositoryService {
+
+ private GitHubClient client;
+
+ /**
+ * Create repository service
+ *
+ * @param client
+ * cannot be null
+ */
+ public RepositoryService(GitHubClient client) {
+ Assert.isNotNull(client, "Client cannot be null"); //$NON-NLS-1$
+ this.client = client;
+ }
+
+ /**
+ * Get all repositories accessible through organizational membership
+ *
+ * @return list of repositories
+ * @throws IOException
+ */
+
+ public List<Repository> getOrganizationRepositories() throws IOException {
+ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_V2_API);
+ uri.append(IGitHubConstants.SEGMENT_ORGANIZATIONS).append(
+ IGitHubConstants.SEGMENT_REPOSITORIES);
+
+ RepositoryContainer container = client.get(uri.toString(),
+ RepositoryContainer.class);
+ return container.getRepositories();
+ }
+
+ /**
+ * Get repositories
+ *
+ * @param user
+ * @return list of repositories
+ * @throws IOException
+ */
+ public List<Repository> getRepositories(String user) throws IOException {
+ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_V2_API);
+ uri.append(IGitHubConstants.SEGMENT_REPOS)
+ .append(IGitHubConstants.SEGMENT_SHOW).append('/').append(user);
+
+ RepositoryContainer container = client.get(uri.toString(),
+ RepositoryContainer.class);
+ return container.getRepositories();
+ }
+}

Back to the top