Project init by claude
This commit is contained in:
1 parent
0f63311c6a
commit
830765cb13
7 files changed
+345
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package ch.ergon.anytask.api
|
||||
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.call.*
|
||||
import io.ktor.client.engine.cio.*
|
||||
import io.ktor.client.plugins.contentnegotiation.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
/**
|
||||
* Client für die lokale AnyType-API (anytype-heart Middleware).
|
||||
* Die API läuft standardmässig auf http://localhost:31007.
|
||||
*
|
||||
* TODO: App-Key via Einstellungen konfigurierbar machen.
|
||||
*/
|
||||
class AnyTypeClient(
|
||||
private val baseUrl: String = "http://localhost:31007",
|
||||
private val appKey: String = "", // wird nach erstem Login gesetzt
|
||||
) {
|
||||
private val http = HttpClient(CIO) {
|
||||
install(ContentNegotiation) {
|
||||
json(Json { ignoreUnknownKeys = true })
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun createTask(title: String, details: String = "", spaceId: String = ""): Result<String> =
|
||||
runCatching {
|
||||
val response = http.post("$baseUrl/v1/spaces/$spaceId/objects") {
|
||||
contentType(ContentType.Application.Json)
|
||||
header("Anytype-Version", "0.1")
|
||||
bearerAuth(appKey)
|
||||
setBody(CreateObjectRequest(title = title, details = details, typeKey = "ot-task"))
|
||||
}
|
||||
response.body<CreateObjectResponse>().objectId
|
||||
}
|
||||
|
||||
fun close() = http.close()
|
||||
}
|
||||
|
||||
@Serializable
|
||||
private data class CreateObjectRequest(
|
||||
val title: String,
|
||||
val details: String,
|
||||
val typeKey: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
private data class CreateObjectResponse(
|
||||
val objectId: String,
|
||||
)
|
||||