Implement some team endpoints for APIv4 (#5745)

* Implement PUT /teams/{team_id} endpoint for APIv4

* Implement GET /users/{user_id}/teams/{team_id}/unread endpoint for APIv4

* Implement POST /teams/{team_id}/members/ids endpoint for APIv4

* Remove debug statement
Этот коммит содержится в:
Joram Wilander
2017-03-13 09:46:28 -04:00
коммит произвёл Christopher Speller
родитель 5ec49c0db0
Коммит a284cd8c18
11 изменённых файлов: 451 добавлений и 25 удалений

Просмотреть файл

@@ -549,8 +549,8 @@ func (c *Client4) RevokeSession(userId, sessionId string) (bool, *Response) {
}
}
// getTeamsUnreadForUser will return an array with TeamUnread objects that contain the amount of
// unread messages and mentions the current user has for the teams it belongs to.
// GetTeamsUnreadForUser will return an array with TeamUnread objects that contain the amount
// of unread messages and mentions the current user has for the teams it belongs to.
// An optional team ID can be set to exclude that team from the results. Must be authenticated.
func (c *Client4) GetTeamsUnreadForUser(userId, teamIdToExclude string) ([]*TeamUnread, *Response) {
optional := ""
@@ -696,7 +696,7 @@ func (c *Client4) GetTeamMember(teamId, userId, etag string) (*TeamMember, *Resp
}
}
// UpdateTeamMemberRoles will update the roles on a team for a user
// UpdateTeamMemberRoles will update the roles on a team for a user.
func (c *Client4) UpdateTeamMemberRoles(teamId, userId, newRoles string) (bool, *Response) {
requestBody := map[string]string{"roles": newRoles}
if r, err := c.DoApiPut(c.GetTeamMemberRoute(teamId, userId)+"/roles", MapToJson(requestBody)); err != nil {
@@ -707,6 +707,16 @@ func (c *Client4) UpdateTeamMemberRoles(teamId, userId, newRoles string) (bool,
}
}
// UpdateTeam will update a team.
func (c *Client4) UpdateTeam(team *Team) (*Team, *Response) {
if r, err := c.DoApiPut(c.GetTeamRoute(team.Id), team.ToJson()); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
return TeamFromJson(r.Body), BuildResponse(r)
}
}
// GetTeamMembers returns team members based on the provided team id string.
func (c *Client4) GetTeamMembers(teamId string, page int, perPage int, etag string) ([]*TeamMember, *Response) {
query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)
@@ -718,6 +728,17 @@ func (c *Client4) GetTeamMembers(teamId string, page int, perPage int, etag stri
}
}
// GetTeamMembersByIds will return an array of team members based on the
// team id and a list of user ids provided. Must be authenticated.
func (c *Client4) GetTeamMembersByIds(teamId string, userIds []string) ([]*TeamMember, *Response) {
if r, err := c.DoApiPost(fmt.Sprintf("/teams/%v/members/ids", teamId), ArrayToJson(userIds)); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
return TeamMembersFromJson(r.Body), BuildResponse(r)
}
}
// GetTeamStats returns a team stats based on the team id string.
// Must be authenticated.
func (c *Client4) GetTeamStats(teamId, etag string) (*TeamStats, *Response) {
@@ -729,6 +750,18 @@ func (c *Client4) GetTeamStats(teamId, etag string) (*TeamStats, *Response) {
}
}
// GetTeamUnread will return a TeamUnread object that contains the amount of
// unread messages and mentions the user has for the specified team.
// Must be authenticated.
func (c *Client4) GetTeamUnread(teamId, userId string) (*TeamUnread, *Response) {
if r, err := c.DoApiGet(c.GetUserRoute(userId)+c.GetTeamRoute(teamId)+"/unread", ""); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
return TeamUnreadFromJson(r.Body), BuildResponse(r)
}
}
// Channel Section
// CreateChannel creates a channel based on the provided channel struct.