2016-12-13 18:52:41 +00:00
|
|
|
module Mattermost
|
2016-12-19 23:22:10 +00:00
|
|
|
class Team < Client
|
2017-02-02 14:04:02 +00:00
|
|
|
# Returns **all** teams for an admin
|
2016-12-19 23:22:10 +00:00
|
|
|
def all
|
2017-01-23 11:58:51 +00:00
|
|
|
session_get('/api/v3/teams/all')
|
2016-12-16 14:45:56 +00:00
|
|
|
end
|
2017-02-02 14:04:02 +00:00
|
|
|
|
2017-02-03 10:29:56 +00:00
|
|
|
# Creates a team on the linked Mattermost instance, the team admin will be the
|
|
|
|
# `current_user` passed to the Mattermost::Client instance
|
2017-02-20 12:41:50 +00:00
|
|
|
def create(group)
|
|
|
|
session_post('/api/v3/teams/create', body: new_team_params(group).to_json)
|
2017-02-03 10:29:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
MATTERMOST_TEAM_LENGTH_MAX = 59
|
|
|
|
|
2017-02-20 12:41:50 +00:00
|
|
|
def new_team_params(group)
|
2017-02-03 10:29:56 +00:00
|
|
|
{
|
|
|
|
name: group.path[0..MATTERMOST_TEAM_LENGTH_MAX],
|
|
|
|
display_name: group.name[0..MATTERMOST_TEAM_LENGTH_MAX],
|
|
|
|
type: group.public? ? 'O' : 'I' # Open vs Invite-only
|
2017-02-20 12:41:50 +00:00
|
|
|
}
|
2017-02-02 14:04:02 +00:00
|
|
|
end
|
2016-12-13 18:52:41 +00:00
|
|
|
end
|
|
|
|
end
|