<aside> 👉 Links (Block base class)
Notion Ruby Mapping Public API Reference
</aside>
Database.find(id)
creates a Database object with retrieving database API
. The created object has database information generated from the JSON response.
Database.find "c37a2c66-e3aa-4a0d-a447-73de3b80c253" # Notion API call
# => #<NotionRubyMapping::Database:...> # retrieved Database object
Database.find id, dry_run: true
creates shell script using Retrieve a database API for verification.
print Database.find "c37a2c66-e3aa-4a0d-a447-73de3b80c253", dry_run: true
# =>
# #!/bin/sh
# curl '<https://api.notion.com/v1/databases/c37a2c66-e3aa-4a0d-a447-73de3b80c253>'\\\\
# -H 'Notion-Version: 2022-02-22'\\\\
# -H 'Authorization: Bearer '"$NOTION_API_KEY"''\\\\
# -H 'Content-Type: application/json'
add_property
adds a database property. After setting the property, please call db.save
to send database information to Notion.
db = Database.find "c7697137d49f49c2bbcdd6a665c4f921"
db.add_property NumberProperty, "added number property" do |np|
np.format = "euro" # arrange option
end
db.add_property UrlProperty, "added url property" # UrlProperty has no option
db.save
# => #<NotionRubyMapping::Database:...> # updated Database object
db.save dry_run: true
creates a shell script for verification (Update database API using database_id as parent)
db = Database.find "c7697137d49f49c2bbcdd6a665c4f921"
db.add_property NumberProperty, "added number property" do |np|
np.format = "euro" # arrange option
end
db.add_property UrlProperty, "added url property" # UrlProperty has no option
db.save dry_run: true
# =>
# #!/bin/sh
# curl -X PATCH '<https://api.notion.com/v1/databases/c7697137d49f49c2bbcdd6a665c4f921>'\\\\
# -H 'Notion-Version: 2022-02-22'\\\\
# -H 'Authorization: Bearer '"$NOTION_API_KEY"''\\\\
# -H 'Content-Type: application/json'\\\\
# --data '{"properties":{"added number property":{"number":{"format":"euro"}},"added url property":{"url":{}}}}'
build_child_page
creates a child page object of the database. After setting some properties, please call page.save
to send page information to Notion. Properties of the created child page are automatically assigned using the parent database. if a block is provided, the method will yield the new Page object(p
) and the properties (PropertyCache object pc
) to that block for initialization.
page = db.create_child_page do |p, pc|
# p is the new Page object
# pc is the properties of the new Page object (PropertyCache Object)
p.set_icon emoji: "🎉"
pc["Title"] << "New Page"
end
page.save
# => #<NotionRubyMapping::Page:...> # Page object generated from response from Notion (created Page)
page.save dry_run: true
creates a shell script for verification (Create a page API using database_id as parent)
page = db.create_child_page do |p, pc|
p.set_icon emoji: "🎉"
pc["Title"] << "New Page"
end
page.save dry_run: true
# =>
# #!/bin/sh
# curl -X POST '<https://api.notion.com/v1/pages>' \\
# -H 'Notion-Version: 2022-02-22' \\
# -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \\
# -H 'Content-Type: application/json' \\
# --data '{"properties":{"Title":{"type":"title","title":[{"type":"text","text":{"content":"New Page","link":null},"plain_text":"New Page","href":null}]}},"parent":{"database_id":"c37a2c66e3aa4a0da44773de3b80c253"},"icon":{"type":"emoji","emoji":"🎉"}}'
create_child_page
creates a child page object of the database and send to Notion. Properties of the created child page are automatically assigned using the parent database. if a block is provided, the method will yield the new Page object (p
) and the properties (PropertyCache object pc
) to that block for initialization.
page = db.create_child_page do |p, pc|
# p is the new Page object
# pc is the properties of the new Page object (PropertyCache Object)
p.set_icon emoji: "🎉"
pc["Title"] << "New Page"
end
# => #<NotionRubyMapping::Page:...> # Page object generated from response from Notion (created Page)
create_child_page dry_run: true
creates a shell script for verification (Create a page API using database_id as parent)
spage = db.create_child_page dry_run: true do |p, pc|
p.set_icon emoji: "🎉"
pc["Title"] << "New Page"
end
# =>
# #!/bin/sh
# curl -X POST '<https://api.notion.com/v1/pages>' \\
# -H 'Notion-Version: 2022-02-22' \\
# -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \\
# -H 'Content-Type: application/json' \\
# --data '{"properties":{"Title":{"type":"title","title":[{"type":"text","text":{"content":"New Page","link":null},"plain_text":"New Page","href":null}]}},"parent":{"database_id":"c37a2c66e3aa4a0da44773de3b80c253"},"icon":{"type":"emoji","emoji":"🎉"}}'