com.pubnub.extension.RetrofitResponse.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.extension
import com.pubnub.api.models.consumer.objects.PNPage
import com.pubnub.api.models.consumer.objects.member.PNMember
import com.pubnub.api.models.consumer.objects.member.PNMemberArrayResult
import com.pubnub.api.models.consumer.objects.membership.PNChannelMembership
import com.pubnub.api.models.consumer.objects.membership.PNChannelMembershipArrayResult
import com.pubnub.api.models.server.objects_api.EntityArrayEnvelope
import retrofit2.Response
internal fun Response>.toPNMemberArrayResult(): PNMemberArrayResult? =
body()?.let { arrayEnvelope ->
PNMemberArrayResult(
status = arrayEnvelope.status,
data = arrayEnvelope.data,
totalCount = arrayEnvelope.totalCount,
next = arrayEnvelope.next?.let { PNPage.PNNext(it) },
prev = arrayEnvelope.prev?.let { PNPage.PNPrev(it) }
)
}
internal fun Response>.toPNChannelMembershipArrayResult(): PNChannelMembershipArrayResult? =
body()?.let { arrayEnvelope ->
PNChannelMembershipArrayResult(
status = arrayEnvelope.status,
data = arrayEnvelope.data,
totalCount = arrayEnvelope.totalCount,
next = arrayEnvelope.next?.let { PNPage.PNNext(it) },
prev = arrayEnvelope.prev?.let { PNPage.PNPrev(it) }
)
}