diff --git a/build.gradle.kts b/build.gradle.kts index ad7a002..286c418 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,7 @@ repositories { } group = "com.petersamokhin.notionsdk" -version = "1.0.1" +version = "1.0.3" dependencies { diff --git a/src/main/kotlin/com/petersamokhin/notionapi/mapper/NotionPropertyMapper.kt b/src/main/kotlin/com/petersamokhin/notionapi/mapper/NotionPropertyMapper.kt index becde00..fdcc0e9 100644 --- a/src/main/kotlin/com/petersamokhin/notionapi/mapper/NotionPropertyMapper.kt +++ b/src/main/kotlin/com/petersamokhin/notionapi/mapper/NotionPropertyMapper.kt @@ -23,7 +23,8 @@ fun parseNotionColumn(json: Json, name: String, type: NotionColumnType, field: J return when (type) { NotionColumnType.Title, NotionColumnType.Text, NotionColumnType.Number, - NotionColumnType.Checkbox, NotionColumnType.Select, NotionColumnType.MultiSelect -> { + NotionColumnType.Checkbox, NotionColumnType.Select, NotionColumnType.MultiSelect, + NotionColumnType.Email, NotionColumnType.Url, NotionColumnType.PhoneNumber -> { val label = masterList.firstOrNull()?.getOrNull(0)?.contentAsStringOrNull ?: return NotionColumn.SingleValue(name, type, null) @@ -36,11 +37,13 @@ fun parseNotionColumn(json: Json, name: String, type: NotionColumnType, field: J NotionColumnType.Checkbox -> NotionProperty.Value.Checkbox(label == NotionBooleanSerializer.NOTION_TRUE) NotionColumnType.Select -> NotionProperty.Value.Select(label) NotionColumnType.MultiSelect -> NotionProperty.Value.MultiSelect(label.split(",")) + NotionColumnType.Email -> NotionProperty.Value.Email(label) + NotionColumnType.Url -> NotionProperty.Value.Url(label) + NotionColumnType.PhoneNumber -> NotionProperty.Value.PhoneNumber(label) else -> throw IllegalStateException("exhaustive") }.let { NotionProperty(label = label, it) } ) } - NotionColumnType.Email, NotionColumnType.Url, NotionColumnType.PhoneNumber, NotionColumnType.Person, NotionColumnType.File -> { NotionColumn.MultiValue( name = name, @@ -56,9 +59,6 @@ fun parseNotionColumn(json: Json, name: String, type: NotionColumnType, field: J }.flatten() .map { (label, item) -> val v = when (type) { - NotionColumnType.Email -> NotionProperty.Value.Entry.Email(item) - NotionColumnType.Url -> NotionProperty.Value.Entry.Link(item) - NotionColumnType.PhoneNumber -> NotionProperty.Value.Entry.PhoneNumber(item) NotionColumnType.Person -> NotionProperty.Value.Entry.Person(item) NotionColumnType.File -> NotionProperty.Value.Entry.File(item) else -> null diff --git a/src/main/kotlin/com/petersamokhin/notionapi/model/NotionTable.kt b/src/main/kotlin/com/petersamokhin/notionapi/model/NotionTable.kt index a4e71f0..c6be829 100644 --- a/src/main/kotlin/com/petersamokhin/notionapi/model/NotionTable.kt +++ b/src/main/kotlin/com/petersamokhin/notionapi/model/NotionTable.kt @@ -130,6 +130,24 @@ data class NotionProperty(val label: String, val value: Value? = null) { override fun simpleJson(json: Json) = JsonArray(options.map(::JsonPrimitive)) } + @Serializable + @SerialName("url") + data class Url(val url: String) : Value() { + override fun simpleJson(json: Json) = JsonPrimitive(url) + } + + @Serializable + @SerialName("email") + data class Email(val email: String) : Value() { + override fun simpleJson(json: Json) = JsonPrimitive(email) + } + + @Serializable + @SerialName("phone_number") + data class PhoneNumber(@SerialName("phone_number") val phoneNumber: String) : Value() { + override fun simpleJson(json: Json) = JsonPrimitive(phoneNumber) + } + @Serializable @SerialName("entry") sealed class Entry : Value() { @@ -139,30 +157,12 @@ data class NotionProperty(val label: String, val value: Value? = null) { override fun simpleJson(json: Json) = JsonPrimitive(id) } - @Serializable - @SerialName("link") - data class Link(val url: String) : Entry() { - override fun simpleJson(json: Json) = JsonPrimitive(url) - } - @Serializable @SerialName("file") data class File(val url: String) : Entry() { override fun simpleJson(json: Json) = JsonPrimitive(url) } - @Serializable - @SerialName("email") - data class Email(val email: String) : Entry() { - override fun simpleJson(json: Json) = JsonPrimitive(email) - } - - @Serializable - @SerialName("phone_number") - data class PhoneNumber(@SerialName("phone_number") val phoneNumber: String) : Entry() { - override fun simpleJson(json: Json) = JsonPrimitive(phoneNumber) - } - @Serializable @SerialName("date") data class Date(