Add support for dates without times, fix list props.
This commit is contained in:
parent
2803e7c913
commit
914e14956e
@ -3,23 +3,37 @@ import std/httpclient, std/json, std/logging, std/options, std/sequtils,
|
|||||||
import timeutils
|
import timeutils
|
||||||
|
|
||||||
const NOTION_MAX_PAGE_SIZE* = 100
|
const NOTION_MAX_PAGE_SIZE* = 100
|
||||||
|
const NOTION_DATE_FORMAT = "YYYY-MM-dd"
|
||||||
|
|
||||||
proc parseDate(str: string): DateTime =
|
proc parseDate(str: string): DateTime =
|
||||||
try: result = parseIso8601(str)
|
try: result = parseIso8601(str)
|
||||||
except: result = times.parse(str, "YYYY-MM-dd")
|
except: result = times.parse(str, NOTION_DATE_FORMAT)
|
||||||
|
|
||||||
## Utility functions for creating Page property values
|
## Utility functions for creating Page property values
|
||||||
## ---------------------------------------------------
|
## ---------------------------------------------------
|
||||||
|
|
||||||
|
proc makeDateProp*(d: Option[DateTime]): JsonNode =
|
||||||
|
if d.isSome: return %*{ "date": { "start": format(d.get, NOTION_DATE_FORMAT) } }
|
||||||
|
else: return %*{ "date": nil }
|
||||||
|
|
||||||
proc makeDateTimeProp*(d: Option[DateTime]): JsonNode =
|
proc makeDateTimeProp*(d: Option[DateTime]): JsonNode =
|
||||||
if d.isSome: return %*{ "date": { "start": formatIso8601(d.get) } }
|
if d.isSome: return %*{ "date": { "start": formatIso8601(d.get) } }
|
||||||
else: return %*{ "date": nil }
|
else: return %*{ "date": nil }
|
||||||
|
|
||||||
|
proc makeIntervalProp*(s: Option[DateTime], e: Option[DateTime]): JsonNode =
|
||||||
|
if not s.isSome: result = %*{ "date": nil }
|
||||||
|
|
||||||
|
result = %*{ "date": { "start": formatIso8601(s.get) } }
|
||||||
|
|
||||||
|
if e.isSome: result["date"]["end"] = %formatIso8601(e.get)
|
||||||
|
|
||||||
proc makeMultiSelectProp*(values: seq[string]): JsonNode =
|
proc makeMultiSelectProp*(values: seq[string]): JsonNode =
|
||||||
return %*{ "multi_select": [ values.mapIt(%*{ "name": it }) ] }
|
if values.len == 0: return %*{ "multi_select": [] }
|
||||||
|
return %*{ "multi_select": values.mapIt(%*{ "name": it }) }
|
||||||
|
|
||||||
proc makeRelationProp*(ids: seq[string]): JsonNode =
|
proc makeRelationProp*(ids: seq[string]): JsonNode =
|
||||||
return %*{ "relation": [ ids.mapIt(%*{ "id": it }) ] }
|
if ids.len == 0: return %*{ "relation": [] }
|
||||||
|
return %*{ "relation": ids.mapIt(%*{ "id": it }) }
|
||||||
|
|
||||||
proc makeSelectProp*(value: string): JsonNode =
|
proc makeSelectProp*(value: string): JsonNode =
|
||||||
return %*{ "select": { "name": value } }
|
return %*{ "select": { "name": value } }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user