From 50cebe29de07545d25254e60f96a9af6be31c05b Mon Sep 17 00:00:00 2001 From: David Stotijn Date: Mon, 20 Dec 2021 20:12:44 +0100 Subject: [PATCH] Add file metadata to `file` DB page prop --- block.go | 16 ---------------- client_test.go | 40 ++++++++++++++++++++-------------------- cover.go | 24 ++++-------------------- database.go | 6 +++++- file.go | 17 +++++++++++++++++ icon.go | 13 ++----------- 6 files changed, 48 insertions(+), 68 deletions(-) create mode 100644 file.go diff --git a/block.go b/block.go index 85216a2..e482dc4 100644 --- a/block.go +++ b/block.go @@ -91,22 +91,6 @@ type FileBlock struct { Caption []RichText `json:"caption,omitempty"` } -type FileFile struct { - URL string `json:"url"` - ExpiryTime DateTime `json:"expiry_time"` -} - -type FileExternal struct { - URL string `json:"url"` -} - -type FileType string - -const ( - FileTypeFile FileType = "file" - FileTypeExternal FileType = "external" -) - type Bookmark struct { URL string `json:"url"` Caption []RichText `json:"caption,omitempty"` diff --git a/client_test.go b/client_test.go index b67225c..f8530bc 100644 --- a/client_test.go +++ b/client_test.go @@ -980,8 +980,8 @@ func TestCreateDatabase(t *testing.T) { Emoji: notion.StringPtr("✌️"), }, Cover: ¬ion.Cover{ - Type: notion.CoverTypeExternal, - External: ¬ion.CoverExternal{ + Type: notion.FileTypeExternal, + External: ¬ion.FileExternal{ URL: "https://example.com/image.png", }, }, @@ -1098,8 +1098,8 @@ func TestCreateDatabase(t *testing.T) { Emoji: notion.StringPtr("✌️"), }, Cover: ¬ion.Cover{ - Type: notion.CoverTypeExternal, - External: ¬ion.CoverExternal{ + Type: notion.FileTypeExternal, + External: ¬ion.FileExternal{ URL: "https://example.com/image.png", }, }, @@ -1264,8 +1264,8 @@ func TestUpdateDatabase(t *testing.T) { Emoji: notion.StringPtr("✌️"), }, Cover: ¬ion.Cover{ - Type: notion.CoverTypeExternal, - External: ¬ion.CoverExternal{ + Type: notion.FileTypeExternal, + External: ¬ion.FileExternal{ URL: "https://example.com/image.png", }, }, @@ -1388,8 +1388,8 @@ func TestUpdateDatabase(t *testing.T) { Emoji: notion.StringPtr("✌️"), }, Cover: ¬ion.Cover{ - Type: notion.CoverTypeExternal, - External: ¬ion.CoverExternal{ + Type: notion.FileTypeExternal, + External: ¬ion.FileExternal{ URL: "https://example.com/image.png", }, }, @@ -1676,13 +1676,13 @@ func TestCreatePage(t *testing.T) { }, Icon: ¬ion.Icon{ Type: notion.IconTypeExternal, - External: ¬ion.IconExternal{ + External: ¬ion.FileExternal{ URL: "https://example.com/icon.png", }, }, Cover: ¬ion.Cover{ - Type: notion.CoverTypeExternal, - External: ¬ion.CoverExternal{ + Type: notion.FileTypeExternal, + External: ¬ion.FileExternal{ URL: "https://example.com/cover.png", }, }, @@ -1809,13 +1809,13 @@ func TestCreatePage(t *testing.T) { }, Icon: ¬ion.Icon{ Type: notion.IconTypeExternal, - External: ¬ion.IconExternal{ + External: ¬ion.FileExternal{ URL: "https://example.com/icon.png", }, }, Cover: ¬ion.Cover{ - Type: notion.CoverTypeExternal, - External: ¬ion.CoverExternal{ + Type: notion.FileTypeExternal, + External: ¬ion.FileExternal{ URL: "https://example.com/cover.png", }, }, @@ -2204,7 +2204,7 @@ func TestUpdatePageProps(t *testing.T) { params: notion.UpdatePageParams{ Icon: ¬ion.Icon{ Type: notion.IconTypeExternal, - External: ¬ion.IconExternal{ + External: ¬ion.FileExternal{ URL: "https://www.notion.so/front-static/pages/pricing/pro.png", }, }, @@ -2276,7 +2276,7 @@ func TestUpdatePageProps(t *testing.T) { }, Icon: ¬ion.Icon{ Type: notion.IconTypeExternal, - External: ¬ion.IconExternal{ + External: ¬ion.FileExternal{ URL: "https://www.notion.so/front-static/pages/pricing/pro.png", }, }, @@ -2303,8 +2303,8 @@ func TestUpdatePageProps(t *testing.T) { name: "page cover, successful response", params: notion.UpdatePageParams{ Cover: ¬ion.Cover{ - Type: notion.CoverTypeExternal, - External: ¬ion.CoverExternal{ + Type: notion.FileTypeExternal, + External: ¬ion.FileExternal{ URL: "https://example.com/image.png", }, }, @@ -2375,8 +2375,8 @@ func TestUpdatePageProps(t *testing.T) { PageID: "b0668f48-8d66-4733-9bdb-2f82215707f7", }, Cover: ¬ion.Cover{ - Type: notion.CoverTypeExternal, - External: ¬ion.CoverExternal{ + Type: notion.FileTypeExternal, + External: ¬ion.FileExternal{ URL: "https://example.com/image.png", }, }, diff --git a/cover.go b/cover.go index b61c1bf..48ee544 100644 --- a/cover.go +++ b/cover.go @@ -2,27 +2,11 @@ package notion import "errors" -type CoverType string - -const ( - CoverTypeFile CoverType = "file" - CoverTypeExternal CoverType = "external" -) - type Cover struct { - Type CoverType `json:"type"` + Type FileType `json:"type"` - File *CoverFile `json:"file,omitempty"` - External *CoverExternal `json:"external,omitempty"` -} - -type CoverFile struct { - URL string `json:"url"` - ExpiryTime DateTime `json:"expiry_time"` -} - -type CoverExternal struct { - URL string `json:"url"` + File *FileFile `json:"file,omitempty"` + External *FileExternal `json:"external,omitempty"` } func (cover Cover) Validate() error { @@ -30,7 +14,7 @@ func (cover Cover) Validate() error { return errors.New("cover type cannot be empty") } - if cover.Type == CoverTypeExternal && cover.External == nil { + if cover.Type == FileTypeExternal && cover.External == nil { return errors.New("cover external cannot be empty") } diff --git a/database.go b/database.go index 6210f26..d974b0a 100644 --- a/database.go +++ b/database.go @@ -99,7 +99,11 @@ type People struct { } type File struct { - Name string `json:"name"` + Name string `json:"name"` + Type FileType `json:"type"` + + File *FileFile `json:"file,omitempty"` + External *FileExternal `json:"external,omitempty"` } type DatabaseProperty struct { diff --git a/file.go b/file.go new file mode 100644 index 0000000..09ecea5 --- /dev/null +++ b/file.go @@ -0,0 +1,17 @@ +package notion + +type FileFile struct { + URL string `json:"url"` + ExpiryTime DateTime `json:"expiry_time"` +} + +type FileExternal struct { + URL string `json:"url"` +} + +type FileType string + +const ( + FileTypeFile FileType = "file" + FileTypeExternal FileType = "external" +) diff --git a/icon.go b/icon.go index 4fadf0f..21817c0 100644 --- a/icon.go +++ b/icon.go @@ -16,17 +16,8 @@ type Icon struct { Type IconType `json:"type"` Emoji *string `json:"emoji,omitempty"` - File *IconFile `json:"file,omitempty"` - External *IconExternal `json:"external,omitempty"` -} - -type IconFile struct { - URL string `json:"url"` - ExpiryTime DateTime `json:"expiry_time"` -} - -type IconExternal struct { - URL string `json:"url"` + File *FileFile `json:"file,omitempty"` + External *FileExternal `json:"external,omitempty"` } func (icon Icon) Validate() error {