Sha256: 538436e2234703953fda22ea6289a4436905d51ac9edd1d35c502bcb4310722e

Contents?: true

Size: 1.38 KB

Versions: 5

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Panoptes
  class Client
    module UserGroups
      # Creates a new user group and puts the current user in it as the initial member.
      #
      # @see http://docs.panoptes.apiary.io/#reference/user-group/usergroup-collection/create-a-user-group
      # @param name [String] The name of the user group. Must be unique for the entirity of Zooniverse.
      # @return [Hash] The created user group.
      def create_user_group(name)
        panoptes.post('/user_groups', user_groups: {
                        name: name
                      })['user_groups'][0]
      end

      def user_groups
        panoptes.get('/user_groups')['user_groups']
      end

      def join_user_group(user_group_id, user_id, join_token:)
        panoptes.post('/memberships', memberships: {
                        join_token: join_token,
                        links: { user: user_id, user_group: user_group_id }
                      })['memberships'][0]
      end

      def remove_user_from_user_group(user_group_id, user_id)
        panoptes.delete("/user_groups/#{user_group_id}/links/users/#{user_id}")
      end

      def delete_user_group(user_group_id)
        response = panoptes.connection.get("/api/user_groups/#{user_group_id}")
        etag = response.headers['ETag']

        panoptes.delete("/user_groups/#{user_group_id}", {}, etag: etag)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
panoptes-client-1.2.1 lib/panoptes/client/user_groups.rb
panoptes-client-1.2.0 lib/panoptes/client/user_groups.rb
panoptes-client-1.1.1 lib/panoptes/client/user_groups.rb
panoptes-client-1.1.0 lib/panoptes/client/user_groups.rb
panoptes-client-1.0.0 lib/panoptes/client/user_groups.rb