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

com.pubnub.api.endpoints.files.DeleteFile.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.files

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.files.PNDeleteFileResult
import retrofit2.Call
import retrofit2.Response

/**
 * @see [PubNub.deleteFile]
 */
class DeleteFile(
    private val channel: String,
    private val fileName: String,
    private val fileId: String,
    pubNub: PubNub
) : Endpoint(pubNub) {
    @Throws(PubNubException::class)
    override fun validateParams() {
        if (channel.isEmpty()) {
            throw PubNubException(PubNubError.CHANNEL_MISSING)
        }
    }

    @Throws(PubNubException::class)
    override fun doWork(queryParams: HashMap): Call =
        pubnub.retrofitManager.filesService.deleteFile(
            pubnub.configuration.subscribeKey,
            channel,
            fileId,
            fileName,
            queryParams
        )

    @Throws(PubNubException::class)
    override fun createResponse(input: Response): PNDeleteFileResult = if (input.isSuccessful) {
        PNDeleteFileResult(input.code())
    } else {
        throw PubNubException(PubNubError.HTTP_ERROR)
    }

    override fun getAffectedChannels() = listOf(channel)
    override fun getAffectedChannelGroups(): List = listOf()
    override fun operationType(): PNOperationType = PNOperationType.FileOperation
    override fun isAuthRequired(): Boolean = true
    override fun isSubKeyRequired(): Boolean = true
    override fun isPubKeyRequired(): Boolean = false
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy