com.pubnub.api.endpoints.DeleteMessages.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
import com.pubnub.api.Endpoint
import com.pubnub.api.PubNub
import com.pubnub.api.PubNubError
import com.pubnub.api.PubNubException
import com.pubnub.api.enums.PNOperationType
import com.pubnub.api.models.consumer.history.PNDeleteMessagesResult
import com.pubnub.api.toCsv
import retrofit2.Call
import retrofit2.Response
import java.util.HashMap
import java.util.Locale
/**
* @see [PubNub.deleteMessages]
*/
class DeleteMessages internal constructor(
pubnub: PubNub,
val channels: List,
val start: Long? = null,
val end: Long? = null
) : Endpoint(pubnub) {
override fun validateParams() {
super.validateParams()
if (channels.isEmpty()) throw PubNubException(PubNubError.CHANNEL_MISSING)
}
override fun doWork(queryParams: HashMap): Call {
addQueryParams(queryParams)
return pubnub.retrofitManager.historyService.deleteMessages(
pubnub.configuration.subscribeKey,
channels.toCsv(),
queryParams
)
}
override fun createResponse(input: Response): PNDeleteMessagesResult =
PNDeleteMessagesResult()
override fun operationType() = PNOperationType.PNDeleteMessagesOperation
private fun addQueryParams(queryParams: MutableMap) {
start?.run { queryParams["start"] = this.toString().lowercase(Locale.US) }
end?.run { queryParams["end"] = this.toString().lowercase(Locale.US) }
}
}