From 4f9cace3fedad1a4e81ff6e6d5c53e2108f62b87 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sun, 18 Apr 2010 22:04:28 -0700 Subject: [PATCH 1/4] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9f5452a9e5..b802bacfd1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.kohsuke github-api jar - 1.0 + 1.1-SNAPSHOT GitHub API for Java http://kohsuke.org/github-api/ GitHub API for Java From db717c86bbadda2447a40f2ad3a5fb75d2dc43fc Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sun, 18 Apr 2010 22:12:10 -0700 Subject: [PATCH 2/4] added following/follows support --- src/main/java/org/kohsuke/github/GHUser.java | 29 +++++++++++++ .../java/org/kohsuke/github/JsonUsers.java | 43 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/main/java/org/kohsuke/github/JsonUsers.java diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index 2a5b73f1ff..1fe875c74a 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -27,6 +27,7 @@ import java.net.URL; import java.util.Collections; import java.util.Map; +import java.util.Set; import java.util.TreeMap; import static org.kohsuke.github.GitHub.MAPPER; @@ -143,6 +144,34 @@ public GHRepository getRepository(String name) throws IOException { return getRepositories().get(name); } + /** + * Follow this user. + */ + public void follow() throws IOException { + new Poster(root).to(root.getApiURL("/user/follow/"+login)); + } + + /** + * Unfollow this user. + */ + public void unfollow() throws IOException { + new Poster(root).to(root.getApiURL("/user/unfollow/"+login)); + } + + /** + * Lists the users that this user is following + */ + public Set getFollows() throws IOException { + return root.retrieve("/user/show/"+login+"/followers",JsonUsers.class).toSet(root); + } + + /** + * Lists the users who are following this user. + */ + public Set getFollowings() throws IOException { + return root.retrieve("/user/show/"+login+"/following",JsonUsers.class).toSet(root); + } + @Override public String toString() { return "User:"+login; diff --git a/src/main/java/org/kohsuke/github/JsonUsers.java b/src/main/java/org/kohsuke/github/JsonUsers.java new file mode 100644 index 0000000000..257f6001f0 --- /dev/null +++ b/src/main/java/org/kohsuke/github/JsonUsers.java @@ -0,0 +1,43 @@ +/* + * The MIT License + * + * Copyright (c) 2010, Kohsuke Kawaguchi + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.kohsuke.github; + +import java.io.IOException; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * @author Kohsuke Kawaguchi + */ +class JsonUsers { + public List users; + + public Set toSet(GitHub root) throws IOException { + Set r = new HashSet(); + for (String u : users) + r.add(root.getUser(u)); + return r; + } +} From 540d473e4218912ce10ab57a48d7014cfe2d5d6f Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sun, 18 Apr 2010 22:21:30 -0700 Subject: [PATCH 3/4] bug fix --- src/main/java/org/kohsuke/github/GHUser.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index 1fe875c74a..b439ca4ee8 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -148,28 +148,28 @@ public GHRepository getRepository(String name) throws IOException { * Follow this user. */ public void follow() throws IOException { - new Poster(root).to(root.getApiURL("/user/follow/"+login)); + new Poster(root).withCredential().to(root.getApiURL("/user/follow/"+login)); } /** * Unfollow this user. */ public void unfollow() throws IOException { - new Poster(root).to(root.getApiURL("/user/unfollow/"+login)); + new Poster(root).withCredential().to(root.getApiURL("/user/unfollow/"+login)); } /** * Lists the users that this user is following */ public Set getFollows() throws IOException { - return root.retrieve("/user/show/"+login+"/followers",JsonUsers.class).toSet(root); + return root.retrieve("/user/show/"+login+"/following",JsonUsers.class).toSet(root); } /** * Lists the users who are following this user. */ - public Set getFollowings() throws IOException { - return root.retrieve("/user/show/"+login+"/following",JsonUsers.class).toSet(root); + public Set getFollowers() throws IOException { + return root.retrieve("/user/show/"+login+"/followers",JsonUsers.class).toSet(root); } @Override From 6c3884b94dd08867076d1f8c477230473b48e7bc Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sun, 18 Apr 2010 22:24:07 -0700 Subject: [PATCH 4/4] [maven-release-plugin] prepare release github-api-1.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b802bacfd1..739a0e4f4b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.kohsuke github-api jar - 1.1-SNAPSHOT + 1.1 GitHub API for Java http://kohsuke.org/github-api/ GitHub API for Java