Skip to content

Commit a4024f5

Browse files
authored
Merge pull request #5 from H0R15H0/add-create-database-endpoint
Add create database endpoint.
2 parents 7a867a8 + 8b82b69 commit a4024f5

File tree

10 files changed

+413
-147
lines changed

10 files changed

+413
-147
lines changed

.rspec_status

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
example_id | status | run_time |
22
---------------------------------------------------- | ------ | --------------- |
3-
./spec/notion/api/endpoints/blocks_spec.rb[1:1:1] | passed | 0.01423 seconds |
4-
./spec/notion/api/endpoints/blocks_spec.rb[1:1:2] | passed | 0.02323 seconds |
5-
./spec/notion/api/endpoints/blocks_spec.rb[1:1:3] | passed | 0.00704 seconds |
6-
./spec/notion/api/endpoints/databases_spec.rb[1:1:1] | passed | 0.00598 seconds |
7-
./spec/notion/api/endpoints/databases_spec.rb[1:1:2] | passed | 0.00628 seconds |
8-
./spec/notion/api/endpoints/databases_spec.rb[1:1:3] | passed | 0.00548 seconds |
9-
./spec/notion/api/endpoints/databases_spec.rb[1:1:4] | passed | 0.00596 seconds |
10-
./spec/notion/api/endpoints/databases_spec.rb[1:1:5] | passed | 0.00606 seconds |
11-
./spec/notion/api/endpoints/pages_spec.rb[1:1:1] | passed | 0.00581 seconds |
12-
./spec/notion/api/endpoints/pages_spec.rb[1:1:2] | passed | 0.00598 seconds |
13-
./spec/notion/api/endpoints/pages_spec.rb[1:1:3] | passed | 0.00717 seconds |
14-
./spec/notion/api/endpoints/users_spec.rb[1:1:1] | passed | 0.00637 seconds |
15-
./spec/notion/api/endpoints/users_spec.rb[1:1:2] | passed | 0.00671 seconds |
16-
./spec/notion/api/endpoints/users_spec.rb[1:1:3] | passed | 0.00567 seconds |
17-
./spec/notion/config_spec.rb[1:1:1] | passed | 0.00005 seconds |
18-
./spec/notion/version_spec.rb[1:1] | passed | 0.00005 seconds |
3+
./spec/notion/api/endpoints/blocks_spec.rb[1:1:1] | passed | 0.03873 seconds |
4+
./spec/notion/api/endpoints/blocks_spec.rb[1:1:2] | passed | 0.0494 seconds |
5+
./spec/notion/api/endpoints/blocks_spec.rb[1:1:3] | passed | 0.02657 seconds |
6+
./spec/notion/api/endpoints/databases_spec.rb[1:1:1] | passed | 0.02458 seconds |
7+
./spec/notion/api/endpoints/databases_spec.rb[1:1:2] | passed | 0.02588 seconds |
8+
./spec/notion/api/endpoints/databases_spec.rb[1:1:3] | passed | 0.0268 seconds |
9+
./spec/notion/api/endpoints/databases_spec.rb[1:1:4] | passed | 0.01669 seconds |
10+
./spec/notion/api/endpoints/databases_spec.rb[1:1:5] | passed | 0.01661 seconds |
11+
./spec/notion/api/endpoints/databases_spec.rb[1:1:6] | passed | 0.0173 seconds |
12+
./spec/notion/api/endpoints/pages_spec.rb[1:1:1] | passed | 0.01728 seconds |
13+
./spec/notion/api/endpoints/pages_spec.rb[1:1:2] | passed | 0.01656 seconds |
14+
./spec/notion/api/endpoints/pages_spec.rb[1:1:3] | passed | 0.0206 seconds |
15+
./spec/notion/api/endpoints/users_spec.rb[1:1:1] | passed | 0.02992 seconds |
16+
./spec/notion/api/endpoints/users_spec.rb[1:1:2] | passed | 0.02664 seconds |
17+
./spec/notion/api/endpoints/users_spec.rb[1:1:3] | passed | 0.02533 seconds |
18+
./spec/notion/config_spec.rb[1:1:1] | passed | 0.00016 seconds |
19+
./spec/notion/version_spec.rb[1:1] | passed | 0.00016 seconds |

README.md

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,26 +133,78 @@ client.databases_list do |page|
133133
end
134134
```
135135

136+
Create a Database:
137+
138+
```ruby
139+
title = [
140+
{
141+
"type": "text",
142+
"text": {
143+
"content": "Grocery List",
144+
"link": nil
145+
}
146+
}
147+
],
148+
properties = {
149+
"Name": {
150+
"title": {}
151+
},
152+
"Description": {
153+
"rich_text": {}
154+
},
155+
"In stock": {
156+
"checkbox": {}
157+
},
158+
"Food group": {
159+
"select": {
160+
"options": [
161+
{
162+
"name": "🥦Vegetable",
163+
"color": "green"
164+
},
165+
{
166+
"name": "🍎Fruit",
167+
"color": "red"
168+
},
169+
{
170+
"name": "💪Protein",
171+
"color": "yellow"
172+
}
173+
]
174+
}
175+
}
176+
}
177+
client.create_database(
178+
parent: { page_id: '98ad959b-2b6a-4774-80ee-00246fb0ea9b' },
179+
title: title,
180+
properties: properties
181+
)
182+
```
183+
136184
#### Pages
137185

138186
Create a page:
139187

140188
```ruby
141189
properties = {
142-
"Name": [
143-
{
144-
"text": {
145-
"content": "Tuscan Kale"
190+
"Name": {
191+
"title": [
192+
{
193+
"text": {
194+
"content": "Tuscan Kale"
195+
}
146196
}
147-
}
148-
],
149-
"Description": [
150-
{
151-
"text": {
152-
"content": "A dark green leafy vegetable"
197+
]
198+
},
199+
"Description": {
200+
"rich_text": [
201+
{
202+
"text": {
203+
"content": "A dark green leafy vegetable"
204+
}
153205
}
154-
}
155-
],
206+
]
207+
},
156208
"Food group": {
157209
"name": "🥦 Vegetable"
158210
},

lib/notion/api/endpoints/databases.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,28 @@ def database(options = {})
1818
get("databases/#{options[:id]}")
1919
end
2020

21+
#
22+
# Creates a new database in the specified page.
23+
#
24+
# @option options [Object] :parent
25+
# Parent of the database, which is always going to be a page.
26+
#
27+
# @option options [Object] :title
28+
# Title of this database.
29+
#
30+
# @option options [Object] :properties
31+
# Property schema of database.
32+
# The keys are the names of properties as they appear in Notion and the values are
33+
# property schema objects. Property Schema Object is a metadata that controls
34+
# how a database property behaves, e.g. {"checkbox": {}}.
35+
# Each database must have exactly one database property schema object of type "title".
36+
def create_database(options = {})
37+
throw ArgumentError.new('Required arguments :parent.page_id missing') if options.dig(:parent, :page_id).nil?
38+
throw ArgumentError.new('Required arguments :title missing') if options.dig(:title).nil?
39+
throw ArgumentError.new('Required arguments :properties missing') if options.dig(:properties).nil?
40+
post('databases', options)
41+
end
42+
2143
#
2244
# Gets a paginated array of Page object s contained in the requested database,
2345
# filtered and ordered according to the filter and sort objects provided in the request.

lib/notion/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22
module Notion
33
VERSION = '0.0.7'
4-
NOTION_REQUEST_VERSION = '2021-05-11'
4+
NOTION_REQUEST_VERSION = '2021-05-13'
55
end

spec/fixtures/notion/create_database.yml

Lines changed: 140 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)