NotionRubyMapping idea noteNotionRubyMapping idea note

NotionRubyMapping idea note

コメント
personal memo for notion_ruby_mapping
種別
Notion 関係

Current repository

RubyGem

API reference

Notion Ruby Mapping Public API ReferenceNotion Ruby Mapping Public API Reference
Notion Ruby Mapping Public API Reference

Use case

💡
Please create a client before you use the following class.
NotionRubyMapping.configure { |c| c.token = "secret_XXXXXXXXXXXXXXXXXXXX" } # write directly NotionRubyMapping.configure { |c| c.token = ENV["NOTION_API_TOKEN"] } # from environment
💽
Database and page access sample
🧪
Append block children sample
🧪
update block sample
🧪
RichTextArray and RichTextObject sample
🧪
notionErDiagram Sample
🧪
notionSitemap sample
🧪
erdToNotionDb sample
🧪
NotionTimeRecorder & GTD template

Checklist for development of this tool

  • +method means public methods
  • -method means private methods
  • #method means protected methods
  • +red code means public announced methods

Block base classes

Base

+[](key)
+children
+create_child_bookmark(url, caption: [])
+created_time
+icon
+last_edited_time
+new_record?
+parent
+properties
+save(dry_run: false)
+set_icon(emoji: nil, url: nil)
+new(json: nil, id: nil, assign: [])
+self.create_from_json(json)
+assign_property(klass, title)
+property_values_json
+reload
restore_from_json
+update_json(json)
#json_properties

SubClasses

Page < Base

Public API reference →
+self.find(id, dry_run: false)
+build_child_database(title, *assigns)
+create_child_database(title, *assigns, dry_run: false)
+title
#create
#reload_json
 
#update

Database < Base

Public API reference →
+self.find(id, dry_run: false)
+add_property(klass, title)
+build_child_page(*assign)
+create_child_page(*assign, dry_run: false)
+database_title
+description
+description=(text_info)
+is_inline
+is_inline=(flag)
+query_database(query = Query.new, dry_run: false)
+remove_properties(*property_names)
+rename_property(name, new_name)
#reload_json → json obtained from API results
#update → updated Database object

List (Enumerable) < Base

Public API refenece →
+each { |item| ...}
+new(json: nil, id: nil, database: nil, query: nil)
-results

Block < Base

Public API reference →
+self.new
+self.find(dry_run: true)
+destroy(dry_run: true)
+save(dry_run: true)
+block_json
+decode_block
#reload_json

BreadcrumbBlock

+type

CalloutBlock

+self.new(text_info, emoji: nil, file_url: nil, sub_blocks: nil, color: "default")
+color
+color=(new_color)
+emoji
+emoji=(emoji)
+file_url
+file_url=(url)
+rich_text_array
+type

ChildBaseBlock

+new(json: json)

ChildDatabaseBlock

+type

ChildPageBlock

+type

CodeBlock

+self.new(text_info, caption: [], language: "Shell")
+language
+language=(new_langage)
+rich_text_array
+type

ColumnBlock

+self.new(subblocks)
+type

ColumnListBlock

+self.new(array_of_subblocks)
+type

DividerBlock

+type

EquationBlock

+self.new(expression)
+expression
+expression=(new_expression)

FileBaseBlock

+self.new(url, caption: [])
+caption
+url
+url=(url)

FileBlock

+type

ImageBlock

+type

PdfBlock

+type

LinkToPageBlock

+self.new(page_id: nil, database_id: nil)
+dataabse_id
+database_id=(database_id)
+page_id
+page_id=(page_id)
 

SyncedBlock

+new(block_id: nil, sub_blocks: nil)
+block_id

TableBlock

+self.new()

TableOfContentsBlock

+self.new(color)
+color
+color(new_color)

TemplateBlock

TextSubBlockColorBaseBlock

+self.new(text_info, sub_blocks: nil, color: "default")
+color
+color=(new_color)
+rich_text_array

