<aside> 👉
Links (Block base class)
Notion Ruby Mapping Public API Reference
</aside>
[PARAM(optional)] text_info
<aside> 📃
The following objects are used for this argument.
[PARAM(optional)] caption
[PARAM(optional)] language
language identifier for code. The default value is "shell". The value is sent as provided, so specify an identifier supported by the Notion API.
self.new creates a CodeBlock. text_info is optional; when omitted, the Block has empty rich text. caption is optional and defaults to an empty RichTextArray. When a RichTextArray is supplied for text_info or caption, its contents are copied using the key required by CodeBlock. A CodeBlock cannot have children blocks.
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"}}
caption returns the caption of CodeBlock as a RichTextArray. Modify the returned object to update the caption; the change is included in the next Block update.
b = CodeBlock.new "Ruby code", language: "ruby", caption: "sample caption"
b.caption
# => #<NotionRubyMapping::RichTextArray:...>
b.caption.rich_text_objects = "updated caption"
b.update_block_json
# => {"code"=>{"caption"=>[{"type"=>"text", "text"=>{"content"=>"updated caption", "link"=>nil}, "plain_text"=>"updated caption", "href"=>nil}]}}
language returns the language identifier of CodeBlock.
b = CodeBlock.new "Ruby code", language: "ruby", caption: "sample caption"
b.language
# => "ruby"
language= changes the language identifier of CodeBlock and marks language for the next Block update. The value is not validated by NotionRubyMapping; specify an identifier supported by the Notion API.
b = CodeBlock.new "Ruby code", language: "ruby", caption: "sample caption"
b.language = "shell"
b.update_block_json
# => {"code"=>{"language"=>"shell"}}
$\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 returns the rich_text value of CodeBlock as a RichTextArray. Modify the returned object to update the code text.
b = CodeBlock.new "Ruby code", language: "ruby", caption: "sample caption"
b.rich_text_array
# => #<NotionRubyMapping::RichTextArray:...>