class NotionRb::Api::Get

Public Class Methods

new(_params) click to toggle source
Calls superclass method NotionRb::Api::Base::new
# File lib/notion_rb/api/get.rb, line 6
def initialize(_params)
  super

  @blocks = []
  @data = {}
end

Public Instance Methods

blocks() click to toggle source
# File lib/notion_rb/api/get.rb, line 13
def blocks
  return @blocks if @blocks.any?

  call
  @blocks
end
call() click to toggle source
# File lib/notion_rb/api/get.rb, line 20
def call
  body = JSON.parse(response.body)
  @collection_rows = body.dig('result', 'blockIds')
  data = body.dig('recordMap', 'block').merge(body.dig('recordMap', 'collection') || {})
  data.values.each do |value|
    convert_values(value.dig('value'))
  end
end

Private Instance Methods

add_collection_data(value) click to toggle source
# File lib/notion_rb/api/get.rb, line 50
def add_collection_data(value)
  return unless value.key? 'schema'

  value['content'] = @collection_rows if @collection_rows
  value['type'] = 'collection'
end
convert_values(value) click to toggle source
# File lib/notion_rb/api/get.rb, line 45
def convert_values(value)
  add_collection_data(value)
  @blocks << @converter.convert(value)
end
params() click to toggle source
# File lib/notion_rb/api/get.rb, line 35
def params
  {
    chunkNumber: 0,
    cursor: { stack: [] },
    limit: 50,
    pageId: @notion_id,
    verticalColumns: false
  }
end
url() click to toggle source
# File lib/notion_rb/api/get.rb, line 31
def url
  'loadPageChunk'
end