はじめに
hkob の雑記録の第391回目(通算787日目)は、NotionRubyMapping の v3.0.6 のリリースと move page のリファレンス追加を解説します。
NotionRubyMapping のリリース
v3.0.5 以降、これまでに以下のような機能を追加してきました。
- Page#move を追加 (move page API への対応)
- DataSource#templates を追加 (List data source templates API への対応)
- Page#create_child_page への position object オプションを追加
これをまとめて v3.0.6 としてリリースしました。
Page#move のリファレンス作成
アップデートはしたものの、リファレンスを記載しなければなりません。せっかくブログを書いたので、それを参考に Page#move のリファレンスを Notion AI に書いてもらうことしましょう。

いい感じに作ってくれました。ただ、残念ながらリファレンスは英語にしていたのですが、ブログが日本語で書いてあるせいか、日本語で作られてしまいました。
以下は作成されたリファレンスです。
move_to(page_or_data_source, dry_run: false) → Page, String
- [PARAM] page_or_data_source 移動先の Page または DataSource オブジェクト
- [PARAM(optional)] dry_run: true if you want to create a verification script
move_toメソッドは、ページを別のページまたはデータソースの下に移動します。移動先が Page オブジェクトの場合は、そのページの子ページとして移動します。移動先が DataSource オブジェクトの場合は、そのデータソース内のページとして移動します。移動先のオブジェクトは、実体を取得する必要はなく、`Page.new(id: page_id)
や [DataSource.new](http://DataSource.new)(id: data_source_id)` で作成したオブジェクトでも使用できます。ページへの移動:
child_page = Page.find "2e8d8e4e-98ab-80c5-b4a1-ef787d32f244" parent_page = Page.new id: "2e8d8e4e-98ab-80ae-9fbe-f2d0fc4c4fea" child_page.move_to parent_page # => #<NotionRubyMapping::Page:...> # 移動後の Page オブジェクトデータソースへの移動:
page = Page.find "2e8d8e4e-98ab-80ae-9fbe-f2d0fc4c4fea" data_source = DataSource.new id: "2e8d8e4e-98ab-80b1-a70e-000b9440843a" page.move_to data_source # => #<NotionRubyMapping::Page:...> # 移動後の Page オブジェクト
move_to(page_or_data_source, dry_run: true)creates a shell script using Move a page API for verification.ページへの移動(dry_run):
child_page = Page.new id: "2e8d8e4e-98ab-80c5-b4a1-ef787d32f244" parent_page = Page.new id: "2e8d8e4e-98ab-80ae-9fbe-f2d0fc4c4fea" print child_page.move_to parent_page, dry_run: true # => # #!/bin/sh # curl -X POST 'https://api.notion.com/v1/pages/2e8d8e4e98ab80c5b4a1ef787d32f244/move' \\ # -H 'Notion-Version: 2022-06-28' \\ # -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \\ # -H 'Content-Type: application/json' \\ # --data '{"parent":{"type":"page_id","page_id":"2e8d8e4e98ab80ae9fbef2d0fc4c4fea"}}'データソースへの移動(dry_run):
page = Page.new id: "2e8d8e4e-98ab-80ae-9fbe-f2d0fc4c4fea" data_source = DataSource.new id: "2e8d8e4e-98ab-80b1-a70e-000b9440843a" print page.move_to data_source, dry_run: true # => # #!/bin/sh # curl -X POST 'https://api.notion.com/v1/pages/2e8d8e4e98ab80ae9fbef2d0fc4c4fea/move' \\ # -H 'Notion-Version: 2022-06-28' \\ # -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \\ # -H 'Content-Type: application/json' \\ # --data '{"parent":{"type":"data_source_id","data_source_id":"2e8d8e4e98ab80b1a70e000b9440843a"}}'
ここだけ日本語なのも変なので、英語に変更してもらいました。

正しく変更してくれたようです。

最終的に以下のようなリファレンスになりました。
以下が英語に変更されたリファレンスです。
move_to(page_or_data_source, dry_run: false) → Page, String
- [PARAM] page_or_data_source destination Page or DataSource object
- [PARAM(optional)] dry_run: true if you want to create a verification script
move_tomethod moves a page to another page or data source. When the destination is a Page object, the page will be moved as a child page of that page. When the destination is a DataSource object, the page will be moved as a page within that data source.The destination object does not need to be retrieved; you can use an object created with `Page.new(id: page_id)
or [DataSource.new](http://DataSource.new)(id: data_source_id)`.Move to a page:
child_page = Page.find "2e8d8e4e-98ab-80c5-b4a1-ef787d32f244" parent_page = Page.new id: "2e8d8e4e-98ab-80ae-9fbe-f2d0fc4c4fea" child_page.move_to parent_page # => #<NotionRubyMapping::Page:...> # moved Page objectMove to a data source:
page = Page.find "2e8d8e4e-98ab-80ae-9fbe-f2d0fc4c4fea" data_source = DataSource.new id: "2e8d8e4e-98ab-80b1-a70e-000b9440843a" page.move_to data_source # => #<NotionRubyMapping::Page:...> # moved Page object
move_to(page_or_data_source, dry_run: true)creates a shell script using Move a page API for verification.Move to a page (dry_run):
child_page = Page.new id: "2e8d8e4e-98ab-80c5-b4a1-ef787d32f244" parent_page = Page.new id: "2e8d8e4e-98ab-80ae-9fbe-f2d0fc4c4fea" print child_page.move_to parent_page, dry_run: true # => # #!/bin/sh # curl -X POST 'https://api.notion.com/v1/pages/2e8d8e4e98ab80c5b4a1ef787d32f244/move' \\ # -H 'Notion-Version: 2022-06-28' \\ # -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \\ # -H 'Content-Type: application/json' \\ # --data '{"parent":{"type":"page_id","page_id":"2e8d8e4e98ab80ae9fbef2d0fc4c4fea"}}'Move to a data source (dry_run):
page = Page.new id: "2e8d8e4e-98ab-80ae-9fbe-f2d0fc4c4fea" data_source = DataSource.new id: "2e8d8e4e-98ab-80b1-a70e-000b9440843a" print page.move_to data_source, dry_run: true # => # #!/bin/sh # curl -X POST 'https://api.notion.com/v1/pages/2e8d8e4e98ab80ae9fbef2d0fc4c4fea/move' \\ # -H 'Notion-Version: 2022-06-28' \\ # -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \\ # -H 'Content-Type: application/json' \\ # --data '{"parent":{"type":"data_source_id","data_source_id":"2e8d8e4e98ab80b1a70e000b9440843a"}}'
おわりに
このブログを書いているときに move page のリファレンスを見にいったら、見た目が全く変わっているのに気づきました。ここの Try it から直接 API 呼び出しもできるようです。Notion API 活用術では Talend API Tester を使っていましたが、もう必要なさそうです。明日のブログはこのリファレンスの解説をしようと思います。
