FilesProperty(Page): NotionRubyMapping 解説 (43)

はじめに

NotionRubyMapping 解説の第43回目です。ページ側のプロパティを解説しています。今回は Files プロパティの変更です。現在はデータベース内の最初のページを使って説明していきます。

無題

irb(main):002> page = Page.find "https://www.notion.so/hkob/619a113814134c759773175ac988b96a?pvs=4"
=> NotionRubyMapping::Page-619a113814134c759773175ac988b96a

FileProperty

まず、FileProperty を取得します。

irb(main):005> fp = page.properties["Files"]
=>
#<NotionRubyMapping::FilesProperty:0x000000011e351eb0

files でファイルの設定状況を確認できます。現在は何も設定されていないので空です。

irb(main):006> fp.files
=> []

files = で外部ファイルを指定できます。現在、Notion API ではファイルをアップロードすることはできなので、外部から認証なしに参照できるファイルのみが設定できます。

irb(main):007> fp.files = "https://img.icons8.com/ios-filled/250/000000/mac-os.p
ng"
=> "https://img.icons8.com/ios-filled/250/000000/mac-os.png"
irb(main):008> page.save
=> NotionRubyMapping::Page-619a113814134c759773175ac988b96a

png ファイルを指定したので、画像として表示されます。

FilesProperty

結果として、files には以下のように external の File Object が配列として保存されています。

fp.files
=>
[#<NotionRubyMapping::FileObject:0x000000011fba86d0
  @expiry_time=nil,
  @type="external",
  @url="https://img.icons8.com/ios-filled/250/000000/mac-os.png",
  @will_update=false>]

おわりに

今回はページの FilesProperty の変更を説明しました。こちらも機能が少ないので、これで終了です。

FilesProperty のマニュアルはこちらです。

FilesProperty

NotionRubyMapping解説