Add template for fetching database objects.

This commit is contained in:
Jonathan Bernard 2022-04-14 11:26:40 -05:00
parent 042adcb382
commit b6f63cf15b
2 changed files with 9 additions and 1 deletions

View File

@ -1,6 +1,6 @@
# Package # Package
version = "0.3.1" version = "0.3.2"
author = "Jonathan Bernard" author = "Jonathan Bernard"
description = "Utilities and bindings for HFF's Notion API." description = "Utilities and bindings for HFF's Notion API."
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"

View File

@ -76,6 +76,14 @@ proc fetchAllPages*(
if nextCursor.isEmptyOrWhitespace: break if nextCursor.isEmptyOrWhitespace: break
template fetchDatabaseObject*(notion: NotionClient, dbId: string): untyped =
let resp = notion.http.get(notion.apiBaseUrl & "/databases/" & dbId)
if not resp.status.startsWith("2"):
debug resp.body
raise newException(HttpRequestError, "API Request failed: " & resp.body)
parseJson(resp.body)
template fetchPage*(notion: NotionClient, pageId: string): untyped = template fetchPage*(notion: NotionClient, pageId: string): untyped =
let resp = notion.http.get(notion.apiBaseUrl & "/pages/" & pageId) let resp = notion.http.get(notion.apiBaseUrl & "/pages/" & pageId)