summaryrefslogtreecommitdiff
path: root/lib/mattermost/team.rb
blob: d5648f7167f3e750e7d6073a9ac9f46160d11a37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Mattermost
  class Team < Client
    # Returns **all** teams for an admin
    def all
      session_get('/api/v3/teams/all')
    end

    # Creates a team on the linked Mattermost instance, the team admin will be the
    # `current_user` passed to the Mattermost::Client instance
    def create(group, params)
      session_post('/api/v3/teams/create', body: new_team_params(group, params).to_json)
    end

    private

    MATTERMOST_TEAM_LENGTH_MAX = 59

    def new_team_params(group, options)
      {
        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
      }.merge(options)
    end
  end
end