Links (Block base class)
PageBlockCalloutBlockDividerBlockHeading1BlockImageBlockParagraphBlockTableOfContentsBlockToggleHeading2Block
DatabaseBookmarkBlockCodeBlockEmbedBlockHeading2BlockLinkPreviewBlockPdfBlockToDoBlockToggleHeading3Block
1. Class methods
self.find(id, dry_run: false)
- [PARAM] id data_source_id (String)
- [PARAM(optional)] dry_run: true if you want to create a verification script (Boolean)
- [EXCEPTION] StandardError throw StandardError when the data_source is not found.
DataSource.find(id) creates a DataSource object with retrieving data source API. The created object has data source information generated from the JSON response.DataSource.find id, dry_run: true creates shell script using Retrieve a data source API for verification.2. Instance methods
add_property(klass, title)
- [PARAM] klass klass (child class of Property)
- [PARAM] title property title (String)
add_property adds a data source property. After setting the property, please call ds.save to send data source information to Notion.ds.save dry_run: true creates a shell script for verification (Update data source API using data_source_id as parent)build_child_page(template_page: nil, markdown: nil) { |p, pc| ... } → Page
build_child_page creates a child page object of the data source. 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 data source. 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.- [PARAM(optional)] template_page:
apply a template (
"default"or a retrieved template Page object)
- [PARAM(optional)] markdown:
set the page content as Markdown string. If you omit title property, the first H1 (
# ...) in markdown becomes the page title.
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.page.save dry_run: true creates a shell script for verification (Create a page API using data_source_id as parent)create_child_page(template_page: nil, dry_run: false) { |p, pc| ... } → Page
create_child_page creates a child page object of the data source and send to Notion. Properties of the created child page are automatically assigned using the parent data source. 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.- [PARAM(optional)] template_page:
apply a template (
"default"or a retrieved template Page object)
- [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
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.create_child_page dry_run: true creates a shell script for verification (Create a page API using data_source_id as parent)created_time → CreatedTimeProperty
created_time returns the CreatedTimeProperty object for querying data source.data_source_title → RichTextArray
data_source_title returns a RichTextArray object of the data source’s title.description → RichTextArray
description returns a RichTextArray object of the data source’s description.description=(text_info)
- [PARAM] text_info
- a String like as “text” (String)
- an Array of Strings (Array of Strings)
- a RichTextObject (RichTextObject)
- an Array of RichTextObjects (Array of RichTextObjects)
- a RichTextArray (RichTextArray)
The following objects are used for this argument.
description=(text_info) updates the data source description using a text_info.is_inline → Boolean
is_inline returns the value true if the data source appears in the page as an inline block.is_inline=(flag)
is_inline=(flag) updates the data source inline flag a flag value.icon → Hash
icon returns JSON hash for the page icon.last_edited_time → LastEditedTimeProperty
last_edited_time returns the LastEditedTimeProperty object for querying data source.new_record? → Boolean, NilClass
new_record? returns true if the page is generated by create_child_data_source.properties → PropertyCache
properties returns a PropertyCache object. Each DataSource property object can be obtained from PropertyCache object by [] method.query_data_source(query = nil, dry_run: false) → List
- [PARAM(optional)] query Query object including filter conditions and sort criteria. If no query is given, all pages are retrieved. (Query)
- [PARAM(optional)] dry_run: true if you want to create a verification script (Boolean)
A: overview
ds.query_data_source obtains a List object with Page objects contained in the data source. You can obtain filtered and ordered pages using Query object.The query object can be generated from the Property objects included in the data source object. The Property object can be obtained from the retrieved or assigned data source object like as the Page object.
filter_xxxx methods of the property objects generates a query object. These methods are explained in the section of each property object class.B: complex conditions
Complex filters can be generated
and / or methods of the Query object. Here are some sample scripts and the json parameters created from them.- query1: (A and B) filter
- query2: (A and B and C) filter
- query3: (A or B) filter
- query4: (A or B or C) filter
- query5: ((A and B) or C) filter
- query6: ((A or B) and C) filter
- query7: ((A and B) or (C and D)) filter
C: Sort criteria
Sort criteria can be appended to an existing query object. If you don't use the previous filters, you can generate by
Query.new.- sort criteria only
- filter with sort
D: Dry run sample
This is a sample script for query data source. If dry_run flag is set, you can see the verification shell script.
remove_properties(*property_names) → Array
- [PARAM] property_names: property names that you want to remove
remove_properties sets a remove flag for the property objects corresponding to the specified names. After setting the remove flags of some properties, please call ds.save to send data source information to Notion.rename_property(old_property_name, new_property_name) → DataSource 🆕
rename_property sets a rename flag for the property objects corresponding to the specified old name. After setting the rename flags of some properties, please call ds.save to send data source information to Notion.- result of dry run
save(dry_run: false) → DataSource 🆕
- [PARAM(optional)] dry_run: true if you want to create a verification script
save method updates existing data source properties. The data source needs to be retrieved using find to prevent existing settings from disappearing.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.