All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pubnub.api.models.consumer.access_manager.sum.SpacePermissions.kt Maven / Gradle / Ivy

Go to download

PubNub is a cross-platform client-to-client (1:1 and 1:many) push service in the cloud, capable of broadcasting real-time messages to millions of web and mobile clients simultaneously, in less than a quarter second!

There is a newer version: 10.2.0
Show newest version
package com.pubnub.api.models.consumer.access_manager.sum

import com.pubnub.api.PubNubError
import com.pubnub.api.PubNubException
import com.pubnub.api.SpaceId
import com.pubnub.api.models.consumer.access_manager.v3.ChannelGrant
import com.pubnub.api.models.consumer.access_manager.v3.PNChannelPatternGrant
import com.pubnub.api.models.consumer.access_manager.v3.PNChannelResourceGrant
import com.pubnub.api.models.consumer.access_manager.v3.PNGrant
import com.pubnub.api.models.consumer.access_manager.v3.PNSpacePatternPermissionsGrant
import com.pubnub.api.models.consumer.access_manager.v3.PNSpacePermissionsGrant

interface SpacePermissions : PNGrant {

    companion object {
        fun id(
            spaceId: SpaceId,
            read: Boolean = false,
            write: Boolean = false,
            manage: Boolean = false,
            delete: Boolean = false,
            get: Boolean = false,
            join: Boolean = false,
            update: Boolean = false
        ): SpacePermissions = PNSpacePermissionsGrant(
            id = spaceId.value,
            read = read,
            write = write,
            manage = manage,
            delete = delete,
            get = get,
            join = join,
            update = update
        )

        fun pattern(
            pattern: String,
            read: Boolean = false,
            write: Boolean = false,
            manage: Boolean = false,
            delete: Boolean = false,
            get: Boolean = false,
            join: Boolean = false,
            update: Boolean = false
        ): SpacePermissions = PNSpacePatternPermissionsGrant(
            id = pattern,
            read = read,
            write = write,
            manage = manage,
            delete = delete,
            get = get,
            join = join,
            update = update
        )
    }
}

fun SpacePermissions.toChannelGrant(): ChannelGrant {
    return when (this) {
        is PNSpacePermissionsGrant -> PNChannelResourceGrant(spacePermissions = this)
        is PNSpacePatternPermissionsGrant -> PNChannelPatternGrant(spacePermissions = this)
        else -> throw PubNubException(pubnubError = PubNubError.INVALID_ARGUMENTS)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy