diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-03-13 09:46:28 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2017-03-13 09:46:28 -0400 |
commit | a284cd8c1817bb5419cb9eae118c85cd7e99c039 (patch) | |
tree | 71fd6ace54692477acea746f47b3266514ae9292 /model/client4.go | |
parent | 5ec49c0db03d4ec6fd36619055f99c9a3bb34148 (diff) | |
download | chat-a284cd8c1817bb5419cb9eae118c85cd7e99c039.tar.gz chat-a284cd8c1817bb5419cb9eae118c85cd7e99c039.tar.bz2 chat-a284cd8c1817bb5419cb9eae118c85cd7e99c039.zip |
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
Diffstat (limited to 'model/client4.go')
-rw-r--r-- | model/client4.go | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/model/client4.go b/model/client4.go index f2dc7625b..63f65ed48 100644 --- a/model/client4.go +++ b/model/client4.go @@ -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. |