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

com.pubnub.api.endpoints.objects.internal.CollectionQueryParameters.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.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()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy