Module: Notion::Api::Endpoints::Databases
- Included in:
- Notion::Api::Endpoints
- Defined in:
- lib/notion/api/endpoints/databases.rb
Instance Method Summary collapse
-
#create_database(options = {}) ⇒ Object
Creates a new database in the specified page.
-
#database(options = {}) ⇒ Object
Retrieves a Database object using the ID specified in the request.
-
#database_query(options = {}) ⇒ Object
Gets a paginated array of Page object s contained in the requested database, filtered and ordered according to the filter and sort objects provided in the request.
-
#update_database(options = {}) ⇒ Object
Updates an existing database as specified by the parameters.
Instance Method Details
#create_database(options = {}) ⇒ Object
Creates a new database in the specified page.
63 64 65 66 67 68 |
# File 'lib/notion/api/endpoints/databases.rb', line 63 def create_database( = {}) throw ArgumentError.new('Required arguments :parent.page_id missing') if .dig(:parent, :page_id).nil? throw ArgumentError.new('Required arguments :title missing') if .dig(:title).nil? throw ArgumentError.new('Required arguments :properties missing') if .dig(:properties).nil? post('databases', ) end |
#database(options = {}) ⇒ Object
Retrieves a Database object using the ID specified in the request.
Returns a 404 HTTP response if the database doesn’t exist, or if the bot doesn’t have access to the database. Returns a 429 HTTP response if the request exceeds Notion’s Request limits.
102 103 104 105 |
# File 'lib/notion/api/endpoints/databases.rb', line 102 def database( = {}) throw ArgumentError.new('Required arguments :database_id missing') if [:database_id].nil? get("databases/#{[:database_id]}") end |
#database_query(options = {}) ⇒ Object
Gets a paginated array of Page object s contained in the requested database, filtered and ordered according to the filter and sort objects provided in the request.
Filters are similar to the filters provided in the Notion UI. Filters operate on database properties and can be combined. If no filter is provided, all the pages in the database will be returned with pagination.
Sorts are similar to the sorts provided in the Notion UI. Sorts operate on database properties and can be combined. The order of the sorts in the request matter, with earlier sorts taking precedence over later ones.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/notion/api/endpoints/databases.rb', line 36 def database_query( = {}) throw ArgumentError.new('Required arguments :database_id missing') if [:database_id].nil? if block_given? Pagination::Cursor.new(self, :database_query, ).each do |page| yield page end else database_id = .delete(:database_id) post("databases/#{database_id}/query", ) end end |
#update_database(options = {}) ⇒ Object
Updates an existing database as specified by the parameters.
87 88 89 90 91 |
# File 'lib/notion/api/endpoints/databases.rb', line 87 def update_database( = {}) database_id = .delete(:database_id) throw ArgumentError.new('Required arguments :database_id missing') if database_id.nil? patch("databases/#{database_id}", ) end |