Skip to content

Commit

Permalink
Add support for verification page property (#158)
Browse files Browse the repository at this point in the history
* Add support for verification page property

1. Property documented [here](https://developers.notion.com/reference/page-property-values#verification)
2. Replace github.com/pkg/errors with native errors package

* linter warnings

* Add verification to property config

* add verification state enum
  • Loading branch information
evanfuller authored Sep 5, 2023
1 parent 3306ef9 commit 0929e38
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 9 deletions.
7 changes: 7 additions & 0 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
PropertyConfigLastEditedBy PropertyConfigType = "last_edited_by"
PropertyConfigStatus PropertyConfigType = "status"
PropertyConfigUniqueID PropertyConfigType = "unique_id"
PropertyConfigVerification PropertyConfigType = "verification"
)

const (
Expand All @@ -58,6 +59,7 @@ const (
PropertyTypeLastEditedBy PropertyType = "last_edited_by"
PropertyTypeStatus PropertyType = "status"
PropertyTypeUniqueID PropertyType = "unique_id"
PropertyTypeVerification PropertyType = "verification"
)

const (
Expand Down Expand Up @@ -273,3 +275,8 @@ const (
RelationSingleProperty RelationConfigType = "single_property"
RelationDualProperty RelationConfigType = "dual_property"
)

const (
VerificationStateVerified VerificationState = "verified"
VerificationStateUnverified VerificationState = "unverified"
)
2 changes: 1 addition & 1 deletion database.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package notionapi
import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/pkg/errors"
"log"
"net/http"
"time"
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/jomei/notionapi

go 1.14

require github.com/pkg/errors v0.9.1
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
13 changes: 13 additions & 0 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,16 @@ func (uID UniqueID) String() string {
}
return fmt.Sprintf("%d", uID.Number)
}

type VerificationState string

func (vs VerificationState) String() string {
return string(vs)
}

// Verification documented here: https://developers.notion.com/reference/page-property-values#verification
type Verification struct {
State VerificationState `json:"state"`
VerifiedBy *User `json:"verified_by,omitempty"`
Date *DateObject `json:"date,omitempty"`
}
22 changes: 18 additions & 4 deletions property.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"encoding/json"
"fmt"
"time"

"github.com/pkg/errors"
)

type PropertyType string
Expand Down Expand Up @@ -381,6 +379,20 @@ func (p UniqueIDProperty) GetType() PropertyType {
return p.Type
}

type VerificationProperty struct {
ID ObjectID `json:"id,omitempty"`
Type PropertyType `json:"type,omitempty"`
Verification Verification `json:"verification"`
}

func (p VerificationProperty) GetID() string {
return p.ID.String()
}

func (p VerificationProperty) GetType() PropertyType {
return p.Type
}

type Properties map[string]Property

func (p *Properties) UnmarshalJSON(data []byte) error {
Expand Down Expand Up @@ -417,7 +429,7 @@ func parsePageProperties(raw map[string]interface{}) (map[string]Property, error

result[k] = p
default:
return nil, errors.New(fmt.Sprintf("unsupported property format %T", v))
return nil, fmt.Errorf("unsupported property format %T", v)
}
}

Expand Down Expand Up @@ -471,8 +483,10 @@ func decodeProperty(raw map[string]interface{}) (Property, error) {
p = &StatusProperty{}
case PropertyTypeUniqueID:
p = &UniqueIDProperty{}
case PropertyTypeVerification:
p = &VerificationProperty{}
default:
return nil, errors.New(fmt.Sprintf("unsupported property type: %s", raw["type"].(string)))
return nil, fmt.Errorf("unsupported property type: %s", raw["type"].(string))
}

return p, nil
Expand Down
12 changes: 12 additions & 0 deletions property_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ func (i UniqueIDPropertyConfig) GetType() PropertyConfigType {
return ""
}

type VerificationPropertyConfig struct {
ID ObjectID `json:"id,omitempty"`
Type PropertyConfigType `json:"type,omitempty"`
Verification Verification `json:"verification"`
}

func (p VerificationPropertyConfig) GetType() PropertyConfigType {
return p.Type
}

type PropertyConfigs map[string]PropertyConfig

func (p *PropertyConfigs) UnmarshalJSON(data []byte) error {
Expand Down Expand Up @@ -346,6 +356,8 @@ func parsePropertyConfigs(raw map[string]interface{}) (PropertyConfigs, error) {
p = &StatusPropertyConfig{}
case PropertyConfigUniqueID:
p = &UniqueIDPropertyConfig{}
case PropertyConfigVerification:
p = &VerificationPropertyConfig{}
default:

return nil, fmt.Errorf("unsupported property type: %s", rawProperty["type"].(string))
Expand Down

0 comments on commit 0929e38

Please sign in to comment.