<aside> 👉

Links (Block base class)

Page

AudioBlock

Block

CalloutBlock

DividerBlock

Heading1Block

ImageBlock

ParagraphBlock

TableOfContentsBlock

ToggleHeading2Block

Database

BookmarkBlock

CodeBlock

EmbedBlock

Heading2Block

LinkPreviewBlock

PdfBlock

ToDoBlock

ToggleHeading3Block

DataSource 🆕

BreadcrumbBlock

ColumnBlock

EquationBlock

Heading3Block

LinkToPageBlock

QuoteBlock

ToggleBlock

ToggleHeading4Block

List

BulletedListItemBlock

ColumnListBlock

FileBlock

Heading4Block

NumberedListItemBlock

SyncedBlock

ToggleHeading1Block

VideoBlock

Notion Ruby Mapping Public API Reference

</aside>

1. Constructor

self.new(url_or_fuo, caption: []) → FileBlock

$\fbox{implemented in FileBaseBlock}$

Creates a file block from an external URL or an uploaded file. A file source is required; omitting it raises ArgumentError.

block = FileBlock.new(
  "<https://example.com/document.pdf>",
  caption: "Document",
)
upload = NotionRubyMapping::FileUploadObject.new(fname: "document.pdf")
block = FileBlock.new(upload, caption: "Uploaded document")
block.save

2. Instance methods

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/>"}}'

caption → RichTextArray

$\fbox{implemented in FileBaseBlock}$

Returns the block caption.

file_object → FileObject

$\fbox{implemented in FileBaseBlock}$

Returns the current file representation. Use it to inspect type, url, and the pending file_upload_object. Update the file through url= or file_upload_object= on the block.

url → String or nil

$\fbox{implemented in FileBaseBlock}$

Returns the current external or Notion-hosted file URL. It returns nil while the block contains a pending file upload.