@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(long teamId) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("teamid", teamId); return getRestTemplate().getForObject(buildUri("/teams/{teamid}", uriVariables), Team.class); }
@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; }
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 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)); }
@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<GitHubRepo> listOrganizationRepositories(final String organization, final String type) { Map<String, Object> uriVariables = new HashMap<String, Object>(); uriVariables.put("organization", organization); RequestEntity<?> requestEntity = new RequestEntity<>(getDefaultHeaders(), HttpMethod.GET, buildUri("orgs/{organization}/repos?per_page=100", uriVariables)); ResponseEntity<GitHubRepo[]> organizationsEntity = getRestTemplate().exchange(requestEntity, GitHubRepo[].class); // buildUri("orgs/{organization}/repos?per_page=100"), HttpMethod.GET, entity, GitHubRepo[].class, // uriVariables); return asList(organizationsEntity.getBody()); }
@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(); }
@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 boolean isMemberOfOrganization(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}/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(); }
@Override public ExtOrganization updateOrganization(OrganizationUpdate update, String organization) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("organization", organization); RequestEntity<OrganizationUpdate> entity = RequestEntity.patch(buildUri("/orgs/{organization}", uriVariables)) .contentType(MediaType.APPLICATION_JSON).body(update); return getRestTemplate().exchange(entity, ExtOrganization.class).getBody(); }
@Override public Team createTeam(String organization, TeamRequest teamRequest) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("organization", organization); RequestEntity<TeamRequest> entity = RequestEntity.post(buildUri("/orgs/{organization}/teams", uriVariables)) .contentType(MediaType.APPLICATION_JSON).body(teamRequest); return getRestTemplate().exchange(entity, Team.class).getBody(); }
@Override public boolean isTeamMember(String teamId, String username, boolean includePending) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("id", teamId); uriVariables.put("username", username); RequestEntity<?> requestEntity = new RequestEntity<>(getDefaultHeaders(), HttpMethod.GET, buildUri("teams/{id}/members/{username}", uriVariables)); ResponseEntity<?> responseEntity = getRestTemplate().exchange(requestEntity, Object.class); if (responseEntity.getStatusCode().equals(HttpStatus.NO_CONTENT)) { return true; } return false; // } else if (responseEntity.getStatusCode().is2xxSuccessful()) { // Membership membership = responseEntity.getBody(); // if ("active".equals(membership.getState())) { // return true; // } // if ("pending".equals(membership.getState()) && includePending) { // return true; // } else { // return false; // } // } }