Module: DiscourseApi::API::Groups

Included in:
Client
Defined in:
lib/discourse_api/api/groups.rb

Instance Method Summary collapse

Instance Method Details

#create_group(args) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/discourse_api/api/groups.rb', line 4

def create_group(args)
  args = API.params(args)
            .required(:name)
            .default(visible: true)
            .to_h
  post("/admin/groups", args)
end

#group_add(group_id, users) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/discourse_api/api/groups.rb', line 17

def group_add(group_id, users)
  users.keys.each do |key|
    # Accept arrays and convert to comma-delimited string.
    if users[key].respond_to? :join
      users[key] = users[key].join(",")
    end

    # Accept non-plural user_id or username, but send pluralized version in the request.
    if key.to_s[-1] != 's'
      users["#{key}s"] = users[key]
      users.delete(key)
    end
  end

  put("/admin/groups/#{group_id}/members.json", users)
end

#group_remove(group_id, user) ⇒ Object



34
35
36
# File 'lib/discourse_api/api/groups.rb', line 34

def group_remove(group_id, user)
  delete("/admin/groups/#{group_id}/members.json", user)
end

#groupsObject



12
13
14
15
# File 'lib/discourse_api/api/groups.rb', line 12

def groups
  response = get("/admin/groups.json")
  response.body
end