BulletedListItemBlock

+type

Heading1Block

+self.new(text_info, color: "default")
+type

Heading2Block

+self.new(text_info, color: "default")
+type

Heading3Block

+self.new(text_info, color: "default")
+type

ParagraphBlock

+type

QuoteBlock

+type

ToDoBlock

+checked
+checked=()
+type

ToggleBlock

+type

ToggleHeading1Block

+type

ToggleHeading2Block

+type

ToggleHeading3Block

+type

UrlBaseBlock

+self.new(url)
+url
+url=(url)

LinkPreviewBlock

+type

UrlCaptionBaseBlock

+self.new(url, caption: [])
+caption
+url
+url=(url)

BookmarkBlock

+type

EmbedBlock

+type

Modules

ContainsDoesNotContain (module)

+filter_contains(value)
+filter_does_not_contain(value)

EqualsDoesNotEqual (module)

+filter_equals(value)
+filter_does_not_equal(value)

GreaterThanLessThan (module)

+filter_greater_than(value)
+filter_greater_than_or_equal_to(value)
+filter_less_than(value)
+filter_less_than_or_equal_to(value)

IsEmptyIsNotEmpty (module)

+filter_is_empty
+filter_is_not_empty

StartsWithEndsWith (module)

+filter_starts_with(value)
+filter_ends_with(value)

Property base classes

Property

+name
+will_update
+new(name, will_update: false, base_type: :page)
+self.create_from_json(name, input_json)
+make_filter_query(key, value)
+update_from_json(json)
+type

for Database property only

+assert_database_property(method)
+new_name=(new_name)
+property_schema_json
+remove
+update_property_schema_json
#property_schema_json_sub

for Page property only

+assert_page_property(method)
+property_values_json

CheckboxProperty < Property

Public API reference →
+checkbox
+new(name, will_update: false, json: nil, json: nil)

for Page property only

+checkbox=(checkbox)
+property_values_json

EqualsDoesNotEqual (module)

+filter_equals(value)
+filter_does_not_equal(value)

DateBaseProperty < Property

+self.value_str(obj)
+filter_equals(date)
+filter_does_not_equal(date)
+filter_before(date)
+filter_after(date)
+filter_on_or_before(date)
+filter_on_or_after(date)
+filter_past_week
+filter_next_week
+filter_past_month
+filter_next_month
+filter_past_year
+filter_next_year
#value_str(obj) → iso8601 format string

IsEmptyIsNotEmpty (module)

+filter_is_empty
+filter_is_not_empty

SubClasses

CreatedTimeProperty < DateBaseProperty

Public API reference →
+created_time

for Page property only

+property_values_json → property_values_json for create or update

DateProperty < DateBaseProperty

Public API reference →
+date
+new(name, will_update: false, json: nil, start_date:nil, end_date:nil, time_zone: nil)

for Page property only

+start_date
+end_date
+time_zone
+start_date=(start_date)
+end_date=(end_date)
+time_zone=(time_zone)

FormulaProperty < DateBaseProperty

Public API reference →
+formula
 
+new(name, json: nil)
+update_from_json(json)

for Database property only

+formula_expression
+formula_expression=(f_e)
+update_property_schema_json
#property_schema_json_sub

ContainsDoesNotContain (module)

+filter_contains(value)
+filter_does_not_contain(value)

StartsWithEndsWith (module)

+filter_starts_with(value)
+filter_ends_with(value)

GreaterThanLessThan (module)

+filter_greater_than(value)
+filter_greater_than_or_equal_to(value)
+filter_less_than(value)
+filter_less_than_or_equal_to(value)

LastEditedTimeProperty < DateBaseProperty

Public API reference →
+last_edited_time
+new(name, json: nil)
+update_from_json(json)

RollupProperty < DateBaseProperty

