@Override public List<GitHubOrganization> listAllGithubOrganizations() { return listOrganizations("/organizations?per_page=100"); }
@Override public boolean isTeamMember(String teamId, String username) { return isTeamMember(teamId, username, false); }
@Override public List<User> listPublicMembers(String organization) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("organization", organization); return fetchUsers("/orgs/{organization}/public_members?per_page=100", uriVariables); }
@Override public ExtOrganization getOrganization(String organization) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("organization", organization); return getRestTemplate().getForObject(buildUri("/orgs/{organization}", uriVariables), ExtOrganization.class); }
@Override public Team getTeam(String teamId) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("teamId", teamId); RequestEntity<?> requestEntity = new RequestEntity<>(getDefaultHeaders(), HttpMethod.GET, buildUri("teams/{teamId}", uriVariables)); ResponseEntity<Team> organizationsEntity = getRestTemplate().exchange(requestEntity, Team.class); return organizationsEntity.getBody(); }
private void initialize() { userOperations = new UserTemplate(getRestTemplate(), isAuthorized(), this.apiBaseUrl); repositoryOperations = new RepositoryTemplate(getRestTemplate(), isAuthorized(), this.apiBaseUrl); authorizationOperations = new AuthorizationTemplate(getRestTemplate(), isAuthorized(), this.apiBaseUrl); organizationOperations = new OrganizationTemplate(getRestTemplate(), isAuthorized(), this.apiBaseUrl); }
protected boolean isTeamMember(String login, Github github) { final String teamId = configProperties.getTeamId() + ""; boolean isMember = github.getOrganizationOperations().isTeamMember(teamId, login); LOG.info("Is member of " + teamId + " : " + isMember); return isMember; } }
@Override public Team getTeam(long teamId) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("teamid", teamId); return getRestTemplate().getForObject(buildUri("/teams/{teamid}", uriVariables), Team.class); }
private void initialize() { userOperations = new UserTemplate(getRestTemplate(), isAuthorized()); repositoryOperations = new RepositoryTemplate(getRestTemplate(), isAuthorized()); authorizationOperations = new AuthorizationTemplate(getRestTemplate(), isAuthorized()); organizationOperations = new OrganizationTemplate(getRestTemplate(), isAuthorized()); }
@Override public List<GitHubOrganization> listGithubOrganizations() { return listOrganizations("/user/orgs?per_page=100"); }
@Override public List<User> listMembers(String organization) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("organization", organization); return fetchUsers("/orgs/{organization}/members?per_page=100", uriVariables); }
@Override public void removeFromOrganization(String organization, String username) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("organization", organization); uriVariables.put("username", username); getRestTemplate().delete(buildUri("/orgs/{organization}/members/{username}", uriVariables)); }
protected List<GitHubOrganization> listOrganizations(String path) { return listOrganizations(path, Collections.emptyMap()); }
@Override public void deleteTeam(long teamId) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("teamid", teamId); getRestTemplate().delete(buildUri("/teams/{teamid}", uriVariables)); }
@Override public List<GitHubOrganization> listUserOrganizations(String username) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("username", username); return listOrganizations("/user/{username}/orgs?per_page=100", uriVariables); }
protected List<GitHubOrganization> listOrganizations(String path, Map<String, Object> uriVariables) { List<GitHubOrganization> result = new ArrayList<GitHubOrganization>(); Iterator<List<GitHubOrganization>> iter = new PagingIterator<>(getRestTemplate(), buildUri(path, uriVariables), orgaListTypeRef); while (iter.hasNext()) { result.addAll(iter.next()); } return result; }
protected List<User> fetchUsers(String path, Map<String, Object> uriVariables) { List<User> usersList = new ArrayList<User>(); Iterator<List<User>> iter = new PagingIterator<>(getRestTemplate(), buildUri(path, uriVariables), userListTypeRef); while (iter.hasNext()) { usersList.addAll(iter.next()); } return usersList; }
@Override public List<Team> listTeams(String organization) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("organization", organization); List<Team> teamList = new ArrayList<Team>(); Iterator<List<Team>> iter = new PagingIterator<>(getRestTemplate(), buildUri("/orgs/{organization}/teams?per_page=100", uriVariables), teamListTypeRef); while (iter.hasNext()) { teamList.addAll(iter.next()); } return teamList; }
@Override public boolean isPublicMemberOfOrganization(String organization, String username) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("organization", organization); uriVariables.put("username", username); HttpStatus status = HttpStatus.NOT_FOUND; try { ResponseEntity<Void> responseEntity = getRestTemplate() .getForEntity(buildUri("/orgs/{organization}/public_members/{username}", uriVariables), Void.class); status = responseEntity.getStatusCode(); } catch (HttpClientErrorException e) { // skip } return HttpStatus.NO_CONTENT.equals(status) ? true : false; }
@Override public Team updateTeam(long teamId, TeamRequest teamRequest) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("teamid", teamId); RequestEntity<TeamRequest> entity = RequestEntity.patch(buildUri("/teams/{teamid}", uriVariables)) .contentType(MediaType.APPLICATION_JSON).body(teamRequest); return getRestTemplate().exchange(entity, Team.class).getBody(); }