<aside> 👉 Links (Block base class)

Page

BookmarkBlock

CodeBlock

EmbedBlock

Heading2Block

LinkToPageBlock

QuoteBlock

ToDoBlock

ToggleHeading3Block

Database

BreadcrumbBlock

ColumnBlock

EquationBlock

Heading3Block

NumberedListItemBlock

SyncedBlock

ToggleBlock

VideoBlock

List

BulletedListItemBlock

ColumnListBlock

FileBlock

ImageBlock

ParagraphBlock

TableOfContentsBlock

ToggleHeading1Block

Block

CalloutBlock

DividerBlock

Heading1Block

LinkPreviewBlock

PdfBlock

TemplateBlock (Deprecated)

ToggleHeading2Block

Notion Ruby Mapping Public API Reference

</aside>

1. Class methods

self.new(text_info, caption: [], language: “shell”) → CodeBlock

self.new creates a CodeBlock object using a text_info. caption and language are optional parameters.

b = CodeBlock.new "Ruby code", language: "ruby", caption: "sample caption"; b.block_json
# => {"type"=>"code","object"=>"block","code"=>{"rich_text"=>[{"type"=>"text", "text"=>{"content"=>"Ruby code", "link"=>nil}, "plain_text"=>"Ruby code", "href"=>nil}],"caption"=>[{"type"=>"text", "text"=>{"content"=>"sample caption", "link"=>nil}, "plain_text"=>"sample caption", "href"=>nil}],"language"=>"Ruby"}}

2. Instance methods

caption → RichTextArray

caption returns the RichTextArray object for CodeBlock.

b = CodeBlock.new "Ruby code", language: "ruby", caption: "sample caption"; b.caption
=> #<NotionRubyMapping::RichTextArray:...>

language → String

language returns the language string for CodeBlock.

b = CodeBlock.new "Ruby code", language: "ruby", caption: "sample caption"
# => "Ruby"

language=(new_language)

language= updates the language parameter for CodeBlock and sets update_block_key of the payload object.

b = CodeBlock.new "Ruby code", language: "ruby", caption: "sample caption"; b.language
b.language = "shell"
b.update_block_json
# => {"code"=>{"language"=>"shell"}}

save(dry_run: false)

$\fbox{implemented in Block}$

save updates the Block object with update block API. The updated object has block information generated from the JSON response.

block = Block.find "899e342cec84415f9ff86225704cbb75" # Notion API call
block.url = "<https://www.apple.com/>"
block.save
# => #<NotionRubyMapping::Block:...> # updated Block object

Block.find(id, dry_run: true) creates a shell script using Retrieve a block API for verification.

block = Block.find "899e342cec84415f9ff86225704cbb75" # Notion API call
block.url = "<https://www.apple.com/>"
block.save dry_run: true
# => 
# curl -X PATCH '<https://api.notion.com/v1/blocks/899e342cec84415f9ff86225704cbb75>' \\
#   -H 'Notion-Version: 2022-02-22' \\
#   -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \\
#   -H 'Content-Type: application/json' \\
#   --data '{"bookmark":{"url":"<https://www.apple.com/>"}}'

rich_text_array → RichTextArray

rich_text_array returns the rich_text parameter of BulletedListItemBlock.

b = CodeBlock.new "Ruby code", language: "ruby", caption: "sample caption"; b.rich_text_array
# => #<NotionRubyMapping::...>