mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-11 00:11:25 +00:00
Compare commits
4 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c3884b94d | ||
|
|
540d473e42 | ||
|
|
db717c86bb | ||
|
|
4f9cace3fe |
2
pom.xml
2
pom.xml
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
43
src/main/java/org/kohsuke/github/JsonUsers.java
Normal file
43
src/main/java/org/kohsuke/github/JsonUsers.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user