com.pubnub.api.models.consumer.access_manager.sum.UserPermissions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pubnub-kotlin-api Show documentation
Show all versions of pubnub-kotlin-api Show documentation
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!
package com.pubnub.api.models.consumer.access_manager.sum
import com.pubnub.api.PubNubError
import com.pubnub.api.PubNubException
import com.pubnub.api.UserId
import com.pubnub.api.models.consumer.access_manager.v3.PNGrant
import com.pubnub.api.models.consumer.access_manager.v3.PNUUIDPatternGrant
import com.pubnub.api.models.consumer.access_manager.v3.PNUUIDResourceGrant
import com.pubnub.api.models.consumer.access_manager.v3.PNUserPatternPermissionsGrant
import com.pubnub.api.models.consumer.access_manager.v3.PNUserPermissionsGrant
import com.pubnub.api.models.consumer.access_manager.v3.UUIDGrant
interface UserPermissions : PNGrant {
companion object {
fun id(
userId: UserId,
get: Boolean = false,
update: Boolean = false,
delete: Boolean = false,
): UserPermissions =
PNUserPermissionsGrant(
id = userId.value,
delete = delete,
get = get,
update = update,
)
fun pattern(
pattern: String,
get: Boolean = false,
update: Boolean = false,
delete: Boolean = false,
): UserPermissions =
PNUserPatternPermissionsGrant(
id = pattern,
delete = delete,
get = get,
update = update,
)
}
}
fun UserPermissions.toUuidGrant(): UUIDGrant {
return when (this) {
is PNUserPermissionsGrant -> PNUUIDResourceGrant(userPermissions = this)
is PNUserPatternPermissionsGrant -> PNUUIDPatternGrant(userPermissions = this)
else -> throw PubNubException(pubnubError = PubNubError.INVALID_ARGUMENTS)
}
}