Module: Notion::Api::Endpoints::Blocks
- Included in:
- Notion::Api::Endpoints
- Defined in:
- lib/notion/api/endpoints/blocks.rb
Instance Method Summary collapse
-
#block(options = {}) ⇒ Object
Retrieves a Block object using the ID specified.
-
#block_append_children(options = {}) ⇒ Object
Creates and appends new children blocks to the parent block in the requested path using the ID specified.
-
#block_children(options = {}) ⇒ Object
Returns a paginated array of Block objects contained in the block of the requested path using the ID specified.
-
#delete_block(options = {}) ⇒ Object
Sets a Block object, including page blocks, to archived: true using the ID specified.
-
#update_block(options = {}) ⇒ Object
Updates the content for the specified block_id based on the block type.
Instance Method Details
#block(options = {}) ⇒ Object
Retrieves a Block object using the ID specified.
12 13 14 15 |
# File 'lib/notion/api/endpoints/blocks.rb', line 12 def block( = {}) throw ArgumentError.new('Required arguments :block_id missing') if [:block_id].nil? get("blocks/#{[:block_id]}") end |
#block_append_children(options = {}) ⇒ Object
Creates and appends new children blocks to the parent block in the requested path using the ID specified. Returns the Block object being appended to.
Returns a 404 HTTP response if any of the following are true:
-
the ID does not exist
-
the bot doesn’t have access to the block with the given ID
Returns a 400 or 429 HTTP response if the request exceeds Notion’s Request limits.
92 93 94 95 96 |
# File 'lib/notion/api/endpoints/blocks.rb', line 92 def block_append_children( = {}) block_id = .delete(:block_id) throw ArgumentError.new('Required arguments :block_id missing') if block_id.nil? patch("blocks/#{block_id}/children", ) end |
#block_children(options = {}) ⇒ Object
Returns a paginated array of Block objects contained in the block of the requested path using the ID specified.
Returns a 404 HTTP response if any of the following are true:
-
the ID does not exist
-
the bot doesn’t have access to the block with the given ID
Returns a 400 or 429 HTTP response if the request exceeds Notion’s Request limits.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/notion/api/endpoints/blocks.rb', line 64 def block_children( = {}) throw ArgumentError.new('Required arguments :block_id missing') if [:block_id].nil? if block_given? Pagination::Cursor.new(self, :block_children, ).each do |page| yield page end else block_id = .delete(:block_id) get("blocks/#{block_id}/children", ) end end |
#delete_block(options = {}) ⇒ Object
Sets a Block object, including page blocks, to archived: true using the ID specified. Note: in the Notion UI application, this moves the block to the “Trash” where it can still be accessed and restored.
To restore the block with the API, use the Update a block or Update page respectively.
47 48 49 50 |
# File 'lib/notion/api/endpoints/blocks.rb', line 47 def delete_block( = {}) throw ArgumentError.new('Required arguments :block_id missing') if [:block_id].nil? delete("blocks/#{[:block_id]}") end |
#update_block(options = {}) ⇒ Object
Updates the content for the specified block_id based on the block type. Supported fields based on the block object type (see Block object for available fields and the expected input for each field).
30 31 32 33 34 |
# File 'lib/notion/api/endpoints/blocks.rb', line 30 def update_block( = {}) block_id = .delete(:block_id) throw ArgumentError.new('Required arguments :block_id missing') if block_id.nil? patch("blocks/#{block_id}", ) end |