Manuals Notion Ruby Mapping Public API Reference (https://hkob.notion.site/Notion-Ruby-Mapping-Public-API-Reference-4091aca15b664299b63e6253b7601fec) NotionRubyMapping idea note (https://hkob.notion.site/NotionRubyMapping-idea-note-3b0a3bb3c171438a830f9579d41df501)
Examples Database and page access sample (https://hkob.notion.site/Database-and-page-access-sample-d30033e707194faf995741167eb2b6f8) Untitled (https://hkob.notion.site/3867910a437340be931cf7f2c06443c6) Untitled (https://hkob.notion.site/5568c1c36fe84f12b83edfe2dda83028)

A linked view of the test database is placed at the bottom of this page. A link to the method reference is provided at the end of the description.

  1. Preparation (instance → self.instance → NotionCache, create_client → create_client(notion_token, wait: 0.1))

    require "notion_ruby_mapping"
    
    include NotionRubyMapping
    
    token = ENV["NOTION_API_TOKEN"]
    database_id = "c37a2c66e3aa4a0da44773de3b80c253" # ENV["DATABASE_ID"]
    NotionCache.instance.create_client token
    
    
  2. Retrieve a database (find → self.find(id, dry_run: false))

    db = Database.find database_id
    => 
    #<NotionRubyMapping::Database:0x0000000104f6cb10
    
  3. Obtain properties (properties → properties → PropertyCache)

    title_property = db.properties["Title"]
    => #<NotionRubyMapping::TitleProperty:0x0000000106f7d288 ...
    
    select_property = db.properties["SelectTitle"]
    => 
    #<NotionRubyMapping::SelectProperty:0x00000001055b3320 ...
    
  4. Query database without filter (query_database → query_database(query = nil, dry_run: false) → List)

    all_pages = db.query_database
    => 
    #<NotionRubyMapping::List:0x0000000106f9c890 ...
    
  5. Count all_pages (Enumerable → each { |item| ... } → self each → Enumerator)

    all_pages.count
    => 6
    
  6. Obtain all page title (Enumerable → each { |item| ... } → self each → Enumerator, title → title → String)

    all_pages.map(&:title)
    => ["", "JKL", "MNO", "DEF", "GHI", "ABC"]
    
  7. Query database with filter (query_database → query_database(query = nil, dry_run: false) → List, filter_equals → , ascending → ascending(property) )

    select3_pages = db.query_database select_property.filter_equals("Select 3").ascending(title_property)
    => 
    #<NotionRubyMapping::List:0x000000010889ef28 ...
    
  8. Count select3_pages (Enumerable → each { |item| ... } → self each → Enumerator)

    select3_pages.count
    => 2
    
  9. Obtain select3_pages title (Enumerable → each { |item| ... } → self each → Enumerator, title → title → String)

    select3_pages.map(&:title)
    => ["ABC", "MNO"]
    
  10. Obtain the first page (Enumerable → each { |item| ... } → self each → Enumerator)

    abc_page = select3_pages.first
    => 
    #<NotionRubyMapping::Page:0x0000000108494860
    
  11. Obtain the multi_select_names of the page (properties → properties → PropertyCache, multi_select_names → multi_select_names → Array)

    abc_page.properties["MultiSelectTitle"].multi_select_names
    

Untitled Database