mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 08:21:21 +00:00
member addition and removal
This commit is contained in:
@@ -27,10 +27,21 @@ public class GHTeam {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current members.
|
||||
*/
|
||||
public Set<GHUser> getMembers() throws IOException {
|
||||
return org.root.retrieveWithAuth(getApiURL("/members"),JsonUsersWithDetails.class).toSet(org.root);
|
||||
}
|
||||
|
||||
public void add(GHUser u) throws IOException {
|
||||
org.root.retrieveWithAuth(getApiURL("/members?name="+u.getLogin()),null, "POST");
|
||||
}
|
||||
|
||||
public void remove(GHUser u) throws IOException {
|
||||
org.root.retrieveWithAuth(getApiURL("/members?name="+u.getLogin()),null, "DELETE");
|
||||
}
|
||||
|
||||
private URL getApiURL(String tail) throws IOException {
|
||||
return org.root.getApiURL("/organizations/"+org.getLogin()+"/teams/"+id+tail);
|
||||
}
|
||||
|
||||
@@ -108,13 +108,17 @@ public class GitHub {
|
||||
}
|
||||
|
||||
/*package*/ <T> T retrieveWithAuth(URL url, Class<T> type) throws IOException {
|
||||
return retrieveWithAuth(url,type,"GET");
|
||||
}
|
||||
/*package*/ <T> T retrieveWithAuth(URL url, Class<T> type, String method) throws IOException {
|
||||
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
|
||||
|
||||
BASE64Encoder enc = new sun.misc.BASE64Encoder();
|
||||
String userpassword = login + "/token" + ":" + token;
|
||||
String encodedAuthorization = enc.encode(userpassword.getBytes());
|
||||
uc.setRequestProperty("Authorization", "Basic " + encodedAuthorization);
|
||||
|
||||
uc.setRequestMethod(method);
|
||||
|
||||
try {
|
||||
InputStreamReader r = new InputStreamReader(uc.getInputStream(), "UTF-8");
|
||||
if (type==null) {
|
||||
|
||||
@@ -78,11 +78,15 @@ class Poster {
|
||||
* {@link Reader} that reads the response.
|
||||
*/
|
||||
public <T> T to(URL url, Class<T> type) throws IOException {
|
||||
return to(url,type,"POST");
|
||||
}
|
||||
|
||||
public <T> T to(URL url, Class<T> type, String method) throws IOException {
|
||||
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
|
||||
|
||||
uc.setDoOutput(true);
|
||||
uc.setRequestProperty("Content-type","application/x-www-form-urlencoded");
|
||||
uc.setRequestMethod("POST");
|
||||
uc.setRequestMethod(method);
|
||||
|
||||
|
||||
StringBuilder body = new StringBuilder();
|
||||
|
||||
@@ -4,6 +4,7 @@ import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import org.kohsuke.github.GHRepository;
|
||||
import org.kohsuke.github.GHTeam;
|
||||
import org.kohsuke.github.GitHub;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -13,7 +14,12 @@ import java.io.IOException;
|
||||
*/
|
||||
public class AppTest extends TestCase {
|
||||
public void testApp() throws IOException {
|
||||
System.out.println(GitHub.connect().getOrganization("HudsonLabs").getTeams().get("Core Developers").getMembers());
|
||||
GitHub gitHub = GitHub.connect();
|
||||
GHTeam t = gitHub.getOrganization("HudsonLabs").getTeams().get("Core Developers");
|
||||
t.add(gitHub.getMyself());
|
||||
System.out.println(t.getMembers());
|
||||
t.remove(gitHub.getMyself());
|
||||
System.out.println(t.getMembers());
|
||||
|
||||
// GHRepository r = GitHub.connect().getOrganization("HudsonLabs").createRepository("auto-test", "some description", "http://kohsuke.org/", "Plugin Developers", true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user