fixed API
This commit is contained in:
1 parent
af0d8b77a5
commit
6dba8aaa2e
6 files changed
+45
-20
No files matched your search
@@ -6,6 +6,7 @@ import io.ktor.client.call.*
|
||||
import io.ktor.client.engine.cio.*
|
||||
import io.ktor.client.plugins.*
|
||||
import io.ktor.client.plugins.contentnegotiation.*
|
||||
import io.ktor.client.plugins.defaultRequest
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.*
|
||||
import io.ktor.http.*
|
||||
@@ -32,7 +33,10 @@ class AnyTypeApi(
|
||||
|
||||
private val http = HttpClient(CIO) {
|
||||
install(ContentNegotiation) {
|
||||
json(Json { ignoreUnknownKeys = true })
|
||||
json(Json { ignoreUnknownKeys = true; explicitNulls = false })
|
||||
}
|
||||
defaultRequest {
|
||||
header("Anytype-Version", "2025-11-08")
|
||||
}
|
||||
}.also { client ->
|
||||
client.plugin(HttpSend).intercept { request ->
|
||||
@@ -62,7 +66,6 @@ class AnyTypeApi(
|
||||
suspend fun getSpaces(): Result<List<Space>> =
|
||||
runCatching {
|
||||
val response = http.get("$baseUrl/v1/spaces") {
|
||||
header("Anytype-Version", "0.1")
|
||||
bearerAuth(apiKey)
|
||||
}
|
||||
response.body<SpacesResponse>().data
|
||||
@@ -71,7 +74,6 @@ class AnyTypeApi(
|
||||
suspend fun getTypes(): Result<List<ObjectType>> =
|
||||
runCatching {
|
||||
val response = http.get("$baseUrl/v1/spaces/$spaceId/types") {
|
||||
header("Anytype-Version", "0.1")
|
||||
bearerAuth(apiKey)
|
||||
}
|
||||
response.body<TypesResponse>().data
|
||||
@@ -81,7 +83,6 @@ class AnyTypeApi(
|
||||
runCatching {
|
||||
val response = http.post("$baseUrl/v1/spaces/$spaceId/search") {
|
||||
contentType(ContentType.Application.Json)
|
||||
header("Anytype-Version", "0.1")
|
||||
bearerAuth(apiKey)
|
||||
setBody(mapOf("types" to listOf(typeKey)))
|
||||
}
|
||||
@@ -91,7 +92,6 @@ class AnyTypeApi(
|
||||
suspend fun getTags(propertyId: String): Result<List<Tag>> =
|
||||
runCatching {
|
||||
val response = http.get("$baseUrl/v1/spaces/$spaceId/properties/$propertyId/tags") {
|
||||
header("Anytype-Version", "2025-11-08")
|
||||
bearerAuth(apiKey)
|
||||
}
|
||||
response.body<TagsResponse>().data
|
||||
@@ -100,7 +100,6 @@ class AnyTypeApi(
|
||||
suspend fun getTemplates(typeId: String): Result<List<Template>> =
|
||||
runCatching {
|
||||
val response = http.get("$baseUrl/v1/spaces/$spaceId/types/$typeId/templates") {
|
||||
header("Anytype-Version", "0.1")
|
||||
bearerAuth(apiKey)
|
||||
}
|
||||
response.body<TemplatesResponse>().data
|
||||
@@ -108,7 +107,7 @@ class AnyTypeApi(
|
||||
|
||||
suspend fun createObject(
|
||||
title: String,
|
||||
details: String = "",
|
||||
details: String? = null,
|
||||
typeKey: String,
|
||||
templateId: String? = null,
|
||||
properties: List<JsonElement> = emptyList(),
|
||||
@@ -116,12 +115,11 @@ class AnyTypeApi(
|
||||
runCatching {
|
||||
val response = http.post("$baseUrl/v1/spaces/$spaceId/objects") {
|
||||
contentType(ContentType.Application.Json)
|
||||
header("Anytype-Version", "0.1")
|
||||
bearerAuth(apiKey)
|
||||
setBody(
|
||||
CreateObjectRequest(
|
||||
name = title,
|
||||
body = details,
|
||||
body = details?.takeIf { it.isNotBlank() },
|
||||
typeKey = typeKey,
|
||||
templateId = templateId,
|
||||
properties = properties,
|
||||
|
||||
@@ -7,7 +7,7 @@ import kotlinx.serialization.json.JsonElement
|
||||
@Serializable
|
||||
data class CreateObjectRequest(
|
||||
val name: String,
|
||||
val body: String,
|
||||
val body: String? = null,
|
||||
@SerialName("type_key") val typeKey: String,
|
||||
@SerialName("template_id") val templateId: String? = null,
|
||||
val properties: List<JsonElement> = emptyList(),
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package ch.ergon.anytask.api.dto
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Tag(
|
||||
val id: String,
|
||||
val key: String = "",
|
||||
val name: String,
|
||||
val color: String = "",
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
package ch.ergon.anytask.api.dto
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class TagsResponse(
|
||||
val data: List<Tag>,
|
||||
)
|
||||