-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from crowdin/feat/teams
feat: teams API
- Loading branch information
Showing
28 changed files
with
557 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ plugins { | |
} | ||
|
||
sourceCompatibility = 8 | ||
version '1.0.0' | ||
version '1.1.0' | ||
|
||
repositories { | ||
mavenCentral() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package com.crowdin.client.teams; | ||
|
||
import com.crowdin.client.core.CrowdinApi; | ||
import com.crowdin.client.core.http.HttpRequestConfig; | ||
import com.crowdin.client.core.http.exceptions.HttpBadRequestException; | ||
import com.crowdin.client.core.http.exceptions.HttpException; | ||
import com.crowdin.client.core.model.ClientConfig; | ||
import com.crowdin.client.core.model.Credentials; | ||
import com.crowdin.client.core.model.PatchRequest; | ||
import com.crowdin.client.core.model.ResponseList; | ||
import com.crowdin.client.core.model.ResponseObject; | ||
import com.crowdin.client.teams.model.AddTeamMembersRequest; | ||
import com.crowdin.client.teams.model.AddTeamMembersResponse; | ||
import com.crowdin.client.teams.model.AddTeamMembersResponseInternal; | ||
import com.crowdin.client.teams.model.AddTeamRequest; | ||
import com.crowdin.client.teams.model.AddTeamToProjectRequest; | ||
import com.crowdin.client.teams.model.ProjectTeamResources; | ||
import com.crowdin.client.teams.model.Team; | ||
import com.crowdin.client.teams.model.TeamMember; | ||
import com.crowdin.client.teams.model.TeamMemberResponseList; | ||
import com.crowdin.client.teams.model.TeamResponseList; | ||
import com.crowdin.client.teams.model.TeamResponseObject; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class TeamsApi extends CrowdinApi { | ||
public TeamsApi(Credentials credentials) { | ||
super(credentials); | ||
} | ||
|
||
public TeamsApi(Credentials credentials, ClientConfig clientConfig) { | ||
super(credentials, clientConfig); | ||
} | ||
|
||
/** | ||
* @param projectId project identifier | ||
* @param request request object | ||
* @return project team status | ||
*/ | ||
public ProjectTeamResources addTeamToProject(Long projectId, AddTeamToProjectRequest request) throws HttpException, HttpBadRequestException { | ||
return this.httpClient.post(this.url + "/projects/" + projectId + "/teams", request, new HttpRequestConfig(), ProjectTeamResources.class); | ||
} | ||
|
||
/** | ||
* @param limit maximum number of items to retrieve (default 25) | ||
* @param offset starting offset in the collection (default 0) | ||
* @return list of teams | ||
*/ | ||
public ResponseList<Team> listTeams(Integer limit, Integer offset) throws HttpException, HttpBadRequestException { | ||
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams( | ||
"limit", Optional.ofNullable(limit), | ||
"offset", Optional.ofNullable(offset) | ||
); | ||
TeamResponseList teamResponseList = this.httpClient.get(this.url + "/teams", new HttpRequestConfig(queryParams), TeamResponseList.class); | ||
return TeamResponseList.to(teamResponseList); | ||
} | ||
|
||
/** | ||
* @param request request object | ||
* @return newly created team | ||
*/ | ||
public ResponseObject<Team> addTeam(AddTeamRequest request) throws HttpException, HttpBadRequestException { | ||
TeamResponseObject teamResponseObject = this.httpClient.post(this.url + "/teams", request, new HttpRequestConfig(), TeamResponseObject.class); | ||
return ResponseObject.of(teamResponseObject.getData()); | ||
} | ||
|
||
/** | ||
* @param teamId team identifier | ||
* @return team | ||
*/ | ||
public ResponseObject<Team> getTeam(Long teamId) throws HttpException, HttpBadRequestException { | ||
TeamResponseObject teamResponseObject = this.httpClient.get(this.url + "/teams/" + teamId, new HttpRequestConfig(), TeamResponseObject.class); | ||
return ResponseObject.of(teamResponseObject.getData()); | ||
} | ||
|
||
/** | ||
* @param teamId team identifier | ||
*/ | ||
public void deleteTeam(Long teamId) throws HttpException, HttpBadRequestException { | ||
this.httpClient.delete(this.url + "/teams/" + teamId, new HttpRequestConfig(), Void.class); | ||
} | ||
|
||
/** | ||
* @param teamId team identifier | ||
* @param request request object | ||
* @return updated team | ||
*/ | ||
public ResponseObject<Team> editTeam(Long teamId, List<PatchRequest> request) throws HttpException, HttpBadRequestException { | ||
TeamResponseObject teamResponseObject = this.httpClient.patch(this.url + "/teams/" + teamId, request, new HttpRequestConfig(), TeamResponseObject.class); | ||
return ResponseObject.of(teamResponseObject.getData()); | ||
} | ||
|
||
/** | ||
* @param teamId team identifier | ||
* @param limit maximum number of items to retrieve (default 25) | ||
* @param offset starting offset in the collection (default 0) | ||
* @return list of team members | ||
*/ | ||
public ResponseList<TeamMember> listTeamMembers(Long teamId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException { | ||
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams( | ||
"limit", Optional.ofNullable(limit), | ||
"offset", Optional.ofNullable(offset) | ||
); | ||
TeamMemberResponseList teamMemberResponseList = this.httpClient.get(this.url + "/teams/" + teamId + "/members", new HttpRequestConfig(queryParams), TeamMemberResponseList.class); | ||
return TeamMemberResponseList.to(teamMemberResponseList); | ||
} | ||
|
||
/** | ||
* @param teamId team identifier | ||
* @param request request object | ||
* @return response | ||
*/ | ||
public AddTeamMembersResponse addTeamMembers(Long teamId, AddTeamMembersRequest request) throws HttpException, HttpBadRequestException { | ||
AddTeamMembersResponseInternal addTeamMembersResponseInternal = this.httpClient.post(this.url + "/teams/" + teamId + "/members", request, new HttpRequestConfig(), AddTeamMembersResponseInternal.class); | ||
return AddTeamMembersResponseInternal.to(addTeamMembersResponseInternal); | ||
} | ||
|
||
/** | ||
* @param teamId team identifier | ||
*/ | ||
public void deleteAllTeamMembers(Long teamId) throws HttpException, HttpBadRequestException { | ||
this.httpClient.delete(this.url + "/teams/" + teamId + "/members", new HttpRequestConfig(), Void.class); | ||
} | ||
|
||
/** | ||
* @param teamId team identifier | ||
* @param memberId member identifier | ||
*/ | ||
public void deleteTeamMember(Long teamId, Long memberId) throws HttpException, HttpBadRequestException { | ||
this.httpClient.delete(this.url + "/teams/" + teamId + "/members/" + memberId, new HttpRequestConfig(), Void.class); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/crowdin/client/teams/model/AddTeamMembersRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.crowdin.client.teams.model; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class AddTeamMembersRequest { | ||
|
||
private List<Long> userIds; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/crowdin/client/teams/model/AddTeamMembersResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.crowdin.client.teams.model; | ||
|
||
import com.crowdin.client.core.model.Pagination; | ||
import com.crowdin.client.core.model.ResponseObject; | ||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class AddTeamMembersResponse { | ||
|
||
private List<ResponseObject<TeamMember>> skipped; | ||
private List<ResponseObject<TeamMember>> added; | ||
private Pagination pagination; | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/crowdin/client/teams/model/AddTeamMembersResponseInternal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.crowdin.client.teams.model; | ||
|
||
import com.crowdin.client.core.model.Pagination; | ||
import com.crowdin.client.core.model.ResponseObject; | ||
import lombok.Data; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Data | ||
public class AddTeamMembersResponseInternal { | ||
|
||
private List<TeamMemberResponseObject> skipped; | ||
private List<TeamMemberResponseObject> added; | ||
private Pagination pagination; | ||
|
||
public static AddTeamMembersResponse to(AddTeamMembersResponseInternal addTeamMembersResponseInternal) { | ||
AddTeamMembersResponse response = new AddTeamMembersResponse(); | ||
response.setPagination(addTeamMembersResponseInternal.getPagination()); | ||
response.setAdded(addTeamMembersResponseInternal.getAdded().stream().map(TeamMemberResponseObject::getData).map(ResponseObject::of).collect(Collectors.toList())); | ||
response.setSkipped(addTeamMembersResponseInternal.getSkipped().stream().map(TeamMemberResponseObject::getData).map(ResponseObject::of).collect(Collectors.toList())); | ||
return response; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/crowdin/client/teams/model/AddTeamRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.crowdin.client.teams.model; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class AddTeamRequest { | ||
|
||
private String name; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/crowdin/client/teams/model/AddTeamToProjectRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.crowdin.client.teams.model; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class AddTeamToProjectRequest { | ||
|
||
private Long teamId; | ||
private boolean accessToAllWorkflowSteps; | ||
private boolean managerAccess; | ||
private Object permissions; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/crowdin/client/teams/model/ProjectTeamResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.crowdin.client.teams.model; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class ProjectTeamResource { | ||
|
||
private Long id; | ||
private boolean hasManagerAccess; | ||
private boolean hasAccessToAllWorkflowSteps; | ||
private Object permissions; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/crowdin/client/teams/model/ProjectTeamResources.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.crowdin.client.teams.model; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class ProjectTeamResources { | ||
private ProjectTeamResource skipped; | ||
private ProjectTeamResource added; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.crowdin.client.teams.model; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.Date; | ||
|
||
@Data | ||
public class Team { | ||
|
||
private Long id; | ||
private String name; | ||
private Integer totalMembers; | ||
private Date createdAt; | ||
private Date updatedAt; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/crowdin/client/teams/model/TeamMember.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.crowdin.client.teams.model; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.Date; | ||
|
||
@Data | ||
public class TeamMember { | ||
|
||
private Long id; | ||
private String username; | ||
private String firstName; | ||
private String lastName; | ||
private String avatarUrl; | ||
private Date addedAt; | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/crowdin/client/teams/model/TeamMemberResponseList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.crowdin.client.teams.model; | ||
|
||
import com.crowdin.client.core.model.Pagination; | ||
import com.crowdin.client.core.model.ResponseList; | ||
import com.crowdin.client.core.model.ResponseObject; | ||
import lombok.Data; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Data | ||
public class TeamMemberResponseList { | ||
|
||
private List<TeamMemberResponseObject> data; | ||
private Pagination pagination; | ||
|
||
public static ResponseList<TeamMember> to(TeamMemberResponseList teamMemberResponseList) { | ||
return ResponseList.of( | ||
teamMemberResponseList.getData().stream() | ||
.map(TeamMemberResponseObject::getData) | ||
.map(ResponseObject::of) | ||
.collect(Collectors.toList()), | ||
teamMemberResponseList.getPagination() | ||
); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/crowdin/client/teams/model/TeamMemberResponseObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.crowdin.client.teams.model; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class TeamMemberResponseObject { | ||
|
||
private TeamMember data; | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/crowdin/client/teams/model/TeamResponseList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.crowdin.client.teams.model; | ||
|
||
import com.crowdin.client.core.model.Pagination; | ||
import com.crowdin.client.core.model.ResponseList; | ||
import com.crowdin.client.core.model.ResponseObject; | ||
import lombok.Data; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Data | ||
public class TeamResponseList { | ||
|
||
private List<TeamResponseObject> data; | ||
private Pagination pagination; | ||
|
||
public static ResponseList<Team> to(TeamResponseList teamResponseList) { | ||
return ResponseList.of( | ||
teamResponseList.getData().stream() | ||
.map(TeamResponseObject::getData) | ||
.map(ResponseObject::of) | ||
.collect(Collectors.toList()), | ||
teamResponseList.getPagination() | ||
); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/crowdin/client/teams/model/TeamResponseObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.crowdin.client.teams.model; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class TeamResponseObject { | ||
|
||
private Team data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.