1
0
mirror of https://github.com/dstotijn/go-notion.git synced 2024-11-24 08:42:26 +02:00

Handle changes introduced in version 2022-02-22 (#29)

Ref: https://developers.notion.com/changelog/releasing-notion-version-2022-02-22
This commit is contained in:
David Stotijn 2022-08-13 12:28:49 +02:00 committed by GitHub
parent a7179ae969
commit 264ec2c28f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 125 additions and 62 deletions

View File

@ -97,7 +97,7 @@ func (b baseBlock) Parent() Parent {
type ParagraphBlock struct {
baseBlock
Text []RichText `json:"text"`
RichText []RichText `json:"rich_text"`
Children []Block `json:"children,omitempty"`
}
@ -118,7 +118,7 @@ func (b ParagraphBlock) MarshalJSON() ([]byte, error) {
type BulletedListItemBlock struct {
baseBlock
Text []RichText `json:"text"`
RichText []RichText `json:"rich_text"`
Children []Block `json:"children,omitempty"`
}
@ -139,7 +139,7 @@ func (b BulletedListItemBlock) MarshalJSON() ([]byte, error) {
type NumberedListItemBlock struct {
baseBlock
Text []RichText `json:"text"`
RichText []RichText `json:"rich_text"`
Children []Block `json:"children,omitempty"`
}
@ -160,7 +160,7 @@ func (b NumberedListItemBlock) MarshalJSON() ([]byte, error) {
type QuoteBlock struct {
baseBlock
Text []RichText `json:"text"`
RichText []RichText `json:"rich_text"`
Children []Block `json:"children,omitempty"`
}
@ -181,7 +181,7 @@ func (b QuoteBlock) MarshalJSON() ([]byte, error) {
type ToggleBlock struct {
baseBlock
Text []RichText `json:"text"`
RichText []RichText `json:"rich_text"`
Children []Block `json:"children,omitempty"`
}
@ -202,7 +202,7 @@ func (b ToggleBlock) MarshalJSON() ([]byte, error) {
type TemplateBlock struct {
baseBlock
Text []RichText `json:"text"`
RichText []RichText `json:"rich_text"`
Children []Block `json:"children,omitempty"`
}
@ -223,7 +223,7 @@ func (b TemplateBlock) MarshalJSON() ([]byte, error) {
type Heading1Block struct {
baseBlock
Text []RichText `json:"text"`
RichText []RichText `json:"rich_text"`
Children []Block `json:"children,omitempty"`
}
@ -244,7 +244,7 @@ func (b Heading1Block) MarshalJSON() ([]byte, error) {
type Heading2Block struct {
baseBlock
Text []RichText `json:"text"`
RichText []RichText `json:"rich_text"`
Children []Block `json:"children,omitempty"`
}
@ -265,7 +265,7 @@ func (b Heading2Block) MarshalJSON() ([]byte, error) {
type Heading3Block struct {
baseBlock
Text []RichText `json:"text"`
RichText []RichText `json:"rich_text"`
Children []Block `json:"children,omitempty"`
}
@ -286,7 +286,7 @@ func (b Heading3Block) MarshalJSON() ([]byte, error) {
type ToDoBlock struct {
baseBlock
Text []RichText `json:"text"`
RichText []RichText `json:"rich_text"`
Children []Block `json:"children,omitempty"`
Checked *bool `json:"checked,omitempty"`
}
@ -348,7 +348,7 @@ func (b ChildDatabaseBlock) MarshalJSON() ([]byte, error) {
type CalloutBlock struct {
baseBlock
Text []RichText `json:"text"`
RichText []RichText `json:"rich_text"`
Children []Block `json:"children,omitempty"`
Icon *Icon `json:"icon,omitempty"`
}
@ -370,7 +370,7 @@ func (b CalloutBlock) MarshalJSON() ([]byte, error) {
type CodeBlock struct {
baseBlock
Text []RichText `json:"text"`
RichText []RichText `json:"rich_text"`
Children []Block `json:"children,omitempty"`
Caption []RichText `json:"caption,omitempty"`
Language *string `json:"language,omitempty"`

View File

@ -13,7 +13,7 @@ import (
const (
baseURL = "https://api.notion.com/v1"
apiVersion = "2021-08-16"
apiVersion = "2022-02-22"
clientVersion = "0.0.0"
)

View File

@ -433,8 +433,10 @@ func TestQueryDatabase(t *testing.T) {
query: &notion.DatabaseQuery{
Filter: &notion.DatabaseQueryFilter{
Property: "Name",
Text: &notion.TextDatabaseQueryFilter{
Contains: "foobar",
DatabaseQueryPropertyFilter: notion.DatabaseQueryPropertyFilter{
RichText: &notion.TextPropertyFilter{
Contains: "foobar",
},
},
},
Sorts: []notion.DatabaseQuerySort{
@ -641,7 +643,7 @@ func TestQueryDatabase(t *testing.T) {
expPostBody: map[string]interface{}{
"filter": map[string]interface{}{
"property": "Name",
"text": map[string]interface{}{
"rich_text": map[string]interface{}{
"contains": "foobar",
},
},
@ -1669,7 +1671,7 @@ func TestCreatePage(t *testing.T) {
},
Children: []notion.Block{
&notion.ParagraphBlock{
Text: []notion.RichText{
RichText: []notion.RichText{
{
Text: &notion.Text{
Content: "Lorem ipsum dolor sit amet.",
@ -1761,7 +1763,7 @@ func TestCreatePage(t *testing.T) {
"children": []interface{}{
map[string]interface{}{
"paragraph": map[string]interface{}{
"text": []interface{}{
"rich_text": []interface{}{
map[string]interface{}{
"text": map[string]interface{}{
"content": "Lorem ipsum dolor sit amet.",
@ -1842,7 +1844,7 @@ func TestCreatePage(t *testing.T) {
},
Children: []notion.Block{
&notion.ParagraphBlock{
Text: []notion.RichText{
RichText: []notion.RichText{
{
Text: &notion.Text{
Content: "Lorem ipsum dolor sit amet.",
@ -1908,7 +1910,7 @@ func TestCreatePage(t *testing.T) {
"children": []interface{}{
map[string]interface{}{
"paragraph": map[string]interface{}{
"text": []interface{}{
"rich_text": []interface{}{
map[string]interface{}{
"text": map[string]interface{}{
"content": "Lorem ipsum dolor sit amet.",
@ -2747,15 +2749,20 @@ func TestFindPagePropertyByID(t *testing.T) {
}
}
],
"has_more": false,
"type": "rollup",
"rollup": {
"type": "date",
"date": {
"start": "2021-10-07T14:42:00.000+00:00",
"end": null
},
"function": "latest_date"
"has_more": true,
"type": "property_item",
"property_item": {
"id": "aBcD123",
"next_url": "https://api.notion.com/v1/pages/b55c9c91-384d-452b-81db-d1ef79372b75/properties/aBcD123?start_cursor=some-next-cursor-value",
"type": "rollup",
"rollup": {
"type": "date",
"date": {
"start": "2021-10-07T14:42:00.000+00:00",
"end": null
},
"function": "latest_date"
}
}
}`,
)
@ -2764,6 +2771,10 @@ func TestFindPagePropertyByID(t *testing.T) {
expQueryParams: nil,
expResponse: notion.PagePropResponse{
PagePropItem: notion.PagePropItem{
Type: notion.DBPropTypePropertyItem,
},
PropertyItem: notion.PagePropListItem{
ID: "aBcD123",
Type: notion.DBPropTypeRollup,
Rollup: notion.RollupResult{
Type: notion.RollupResultTypeDate,
@ -2771,7 +2782,9 @@ func TestFindPagePropertyByID(t *testing.T) {
Start: mustParseDateTime("2021-10-07T14:42:00.000+00:00"),
},
},
NextURL: "https://api.notion.com/v1/pages/b55c9c91-384d-452b-81db-d1ef79372b75/properties/aBcD123?start_cursor=some-next-cursor-value",
},
HasMore: true,
Results: []notion.PagePropItem{
{
Type: notion.DBPropTypeRelation,
@ -2903,7 +2916,7 @@ func TestFindBlockChildrenById(t *testing.T) {
"has_children": false,
"type": "paragraph",
"paragraph": {
"text": [
"rich_text": [
{
"type": "text",
"text": {
@ -2938,7 +2951,7 @@ func TestFindBlockChildrenById(t *testing.T) {
expResponse: notion.BlockChildrenResponse{
Results: []notion.Block{
&notion.ParagraphBlock{
Text: []notion.RichText{
RichText: []notion.RichText{
{
Type: notion.RichTextTypeText,
Text: &notion.Text{
@ -3107,7 +3120,7 @@ func TestAppendBlockChildren(t *testing.T) {
name: "successful response",
children: []notion.Block{
&notion.ParagraphBlock{
Text: []notion.RichText{
RichText: []notion.RichText{
{
Text: &notion.Text{
Content: "Lorem ipsum dolor sit amet.",
@ -3129,7 +3142,7 @@ func TestAppendBlockChildren(t *testing.T) {
"has_children": false,
"type": "paragraph",
"paragraph": {
"text": [
"rich_text": [
{
"type": "text",
"text": {
@ -3161,7 +3174,7 @@ func TestAppendBlockChildren(t *testing.T) {
"children": []interface{}{
map[string]interface{}{
"paragraph": map[string]interface{}{
"text": []interface{}{
"rich_text": []interface{}{
map[string]interface{}{
"text": map[string]interface{}{
"content": "Lorem ipsum dolor sit amet.",
@ -3175,7 +3188,7 @@ func TestAppendBlockChildren(t *testing.T) {
expResponse: notion.BlockChildrenResponse{
Results: []notion.Block{
&notion.ParagraphBlock{
Text: []notion.RichText{
RichText: []notion.RichText{
{
Type: notion.RichTextTypeText,
Text: &notion.Text{
@ -3207,7 +3220,7 @@ func TestAppendBlockChildren(t *testing.T) {
name: "error response",
children: []notion.Block{
&notion.ParagraphBlock{
Text: []notion.RichText{
RichText: []notion.RichText{
{
Text: &notion.Text{
Content: "Lorem ipsum dolor sit amet.",
@ -3231,7 +3244,7 @@ func TestAppendBlockChildren(t *testing.T) {
"children": []interface{}{
map[string]interface{}{
"paragraph": map[string]interface{}{
"text": []interface{}{
"rich_text": []interface{}{
map[string]interface{}{
"text": map[string]interface{}{
"content": "Lorem ipsum dolor sit amet.",
@ -4141,7 +4154,7 @@ func TestUpdateBlock(t *testing.T) {
{
name: "successful response",
block: &notion.ParagraphBlock{
Text: []notion.RichText{
RichText: []notion.RichText{
{
Text: &notion.Text{
Content: "Foobar",
@ -4160,7 +4173,7 @@ func TestUpdateBlock(t *testing.T) {
"archived": false,
"type": "paragraph",
"paragraph": {
"text": [
"rich_text": [
{
"type": "text",
"text": {
@ -4186,7 +4199,7 @@ func TestUpdateBlock(t *testing.T) {
respStatusCode: http.StatusOK,
expPostBody: map[string]interface{}{
"paragraph": map[string]interface{}{
"text": []interface{}{
"rich_text": []interface{}{
map[string]interface{}{
"text": map[string]interface{}{
"content": "Foobar",
@ -4196,7 +4209,7 @@ func TestUpdateBlock(t *testing.T) {
},
},
expResponse: &notion.ParagraphBlock{
Text: []notion.RichText{
RichText: []notion.RichText{
{
Type: notion.RichTextTypeText,
Text: &notion.Text{
@ -4219,7 +4232,7 @@ func TestUpdateBlock(t *testing.T) {
{
name: "error response",
block: &notion.ParagraphBlock{
Text: []notion.RichText{
RichText: []notion.RichText{
{
Text: &notion.Text{
Content: "Foobar",
@ -4240,7 +4253,7 @@ func TestUpdateBlock(t *testing.T) {
respStatusCode: http.StatusBadRequest,
expPostBody: map[string]interface{}{
"paragraph": map[string]interface{}{
"text": []interface{}{
"rich_text": []interface{}{
map[string]interface{}{
"text": map[string]interface{}{
"content": "Foobar",
@ -4359,7 +4372,7 @@ func TestDeleteBlock(t *testing.T) {
"archived": true,
"type": "paragraph",
"paragraph": {
"text": [
"rich_text": [
{
"type": "text",
"text": {
@ -4384,7 +4397,7 @@ func TestDeleteBlock(t *testing.T) {
},
respStatusCode: http.StatusOK,
expResponse: &notion.ParagraphBlock{
Text: []notion.RichText{
RichText: []notion.RichText{
{
Type: notion.RichTextTypeText,
Text: &notion.Text{

View File

@ -154,21 +154,46 @@ type DatabaseQueryResponse struct {
type DatabaseQueryFilter struct {
Property string `json:"property,omitempty"`
Text *TextDatabaseQueryFilter `json:"text,omitempty"`
DatabaseQueryPropertyFilter
Timestamp Timestamp `json:"timestamp,omitempty"`
Or []DatabaseQueryFilter `json:"or,omitempty"`
And []DatabaseQueryFilter `json:"and,omitempty"`
}
type DatabaseQueryPropertyFilter struct {
Title *TextPropertyFilter `json:"title,omitempty"`
RichText *TextPropertyFilter `json:"rich_text,omitempty"`
URL *TextPropertyFilter `json:"url,omitempty"`
Email *TextPropertyFilter `json:"email,omitempty"`
PhoneNumber *TextPropertyFilter `json:"phone_number,omitempty"`
Date *DatePropertyFilter `json:"date,omitempty"`
CreatedTime *DatePropertyFilter `json:"created_time,omitempty"`
LastEditedTime *DatePropertyFilter `json:"last_edited_time,omitempty"`
Number *NumberDatabaseQueryFilter `json:"number,omitempty"`
Checkbox *CheckboxDatabaseQueryFilter `json:"checkbox,omitempty"`
Select *SelectDatabaseQueryFilter `json:"select,omitempty"`
MultiSelect *MultiSelectDatabaseQueryFilter `json:"multi_select,omitempty"`
Date *DateDatabaseQueryFilter `json:"date,omitempty"`
People *PeopleDatabaseQueryFilter `json:"people,omitempty"`
Files *FilesDatabaseQueryFilter `json:"files,omitempty"`
Relation *RelationDatabaseQueryFilter `json:"relation,omitempty"`
Formula *FormulaDatabaseQueryFilter `json:"formula,omitempty"`
Rollup *RollupDatabaseQueryFilter `json:"rollup,omitempty"`
Or []DatabaseQueryFilter `json:"or,omitempty"`
And []DatabaseQueryFilter `json:"and,omitempty"`
CreatedBy *PeopleDatabaseQueryFilter `json:"created_by,omitempty"`
LastEditedBy *PeopleDatabaseQueryFilter `json:"last_edited_by,omitempty"`
}
type TextDatabaseQueryFilter struct {
type Timestamp string
const (
TimestampCreatedTime = "created_time"
TimestampLastEditedTime = "last_edited_time"
)
type TextPropertyFilter struct {
Equals string `json:"equals,omitempty"`
DoesNotEqual string `json:"does_not_equal,omitempty"`
Contains string `json:"contains,omitempty"`
@ -209,7 +234,7 @@ type MultiSelectDatabaseQueryFilter struct {
IsNotEmpty bool `json:"is_not_empty,omitempty"`
}
type DateDatabaseQueryFilter struct {
type DatePropertyFilter struct {
Equals *time.Time `json:"equals,omitempty"`
Before *time.Time `json:"before,omitempty"`
After *time.Time `json:"after,omitempty"`
@ -244,11 +269,19 @@ type RelationDatabaseQueryFilter struct {
IsNotEmpty bool `json:"is_not_empty,omitempty"`
}
type RollupDatabaseQueryFilter struct {
Any *DatabaseQueryPropertyFilter `json:"any,omitempty"`
Every *DatabaseQueryPropertyFilter `json:"every,omitempty"`
None *DatabaseQueryPropertyFilter `json:"none,omitempty"`
Number *NumberDatabaseQueryFilter `json:"number,omitempty"`
Date *DatePropertyFilter `json:"date,omitempty"`
}
type FormulaDatabaseQueryFilter struct {
Text TextDatabaseQueryFilter `json:"text,omitempty"`
Checkbox CheckboxDatabaseQueryFilter `json:"checkbox,omitempty"`
Number NumberDatabaseQueryFilter `json:"number,omitempty"`
Date DateDatabaseQueryFilter `json:"date,omitempty"`
String *TextPropertyFilter `json:"string,omitempty"`
Checkbox *CheckboxDatabaseQueryFilter `json:"checkbox,omitempty"`
Number *NumberDatabaseQueryFilter `json:"number,omitempty"`
Date *DatePropertyFilter `json:"date,omitempty"`
}
type DatabaseQuerySort struct {
@ -297,6 +330,10 @@ const (
DBPropTypeLastEditedTime DatabasePropertyType = "last_edited_time"
DBPropTypeLastEditedBy DatabasePropertyType = "last_edited_by"
// Used for paginated property values.
// See: https://developers.notion.com/reference/property-item-object#paginated-property-values
DBPropTypePropertyItem DatabasePropertyType = "property_item"
// Number format enums.
NumberFormatNumber NumberFormat = "number"
NumberFormatNumberWithCommas NumberFormat = "number_with_commas"
@ -337,9 +374,11 @@ const (
FormulaResultTypeDate FormulaResultType = "date"
// Rollup result type enums.
RollupResultTypeNumber RollupResultType = "number"
RollupResultTypeDate RollupResultType = "date"
RollupResultTypeArray RollupResultType = "array"
RollupResultTypeNumber RollupResultType = "number"
RollupResultTypeDate RollupResultType = "date"
RollupResultTypeArray RollupResultType = "array"
RollupResultTypeUnsupported RollupResultType = "unsupported"
RollupResultTypeIncomplete RollupResultType = "incomplete"
// Sort timestamp enums.
SortTimeStampCreatedTime SortTimestamp = "created_time"

19
page.go
View File

@ -117,14 +117,25 @@ type PagePropItem struct {
// PagePropResponse contains a single database page property item or a list
// of items. For rollup props with an aggregation, both a `results` array and a
// `rollup` field is included.
// `rollup` field (inside `page_property`) is included.
// See: https://developers.notion.com/reference/retrieve-a-page-property#rollup-properties
type PagePropResponse struct {
PagePropItem
Results []PagePropItem `json:"results"`
HasMore bool `json:"has_more"`
NextCursor string `json:"next_cursor"`
Results []PagePropItem `json:"results"`
HasMore bool `json:"has_more"`
NextCursor string `json:"next_cursor"`
PropertyItem PagePropListItem `json:"property_item"`
}
// PagePropListItem describes the property returned in a paginated list
// response (e.g. `type` is `title`, `rich_text`, `relation` or `people`).
// See: https://developers.notion.com/reference/property-item-object#paginated-property-values
type PagePropListItem struct {
ID string `json:"id"`
Type DatabasePropertyType `json:"type"`
NextURL string `json:"next_url"`
Rollup RollupResult `json:"rollup"`
}
// Value returns the underlying database page property value, based on its `type` field.