diff --git a/const.go b/const.go index 8460bd4..83ba6e1 100644 --- a/const.go +++ b/const.go @@ -33,6 +33,7 @@ const ( PropertyConfigLastEditedBy PropertyConfigType = "last_edited_by" PropertyConfigStatus PropertyConfigType = "status" PropertyConfigUniqueID PropertyConfigType = "unique_id" + PropertyConfigVerification PropertyConfigType = "verification" ) const ( @@ -58,6 +59,7 @@ const ( PropertyTypeLastEditedBy PropertyType = "last_edited_by" PropertyTypeStatus PropertyType = "status" PropertyTypeUniqueID PropertyType = "unique_id" + PropertyTypeVerification PropertyType = "verification" ) const ( @@ -273,3 +275,8 @@ const ( RelationSingleProperty RelationConfigType = "single_property" RelationDualProperty RelationConfigType = "dual_property" ) + +const ( + VerificationStateVerified VerificationState = "verified" + VerificationStateUnverified VerificationState = "unverified" +) diff --git a/database.go b/database.go index c384092..7c24622 100644 --- a/database.go +++ b/database.go @@ -3,8 +3,8 @@ package notionapi import ( "context" "encoding/json" + "errors" "fmt" - "github.com/pkg/errors" "log" "net/http" "time" diff --git a/go.mod b/go.mod index 846981f..ef36227 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,3 @@ module github.com/jomei/notionapi go 1.14 - -require github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 7c401c3..e69de29 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/object.go b/object.go index ad16919..eb6f84b 100644 --- a/object.go +++ b/object.go @@ -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"` +} diff --git a/property.go b/property.go index 32913ac..40ba426 100644 --- a/property.go +++ b/property.go @@ -4,8 +4,6 @@ import ( "encoding/json" "fmt" "time" - - "github.com/pkg/errors" ) type PropertyType string @@ -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 { @@ -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) } } @@ -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 diff --git a/property_config.go b/property_config.go index 951ce3e..2089e14 100644 --- a/property_config.go +++ b/property_config.go @@ -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 { @@ -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))