Module: Notion::Api::Endpoints::Blocks

Included in:
Notion::Api::Endpoints
Defined in:
lib/notion/api/endpoints/blocks.rb

Instance Method Summary collapse

Instance Method Details

#block(options = {}) ⇒ Object

Retrieves a Block object using the ID specified.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :block_id (id)

    Block to get children info on.



12
13
14
15
# File 'lib/notion/api/endpoints/blocks.rb', line 12

def block(options = {})
  throw ArgumentError.new('Required arguments :block_id missing') if options[:block_id].nil?
  get("blocks/#{options[: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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :block_id (id)

    Block to append children to.

  • :children ([Object])

    Children blocks to append



92
93
94
95
96
# File 'lib/notion/api/endpoints/blocks.rb', line 92

def block_append_children(options = {})
  block_id = options.delete(:block_id)
  throw ArgumentError.new('Required arguments :block_id missing') if block_id.nil?
  patch("blocks/#{block_id}/children", options)
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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :block_id (id)

    Block to get children info on.



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/notion/api/endpoints/blocks.rb', line 64

def block_children(options = {})
  throw ArgumentError.new('Required arguments :block_id missing') if options[:block_id].nil?
  if block_given?
    Pagination::Cursor.new(self, :block_children, options).each do |page|
      yield page
    end
  else
    block_id = options.delete(:block_id)
    get("blocks/#{block_id}/children", options)
  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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :block_id (id)

    Block to get children info on.



47
48
49
50
# File 'lib/notion/api/endpoints/blocks.rb', line 47

def delete_block(options = {})
  throw ArgumentError.new('Required arguments :block_id missing') if options[:block_id].nil?
  delete("blocks/#{options[: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).

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :block_id (id)

    Block to get children info on.

  • {type} (string)

    The block object type value with the properties to be updated. Currently only text (for supported block types) and checked (for to_do blocks) fields can be updated.



30
31
32
33
34
# File 'lib/notion/api/endpoints/blocks.rb', line 30

def update_block(options = {})
  block_id = options.delete(:block_id)
  throw ArgumentError.new('Required arguments :block_id missing') if block_id.nil?
  patch("blocks/#{block_id}", options)
end