Sha256: 3e9b889d94506a2bba2746b5a2b710cf0ff932f76bb1c1010a05e63ec2c0042a

Contents?: true

Size: 1022 Bytes

Versions: 4

Compression:

Stored size: 1022 Bytes

Contents

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

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

      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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
discourse_api-0.4.4 lib/discourse_api/api/groups.rb
discourse_api-0.4.3 lib/discourse_api/api/groups.rb
discourse_api-0.4.2 lib/discourse_api/api/groups.rb
discourse_api-0.4.1 lib/discourse_api/api/groups.rb