Public API reference →
+rollup
+new(name, json: nil)
ℹ️
for Database property only
+function
+function=(func)
+relation_property_name
+relation_property_name=(rpn)
+rollup_property_name
+rollup_property_name=(rpn)
#property_schema_json_sub

ContainsDoesNotContain (module)

+filter_contains(value)
+filter_does_not_contain(value)

StartsWithEndsWith (module)

+filter_starts_with(value)
+filter_ends_with(value)

GreaterThanLessThan (module)

+filter_greater_than(value)
+filter_greater_than_or_equal_to(value)
+filter_less_than(value)
+filter_less_than_or_equal_to(value)

EmailProperty < Property

Public API reference →
+email
+new(name, will_update: false, json: nil, email: nil)
+property_values_json

for Page property only

+email=(email)

EqualsDoesNotEqual (module)

+filter_equals(value)
+filter_does_not_equal(value)

ContainsDoesNotContain (module)

+filter_contains(value)
+filter_does_not_contain(value)

StartsWithEndsWith (module)

+filter_starts_with(value)
+filter_ends_with(value)

IsEmptyIsNotEmpty (module)

+filter_is_empty
+filter_is_not_empty

FilesProperty < Property

Public API reference →
+files
+new(name, will_update: false, json: nil, files: nil)
+property_values_json
#url_to_hash(url)

for Page property only

+files=(files)

IsEmptyIsNotEmpty (module)

+filter_is_empty
+filter_is_not_empty

MultiProperty < Property

ContainsDoesNotContain (module)

+filter_contains(value)
+filter_does_not_contain(value)

IsEmptyIsNotEmpty (module)

+filter_is_empty
+filter_is_not_empty

Subclass

CreatedByProperty < MultiProperty

Public API reference →
+created_by
+new(name, will_update: false, json: nil, user_id: nil)
+update_from_json(json)

LastEditedByProperty < MultiProperty

Public API reference →
+last_edited_by
+new(name, will_update: false, json: nil, user_id: nil)
+update_from_json(json)

MultiSelectProperty < MultiProperty

Public API reference →
+multi_select
+multi_select_names
+new(name, will_update: false, json: nil, multi_select: nil)
+update_from_json(json)

for Database property only

+add_multi_select_options(name:, color:)
+multi_select_options
+edit_multi_select_options
+update_property_schema_json
#property_schema_json_sub

for Page property only

+multi_select=(multi_select)
+property_values_json

PeopleProperty < MultiProperty

Public API reference →
+people
+new(name, will_update: false, json: nil, people: nil)
+update_from_json(json)

for Page property only

+add_person=(user_or_user_id)
+people=(people)
+property_values_json

ContainsDoesNotContain (module)

+filter_contains(value)
+filter_does_not_contain(value)

IsEmptyIsNotEmpty (module)

+filter_is_empty
+filter_is_not_empty

RelationProperty < MultiProperty

Public API reference →
+relation
+new(name, will_update: false, json: nil, relation: nil)

for Database property only

+relation_database_id
+replace_relation_database(database_id:, synced_property_name:)
+update_property_schema_json
#property_schema_json_sub

for Page property only

+add_relation(page_id_or_json)
+relation=(page_ids_or_jsons)
+property_values_json

ContainsDoesNotContain (module)

+filter_contains(value)
+filter_does_not_contain(value)

IsEmptyIsNotEmpty (module)

+filter_is_empty
+filter_is_not_empty

NumberProperty < Property

Public API reference →
+number
+new(name, will_update: false, base_type: :page, json: nil, format: nil)
+update_from_json(json)

for Database property only

+format
+format=(format)
#property_schema_json_sub

for Page property only

+number=(num)

EqualsDoesNotEqual (module)

+filter_equals(value)
+filter_does_not_equal(value)

GreaterThanLessThan (module)

+filter_greater_than(value)
+filter_greater_than_or_equal_to(value)
+filter_less_than(value)
+filter_less_than_or_equal_to(value)

