Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
Fix email, phone, url to be single values property
Browse files Browse the repository at this point in the history
  • Loading branch information
petersamokhin committed Nov 26, 2020
1 parent c16f212 commit 9426fb8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
}

group = "com.petersamokhin.notionsdk"
version = "1.0.1"
version = "1.0.3"


dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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,
Expand All @@ -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
Expand Down
36 changes: 18 additions & 18 deletions src/main/kotlin/com/petersamokhin/notionapi/model/NotionTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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(
Expand Down

0 comments on commit 9426fb8

Please sign in to comment.