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

io.contentchef.callback.common.Channel.kt Maven / Gradle / Ivy

There is a newer version: 1.3.0
Show newest version
package io.contentchef.callback.common

import io.contentchef.common.data.ContentChefItemResponse
import io.contentchef.common.data.ContentChefSearchResponse
import io.contentchef.common.request.RequestData
import org.json.JSONObject

/**
 * A channel is a collector of contents which can be used to retrieve them from ContentChef's backend
 * [C] is the Class Type which identifies parameters used for content services
 * [S] is the Class Type which identifies parameters used for search services
 */
interface Channel {

    /**
     * Retrieves a content by the parameters specified in [contentRequestData]
     * Calls [onSuccess] on a successful operation, otherwise calls [onError]
     */
    fun getContent(
        contentRequestData: C,
        onSuccess: (responseContent: ContentChefItemResponse) -> Unit,
        onError: (throwable: Throwable) -> Unit
    )

    /**
     * Retrieves a content by the parameters specified in [contentRequestData]
     * Calls [onSuccess] on a successful operation, otherwise calls [onError]
     * The [mapper] is used to transform the [JSONObject] into [K]. If an error happens during the transformation [onError] will be called
     */
    fun  getContent(
        contentRequestData: C,
        onSuccess: (responseContent: ContentChefItemResponse) -> Unit,
        onError: (throwable: Throwable) -> Unit,
        mapper: (JSONObject) -> K
    )

    /**
     * Retrieves a list of content based on the chosen search criteria as specified in [searchRequestData]
     * Calls [onSuccess] on a successful operation, otherwise calls [onError]
     */
    fun search(
        searchRequestData: S,
        onSuccess: (responseContent: ContentChefSearchResponse) -> Unit,
        onError: (throwable: Throwable) -> Unit
    )

    /**
     * Retrieves a list of content based on the chosen search criteria as specified in [searchRequestData]
     * Calls [onSuccess] on a successful operation, otherwise calls [onError]
     * The [mapper] is used to transform the [JSONObject] into [K]. If an error happens during the transformation [onError] will be called
     */
    fun  search(
        searchRequestData: S,
        onSuccess: (responseContent: ContentChefSearchResponse) -> Unit,
        onError: (throwable: Throwable) -> Unit,
        mapper: (JSONObject) -> K
    )
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy