com.pubnub.api.endpoints.objects.internal.CollectionQueryParameters.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pubnub-kotlin Show documentation
Show all versions of pubnub-kotlin 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.endpoints.objects.internal
import com.pubnub.api.models.consumer.objects.PNPage
import com.pubnub.api.models.consumer.objects.PNSortKey
data class CollectionQueryParameters(
private val limit: Int? = null,
private val page: PNPage? = null,
private val filter: String? = null,
private val sort: Collection> = listOf(),
private val includeCount: Boolean = false,
) {
internal fun createCollectionQueryParams(): Map {
val additionalParams = mutableMapOf()
val f = filter
if (f != null) additionalParams["filter"] = f
if (sort.isNotEmpty()) additionalParams["sort"] =
sort.joinToString(",") { it.toSortParameter() }
if (limit != null) additionalParams["limit"] = limit.toString()
if (includeCount) additionalParams["count"] = includeCount.toString()
val p = page
when (p) {
is PNPage.PNNext -> additionalParams["start"] = p.pageHash
is PNPage.PNPrev -> additionalParams["end"] = p.pageHash
null -> {}
}
return additionalParams.toMap()
}
}