Skip to content

Commit

Permalink
Prepare for release 0.0.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
petersamokhin committed Nov 18, 2021
1 parent 1b01490 commit a2fffbb
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 49 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log

Version 0.0.5 *(2021-11-18)*
----------------------------
* Unify Notion icon model
* Add `icon` to the database rows

Version 0.0.4 *(2021-11-16)*
----------------------------
* Fix missing pagination logic for block children endpoint
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ implementation("com.petersamokhin.notionsdk:notionsdk:$latestVersion")
```
Library is published to the Maven Central repository.

Latest version: [![maven-central](https://img.shields.io/badge/Maven%20Central-0.0.4-yellowgreen?style=flat)](https://search.maven.org/search?q=g:com.petersamokhin.notionsdk)
Latest version: [![maven-central](https://img.shields.io/badge/Maven%20Central-0.0.5-yellowgreen?style=flat)](https://search.maven.org/search?q=g:com.petersamokhin.notionsdk)

### Supported endpoints
- [`/databases/:id/query`](https://developers.notion.com/reference/retrieve-a-database)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=com.petersamokhin.notionsdk
VERSION_NAME=0.0.4
VERSION_NAME=0.0.5

POM_ARTIFACT_ID=notionsdk
POM_NAME=Notion SDK Kotlin Multiplatform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,4 @@ internal fun BlockFileValue.toDomain(): NotionFile =
file != null -> NotionFile.File(url = file.url, expiryTime = file.expiryTime)
external != null -> NotionFile.External(url = external.url)
else -> error("cannot map block file value: $this")
}

internal fun Block.Callout.Value.Icon.toDomain(): NotionBlock.Callout.Icon =
when (this) {
is Block.Callout.Value.Icon.Emoji -> NotionBlock.Callout.Icon.Emoji(emoji = emoji)
is Block.Callout.Value.Icon.File -> NotionBlock.Callout.Icon.File(url = url, expiryTime = expiryTime)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ import com.petersamokhin.notionsdk.data.model.result.NotionDatabaseRow
internal fun PageObject.toDomain(): NotionDatabaseRow =
NotionDatabaseRow(
id = id,
icon = icon?.toDomain(),
columns = properties.mapValues { (key, value) -> NotionDatabaseColumn(key, value.toDomain()) }
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.petersamokhin.notionsdk.data.mapper

import com.petersamokhin.notionsdk.data.model.internal.obj.Icon
import com.petersamokhin.notionsdk.data.model.result.NotionIcon

internal fun Icon.toDomain(): NotionIcon =
when {
emoji != null -> NotionIcon.Emoji(emoji)
file != null -> NotionIcon.File(file.url, file.expiryTime)
else -> error("$this is not a valid Notion icon")
}
Original file line number Diff line number Diff line change
Expand Up @@ -365,24 +365,7 @@ internal sealed class Block {
internal data class Value(
val text: List<RichText>,
val icon: Icon,
) {
@Serializable
internal sealed class Icon {
@Serializable
@SerialName("emoji")
internal data class Emoji(
val emoji: String,
) : Icon()

@Serializable
@SerialName("file")
internal data class File(
val url: String,
@SerialName("expiry_time")
val expiryTime: String? = null,
) : Icon()
}
}
)
}

@SerialName("quote")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.petersamokhin.notionsdk.data.model.internal.obj

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
internal data class Icon(
val type: String,
val emoji: String? = null,
val file: File? = null,
) {
@Serializable
data class File(
val url: String,
@SerialName("expiry_time")
val expiryTime: String? = null,
)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.petersamokhin.notionsdk.data.model.internal.response

import com.petersamokhin.notionsdk.data.model.internal.obj.Icon
import kotlinx.serialization.Serializable

@Serializable
internal data class PageObject(
val id: String,
val url: String,
val properties: Map<String, PageProperty>,
val icon: Icon? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -280,26 +280,8 @@ public sealed class NotionBlock {
override val hasChildren: Boolean,

public val text: List<NotionRichText>,
public val icon: Icon,
) : NotionBlock() {

@Serializable
public sealed class Icon {
@Serializable
@SerialName("emoji")
public data class Emoji(
val emoji: String,
) : Icon()

@Serializable
@SerialName("file")
public data class File(
val url: String,
@SerialName("expiry_time")
val expiryTime: String? = null,
) : Icon()
}
}
public val icon: NotionIcon,
) : NotionBlock()

@SerialName("quote")
@Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.petersamokhin.notionsdk.data.model.result

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
public sealed class NotionIcon {
@Serializable
@SerialName("emoji")
public data class Emoji(
val emoji: String,
) : NotionIcon()

@Serializable
@SerialName("file")
public data class File(
val url: String,
@SerialName("expiry_time")
val expiryTime: String? = null,
) : NotionIcon()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public data class NotionResults<T>(
@Serializable
public data class NotionDatabaseRow(
val id: String,
val icon: NotionIcon? = null,
val columns: Map<String, NotionDatabaseColumn>,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ internal class NotionMarkdownExporterImpl : NotionMarkdownExporter {
is NotionRichText.Equation -> copy(annotations = annotations.copy(strikethrough = true))
}

private fun NotionBlock.Callout.Icon.toMarkdown(settings: NotionMarkdownExporter.Settings): String =
private fun NotionIcon.toMarkdown(settings: NotionMarkdownExporter.Settings): String =
when (this) {
is NotionBlock.Callout.Icon.Emoji -> emoji
is NotionBlock.Callout.Icon.File -> {
is NotionIcon.Emoji -> emoji
is NotionIcon.File -> {
val resultMarkdown = "![image](${url})"

if (expiryTime != null && settings.addExpiryNoticeForInternalFiles) {
Expand Down

0 comments on commit a2fffbb

Please sign in to comment.