Compare commits

...

4 Commits

Author SHA1 Message Date
Kohsuke Kawaguchi
6c3884b94d [maven-release-plugin] prepare release github-api-1.1 2010-04-18 22:24:07 -07:00
Kohsuke Kawaguchi
540d473e42 bug fix 2010-04-18 22:21:30 -07:00
Kohsuke Kawaguchi
db717c86bb added following/follows support 2010-04-18 22:12:10 -07:00
Kohsuke Kawaguchi
4f9cace3fe [maven-release-plugin] prepare for next development iteration 2010-04-18 22:04:28 -07:00
3 changed files with 73 additions and 1 deletions

View File

@@ -3,7 +3,7 @@
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<version>1.1</version>
<name>GitHub API for Java</name>
<url>http://kohsuke.org/github-api/</url>
<description>GitHub API for Java</description>

View File

@@ -27,6 +27,7 @@ import java.io.IOException;
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 class GHUser {
return getRepositories().get(name);
}
/**
* Follow this user.
*/
public void follow() throws IOException {
new Poster(root).withCredential().to(root.getApiURL("/user/follow/"+login));
}
/**
* Unfollow this user.
*/
public void unfollow() throws IOException {
new Poster(root).withCredential().to(root.getApiURL("/user/unfollow/"+login));
}
/**
* Lists the users that this user is following
*/
public Set<GHUser> getFollows() throws IOException {
return root.retrieve("/user/show/"+login+"/following",JsonUsers.class).toSet(root);
}
/**
* Lists the users who are following this user.
*/
public Set<GHUser> getFollowers() throws IOException {
return root.retrieve("/user/show/"+login+"/followers",JsonUsers.class).toSet(root);
}
@Override
public String toString() {
return "User:"+login;

View File

@@ -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<String> users;
public Set<GHUser> toSet(GitHub root) throws IOException {
Set<GHUser> r = new HashSet<GHUser>();
for (String u : users)
r.add(root.getUser(u));
return r;
}
}