summaryrefslogtreecommitdiff
path: root/lib/mattermost/team.rb
blob: 52486fd1a54c02d7a8d14ebc188e1ef661d0a827 (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)
      session_post('/api/v3/teams/create', body: new_team_params(group).to_json)
    end

    private

    MATTERMOST_TEAM_LENGTH_MAX = 59

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