IsEmptyIsNotEmpty (module)

+filter_is_empty
+filter_is_not_empty

PhoneNumberProperty < Property

Public API reference →
+phone_number
+new(name, will_update: false, json: nil, phone_number: nil)

for Page property only

+phone_number=(phone_number)

EqualsDoesNotEqual (module)

+filter_equals(value)
+filter_does_not_equal(value)

ContainsDoesNotContain (module)

+filter_contains(value)
+filter_does_not_contain(value)

StartsWithEndsWith (module)

+filter_starts_with(value)
+filter_ends_with(value)

IsEmptyIsNotEmpty (module)

+filter_is_empty
+filter_is_not_empty

SelectProperty < Property

Public API reference →
+select
+new(name, will_update: false, json: nil, select: nil)

for Database property only

+add_select_options(name:, color:)
+select_options
+select_names
+edit_select_options
+update_property_schema_json
#property_schema_json_sub

for Page property only

+select=(select)
+select_name
+property_values_json

EqualsDoesNotEqual (module)

+filter_equals(value)
+filter_does_not_equal(value)

TextProperty (Enumerable) < Property

+new(name, will_update: false, json: nil, text_objects: nil)
+text_objects
+update_from_json(json)
+will_udpate (true when any inner TextObject’s will_update is true)

for Page property only

+delete_at(index)
+each
+full_text
<<(to)
[](index)

EqualsDoesNotEqual (module)

+filter_equals(value)
+filter_does_not_equal(value)

ContainsDoesNotContain (module)

+filter_contains(value)
+filter_does_not_contain(value)

StartsWithEndsWith (module)

+filter_starts_with(value)
+filter_ends_with(value)

IsEmptyIsNotEmpty (module)

+filter_is_empty
+filter_is_not_empty

SubClasses

TitleProperty < TextProperty

Public API reference →
+update_from_json(json)

for Page property only

+property_values_json

RichTextProperty < TextProperty

Public API reference →
+update_from_json(json)
ℹ️
for Page property only
+property_values_json

UrlProperty < Property

Public API reference →
+url
+url=(url)
+new(name, will_update: false, json: nil, url: nil)
+update_from_json(json)

EqualsDoesNotEqual (module)

+filter_equals(value)
+filter_does_not_equal(value)

ContainsDoesNotContain (module)

+filter_contains(value)
+filter_does_not_contain(value)

StartsWithEndsWith (module)

+filter_starts_with(value)
+filter_ends_with(value)

IsEmptyIsNotEmpty (module)

+filter_is_empty
+filter_is_not_empty

Objects

EmojiObject

Public API reference →
+emoji_object(emoji_or_eo)
+emoji=(str)

FileObject

Public API reference →
+self.file_object(url_or_file_object)
+url=(url)

RichTextObject

+new(type, options = {})
+self.create_from_json(name, input_json)
+plain_text=(plain_text)
+italic=(flag)
+underline=(flag)
+color=(color)
#annotaions_json
+bold=(flag)
+strikethrough=(flag)
+code=(flag)

TextObject < RichTextObject

Public API reference →
+self.text_object(value)
+text=(text)
#partial_property_values_json

MentionObject < RichTextObject

Public API reference →
+new(options = {})
#partial_property_values_json
+text

EquationObject < RichTextObject

Public API reference →
+self.equation_object(extression_or_eo)
+expression=(expression)
#partial_property_values_json

UserObject

Public API reference →
+user_object(user_id_or_uo)
+user_id=(str)

Other classes

NotionCache (Singleton)

