Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2012-04-25 19:16:36 -0400
committerKevin Sawicki2012-04-25 19:16:36 -0400
commit1337b6d25b1d4c1ecb55f712e839c5dbcb4faf44 (patch)
treeb7ddfe3b5966308d5bc75947a4da7f2ea8f8f9db
parenta09ca3590db2137447a03395fafdbb9e2378eeba (diff)
downloadegit-github-1337b6d25b1d4c1ecb55f712e839c5dbcb4faf44.tar.gz
egit-github-1337b6d25b1d4c1ecb55f712e839c5dbcb4faf44.tar.xz
egit-github-1337b6d25b1d4c1ecb55f712e839c5dbcb4faf44.zip
Add support for paging over starred gists
Previously only the entire list could be fetched but paging should be supported as well. Change-Id: I672cd76abc87916d5d05432f920d171f23a8f1bf
-rw-r--r--org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistServiceTest.java14
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GistService.java57
2 files changed, 60 insertions, 11 deletions
diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistServiceTest.java
index edb0c537..abc59384 100644
--- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistServiceTest.java
+++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GistServiceTest.java
@@ -327,6 +327,20 @@ public class GistServiceTest {
}
/**
+ * Get iterator for starred gists
+ *
+ * @throws IOException
+ */
+ @Test
+ public void pageStarredGists() throws IOException {
+ PageIterator<Gist> iterator = gistService.pageStarredGists();
+ assertNotNull(iterator);
+ assertTrue(iterator.hasNext());
+ assertEquals(Utils.page("/gists/starred"), iterator.getRequest()
+ .generateUri());
+ }
+
+ /**
* Get gists for null login name
*
* @throws IOException
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GistService.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GistService.java
index 0785dc34..393f801c 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GistService.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GistService.java
@@ -17,6 +17,8 @@ import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_PUBLI
import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_STAR;
import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_STARRED;
import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_USERS;
+import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_FIRST;
+import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_SIZE;
import com.google.gson.reflect.TypeToken;
@@ -90,17 +92,50 @@ public class GistService extends GitHubService {
}
/**
+ * Create page iterator for the current user's starred gists
+ *
+ * @return gist page iterator
+ */
+ public PageIterator<Gist> pageStarredGists() {
+ return pageStarredGists(PAGE_SIZE);
+ }
+
+ /**
+ * Create page iterator for the current user's starred gists
+ *
+ * @param size
+ * size of page
+ * @return gist page iterator
+ */
+ public PageIterator<Gist> pageStarredGists(final int size) {
+ return pageStarredGists(PAGE_FIRST, size);
+ }
+
+ /**
+ * Create page iterator for the current user's starred gists
+ *
+ * @param size
+ * size of page
+ * @param start
+ * starting page
+ * @return gist page iterator
+ */
+ public PageIterator<Gist> pageStarredGists(final int start, final int size) {
+ PagedRequest<Gist> request = createPagedRequest(start, size);
+ request.setUri(SEGMENT_GISTS + SEGMENT_STARRED);
+ request.setType(new TypeToken<List<Gist>>() {
+ }.getType());
+ return createPageIterator(request);
+ }
+
+ /**
* Get starred gists for currently authenticated user
*
* @return list of gists
* @throws IOException
*/
public List<Gist> getStarredGists() throws IOException {
- PagedRequest<Gist> request = createPagedRequest();
- request.setUri(SEGMENT_GISTS + SEGMENT_STARRED);
- request.setType(new TypeToken<List<Gist>>() {
- }.getType());
- return getAll(request);
+ return getAll(pageStarredGists());
}
/**
@@ -135,8 +170,8 @@ public class GistService extends GitHubService {
* @throws IOException
*/
public List<Gist> getGists(String user) throws IOException {
- PagedRequest<Gist> request = createUserGistRequest(user,
- PagedRequest.PAGE_FIRST, PagedRequest.PAGE_SIZE);
+ PagedRequest<Gist> request = createUserGistRequest(user, PAGE_FIRST,
+ PAGE_SIZE);
return getAll(request);
}
@@ -147,7 +182,7 @@ public class GistService extends GitHubService {
* @return gist page iterator
*/
public PageIterator<Gist> pageGists(final String user) {
- return pageGists(user, PagedRequest.PAGE_SIZE);
+ return pageGists(user, PAGE_SIZE);
}
/**
@@ -159,7 +194,7 @@ public class GistService extends GitHubService {
* @return gist page iterator
*/
public PageIterator<Gist> pageGists(final String user, final int size) {
- return pageGists(user, PagedRequest.PAGE_FIRST, size);
+ return pageGists(user, PAGE_FIRST, size);
}
/**
@@ -184,7 +219,7 @@ public class GistService extends GitHubService {
* @return gist page iterator
*/
public PageIterator<Gist> pagePublicGists() {
- return pagePublicGists(PagedRequest.PAGE_SIZE);
+ return pagePublicGists(PAGE_SIZE);
}
/**
@@ -195,7 +230,7 @@ public class GistService extends GitHubService {
* @return gist page iterator
*/
public PageIterator<Gist> pagePublicGists(final int size) {
- return pagePublicGists(PagedRequest.PAGE_FIRST, size);
+ return pagePublicGists(PAGE_FIRST, size);
}
/**

Back to the top