| Invalid Date
字数 0阅读时长 1 分钟

1. Class methods

self.find(id, dry_run: false) →
🧱
Page

  • [PARAM] id page_id (String) or page_url(String)
  • [PARAM(optional)] dry_run: true if you want to create a verification script
  • [EXCEPTION] StandardError: throw StandardError when the page is not found.
Page.find(id) creates a Page object with retrieving page API. The created object has page information generated from the JSON response.
Page.find(id, dry_run: true) creates a shell script using Retrieve a page API for verification.

2. Instance methods

append_block_children(*blocks, dry_run: false) → Array<Block>, String

  • [PARAM] blocks array of blocks
  • [PARAM(optional)] dry_run: true if you want to create a verification script
append_block_children method of an existing page appends some block objects. Some blocks allow child blocks to be set up at the same time. However, due to API limitations, grandchild blocks cannot be created at once. There are many types of blocks, so check the page(
🧪
Append block children sample
) to see how to create blocks.

append_block_children(blocks, dry_run: true) creates a shell script using Append block children API for verification.

build_child_database(title, *assigns) { |d, pc| ... } →
🧱
Database

  • [PARAM] title Database title
  • [PARAM] assigns variable-length array of property class and property name pairs
build_child_database method of an existing page creates a child database object. Some properties of the database can be arrange the option. if a block is provided, the method will yield the new Database object(d) and the properties (PropertyCache object pc) to that block for initialization. After setting some properties, please call db.save to send database information to Notion. If you can set properties in the block, please use create_child_database instead of build_child_database + save. Here is a sample script for creating a database that set all types of properties.
db.save(dry_run: true) creates a shell script using Create a database API for verification.

create_child_database(title, *assigns, dry_run: false) { |d, pc| ... } →
🧱
Database

  • [PARAM] title Database title
  • [PARAM] assigns variable-length array of property class and property name pairs
  • [PARAM (optional)] dry_run: true if you want to create a verification script
create_child_database method of an existing page creates a child database object and send to Notion. Some properties of the database can be arrange the option. if a block is provided, the method will yield the new Database object(d) and the properties (PropertyCache object pc) to that block for initialization. Here is a sample script for creating a database that set all types of properties.
db.save(dry_run: true) creates a shell script using Create a database API for verification.

build_child_page(template_page: nil, position: nil, markdown: nil) { |p, pp| ... } →
🧱
Page

  • [PARAM(optional)] template_page: template page to apply when creating the page (String or Page)
  • [PARAM(optional)] position: position of the new page ("page_start", "page_end", or block_id)
  • [PARAM(optional)] markdown: set the page content as Markdown string. If you omit title property, the first H1 (# ...) in markdown becomes the page title.
build_child_page method of an existing page builds a child page object without sending it to Notion. After setting properties, call page.save.

create_child_page(template_page: nil, position: nil, markdown: nil, dry_run: false) { |p, pp| ... } →
🧱
Page

  • [PARAM(optional)] template_page: template page to apply when creating the page (String or Page)
  • [PARAM(optional)] position: position of the new page ("page_start", "page_end", or block_id)
  • [PARAM(optional)] markdown: set the page content as Markdown string. If you omit title property, the first H1 (# ...) in markdown becomes the page title.
  • [PARAM(optional)] dry_run: true if you want to create a verification script
create_child_page method of an existing page creates a child page object and sends it to Notion. When creating a page under another page, only the TitleProperty is available (it is automatically created). By setting the template_page option, you can apply a template when creating a page. The value is either the string "default" or a Page object of the retrieved template page. The position parameter can be one of the following:
  • "page_end" - adds the page at the end (default)
  • "page_start" - adds the page at the beginning
  • block_id (String) - adds the page after the specified block
if a block is provided, the method will yield the new Page object(p) and the properties (PropertyCache object pp) to that block for initialization.
Create a page with the default template:
Create a page with a specific template:
Create a page at the start of the parent page:
Create a page after a specific block:
create_child_page(dry_run: true) creates a shell script using Create a page API for verification.

created_time → CreatedTimeProperty

created_time returns the CreatedTimeProperty object for querying database.

icon → Hash

icon returns JSON hash for the page icon.

insert_markdown(markdown, after: nil, dry_run: false) →
🧱
Page
, String

  • [PARAM] markdown: Markdown string to insert
  • [PARAM(optional)] after: if specified, insert after this markdown snippet (String). If omitted, inserts at the bottom.
  • [PARAM(optional)] dry_run: true if you want to create a verification script
insert_markdown inserts markdown content into an existing page using the Page Markdown API (PATCH /v1/pages/{page_id}/markdown).
Insert after a specific existing markdown line:
insert_markdown(dry_run: true) creates a shell script for verification.

last_edited_time → LastEditedTimeProperty

last_edited_time returns theLastEditedTimeProperty object for querying database.

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_to method 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(id: data_source_id).
Move to a page:
Move to a data source:
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):
Move to a data source (dry_run):

new_record? → Boolean, NilClass

new_record? returns true if the page is generated by create_child_page.

parent(dry_run: false) →
🧱
Page
🧱
Database
🧱
Block
, String

parent returns a parent object.

properties → PropertyCache

properties returns a PropertyCache object. Each Page property object can be obtained from PropertyCache object by [] method.

replace_markdown(replace, replace_range, allow_deleting_content: nil, dry_run: false) →
🧱
Page
, String

  • [PARAM] replace: replacement Markdown string
  • [PARAM] replace_range: target Markdown range (String)
  • [PARAM(optional)] allow_deleting_content: set true to allow deleting content while replacing (safety flag)
  • [PARAM(optional)] dry_run: true if you want to create a verification script
replace_markdown replaces a specified markdown range using the Page Markdown API (PATCH /v1/pages/{page_id}/markdown) with type: "replace_content_range".
Example: check a To Do item
With allow_deleting_content flag:
replace_markdown(dry_run: true) creates a shell script for verification.

save(dry_run: false) →
🧱
Page

  • [PARAM (optional)] dry_run: true if you want to create a verification script
Page properties with values can be obtained from the retrieved page using find.
Each property object can change values using corresponded methods. After changing value, will_update flag of the property object also set to true. These methods are explained in the section of each property object class.
After update some properties, page.save method sends Notion API and replace the page information using the response of API.
save dry_run: true creates a shell script using Update page API for verification

set_cover(url: nil, file_upload_object: nil)

  • [PARAM(optional)] a_url
    • external url (String)
  • [PARAM(optional)] a_fuo
    • file upload object (FileUploadObject)
set_cover can change the page cover using external url or file upload object.

set_icon(emoji: nil, url: nil, file_upload_object: nil)

  • [PARAM(optional)] an_emoji
    • emoji string (String)
  • [PARAM(optional)] a_url
    • external url (String)
  • [PARAM(optional)] a_fuo
    • file upload object (FileUploadObject)
set_icon can change the page icon using emoji, external url, or file upload object.

title → String

page.title returns plain_text string of Title.
 
Loading...
目录