Class: NotionCf::NotionApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/notion_cf/notion_api_client.rb

Overview

Notion API client

Instance Method Summary collapse

Constructor Details

#initializeNotionApiClient

Returns a new instance of NotionApiClient.



6
7
8
# File 'lib/notion_cf/notion_api_client.rb', line 6

def initialize
  @client = Notion::Client.new(token: ENV['NOTION_API_TOKEN'])
end

Instance Method Details

#block_append_children(block_id:, children:) ⇒ Object



31
32
33
# File 'lib/notion_cf/notion_api_client.rb', line 31

def block_append_children(block_id:, children:)
  @client.block_append_children(block_id:, children:)
end

#block_children(block_id:) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/notion_cf/notion_api_client.rb', line 10

def block_children(block_id:)
  children = retrieve_children(block_id)
  children.filter_map do |child|
    resource = NotionCf::Resource.build_resource(child)
    resource.retrieve_additional_information(self, children)
  end
  children
end

#create_database(parameter) ⇒ Object



35
36
37
# File 'lib/notion_cf/notion_api_client.rb', line 35

def create_database(parameter)
  @client.create_database(parameter)
end

#create_page(parameter) ⇒ Object



39
40
41
# File 'lib/notion_cf/notion_api_client.rb', line 39

def create_page(parameter)
  @client.create_page(parameter)
end

#database(database_id:) ⇒ Object



27
28
29
# File 'lib/notion_cf/notion_api_client.rb', line 27

def database(database_id:)
  @client.database(database_id:)
end

#page(page_id:) ⇒ Object



23
24
25
# File 'lib/notion_cf/notion_api_client.rb', line 23

def page(page_id:)
  @client.page(page_id:)
end

#retrieve_children(block_id) ⇒ Object



19
20
21
# File 'lib/notion_cf/notion_api_client.rb', line 19

def retrieve_children(block_id)
  @client.block_children(block_id:)[:results]
end

#update_block(id:, parameter:) ⇒ Object



43
44
45
# File 'lib/notion_cf/notion_api_client.rb', line 43

def update_block(id:, parameter:)
  @client.update_block(block_id: id, **parameter)
end

#update_database(database_id:, parameter:) ⇒ Object



47
48
49
# File 'lib/notion_cf/notion_api_client.rb', line 47

def update_database(database_id:, parameter:)
  @client.update_database(database_id:, **parameter)
end

#update_page(page_id:, parameter:) ⇒ Object



51
52
53
# File 'lib/notion_cf/notion_api_client.rb', line 51

def update_page(page_id:, parameter:)
  @client.update_page(page_id:, **parameter)
end