Files
sdk-for-android/library/src/main/java/io/appwrite/services/Functions.kt
T
2021-06-09 11:04:54 +05:30

107 lines
2.9 KiB
Kotlin

package io.appwrite.services
import android.net.Uri
import io.appwrite.Client
import io.appwrite.exceptions.AppwriteException
import okhttp3.Cookie
import okhttp3.Response
import java.io.File
class Functions(private val client: Client) : BaseService(client) {
/**
* List Executions
*
* Get a list of all the current user function execution logs. You can use the
* query params to filter your results. On admin mode, this endpoint will
* return a list of all of the project's executions. [Learn more about
* different API modes](/docs/admin).
*
* @param functionId
* @param search
* @param limit
* @param offset
* @param orderType
* @return [Response]
*/
@JvmOverloads
@Throws(AppwriteException::class)
suspend fun listExecutions(
functionId: String,
search: String? = null,
limit: Int? = null,
offset: Int? = null,
orderType: String? = null
): Response {
val path = "/functions/{functionId}/executions".replace("{functionId}", functionId)
val params = mapOf<String, Any?>(
"search" to search,
"limit" to limit,
"offset" to offset,
"orderType" to orderType
)
val headers = mapOf(
"content-type" to "application/json"
)
return client.call("GET", path, headers, params)
}
/**
* Create Execution
*
* Trigger a function execution. The returned object will return you the
* current execution status. You can ping the `Get Execution` endpoint to get
* updates on the current execution status. Once this endpoint is called, your
* function execution process will start asynchronously.
*
* @param functionId
* @param data
* @return [Response]
*/
@JvmOverloads
@Throws(AppwriteException::class)
suspend fun createExecution(
functionId: String,
data: String? = null
): Response {
val path = "/functions/{functionId}/executions".replace("{functionId}", functionId)
val params = mapOf<String, Any?>(
"data" to data
)
val headers = mapOf(
"content-type" to "application/json"
)
return client.call("POST", path, headers, params)
}
/**
* Get Execution
*
* Get a function execution log by its unique ID.
*
* @param functionId
* @param executionId
* @return [Response]
*/
@JvmOverloads
@Throws(AppwriteException::class)
suspend fun getExecution(
functionId: String,
executionId: String
): Response {
val path = "/functions/{functionId}/executions/{executionId}".replace("{functionId}", functionId).replace("{executionId}", executionId)
val params = mapOf<String, Any?>(
)
val headers = mapOf(
"content-type" to "application/json"
)
return client.call("GET", path, headers, params)
}
}