Module: Notion::Http::Endpoints::DatabaseMethods

Included in:
Client
Defined in:
lib/notion/http/endpoints/database_methods.rb

Overview

Notion::Http::Client.new(token: NOTION_TOKEN).retrieve_a_database(DATABASE_ID)

Instance Method Summary collapse

Instance Method Details

#create_a_database(options = {}) ⇒ Object

Creates a database as a subpage in the specified parent page, with the specified properties schema.



25
26
27
28
29
30
# File 'lib/notion/http/endpoints/database_methods.rb', line 25

def create_a_database(options = {})
  raise Notion::Errors::ParamError, "Missing required params :parent.page_id" if options.dig(:parent, :page_id).nil?
  raise Notion::Errors::ParamError, "Missing required params :parent.properties" if options[:properties].nil?

  post("databases", options)
end

#query_a_database(options = {}) ⇒ Object

Gets a list of Pages contained in the database, filtered and ordered according to the filter conditions and sort criteria provided in the request.



17
18
19
20
21
22
# File 'lib/notion/http/endpoints/database_methods.rb', line 17

def query_a_database(options = {})
  raise Notion::Errors::ParamError, "Missing required params :database_id" if options[:database_id].nil?

  database_id = options.delete(:database_id)
  post("databases/#{database_id}/query", options)
end

#retrieve_a_database(options = {}) ⇒ Object

Retrieves a database object.



9
10
11
12
13
# File 'lib/notion/http/endpoints/database_methods.rb', line 9

def retrieve_a_database(options = {})
  raise Notion::Errors::ParamError, "Missing required params :database_id" if options[:database_id].nil?

  get("databases/#{options[:database_id]}")
end

#update_a_database(options = {}) ⇒ Object

Update the title, description, or properties of a specified database. Properties define the columns of a database.



33
34
35
36
37
38
# File 'lib/notion/http/endpoints/database_methods.rb', line 33

def update_a_database(options = {})
  raise Notion::Errors::ParamError, "Missing required params :database_id" if options[:database_id].nil?

  database_id = options.delete(:database_id)
  patch("databases/#{database_id}", options)
end