Public API reference →
+instance
+create_client(notion_token, wait: 0.3333, debug: false)
+hex_id(id)
+append_block_children_block_path(block_id)
+append_block_children_page_path(page_id)
+append_block_children_request(id, payload)
+block(id)
+block_children_page_path(page_id, query_string = “”)
+block_children_request(id, query_string)
+block_path(block_id)
+block_request(block_id)
+clear_object_hash
+create_database_request(payload)
+create_page_request(payload)
+dataabse(id)
+database_path(database_id)
+database_query(id, query)
+database_query_request(database_id)
+database_request(database_id)
+databases_path
+destroy_block(id)
+destroy_block_request(id)
+inspect
+object_for_key(id)
+page(id)
+page_path(page_id)
+page_request(page_id)
+pages_path
+query_database_path(database_id)
+request(method, path, options = {})
+update_block_request(block_id, payload)
+update_database_request(database_id, payload)
+update_page_request(page_id, request)

Payload

Public API reference →
+new
+add_update_block_key(key)
+clear
+merge_property(json)
+property_values_json(*others))
+property_schema_json(*others)
+set_icon(emoji: nil, ufl: nil)
+update_block_json(type, json)
+update_property_schema_json(*others)

PropertyCache

+new(json = {}, base_type: :page, page_id: nil)
+[](key)
+add_property(property)

Query

Public API reference →
+new(filter: {}, sort: [], page_size: 100, start_cursor)
+and(other_query)
+or(other_query)
+ascending(property)
+descending(property)å
+query_json
+query_stringå

RichTextArray

+self.rich_text_array(key, text_info = [])
+<<(value)
+self[pos]
+delete_at(pos)
+each
+full_text
+rich_text_objets=(text_objects)
 

Class Diagram

Base objects

classDiagram class Base { +Message json +String id -NotionCache nc -Payload payload -PropertyCache property_cache } <<abstract>> Base class NotionCache { +Hash object_hash +Faraday client +wait +notion_token } class Page { } class Database { } class Block { } class List { } Base "*" --> "1" NotionCache : nc Base <|-- Page Base <|-- Database Base <|-- Block Base <|-- List class Payload { -Hash json } Base "1" --> "1" Payload : payload class PropertyCache { -Hash properties } Base "1" --> "1" PropertyCache : property_cache

Property objects

classDiagram class Property { } <<abstract>> Property class Query { - Hash filter - Array<Property> sort } Query "1" <-- "*" Property : sort class TextProperty { } <<abstract>> TextProperty Property <|-- TextProperty class TitleProperty { } TextProperty <|-- TitleProperty class RichTextProperty { } TextProperty <|-- RichTextProperty class UrlProperty { } Property <|-- UrlProperty class EmailProperty { } Property <|-- EmailProperty class PhoneNumberProperty { } Property <|-- PhoneNumberProperty class NumberProperty { } Property <|-- NumberProperty class CheckboxProperty { } Property <|-- CheckboxProperty class SelectProperty { } Property <|-- SelectProperty class MultiProperty { } Property <|-- MultiProperty class MultiSelectProperty { } MultiProperty <|-- MultiSelectProperty class DateBaseProperty { } Property <|-- DateBaseProperty class DateProperty { } DateBaseProperty <|-- DateProperty class CreatedTimeProperty { } DateBaseProperty <|-- CreatedTimeProperty class LastEditedTimeProperty { } DateBaseProperty <|-- LastEditedTimeProperty class PeopleProperty { } MultiProperty <|-- PeopleProperty class CreatedByProperty { } MultiProperty <|-- CreatedByProperty class LastEditedByProperty { } MultiProperty <|-- LastEditedByProperty class FilesProperty { } Property <|-- FilesProperty class FormulaProperty { } DateBaseProperty <|-- FormulaProperty

Object objects

classDiagram class RichTextObject { String type Hash options Boolean will_update } class TextObject { String text } class MentionObject { } class EquationObject { String expression } class FileObject { String type String url String expiry_time Boolean will_update } class EmojiObject { String emoji Boolean will_update } class UserObject { String user_id Hash json Boolean will_update } RichTextObject <|-- TextObject RichTextObject <|-- MentionObject RichTextObject <|-- EquationObject class commentObject { Hash json }

ChangeLog

 

pages for test