Skip to content

Commit

Permalink
feat: implement update page
Browse files Browse the repository at this point in the history
  • Loading branch information
mkfsn committed May 16, 2021
1 parent f26e115 commit a74890c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ go get -u github.com/mkfsn/notion-go
* [x] Retrieve ✅
* [x] List ✅
* [x] Query ✅
- [ ] Pages ⚠️
- [x] Pages
* [x] Retrieve ✅
* [x] Create ✅️
* [ ] Update
* [x] Update ✅️
- [x] Blocks ✅️
* [x] Children ✅
- [x] Retrieve ✅
Expand Down
34 changes: 34 additions & 0 deletions examples/update-page/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"context"
"log"
"os"

"github.com/mkfsn/notion-go"
)

func main() {
c := notion.New(notion.WithAuthToken(os.Getenv("NOTION_AUTH_TOKEN")))

page, err := c.Pages().Update(context.Background(),
notion.PagesUpdateParameters{
PageID: "6eaac3811afd4f368209b572e13eace4",
Properties: map[string]notion.PropertyValue{
"In stock": notion.CheckboxPropertyValue{
Checkbox: true,
},

"Price": notion.NumberPropertyValue{
Number: 30,
},
},
},
)

if err != nil {
log.Fatal(err)
}

log.Printf("page: %#v\n", page)
}
19 changes: 16 additions & 3 deletions pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,8 @@ type PagesRetrieveResponse struct {
}

type PagesUpdateParameters struct {
PageID string
Properties map[string]PropertyValue `json:"properties"`
PageID string `json:"-" url:"-"`
Properties map[string]PropertyValue `json:"properties" url:"-"`
}

type PagesUpdateResponse struct {
Expand Down Expand Up @@ -703,7 +703,20 @@ func (p *pagesClient) Retrieve(ctx context.Context, params PagesRetrieveParamete
}

func (p *pagesClient) Update(ctx context.Context, params PagesUpdateParameters) (*PagesUpdateResponse, error) {
return nil, ErrUnimplemented
endpoint := strings.Replace(APIPagesUpdateEndpoint, "{page_id}", params.PageID, 1)

b, err := p.client.Request(ctx, http.MethodPatch, endpoint, params)
if err != nil {
return nil, err
}

var response PagesUpdateResponse

if err := json.Unmarshal(b, &response); err != nil {
return nil, err
}

return &response, nil
}

func (p *pagesClient) Create(ctx context.Context, params PagesCreateParameters) (*PagesCreateResponse, error) {
Expand Down

0 comments on commit a74890c

Please sign in to comment.