notion_ruby_mapping 0.3.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -1237
- data/env.yml.sample +0 -13
- data/examples/change_title.md +1 -1
- data/examples/renumbering_pages.md +3 -3
- data/examples/set_icon_to_all_icon_unsettled_pages.md +4 -4
- data/lib/notion_ruby_mapping/{base.rb → blocks/base.rb} +163 -92
- data/lib/notion_ruby_mapping/blocks/block.rb +145 -0
- data/lib/notion_ruby_mapping/blocks/bookmark_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/breadcrumb_block.rb +19 -0
- data/lib/notion_ruby_mapping/blocks/bulleted_list_item_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/callout_block.rb +82 -0
- data/lib/notion_ruby_mapping/blocks/child_base_block.rb +21 -0
- data/lib/notion_ruby_mapping/blocks/child_database_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/child_page_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/code_block.rb +50 -0
- data/lib/notion_ruby_mapping/blocks/column_block.rb +29 -0
- data/lib/notion_ruby_mapping/blocks/column_list_block.rb +33 -0
- data/lib/notion_ruby_mapping/{database.rb → blocks/database.rb} +41 -8
- data/lib/notion_ruby_mapping/blocks/divider_block.rb +19 -0
- data/lib/notion_ruby_mapping/blocks/embed_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/equation_block.rb +43 -0
- data/lib/notion_ruby_mapping/blocks/file_base_block.rb +50 -0
- data/lib/notion_ruby_mapping/blocks/file_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/heading1_block.rb +18 -0
- data/lib/notion_ruby_mapping/blocks/heading2_block.rb +18 -0
- data/lib/notion_ruby_mapping/blocks/heading3_block.rb +18 -0
- data/lib/notion_ruby_mapping/blocks/image_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/link_preview_block.rb +16 -0
- data/lib/notion_ruby_mapping/blocks/link_to_page_block.rb +40 -0
- data/lib/notion_ruby_mapping/{list.rb → blocks/list.rb} +37 -6
- data/lib/notion_ruby_mapping/blocks/numbered_list_item_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/page.rb +77 -0
- data/lib/notion_ruby_mapping/blocks/paragraph_block.rb +11 -0
- data/lib/notion_ruby_mapping/{block.rb → blocks/pdf_block.rb} +4 -3
- data/lib/notion_ruby_mapping/blocks/quote_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/synced_block.rb +44 -0
- data/lib/notion_ruby_mapping/blocks/table_block.rb +50 -0
- data/lib/notion_ruby_mapping/blocks/table_of_contents_block.rb +34 -0
- data/lib/notion_ruby_mapping/blocks/table_row_block.rb +34 -0
- data/lib/notion_ruby_mapping/blocks/template_block.rb +34 -0
- data/lib/notion_ruby_mapping/blocks/text_sub_block_color_base_block.rb +45 -0
- data/lib/notion_ruby_mapping/blocks/to_do_block.rb +42 -0
- data/lib/notion_ruby_mapping/blocks/toggle_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/toggle_heading1_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/toggle_heading2_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/toggle_heading3_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/url_base_block.rb +34 -0
- data/lib/notion_ruby_mapping/blocks/url_caption_base_block.rb +46 -0
- data/lib/notion_ruby_mapping/blocks/video_block.rb +11 -0
- data/lib/notion_ruby_mapping/{notion_cache.rb → controllers/notion_cache.rb} +144 -102
- data/lib/notion_ruby_mapping/{payload.rb → controllers/payload.rb} +32 -18
- data/lib/notion_ruby_mapping/{property_cache.rb → controllers/property_cache.rb} +21 -20
- data/lib/notion_ruby_mapping/{query.rb → controllers/query.rb} +27 -19
- data/lib/notion_ruby_mapping/{rich_text_array.rb → controllers/rich_text_array.rb} +39 -17
- data/lib/notion_ruby_mapping/objects/emoji_object.rb +40 -0
- data/lib/notion_ruby_mapping/objects/equation_object.rb +43 -0
- data/lib/notion_ruby_mapping/objects/file_object.rb +60 -0
- data/lib/notion_ruby_mapping/{mention_object.rb → objects/mention_object.rb} +11 -0
- data/lib/notion_ruby_mapping/{rich_text_object.rb → objects/rich_text_object.rb} +12 -4
- data/lib/notion_ruby_mapping/{text_object.rb → objects/text_object.rb} +0 -1
- data/lib/notion_ruby_mapping/{user_object.rb → objects/user_object.rb} +9 -4
- data/lib/notion_ruby_mapping/{checkbox_property.rb → properties/checkbox_property.rb} +3 -0
- data/lib/notion_ruby_mapping/{created_by_property.rb → properties/created_by_property.rb} +1 -0
- data/lib/notion_ruby_mapping/{created_time_property.rb → properties/created_time_property.rb} +1 -0
- data/lib/notion_ruby_mapping/properties/date_base_property.rb +135 -0
- data/lib/notion_ruby_mapping/{date_property.rb → properties/date_property.rb} +13 -0
- data/lib/notion_ruby_mapping/{email_property.rb → properties/email_property.rb} +2 -2
- data/lib/notion_ruby_mapping/{files_property.rb → properties/files_property.rb} +26 -13
- data/lib/notion_ruby_mapping/{formula_property.rb → properties/formula_property.rb} +5 -1
- data/lib/notion_ruby_mapping/{last_edited_by_property.rb → properties/last_edited_by_property.rb} +1 -0
- data/lib/notion_ruby_mapping/{last_edited_time_property.rb → properties/last_edited_time_property.rb} +1 -0
- data/lib/notion_ruby_mapping/{multi_property.rb → properties/multi_property.rb} +0 -0
- data/lib/notion_ruby_mapping/{multi_select_property.rb → properties/multi_select_property.rb} +4 -3
- data/lib/notion_ruby_mapping/{number_property.rb → properties/number_property.rb} +4 -0
- data/lib/notion_ruby_mapping/{people_property.rb → properties/people_property.rb} +8 -3
- data/lib/notion_ruby_mapping/{phone_number_property.rb → properties/phone_number_property.rb} +4 -1
- data/lib/notion_ruby_mapping/{property.rb → properties/property.rb} +33 -0
- data/lib/notion_ruby_mapping/{relation_property.rb → properties/relation_property.rb} +30 -10
- data/lib/notion_ruby_mapping/{rich_text_property.rb → properties/rich_text_property.rb} +0 -0
- data/lib/notion_ruby_mapping/{rollup_property.rb → properties/rollup_property.rb} +7 -0
- data/lib/notion_ruby_mapping/{select_property.rb → properties/select_property.rb} +8 -2
- data/lib/notion_ruby_mapping/{text_property.rb → properties/text_property.rb} +0 -0
- data/lib/notion_ruby_mapping/{title_property.rb → properties/title_property.rb} +0 -0
- data/lib/notion_ruby_mapping/{url_property.rb → properties/url_property.rb} +4 -1
- data/lib/notion_ruby_mapping/version.rb +1 -1
- data/lib/notion_ruby_mapping.rb +21 -7
- metadata +82 -40
- data/lib/notion_ruby_mapping/date_base_property.rb +0 -75
- data/lib/notion_ruby_mapping/page.rb +0 -50
data/README.md
CHANGED
@@ -8,75 +8,23 @@ Development note is here. → [Idea note of "notion_ruby_mapping"](https://www.n
|
|
8
8
|
|
9
9
|
- [notion_ruby_mapping](#notion_ruby_mapping)
|
10
10
|
- [Table of Contents](#table-of-contents)
|
11
|
+
- [0. Changes in v0.5.0](#0-changes-in-v050)
|
11
12
|
- [1. Installation](#1-installation)
|
12
|
-
- [2.
|
13
|
-
|
14
|
-
- [
|
15
|
-
- [3
|
16
|
-
|
17
|
-
- [
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- [4.2.2.3 Dry run sample](#4223-dry-run-sample)
|
28
|
-
- [4.2.3 Create child page](#423-create-child-page)
|
29
|
-
- [4.2.4 Create database](#424-create-database)
|
30
|
-
- [4.2.5 Update database properties](#425-update-database-properties)
|
31
|
-
- [4.2.6 Add a database property](#426-add-a-database-property)
|
32
|
-
- [4.2.7 Rename a database property](#427-rename-a-database-property)
|
33
|
-
- [4.2.8 Remove database properties](#428-remove-database-properties)
|
34
|
-
- [4.2.9 other methods](#429-other-methods)
|
35
|
-
- [4.3 List class](#43-list-class)
|
36
|
-
- [4.4 Block class](#44-block-class)
|
37
|
-
- [4.5 Property classes](#45-property-classes)
|
38
|
-
- [4.5.1 How to obtain Property object](#451-how-to-obtain-property-object)
|
39
|
-
- [4.5.2 Query object generator of property objects](#452-query-object-generator-of-property-objects)
|
40
|
-
- [4.5.3 create or update values for Page properties](#453-create-or-update-values-for-page-properties)
|
41
|
-
- [4.5.3.1 NumberProperty](#4531-numberproperty)
|
42
|
-
- [4.5.3.2 SelectProperty](#4532-selectproperty)
|
43
|
-
- [4.5.3.3 MultiSelectProperty](#4533-multiselectproperty)
|
44
|
-
- [4.5.3.4 DateProperty](#4534-dateproperty)
|
45
|
-
- [4.5.3.4 UrlProperty](#4534-urlproperty)
|
46
|
-
- [4.5.3.5 EmailProperty](#4535-emailproperty)
|
47
|
-
- [4.5.3.6 PhoneNumberProperty](#4536-phonenumberproperty)
|
48
|
-
- [4.5.3.7 PeopleProperty](#4537-peopleproperty)
|
49
|
-
- [4.5.3.8 TitleProperty, RichTextProperty](#4538-titleproperty-richtextproperty)
|
50
|
-
- [4.5.3.9 CheckboxProperty](#4539-checkboxproperty)
|
51
|
-
- [4.5.3.10 FilesProperty](#45310-filesproperty)
|
52
|
-
- [4.5.3.11 RelationProperty](#45311-relationproperty)
|
53
|
-
- [4.5.4 create or update values for Database properties](#454-create-or-update-values-for-database-properties)
|
54
|
-
- [4.5.4.1 NumberProperty](#4541-numberproperty)
|
55
|
-
- [4.5.4.2 SelectProperty](#4542-selectproperty)
|
56
|
-
- [4.5.4.3 MultiSelectProperty](#4543-multiselectproperty)
|
57
|
-
- [4.5.4.4 DateProperty](#4544-dateproperty)
|
58
|
-
- [4.5.4.4 UrlProperty](#4544-urlproperty)
|
59
|
-
- [4.5.4.5 EmailProperty](#4545-emailproperty)
|
60
|
-
- [4.5.4.6 PhoneNumberProperty](#4546-phonenumberproperty)
|
61
|
-
- [4.5.4.7 PeopleProperty](#4547-peopleproperty)
|
62
|
-
- [4.5.4.8 TitleProperty, RichTextProperty](#4548-titleproperty-richtextproperty)
|
63
|
-
- [4.5.4.9 CheckboxProperty](#4549-checkboxproperty)
|
64
|
-
- [4.5.4.10 FilesProperty](#45410-filesproperty)
|
65
|
-
- [4.5.4.11 RelationProperty](#45411-relationproperty)
|
66
|
-
- [4.5.4.12 RollupProperty](#45412-rollupproperty)
|
67
|
-
- [5. XXXObjects and RichTextArray](#5-xxxobjects-and-richtextarray)
|
68
|
-
- [5.1 RichTextObject](#51-richtextobject)
|
69
|
-
- [5.2 TextObject](#52-textobject)
|
70
|
-
- [5.3 MentionObject](#53-mentionobject)
|
71
|
-
- [5.4 UserObject](#54-userobject)
|
72
|
-
- [5.5 RichTextArray](#55-richtextarray)
|
73
|
-
- [5.5.1 Constructor for RichTextArray](#551-constructor-for-richtextarray)
|
74
|
-
- [5.5.2 Instance methods](#552-instance-methods)
|
75
|
-
- [6. ChangeLog](#6-changelog)
|
76
|
-
- [7. Contributing](#7-contributing)
|
77
|
-
- [8. License](#8-license)
|
78
|
-
- [9. Code of Conduct](#9-code-of-conduct)
|
79
|
-
- [10. Acknowledgements](#10-acknowledgements)
|
13
|
+
- [2. How to use](#2-how-to-use)
|
14
|
+
- [2.1 Create a New Integration](#21-create-a-new-integration)
|
15
|
+
- [2.2 Create client](#22-create-client)
|
16
|
+
- [2.3 Sample codes](#23-sample-codes)
|
17
|
+
- [2.4. Another example code (Use case)](#24-another-example-code-use-case)
|
18
|
+
- [2.5 API reference](#25-api-reference)
|
19
|
+
- [3. ChangeLog](#3-changelog)
|
20
|
+
- [4. Contributing](#4-contributing)
|
21
|
+
- [5. License](#5-license)
|
22
|
+
- [6. Code of Conduct](#6-code-of-conduct)
|
23
|
+
|
24
|
+
## 0. Changes in v0.5.0
|
25
|
+
|
26
|
+
NotionRubyMapping v.0.5.0 now supports block updates.
|
27
|
+
For efficiency, subclasses are provided under Block class. As a result, they are no longer compatible with the scripts used in v0.4.0.
|
80
28
|
|
81
29
|
## 1. Installation
|
82
30
|
|
@@ -98,1187 +46,50 @@ Or install it yourself as:
|
|
98
46
|
gem install notion_ruby_mapping
|
99
47
|
```
|
100
48
|
|
101
|
-
## 2.
|
49
|
+
## 2. How to use
|
102
50
|
|
103
|
-
1
|
104
|
-
1. [Renumbering pages](examples/renumbering_pages.md)
|
105
|
-
1. [Change title](examples/change_title.md)
|
106
|
-
|
107
|
-
## 3. Preparation
|
108
|
-
|
109
|
-
### 3.1 Create a New Integration
|
51
|
+
### 2.1 Create a New Integration
|
110
52
|
|
111
53
|
Please check [Notion documentation](https://developers.notion.com/docs#getting-started).
|
112
54
|
|
113
|
-
###
|
55
|
+
### 2.2 Create client
|
114
56
|
|
115
57
|
Please create a client (notion-ruby-client) before you use the following class.
|
116
58
|
|
117
59
|
```Ruby
|
118
|
-
NotionCache.instance.create_client "
|
60
|
+
NotionCache.instance.create_client "secret_XXXXXXXXXXXXXXXXXXXX" # write directly
|
119
61
|
NotionCache.instance.create_client ENV["NOTION_API_TOKEN"] # from environment
|
120
62
|
```
|
121
63
|
|
122
|
-
|
123
|
-
|
124
|
-
From v0.3.0, `find`, `save` and `query_database` methods can set `dry_run: true` option. When this option is set, these methods create create a shell script for verification instead of calling the Notion API. Some sample codes show the results of dry_run in order to make it easy to understand what the method runs.
|
125
|
-
|
126
|
-
### 4.1 Page
|
127
|
-
|
128
|
-
#### 4.1.1 Retrieve a page
|
129
|
-
|
130
|
-
`Page.find(id)` creates a Page object with `retrieving page API`. The created object has page information generated from the JSON response.
|
131
|
-
|
132
|
-
```Ruby
|
133
|
-
page = Page.find "c01166c6-13ae-45cb-b968-18b4ef2f5a77" # Notion API call
|
134
|
-
```
|
135
|
-
|
136
|
-
- result of dry run
|
137
|
-
|
138
|
-
```bash
|
139
|
-
#!/bin/sh
|
140
|
-
curl 'https://api.notion.com/v1/pages/c01166c6-13ae-45cb-b968-18b4ef2f5a77' \
|
141
|
-
-H 'Notion-Version: 2022-02-22' \
|
142
|
-
-H 'Authorization: Bearer '"$NOTION_API_KEY"'' \
|
143
|
-
-H 'Content-Type: application/json'
|
144
|
-
```
|
145
|
-
|
146
|
-
`Page.new(id)` creates a Page object without the Notion API. Since Page.new does not acquire property information, so you need to assign yourself.
|
147
|
-
|
148
|
-
```Ruby
|
149
|
-
# Assign some properties for update manually
|
150
|
-
# The argument of assign keyword is Array with the multiple pairs of PropertyClass and Property name
|
151
|
-
page = Page.new id: "c01166c6-13ae-45cb-b968-18b4ef2f5a77",
|
152
|
-
assign: [TitleProperty, "Title", NumberProperty, "NumberTitle"]
|
153
|
-
```
|
154
|
-
|
155
|
-
#### 4.1.2 Update page properties
|
156
|
-
|
157
|
-
Page properties with values can be obtained from the retrieved page using `find`. On the other hand, Page properties without values can be obtained from the property assigned page.
|
158
|
-
|
159
|
-
```Ruby
|
160
|
-
tp = page.properties["Title"] # TitleProperty
|
161
|
-
np = page.properties["Number"] # NumberProperty
|
162
|
-
```
|
163
|
-
|
164
|
-
Each property object can change values using corresponded methods. After changing value, `will_update` flag of the property object also set to true. These methods are explained in the section of each property object class.
|
165
|
-
|
166
|
-
```Ruby
|
167
|
-
to = tp[1] # TitleProperty has Array of TextObject
|
168
|
-
to.text = "ABC" # TextObject can set text by ".text="
|
169
|
-
# or tp[1].text = "ABC"
|
170
|
-
|
171
|
-
np.number = 3.14159
|
172
|
-
```
|
173
|
-
|
174
|
-
After update some properties, `page.save` method sends `Notion API` and replace the page information using the response of API.
|
175
|
-
|
176
|
-
```Ruby
|
177
|
-
page.save # Notion API call
|
178
|
-
```
|
179
|
-
|
180
|
-
#### 4.1.3 Update other page information
|
181
|
-
|
182
|
-
`page.set_icon` can change the page icon using emoji or external url.
|
183
|
-
|
184
|
-
[Breaking change on v0.2.2]
|
185
|
-
`page.set_icon` has no longer calling the Notion API. Please use `page.save` after `page.set_icon` if you want to update or create the page.
|
186
|
-
|
187
|
-
```Ruby
|
188
|
-
# both methods call Notion API
|
189
|
-
obj.set_icon emoji: "💿" # set emoji
|
190
|
-
obj.save
|
191
|
-
|
192
|
-
obj.set_icon url: "https://cdn.profile-image.st-hatena.com/users/hkob/profile.png" # set external url
|
193
|
-
obj.save
|
194
|
-
```
|
195
|
-
|
196
|
-
#### 4.1.4 other methods
|
197
|
-
|
198
|
-
- `Page.find id, dry_run: true` create shell script for verification.
|
199
|
-
- `page.save` call Notion API, and so on and replace object information.
|
200
|
-
- `page.save dry_run: true` create shell script for verification.
|
201
|
-
- `page.new_record?` returns true if the page was generated by `create_child_page`.
|
202
|
-
- `page.title` returns plain_text string of `Title`.
|
203
|
-
- `page.icon` returns JSON hash for the page icon.
|
204
|
-
- `page[key]` returns a hash or an array object except "properties".
|
205
|
-
|
206
|
-
### 4.2 Database
|
207
|
-
|
208
|
-
#### 4.2.1 Retrieve a database
|
209
|
-
|
210
|
-
`Database.find(id)` creates a Database object with `retrieving database API`. The created object has database information generated from the JSON response.
|
211
|
-
|
212
|
-
```Ruby
|
213
|
-
db = Database.find "c37a2c66-e3aa-4a0d-a447-73de3b80c253" # Notion API call
|
214
|
-
```
|
215
|
-
|
216
|
-
```bash
|
217
|
-
# result of dry run
|
218
|
-
#!/bin/sh
|
219
|
-
curl 'https://api.notion.com/v1/databases/c37a2c66-e3aa-4a0d-a447-73de3b80c253'\
|
220
|
-
-H 'Notion-Version: 2022-02-22'\
|
221
|
-
-H 'Authorization: Bearer '"$NOTION_API_KEY"''\
|
222
|
-
-H 'Content-Type: application/json'
|
223
|
-
```
|
224
|
-
|
225
|
-
`Database.new(id)` creates a Database object without the Notion API. Since Database.new does not acquire property information, so you need to assign yourself.
|
226
|
-
|
227
|
-
```Ruby
|
228
|
-
# assign some properties for update manually
|
229
|
-
db = Database.new id: "c37a2c66-e3aa-4a0d-a447-73de3b80c253",
|
230
|
-
assign: [TitleProperty, "Title", NumberProperty, "NumberTitle"]
|
231
|
-
```
|
232
|
-
|
233
|
-
#### 4.2.2 Query a database
|
234
|
-
|
235
|
-
`db.query_database` obtains a List object with Page objects contained in the database. You can obtain filtered and ordered pages using Query object.
|
236
|
-
|
237
|
-
```Ruby
|
238
|
-
# query_database method calls Notion API
|
239
|
-
db.query_database # retrieves all pages (no filter, no sort)
|
240
|
-
db.query_database query # retrieves using query
|
241
|
-
```
|
242
|
-
|
243
|
-
The query object can be generated from the Property objects included in the database object. The Property object can be obtained from the retrieved or assigned database object like as the Page object.
|
244
|
-
|
245
|
-
`filter_xxxx` methods of the property objects generates a query object. These methods are explained in the section of each property object class.
|
246
|
-
|
247
|
-
```Ruby
|
248
|
-
tp = db.properties["Title"]
|
249
|
-
query = tp.filter_starts_with("A").ascending(tp)
|
250
|
-
pages = db.query_database query
|
251
|
-
```
|
252
|
-
|
253
|
-
##### 4.2.2.1 Complex conditions
|
254
|
-
|
255
|
-
Complex filters can be generated `and` / `or` methods of the Query object. Here are some sample scripts and the json parameters created from them.
|
256
|
-
|
257
|
-
```Ruby
|
258
|
-
# Prepare some sample properties
|
259
|
-
db = Database.new id: "sample database id",
|
260
|
-
assign: [
|
261
|
-
TitleProperty, "tp",
|
262
|
-
NumberProperty, "np",
|
263
|
-
CheckboxProperty, "cp",
|
264
|
-
LastEditedTimeProperty, "letp",
|
265
|
-
]
|
266
|
-
properties = db.properties # PropertyCache object
|
267
|
-
# PropertyCache object can receive [] or values_at methods.
|
268
|
-
# `values_at` method is useful when retrieving multiple properties at once.
|
269
|
-
(tp, np, cp, letp) = properties.values_at "tp", "np", "cp", "letp"
|
270
|
-
```
|
271
|
-
|
272
|
-
- query1: (A and B) filter
|
273
|
-
|
274
|
-
```Ruby
|
275
|
-
query1 = tp.filter_starts_with("start")
|
276
|
-
.and(np.filter_greater_than(100))
|
277
|
-
|
278
|
-
# Result of query1.filter
|
279
|
-
{
|
280
|
-
"and" => [
|
281
|
-
{
|
282
|
-
"property" => "tp",
|
283
|
-
"title" => {"starts_with" => "start"},
|
284
|
-
},
|
285
|
-
{
|
286
|
-
"property" => "np",
|
287
|
-
"number" => {"greater_than" => 100},
|
288
|
-
},
|
289
|
-
],
|
290
|
-
}
|
291
|
-
```
|
292
|
-
|
293
|
-
- query2: (A and B and C) filter
|
294
|
-
|
295
|
-
```Ruby
|
296
|
-
query2 = tp.filter_starts_with("start")
|
297
|
-
.and(np.filter_greater_than(100))
|
298
|
-
.and(cp.filter_equals(true))
|
299
|
-
|
300
|
-
# Result of query2.filter
|
301
|
-
{
|
302
|
-
"and" => [
|
303
|
-
{
|
304
|
-
"property" => "tp",
|
305
|
-
"title" => {"starts_with" => "start"},
|
306
|
-
},
|
307
|
-
{
|
308
|
-
"property" => "np",
|
309
|
-
"number" => {"greater_than" => 100},
|
310
|
-
},
|
311
|
-
{
|
312
|
-
"property" => "cp",
|
313
|
-
"checkbox" => {"equals" => true},
|
314
|
-
},
|
315
|
-
],
|
316
|
-
}
|
317
|
-
```
|
318
|
-
|
319
|
-
- query3: (A or B) filter
|
320
|
-
|
321
|
-
```Ruby
|
322
|
-
query3 = tp.filter_starts_with("start")
|
323
|
-
.or(np.filter_greater_than(100))
|
324
|
-
|
325
|
-
# Result of query3.filter
|
326
|
-
{
|
327
|
-
"or" => [
|
328
|
-
{
|
329
|
-
"property" => "tp",
|
330
|
-
"title" => {"starts_with" => "start"},
|
331
|
-
},
|
332
|
-
{
|
333
|
-
"property" => "np",
|
334
|
-
"number" => {"greater_than" => 100},
|
335
|
-
},
|
336
|
-
],
|
337
|
-
}
|
338
|
-
```
|
339
|
-
|
340
|
-
- query4: (A or B or C) filter
|
341
|
-
|
342
|
-
```Ruby
|
343
|
-
query4 = tp.filter_starts_with("start")
|
344
|
-
.or(np.filter_greater_than(100))
|
345
|
-
.or(cp.filter_equals(true))
|
346
|
-
|
347
|
-
# Result of query4.filter
|
348
|
-
{
|
349
|
-
"or" => [
|
350
|
-
{
|
351
|
-
"property" => "tp",
|
352
|
-
"title" => {"starts_with" => "start"},
|
353
|
-
},
|
354
|
-
{
|
355
|
-
"property" => "np",
|
356
|
-
"number" => {"greater_than" => 100},
|
357
|
-
},
|
358
|
-
{
|
359
|
-
"property" => "cp",
|
360
|
-
"checkbox" => {"equals" => true},
|
361
|
-
},
|
362
|
-
],
|
363
|
-
}
|
364
|
-
```
|
365
|
-
|
366
|
-
- query5: ((A and B) or C) filter
|
367
|
-
|
368
|
-
```Ruby
|
369
|
-
query5 = tp.filter_starts_with("start")
|
370
|
-
.and(np.filter_greater_than(100))
|
371
|
-
.or(cp.filter_equals(true))
|
372
|
-
|
373
|
-
# Result of query5.filter
|
374
|
-
{
|
375
|
-
"or" => [
|
376
|
-
{
|
377
|
-
"and" => [
|
378
|
-
{
|
379
|
-
"property" => "tp",
|
380
|
-
"title" => {"starts_with" => "start"},
|
381
|
-
},
|
382
|
-
{
|
383
|
-
"property" => "np",
|
384
|
-
"number" => {"greater_than" => 100},
|
385
|
-
},
|
386
|
-
],
|
387
|
-
},
|
388
|
-
{
|
389
|
-
"property" => "cp",
|
390
|
-
"checkbox" => {"equals" => true},
|
391
|
-
},
|
392
|
-
],
|
393
|
-
}
|
394
|
-
```
|
395
|
-
|
396
|
-
- query6: ((A or B) and C) filter
|
397
|
-
|
398
|
-
```Ruby
|
399
|
-
query6 = tp.filter_starts_with("start")
|
400
|
-
.or(np.filter_greater_than(100))
|
401
|
-
.and(cp.filter_equals(true))
|
402
|
-
|
403
|
-
# Result of query6.filter
|
404
|
-
{
|
405
|
-
"and" => [
|
406
|
-
{
|
407
|
-
"or" => [
|
408
|
-
{
|
409
|
-
"property" => "tp",
|
410
|
-
"title" => {"starts_with" => "start"},
|
411
|
-
},
|
412
|
-
{
|
413
|
-
"property" => "np",
|
414
|
-
"number" => {"greater_than" => 100},
|
415
|
-
},
|
416
|
-
],
|
417
|
-
},
|
418
|
-
{
|
419
|
-
"property" => "cp",
|
420
|
-
"checkbox" => {"equals" => true},
|
421
|
-
},
|
422
|
-
],
|
423
|
-
}
|
424
|
-
```
|
425
|
-
|
426
|
-
- query7: ((A and B) or (C and D)) filter
|
427
|
-
|
428
|
-
```Ruby
|
429
|
-
query7 = np.filter_greater_than(100).and(np.filter_less_than(200))
|
430
|
-
.or(np.filter_greater_than(300).and(np.filter_less_than(400)))
|
431
|
-
|
432
|
-
# Result of query7.filter
|
433
|
-
{
|
434
|
-
"or" => [
|
435
|
-
{
|
436
|
-
"and" => [
|
437
|
-
{
|
438
|
-
"property" => "np",
|
439
|
-
"number" => {"greater_than" => 100},
|
440
|
-
},
|
441
|
-
{
|
442
|
-
"property" => "np",
|
443
|
-
"number" => {"less_than" => 200},
|
444
|
-
},
|
445
|
-
],
|
446
|
-
},
|
447
|
-
{
|
448
|
-
"and" => [
|
449
|
-
{
|
450
|
-
"property" => "np",
|
451
|
-
"number" => {"greater_than" => 300},
|
452
|
-
},
|
453
|
-
{
|
454
|
-
"property" => "np",
|
455
|
-
"number" => {"less_than" => 400},
|
456
|
-
},
|
457
|
-
],
|
458
|
-
},
|
459
|
-
],
|
460
|
-
}
|
461
|
-
```
|
462
|
-
|
463
|
-
##### 4.2.2.2 Sort criteria
|
464
|
-
|
465
|
-
Sort criteria can be appended to an existing query object. If you don't use the previous filters, you can generate by `Query.new`.
|
466
|
-
|
467
|
-
- sort criteria only
|
468
|
-
|
469
|
-
```Ruby
|
470
|
-
query8 = Query.new.ascending tp
|
471
|
-
query9 = Query.new.ascending letp
|
472
|
-
query10 = Query.new.descending tp
|
473
|
-
query11 = Query.new.descending letp
|
474
|
-
query12 = Query.new.ascending(tp).descending letp
|
475
|
-
|
476
|
-
# Result of query8.sort
|
477
|
-
[{"property" => "tp", "direction" => "ascending"}]
|
478
|
-
|
479
|
-
# Result of query9.sort
|
480
|
-
[{"timestamp" => "letp", "direction" => "ascending"}]
|
481
|
-
|
482
|
-
# Result of query10.sort
|
483
|
-
[{"property" => "tp", "direction" => "descending"}]
|
484
|
-
|
485
|
-
# Result of query11.sort
|
486
|
-
[{"timestamp" => "letp", "direction" => "descending"}]
|
487
|
-
|
488
|
-
# Result of query12.sort
|
489
|
-
[
|
490
|
-
{"property" => "tp", "direction" => "ascending"},
|
491
|
-
{"timestamp" => "letp", "direction" => "descending"},
|
492
|
-
]
|
493
|
-
```
|
494
|
-
|
495
|
-
- filter with sort
|
496
|
-
|
497
|
-
```Ruby
|
498
|
-
query13 = tp.filter_starts_with("A").ascending(tp)
|
499
|
-
|
500
|
-
# Result of query13.filter
|
501
|
-
{"property" => "tp", "title" => {"starts_with" => "start"}}
|
502
|
-
|
503
|
-
# Result of query13.sort
|
504
|
-
[{"property" => "tp", "direction" => "ascending"}]
|
505
|
-
```
|
506
|
-
|
507
|
-
##### 4.2.2.3 Dry run sample
|
508
|
-
|
509
|
-
This is a sample script for query database. If dry_run flag is set, you can see the verification shell script.
|
510
|
-
|
511
|
-
```Ruby
|
512
|
-
db = Database.new id: tc.database_id, assign: [NumberProperty, "NumberTitle", UrlProperty, "UrlTitle"]
|
513
|
-
np, up = target.properties.values_at "NumberTitle", "UrlTitle"
|
514
|
-
query = np.filter_greater_than(100).and(up.filter_starts_with("https")).ascending(np)
|
515
|
-
print db.query_database query, dry_run: true
|
516
|
-
# => Result
|
517
|
-
# #!/bin/sh
|
518
|
-
# curl -X POST 'https://api.notion.com/v1/databases/XXXXX/query'\
|
519
|
-
# -H 'Notion-Version: 2022-02-22'\
|
520
|
-
# -H 'Authorization: Bearer '"$NOTION_API_KEY"''\
|
521
|
-
# -H 'Content-Type: application/json'\
|
522
|
-
# --data '{"filter":{"and":[{"property":"NumberTitle","number":{"greater_than":100}},{"property":"UrlTitle","url":{"starts_with":"https"}}]},"sorts":[{"property":"NumberTitle","direction":"ascending"}],"page_size":100}'⏎
|
523
|
-
|
524
|
-
|
525
|
-
```
|
526
|
-
|
527
|
-
#### 4.2.3 Create child page
|
528
|
-
|
529
|
-
`create_child_page` creates a child page object of the database. After setting some properties, please call `page.save` to send page information to Notion. Properties of the created child page are automatically assigned using the parent database. if a block is provided, the method will yield the new Page object and the properties (PropertyCache object) to that block for initialization.
|
530
|
-
|
531
|
-
```Ruby
|
532
|
-
page = db.create_child_page do |p, pp|
|
533
|
-
# p is the new Page object
|
534
|
-
# pp is the properties of the new Page object (PropertyCache Object)
|
535
|
-
p.set_icon emoji: "🎉"
|
536
|
-
pp["Name"] << "New Page"
|
537
|
-
end
|
538
|
-
page.save
|
539
|
-
```
|
540
|
-
|
541
|
-
- result of dry run
|
542
|
-
|
543
|
-
```bash
|
544
|
-
#!/bin/sh
|
545
|
-
curl -X POST 'https://api.notion.com/v1/pages'\
|
546
|
-
-H 'Notion-Version: 2022-02-22'\
|
547
|
-
-H 'Authorization: Bearer '"$NOTION_API_KEY"''\
|
548
|
-
-H 'Content-Type: application/json'\
|
549
|
-
--data '{"properties":{"Name":{"type":"title","title":[{"type":"text","text":{"content":"New Page","link":null},"plain_text":"New Page","href":null}]}},"parent":{"database_id":"c37a2c66e3aa4a0da44773de3b80c253"}}'⏎
|
550
|
-
```
|
551
|
-
|
552
|
-
#### 4.2.4 Create database
|
553
|
-
|
554
|
-
`create_child_database` method of an existing page creates a child database object. Some properties of the database can be arrange the option. Here is a sample script for creating a database that set all types of properties.
|
555
|
-
|
556
|
-
```Ruby
|
557
|
-
page = Page.find "a sample page id"
|
558
|
-
db = parent_page.create_child_database "New database title",
|
559
|
-
CheckboxProperty, "Checkbox",
|
560
|
-
CreatedByProperty, "CreatedBy",
|
561
|
-
CreatedTimeProperty, "CreatedTime",
|
562
|
-
DateProperty, "Date",
|
563
|
-
EmailProperty, "Email",
|
564
|
-
FilesProperty, "Files",
|
565
|
-
FormulaProperty, "Formula",
|
566
|
-
LastEditedByProperty, "LastEditedBy",
|
567
|
-
LastEditedTimeProperty, "LastEditedTime",
|
568
|
-
MultiSelectProperty, "MultiSelect",
|
569
|
-
NumberProperty, "Number",
|
570
|
-
PeopleProperty, "People",
|
571
|
-
PhoneNumberProperty, "PhoneNumber",
|
572
|
-
RelationProperty, "Relation",
|
573
|
-
RollupProperty, "Rollup",
|
574
|
-
RichTextProperty, "RichText",
|
575
|
-
SelectProperty, "Select",
|
576
|
-
TitleProperty, "Title",
|
577
|
-
UrlProperty, "Url"
|
578
|
-
fp, msp, np, rp, rup, sp = db.properties.values_at "Formula", "MultiSelect", "Number", "Relation", "Rollup", "Select"
|
579
|
-
fp.formula_expression = "now()"
|
580
|
-
msp.add_multi_select_options name: "MS1", color: "orange"
|
581
|
-
msp.add_multi_select_options name: "MS2", color: "green"
|
582
|
-
np.format = "yen"
|
583
|
-
rp.replace_relation_database database_id: tc.database_id
|
584
|
-
rup.relation_property_name = "Relation"
|
585
|
-
rup.rollup_property_name = "NumberTitle"
|
586
|
-
rup.function = "sum"
|
587
|
-
sp.add_select_options name: "S1", color: "yellow"
|
588
|
-
sp.add_select_options name: "S2", color: "default"
|
589
|
-
db.set_icon emoji: "🎉"
|
590
|
-
db.save
|
591
|
-
```
|
592
|
-
|
593
|
-
#### 4.2.5 Update database properties
|
594
|
-
|
595
|
-
`save` method updates existing database properties. The database needs to be retrieved using `find` to prevent existing settings from disappearing.
|
596
|
-
|
597
|
-
```Ruby
|
598
|
-
db = Database.find "c7697137d49f49c2bbcdd6a665c4f921"
|
599
|
-
fp, msp, np, rp, rup, sp = db.properties.values_at "Formula", "MultiSelect", "Number", "Relation", "Rollup", "Select"
|
600
|
-
fp.formula_expression = "pi"
|
601
|
-
msp.add_multi_select_options name: "MS3", color: "blue"
|
602
|
-
np.format = "percent"
|
603
|
-
rp.replace_relation_database database_id: tc.database_id, synced_property_name: "Renamed table"
|
604
|
-
rup.function = "average"
|
605
|
-
sp.add_select_options name: "S3", color: "red"
|
606
|
-
db.set_icon emoji: "🎉"
|
607
|
-
db.database_title << "(Added)"
|
608
|
-
db.save
|
609
|
-
```
|
610
|
-
|
611
|
-
#### 4.2.6 Add a database property
|
612
|
-
|
613
|
-
`add_property` can add a database property.
|
614
|
-
|
615
|
-
```Ruby
|
616
|
-
db = Database.find "c7697137d49f49c2bbcdd6a665c4f921"
|
617
|
-
db.add_property NumberProperty, "added number property" do |np|
|
618
|
-
np.format = "euro" # arrange option
|
619
|
-
end
|
620
|
-
db.add_property UrlProperty, "added url property" # UrlProperty has no option
|
621
|
-
db.save
|
622
|
-
```
|
623
|
-
|
624
|
-
- result of dry run
|
625
|
-
|
626
|
-
```bash
|
627
|
-
#!/bin/sh
|
628
|
-
curl -X PATCH 'https://api.notion.com/v1/databases/c7697137d49f49c2bbcdd6a665c4f921'\
|
629
|
-
-H 'Notion-Version: 2022-02-22'\
|
630
|
-
-H 'Authorization: Bearer '"$NOTION_API_KEY"''\
|
631
|
-
-H 'Content-Type: application/json'\
|
632
|
-
--data '{"properties":{"added number property":{"number":{"format":"euro"}},"added url property":{"url":{}}}}'⏎
|
633
|
-
```
|
634
|
-
|
635
|
-
#### 4.2.7 Rename a database property
|
636
|
-
|
637
|
-
`rename_property` can rename a database property.
|
638
|
-
|
639
|
-
```Ruby
|
640
|
-
properties = db.properties
|
641
|
-
properties["added number property"].new_name = "renamed number property"
|
642
|
-
properties["added url property"].new_name = "renamed url property"
|
643
|
-
db.save
|
644
|
-
```
|
645
|
-
|
646
|
-
- result of dry run
|
647
|
-
|
648
|
-
```bash
|
649
|
-
#!/bin/sh
|
650
|
-
curl -X PATCH 'https://api.notion.com/v1/databases/c7697137d49f49c2bbcdd6a665c4f921'\
|
651
|
-
-H 'Notion-Version: 2022-02-22'\
|
652
|
-
-H 'Authorization: Bearer '"$NOTION_API_KEY"''\
|
653
|
-
-H 'Content-Type: application/json'\
|
654
|
-
--data '{"properties":{"added number property":{"name":"renamed number property"},"added url property":{"name":"renamed url property"}}}'
|
655
|
-
```
|
656
|
-
|
657
|
-
#### 4.2.8 Remove database properties
|
658
|
-
|
659
|
-
`remove_properties' can remove some database properties.
|
660
|
-
|
661
|
-
```Ruby
|
662
|
-
db.remove_property "renamed number property", "renamed url property"
|
663
|
-
```
|
664
|
-
|
665
|
-
- result of dry run
|
666
|
-
|
667
|
-
```bash
|
668
|
-
#!/bin/sh
|
669
|
-
curl -X PATCH 'https://api.notion.com/v1/databases/c7697137d49f49c2bbcdd6a665c4f921'\
|
670
|
-
-H 'Notion-Version: 2022-02-22'\
|
671
|
-
-H 'Authorization: Bearer '"$NOTION_API_KEY"''\
|
672
|
-
-H 'Content-Type: application/json'\
|
673
|
-
--data '{"properties":{"renamed number property":null,"renamed url property":null}}'
|
674
|
-
```
|
675
|
-
|
676
|
-
#### 4.2.9 other methods
|
677
|
-
|
678
|
-
- `Database.find id, dry_run: true` create shell script for verification.
|
679
|
-
- `db.save` call Notion API, and so on and replace object information.
|
680
|
-
- `db.save dry_run: true` create shell script for verification.
|
681
|
-
- `db.new_record?` returns true if the database was generated by `create_child_database`.
|
682
|
-
- `db.database_title` returns plain_text string of `Database`.
|
683
|
-
- `db.title` returns plain_text string of `TitleProperty`.
|
684
|
-
- `db.icon` returns JSON hash for the page icon.
|
685
|
-
- `db[key]` returns a hash or an array object except "properties".
|
686
|
-
- `db.created_time` returns CreatedTimeProperty for filter
|
687
|
-
- `db.last_edited_time` returns LastEditedTimeProperty for filter
|
688
|
-
|
689
|
-
### 4.3 List class
|
690
|
-
|
691
|
-
`db.query_database` and other API list results returns a List object.
|
692
|
-
The list object is an Enumerable object, so usually combines with `.each` method.
|
693
|
-
|
694
|
-
```Ruby
|
695
|
-
db.query_database(query).each do |page|
|
696
|
-
# exec some methods for a page object
|
697
|
-
end
|
698
|
-
```
|
699
|
-
|
700
|
-
Notion API returns only the first page-size objects.
|
701
|
-
The default page-size of this library is 100.
|
702
|
-
Since the above `.each` method is supported for paging, it will automatically execute API call that obtain the following 100 objects when you used the first 100 objects.
|
703
|
-
Users do not have to worry about paging.
|
704
|
-
|
705
|
-
### 4.4 Block class
|
706
|
-
|
707
|
-
=== under construction ===
|
708
|
-
|
709
|
-
### 4.5 Property classes
|
710
|
-
|
711
|
-
#### 4.5.1 How to obtain Property object
|
712
|
-
|
713
|
-
There are the following 17 XXXProperty classes corresponding to Notion databases.
|
714
|
-
|
715
|
-
1. TitleProperty
|
716
|
-
2. RichTextProperty
|
717
|
-
3. UrlProperty
|
718
|
-
4. EmailProperty
|
719
|
-
5. PhoneNumberProperty
|
720
|
-
6. NumberProperty
|
721
|
-
7. CheckboxProperty
|
722
|
-
8. SelectProperty
|
723
|
-
9. MultiSelectProperty
|
724
|
-
10. PeopleProperty
|
725
|
-
11. CreatedByProperty
|
726
|
-
12. LastEditedByProperty
|
727
|
-
13. DateProperty
|
728
|
-
14. CreatedTimeProperty
|
729
|
-
15. LastEditedTimeProperty
|
730
|
-
16. FilesProperty
|
731
|
-
17. FormulaProperty
|
732
|
-
|
733
|
-
They are child classes of a `Property` class and generated from Page or Database objects.
|
734
|
-
|
735
|
-
```Ruby
|
736
|
-
page = Page.new page_id, assign: [XXXProperty, "property_name"]
|
737
|
-
# or
|
738
|
-
page = Page.find page_id
|
739
|
-
|
740
|
-
xp = page.properties["property_name"]
|
741
|
-
# or
|
742
|
-
xp, yp = page.properties.values_at "xp_name", "yp_name"
|
743
|
-
```
|
744
|
-
|
745
|
-
Page properties and database properties are objects of the same class, but there are methods for page properties and methods for database properties.
|
746
|
-
|
747
|
-
#### 4.5.2 Query object generator of property objects
|
748
|
-
|
749
|
-
The following methods for the Property objects generate a query object. These methods can be used for page properties and database properties.
|
750
|
-
|
751
|
-
- TitleProperty, RichTextProperty, UrlProperty, EmailProperty, PhoneNumberProperty
|
752
|
-
- filter_equals(value)
|
753
|
-
- filter_does_not_equal(value)
|
754
|
-
- filter_contains(value)
|
755
|
-
- filter_does_not_contain(value)
|
756
|
-
- filter_starts_with(value)
|
757
|
-
- filter_ends_with(value)
|
758
|
-
- filter_is_empty
|
759
|
-
- filter_is_not_empty
|
760
|
-
- NumberProperty
|
761
|
-
- filter_equals(value)
|
762
|
-
- filter_does_not_equal(value)
|
763
|
-
- filter_greater_than(value)
|
764
|
-
- filter_less_than(value)
|
765
|
-
- filter_greater_than_or_equal_to(value)
|
766
|
-
- filter_less_than_or_equal_to(value)
|
767
|
-
- filter_is_empty
|
768
|
-
- filter_is_not_empty
|
769
|
-
- CheckboxProperty
|
770
|
-
- filter_equals(value)
|
771
|
-
- filter_does_not_equal(value)
|
772
|
-
- SelectProperty
|
773
|
-
- filter_equals(value)
|
774
|
-
- filter_does_not_equal(value)
|
775
|
-
- filter_is_empty
|
776
|
-
- filter_is_not_empty
|
777
|
-
- MultiSelectProperty, PeopleProperty, CreatedByProperty, LastEditedByProperty
|
778
|
-
- filter_contains(value)
|
779
|
-
- filter_does_not_contain(value)
|
780
|
-
- filter_is_empty
|
781
|
-
- filter_is_not_empty
|
782
|
-
- DateProperty, CreatedTimeProperty, LastEditedTimeProperty
|
783
|
-
- filter_equals(value(Date / Time / DateTime / String))
|
784
|
-
- filter_does_not_equal(value(Date / Time / DateTime / String))
|
785
|
-
- filter_before(value(Date / Time / DateTime / String))
|
786
|
-
- filter_after(value(Date / Time / DateTime / String))
|
787
|
-
- filter_on_or_before(value(Date / Time / DateTime / String))
|
788
|
-
- filter_on_or_after(value(Date / Time / DateTime / String))
|
789
|
-
- filter_past_week
|
790
|
-
- filter_past_month
|
791
|
-
- filter_past_year
|
792
|
-
- filter_next_week
|
793
|
-
- filter_next_month
|
794
|
-
- filter_next_year
|
795
|
-
- FilesProperty
|
796
|
-
- filter_is_empty
|
797
|
-
- filter_is_not_empty
|
798
|
-
- FormulaProperty
|
799
|
-
- filter_equals(value(Date / Time / DateTime / String))
|
800
|
-
- filter_does_not_equal(value(Date / Time / DateTime / String))
|
801
|
-
- filter_before(value(Date / Time / DateTime / String))
|
802
|
-
- filter_after(value(Date / Time / DateTime / String))
|
803
|
-
- filter_on_or_before(value(Date / Time / DateTime / String))
|
804
|
-
- filter_on_or_after(value(Date / Time / DateTime / String))
|
805
|
-
- filter_past_week
|
806
|
-
- filter_past_month
|
807
|
-
- filter_past_year
|
808
|
-
- filter_next_week
|
809
|
-
- filter_next_month
|
810
|
-
- filter_next_year
|
811
|
-
- filter_contains(value)
|
812
|
-
- filter_does_not_contain(value)
|
813
|
-
- filter_starts_with(value)
|
814
|
-
- filter_ends_with(value)
|
815
|
-
- filter_greater_than(value)
|
816
|
-
- filter_less_than(value)
|
817
|
-
- filter_greater_than_or_equal_to(value)
|
818
|
-
- filter_less_than_or_equal_to(value)
|
819
|
-
- filter_is_empty
|
820
|
-
- filter_is_not_empty
|
821
|
-
|
822
|
-
#### 4.5.3 create or update values for Page properties
|
823
|
-
|
824
|
-
Retrieving Page object with `find` method has page properties of XXXProperties with values. On the other hand, Assigned Page object has also XXXProperties, but they don't have any information for pages.
|
825
|
-
|
826
|
-
XXXProperties can change property values by setter methods. Since the setter method is different for each class, it will be explained separately.
|
827
|
-
|
828
|
-
##### 4.5.3.1 NumberProperty
|
829
|
-
|
830
|
-
NumberProperty can set a number by `.number=`.
|
831
|
-
|
832
|
-
```Ruby
|
833
|
-
np = page.properties["NumberTitle"]
|
834
|
-
np.number = 3.14
|
835
|
-
p np.property_values_json
|
836
|
-
# Result => => {"np"=>{"number"=>3.14, "type"=>"number"}}
|
837
|
-
```
|
838
|
-
|
839
|
-
##### 4.5.3.2 SelectProperty
|
840
|
-
|
841
|
-
SelectProperty can set a select name by `.select=`.
|
842
|
-
|
843
|
-
```Ruby
|
844
|
-
sp = page.properties["SelectTitle"]
|
845
|
-
sp.select = "Select 2"
|
846
|
-
p sp.property_values_json
|
847
|
-
# Result => {"sp"=>{"type"=>"select", "select"=>{"name"=>"Select 2"}}}
|
848
|
-
```
|
849
|
-
|
850
|
-
##### 4.5.3.3 MultiSelectProperty
|
851
|
-
|
852
|
-
MultiSelectProperty can set a select value or Array of select values by `.multi_select=`.
|
853
|
-
|
854
|
-
```Ruby
|
855
|
-
msp = page.properties["MultiSelectTitle"]
|
856
|
-
msp.multi_select = "MS2"
|
857
|
-
p msp.property_values_json
|
858
|
-
# Result => {"msp"=>{"type"=>"multi_select", "multi_select"=>[{"name"=>"MS2"}]}}
|
859
|
-
|
860
|
-
msp.multi_select = %w[MS2 MS1]
|
861
|
-
p msp.property_values_json
|
862
|
-
# Result => {"msp"=>{"type"=>"multi_select", "multi_select"=>[{"name"=>"MS2"}, {"name"=>"MS1"}]}}
|
863
|
-
```
|
864
|
-
|
865
|
-
##### 4.5.3.4 DateProperty
|
866
|
-
|
867
|
-
DateProperty can set a start_date or end_date by `.start_date=` or `end_date=`.
|
868
|
-
Date, Time, DateTime or String object can be used to the argument.
|
869
|
-
|
870
|
-
```Ruby
|
871
|
-
dp = page.properties["DateTitle"]
|
872
|
-
dp.start_date = Date.new(2022, 2, 22)
|
873
|
-
p dp.property_values_json
|
874
|
-
# Result => {"dp"=>{"type"=>"date", "date"=>{"start"=>"2022-02-22", "end"=>nil, "time_zone"=>nil}}}
|
875
|
-
|
876
|
-
dp.start_date = Time.new(2022, 2, 22, 1, 23, 45, "+09:00")
|
877
|
-
p dp.property_values_json
|
878
|
-
# Result =>{"dp"=>{"type"=>"date", "date"=>{"start"=>"2022-02-22T01:23:45+09:00", "end"=>nil, "time_zone"=>nil}}}
|
879
|
-
|
880
|
-
dp.start_date = DateTime.new(2022, 2, 23, 1, 23, 45, "+09:00")
|
881
|
-
p dp.property_values_json
|
882
|
-
# Result => {"dp"=>{"type"=>"date", "date"=>{"start"=>"2022-02-23T01:23:45+09:00", "end"=>nil, "time_zone"=>nil}}}
|
883
|
-
|
884
|
-
dp.start_date = Date.new(2022, 2, 20)
|
885
|
-
dp.end_date = Date.new(2022, 2, 22)
|
886
|
-
p dp.property_values_json
|
887
|
-
# Result => => {"dp"=>{"type"=>"date", "date"=>{"start"=>"2022-02-20", "end"=>"2022-02-22", "time_zone"=>nil}}}
|
888
|
-
|
889
|
-
dp.start_date = Time.new(2022, 2, 21, 1, 23, 45, "+09:00")
|
890
|
-
dp.end_date = Time.new(2022, 2, 22, 1, 23, 45, "+09:00")
|
891
|
-
p dp.property_values_json
|
892
|
-
# Result => {"start" => "2022-02-21T01:23:45+09:00", "end" => "2022-02-22T01:23:45+09:00"}
|
893
|
-
|
894
|
-
dp.start_date = DateTime.new(2022, 2, 21, 1, 23, 45, "+09:00")
|
895
|
-
dp.end_date = DateTime.new(2022, 2, 22, 1, 23, 45, "+09:00")
|
896
|
-
p dp.property_values_json
|
897
|
-
# result => {"dp"=>{"type"=>"date", "date"=>{"start"=>"2022-02-21T01:23:45+09:00", "end"=>nil, "time_zone"=>nil}}}
|
898
|
-
```
|
899
|
-
|
900
|
-
##### 4.5.3.4 UrlProperty
|
901
|
-
|
902
|
-
UrlProperty can set a url by `.url=`.
|
903
|
-
|
904
|
-
```Ruby
|
905
|
-
up = page.properties["UrlTitle"]
|
906
|
-
up.url = "https://www.google.com/"
|
907
|
-
p up.property_values_json
|
908
|
-
# result => {"up"=>{"url"=>"https://www.google.com/", "type"=>"url"}}
|
909
|
-
```
|
910
|
-
|
911
|
-
##### 4.5.3.5 EmailProperty
|
912
|
-
|
913
|
-
EmailProperty can set an email by `.email=`.
|
914
|
-
|
915
|
-
```Ruby
|
916
|
-
ep = page.properties["MailTitle"]
|
917
|
-
ep.email = "https://www.google.com/"
|
918
|
-
p ep.property_values_json
|
919
|
-
# result => {"ep"=>{"email"=>"hkobhkob@gmail.com", "type"=>"email"}}
|
920
|
-
```
|
921
|
-
|
922
|
-
##### 4.5.3.6 PhoneNumberProperty
|
923
|
-
|
924
|
-
PhoneNumberProperty can set an phone number by `.phone_number=`.
|
925
|
-
|
926
|
-
```Ruby
|
927
|
-
pp = page.properties["TelTitle"]
|
928
|
-
pp.phone_number = "xx-xxxx-xxxx"
|
929
|
-
p pp.property_values_json
|
930
|
-
# result => {"pp"=>{"phone_number"=>"xx-xxxx-xxxx", "type"=>"phone_number"}}
|
931
|
-
```
|
932
|
-
|
933
|
-
##### 4.5.3.7 PeopleProperty
|
934
|
-
|
935
|
-
PeopleProperty can set an people by `.people=`.
|
936
|
-
PeopleProperty can set a user_id/UserObject value or Array of user_id/UserObject values by `.people=`.
|
937
|
-
|
938
|
-
```Ruby
|
939
|
-
pp = page.properties["UserTitle"]
|
940
|
-
pp.people = "user_id1"
|
941
|
-
p pp.property_values_json
|
942
|
-
# result => {"pp"=>{"type"=>"people", "people"=>[{"object"=>"user", "id"=>"user_id1"}]}}
|
943
|
-
|
944
|
-
pp.people = UserObject.new json: user1_json
|
945
|
-
p pp.property_values_json
|
946
|
-
# result => {"pp"=>{"type"=>"people", "people"=>[{"object"=>"user", "id"=>"user_id1_from_json"}]}}
|
947
|
-
```
|
948
|
-
|
949
|
-
```Ruby
|
950
|
-
pp.people = %w[user_id2 user_id3]
|
951
|
-
p pp.property_values_json
|
952
|
-
# result => {"pp"=>{"type"=>"people", "people"=>[{"object"=>"user", "id"=>"user_id2"}, {"object"=>"user", "id"=>"user_id3"}]}}
|
953
|
-
|
954
|
-
u2 = UserObject.new(json: user2_json)
|
955
|
-
u3 = UserObject.new(json: user3_json)
|
956
|
-
pp.people = [u2, u3]
|
957
|
-
p pp.property_values_json
|
958
|
-
# result => {"pp"=>{"type"=>"people", "people"=>[{"object"=>"user", "id"=>"user_id2_from_json"}, {"object"=>"user", "id"=>"user_id3_from_json"}]}}
|
959
|
-
```
|
960
|
-
|
961
|
-
##### 4.5.3.8 TitleProperty, RichTextProperty
|
962
|
-
|
963
|
-
TextProperty's subclasses (TitleProperty, RichTextProperty) have an array of TextObject objects.
|
964
|
-
`[]` method returns an existing TextObject.
|
965
|
-
The obtained TextObject can be set text by `.text=`.
|
966
|
-
|
967
|
-
```Ruby
|
968
|
-
pp = page.properties["Title"]
|
969
|
-
tp[0].text = "ABC\n"
|
970
|
-
p tp.property_values_json
|
971
|
-
# result => {"tp"=>{"type"=>"title", "title"=>[{"type"=>"text", "text"=>{"content"=>"ABC\n", "link"=>nil}, "plain_text"=>"ABC\n", "href"=>nil}]}}
|
972
|
-
```
|
973
|
-
|
974
|
-
`<<` method appends a new TextObject or a String.
|
975
|
-
|
976
|
-
```Ruby
|
977
|
-
to = TextObject.new "DEF"
|
978
|
-
to.bold = true
|
979
|
-
to.italic = true
|
980
|
-
to.strikethrough = true
|
981
|
-
to.underline = true
|
982
|
-
to.code = true
|
983
|
-
to.color = "default"
|
984
|
-
tp << to
|
985
|
-
p tp.property_values_json
|
986
|
-
# result => {"tp"=>{"type"=>"title","title"=>[{"type"=>"text","text"=>{"content"=>"ABC\n","link"=>nil},"plain_text"=>"ABC\n","href"=>nil},{"type"=>"text","text"=>{"content"=>"DEF","link"=>nil},"plain_text"=>"DEF","href"=>nil,"annotations"=>{"bold"=>true,"italic"=>true,"strikethrough"=>true,"underline"=>true,"code"=>true,"color"=>"default"}}]}}
|
987
|
-
```
|
988
|
-
|
989
|
-
`delete_at(index)` method remove a TextObject at index.
|
990
|
-
|
991
|
-
```Ruby
|
992
|
-
tp.delete_at 1
|
993
|
-
tp << "GHI"
|
994
|
-
p tp.property_values_json
|
995
|
-
# result => {"tp"=>{"type"=>"title", "title"=>[{"type"=>"text", "text"=>{"content"=>"ABC\n", "link"=>nil}, "plain_text"=>"ABC\n", "href"=>nil}, {"type"=>"text", "text"=>{"content"=>"DEF", "link"=>nil}, "plain_text"=>"DEF", "href"=>nil, "annotations"=>{"bold"=>true, "italic"=>true, "strikethrough"=>true, "underline"=>true, "code"=>true, "color"=>"default"}}, {"type"=>"text", "text"=>{"content"=>"GHI", "link"=>nil}, "plain_text"=>"GHI", "href"=>nil}]}}
|
996
|
-
```
|
997
|
-
|
998
|
-
##### 4.5.3.9 CheckboxProperty
|
999
|
-
|
1000
|
-
CheckboxProperty can set a boolean value by `.checkbox=`.
|
1001
|
-
|
1002
|
-
```Ruby
|
1003
|
-
cp = page.properties["CheckboxTitle"]
|
1004
|
-
cp.checkbox = true
|
1005
|
-
p cp.property_values_json
|
1006
|
-
# result => {"cp"=>{"checkbox"=>true, "type"=>"checkbox"}}
|
1007
|
-
```
|
1008
|
-
|
1009
|
-
##### 4.5.3.10 FilesProperty
|
1010
|
-
|
1011
|
-
FilesProperty can set an external url or Array of external urls by `.files=`.
|
1012
|
-
|
1013
|
-
```Ruby
|
1014
|
-
fp = page.properties["FilesTitle"]
|
1015
|
-
fp.files = "F1"
|
1016
|
-
p fp.property_values_json
|
1017
|
-
# Result => {"fp"=>{"files"=>[{"name"=>"F1", "type"=>"external", "external"=>{"url"=>"F1"}}], "type"=>"files"}}
|
1018
|
-
|
1019
|
-
fp.files = %w[F2 F3]
|
1020
|
-
p fp.property_values_json
|
1021
|
-
# Result => {"fp"=>{"files"=>[{"name"=>"F2", "type"=>"external", "external"=>{"url"=>"F2"}}, {"name"=>"F3", "type"=>"external", "external"=>{"url"=>"F3"}}], "type"=>"files"}}
|
1022
|
-
```
|
1023
|
-
|
1024
|
-
##### 4.5.3.11 RelationProperty
|
1025
|
-
|
1026
|
-
RelationProperty can set an relation's page_id or Array of relation's page_ids by `.relation=`.
|
1027
|
-
|
1028
|
-
```Ruby
|
1029
|
-
rp = page.properties["RelationTitle"]
|
1030
|
-
rp.relation = "R1"
|
1031
|
-
p rp.property_values_json
|
1032
|
-
# Result => {"rp"=>{"type"=>"relation", "relation"=>[{"id"=>"R1"}]}}
|
1033
|
-
|
1034
|
-
rp.relation = %w[R2 R3]
|
1035
|
-
p rp.property_values_json
|
1036
|
-
# Result => {"rp"=>{"type"=>"relation", "relation"=>[{"id"=>"R2"}, {"id"=>"R3"}]}}
|
1037
|
-
```
|
1038
|
-
|
1039
|
-
#### 4.5.4 create or update values for Database properties
|
1040
|
-
|
1041
|
-
Retrieving Database object with `find` method has database properties of XXXProperties with values. On the other hand, Assigned Database object has also XXXProperties, but they don't have any information for databases.
|
1042
|
-
|
1043
|
-
XXXProperties can change property values by setter methods. Since the setter method is different for each class, it will be explained separately.
|
1044
|
-
|
1045
|
-
##### 4.5.4.1 NumberProperty
|
64
|
+
### 2.3 Sample codes
|
1046
65
|
|
1047
|
-
|
66
|
+
1. [Database and page access sample](https://www.notion.so/hkob/Database-and-page-access-sample-d30033e707194faf995741167eb2b6f8)
|
67
|
+
1. [Append block children sample](https://www.notion.so/hkob/Append-block-children-sample-3867910a437340be931cf7f2c06443c6)
|
68
|
+
1. [Update block sample](https://www.notion.so/hkob/update-block-sample-5568c1c36fe84f12b83edfe2dda83028)
|
1048
69
|
|
1049
|
-
|
1050
|
-
np = db.properties["NumberTitle"]
|
1051
|
-
np.format = "percent"
|
1052
|
-
print np.property_schema_json
|
1053
|
-
# Result => {"NumberTitle"=>{"number"=>{"format"=>"percent"}}}
|
1054
|
-
```
|
1055
|
-
|
1056
|
-
##### 4.5.4.2 SelectProperty
|
70
|
+
### 2.4. Another example code (Use case)
|
1057
71
|
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
sp = db.properties["SelectTitle"]
|
1062
|
-
sp.add_select_options name: "S3", color: "red"
|
1063
|
-
print sp.property_schema_json
|
1064
|
-
# Result => {"Select"=>{"select"=>{"options"=>[{"id"=>"56a526e1-0cec-4b85-b9db-fc68d00e50c6", "name"=>"S1", "color"=>"yellow"}, {"id"=>"6ead7aee-d7f0-40ba-aa5e-59bccf6c50c8", "name"=>"S2", "color"=>"default"}, {"name"=>"S3", "color"=>"red"}]}}}
|
1065
|
-
```
|
1066
|
-
|
1067
|
-
If you want to edit existing values, you should access `edit_select_options` array. It sets `will_update` flag to true.
|
1068
|
-
|
1069
|
-
```Ruby
|
1070
|
-
sp.edit_select_options[0]["name"] = "new S1"
|
1071
|
-
p sp.property_values_json
|
1072
|
-
# Result => {"Select"=>{"select"=>{"options"=>[{"id"=>"56a526e1-0cec-4b85-b9db-fc68d00e50c6", "name"=>"new S1", "color"=>"yellow"}, {"id"=>"6ead7aee-d7f0-40ba-aa5e-59bccf6c50c8", "name"=>"S2", "color"=>"default"}]}}}⏎
|
1073
|
-
```
|
1074
|
-
|
1075
|
-
##### 4.5.4.3 MultiSelectProperty
|
1076
|
-
|
1077
|
-
MultiSelectProperty can add a new option by `.add_multi_select_options`.
|
1078
|
-
|
1079
|
-
```Ruby
|
1080
|
-
msp = db.properties["MultiSelectTitle"]
|
1081
|
-
msp.add_multi_select_options name: "MS3", color: "blue"
|
1082
|
-
print msp.property_schema_json
|
1083
|
-
# Result => {"MultiSelectTitle"=>{"multi_select"=>{"options"=>[{"id"=>"98aaa1c0-4634-47e2-bfae-d739a8c5e564", "name"=>"MS1", "color"=>"orange"}, {"id"=>"71756a93-cfd8-4675-b508-facb1c31af2c", "name"=>"MS2", "color"=>"green"}, {"name"=>"MS3", "color"=>"blue"}]}}}
|
1084
|
-
```
|
1085
|
-
|
1086
|
-
If you want to edit existing values, you should access `edit_multi_select_options` array. It sets `will_update` flag to true.
|
1087
|
-
|
1088
|
-
```Ruby
|
1089
|
-
msp.edit_multi_select_options[0]["name"] = "new MS1"
|
1090
|
-
p msp.property_values_json
|
1091
|
-
# Result => {"MultiSelectTitle"=>{"multi_select"=>{"options"=>[{"id"=>"98aaa1c0-4634-47e2-bfae-d739a8c5e564", "name"=>"new MS1", "color"=>"orange"}, {"id"=>"71756a93-cfd8-4675-b508-facb1c31af2c", "name"=>"MS2", "color"=>"green"}]}}}⏎
|
1092
|
-
```
|
1093
|
-
|
1094
|
-
##### 4.5.4.4 DateProperty
|
1095
|
-
|
1096
|
-
DateProperty has no option.
|
1097
|
-
|
1098
|
-
```Ruby
|
1099
|
-
dp = db.properties["DateTitle"]
|
1100
|
-
print dp.property_schema_json
|
1101
|
-
# Result => {"DateTitle"=>{"date"=>{}}}
|
1102
|
-
```
|
1103
|
-
|
1104
|
-
##### 4.5.4.4 UrlProperty
|
1105
|
-
|
1106
|
-
UrlProperty has no option.
|
1107
|
-
|
1108
|
-
```Ruby
|
1109
|
-
up = db.properties["UrlTitle"]
|
1110
|
-
print up.property_schema_json
|
1111
|
-
# Result => {"UrlTitle"=>{"url"=>{}}}
|
1112
|
-
```
|
1113
|
-
|
1114
|
-
##### 4.5.4.5 EmailProperty
|
1115
|
-
|
1116
|
-
EmailProperty has no option.
|
1117
|
-
|
1118
|
-
```Ruby
|
1119
|
-
ep = db.properties["MailTitle"]
|
1120
|
-
print ep.property_schema_json
|
1121
|
-
# Result => {"MailTitle"=>{"email"=>{}}}
|
1122
|
-
```
|
1123
|
-
|
1124
|
-
##### 4.5.4.6 PhoneNumberProperty
|
1125
|
-
|
1126
|
-
PhoneNumberProperty has no option.
|
1127
|
-
|
1128
|
-
```Ruby
|
1129
|
-
pp = db.properties["TelTitle"]
|
1130
|
-
print ep.property_schema_json
|
1131
|
-
# Result => {"TelTitle"=>{"phone_number"=>{}}}
|
1132
|
-
```
|
1133
|
-
|
1134
|
-
##### 4.5.4.7 PeopleProperty
|
1135
|
-
|
1136
|
-
PeopleProperty has no option.
|
1137
|
-
|
1138
|
-
```Ruby
|
1139
|
-
usp = db.properties["UserTitle"]
|
1140
|
-
print usp.property_schema_json
|
1141
|
-
# Result => {"UserTitle"=>{"people"=>{}}}
|
1142
|
-
```
|
1143
|
-
|
1144
|
-
##### 4.5.4.8 TitleProperty, RichTextProperty
|
1145
|
-
|
1146
|
-
TitleProperty and RichTextProperty have no option.
|
1147
|
-
|
1148
|
-
```Ruby
|
1149
|
-
tp, rtp = db.properties.values_at "Title", "TextTitle"
|
1150
|
-
print tp.property_schema_json
|
1151
|
-
# Result => {"Title"=>{"title"=>{}}}
|
1152
|
-
print rtp.property_schema_json
|
1153
|
-
# Result => {"TextTitle"=>{"rich_text"=>{}}}
|
1154
|
-
```
|
1155
|
-
|
1156
|
-
##### 4.5.4.9 CheckboxProperty
|
1157
|
-
|
1158
|
-
CheckboxProperty has no option.
|
1159
|
-
|
1160
|
-
```Ruby
|
1161
|
-
cp = db.properties["CheckboxTitle"]
|
1162
|
-
print cp.property_schema_json
|
1163
|
-
# Result => {"CheckboxTitle"=>{"checkbox"=>{}}}
|
1164
|
-
```
|
1165
|
-
|
1166
|
-
##### 4.5.4.10 FilesProperty
|
1167
|
-
|
1168
|
-
FilesProperty has no option.
|
1169
|
-
|
1170
|
-
```Ruby
|
1171
|
-
fp = db.properties["FilesTitle"]
|
1172
|
-
print fp.property_schema_json
|
1173
|
-
# Result => {"FilesTitle"=>{"files"=>{}}}
|
1174
|
-
```
|
1175
|
-
|
1176
|
-
##### 4.5.4.11 RelationProperty
|
1177
|
-
|
1178
|
-
RelationProperty can set an relation's database_id by `.replace_relation_database`.
|
1179
|
-
|
1180
|
-
```Ruby
|
1181
|
-
rp = db.properties["RelationTitle"]
|
1182
|
-
rp.replace_relation_database database_id: "new database id"
|
1183
|
-
p rp.property_values_json
|
1184
|
-
# Result => {"Relation"=>{"relation"=>{"database_id"=>"new database id"}}}
|
1185
|
-
```
|
1186
|
-
|
1187
|
-
##### 4.5.4.12 RollupProperty
|
1188
|
-
|
1189
|
-
RollupProperty can set rollup property name, relation property name and function by `.rollup_property_name=`, `relation_property_name=` and `function=`, respectively.
|
1190
|
-
|
1191
|
-
```Ruby
|
1192
|
-
rup = db.properties["RollupTitle"]
|
1193
|
-
rup.relation_property_name = "new relation property name"
|
1194
|
-
rup.rollup_property_name = "new rollup property name"
|
1195
|
-
rup.function = "average"
|
1196
|
-
# Result => {"Rollup"=>{"rollup"=>{"function"=>"average", "relation_property_name"=>"new relation property name", "rollup_property_name"=>"new rollup property name"}}}
|
1197
|
-
```
|
1198
|
-
|
1199
|
-
## 5. XXXObjects and RichTextArray
|
1200
|
-
|
1201
|
-
### 5.1 RichTextObject
|
1202
|
-
|
1203
|
-
RichTextObject is an abstract class for TextObject and MentionObject.
|
1204
|
-
It can store a link and some annotations.
|
1205
|
-
|
1206
|
-
There are common instance methods for its subclass objects.
|
1207
|
-
|
1208
|
-
- plain_text=(value)
|
1209
|
-
- bold=(flag)
|
1210
|
-
- italic=(flag)
|
1211
|
-
- strikethrough=(flag)
|
1212
|
-
- underline=(flag)
|
1213
|
-
- code=(flag)
|
1214
|
-
- color=(color)
|
1215
|
-
|
1216
|
-
### 5.2 TextObject
|
1217
|
-
|
1218
|
-
TextObject is a class for texts.
|
1219
|
-
`TextObject.new(text)` creates a TextObject.
|
1220
|
-
After creating or retrieving TextObject, `to.text=` replaces including text.
|
1221
|
-
|
1222
|
-
```Ruby
|
1223
|
-
to = TextObject.new "first text"
|
1224
|
-
to.text = "replaced text"
|
1225
|
-
```
|
1226
|
-
|
1227
|
-
### 5.3 MentionObject
|
1228
|
-
|
1229
|
-
MentionObject is a class for mentions for user, page, database, date and template_mention.
|
1230
|
-
|
1231
|
-
```Ruby
|
1232
|
-
mention_user = MentionObject.new user_id: "user_id", plain_text: "m_user"
|
1233
|
-
mention_page = MentionObject.new page_id: "page_id", plain_text: "m_page"
|
1234
|
-
mention_db = MentionObject.new database_id: "database_id", plain_text: "m_db"
|
1235
|
-
mention_date = MentionObject.new start: "2022-03-17", plain_text: "m_date"
|
1236
|
-
mention_today = MentionObject.new mention_template: "today"
|
1237
|
-
mention_now = MentionObject.new mention_template: "now"
|
1238
|
-
mention_user = MentionObject.new mention_template: "user"
|
1239
|
-
```
|
1240
|
-
|
1241
|
-
### 5.4 UserObject
|
1242
|
-
|
1243
|
-
UserObject is a class for users.
|
1244
|
-
|
1245
|
-
```Ruby
|
1246
|
-
u = User.new id: "user_id"
|
1247
|
-
```
|
1248
|
-
|
1249
|
-
### 5.5 RichTextArray
|
1250
|
-
|
1251
|
-
Some properties and Database title have an array of RichTextObject. `RichTextArray` is the delegate class for the array of RichTextObject.
|
1252
|
-
Moreover, some methods of TitleProperty, RichTextProperty and Database.title delegate to the included RichTextArray.
|
1253
|
-
|
1254
|
-
#### 5.5.1 Constructor for RichTextArray
|
1255
|
-
|
1256
|
-
RichTextArray can be created by a String, some Strings, a RichTextObject and some RichTextObjects. String values will convert to simple TextObjects.
|
1257
|
-
|
1258
|
-
```Ruby
|
1259
|
-
nullString = RichTextArray.new "title"
|
1260
|
-
aString = RichTextArray.new "title", text_objects: "A string"
|
1261
|
-
twoStrings = RichTextArray.new "title", text_objects: %W[ABC\n DEF]
|
1262
|
-
aTextObject = RichTextArray.new "title", text_objects: TextObject.new "A TextObject"
|
1263
|
-
textMentionObjects = RichTextArray.new "title", [TextObject.new("A TextObject"), MentionObject.new(user_id: "ABC")]
|
1264
|
-
```
|
72
|
+
1. [Set icon to all icon unsettled pages](examples/set_icon_to_all_icon_unsettled_pages.md)
|
73
|
+
1. [Renumbering pages](examples/renumbering_pages.md)
|
74
|
+
1. [Change title](examples/change_title.md)
|
1265
75
|
|
1266
|
-
|
76
|
+
### 2.5 API reference
|
1267
77
|
|
1268
|
-
|
1269
|
-
- `rto[0]`: obtain the object specified by the index
|
1270
|
-
- `delete_at 0`: obtain the object specified by the index and delete from the array
|
1271
|
-
- `full_text`: obtain joined plain text
|
78
|
+
1. [Notion Ruby Mapping Public API reference](https://www.notion.so/hkob/Notion-Ruby-Mapping-Public-API-reference-4091aca15b664299b63e6253b7601fec)
|
1272
79
|
|
1273
|
-
##
|
80
|
+
## 3. ChangeLog
|
1274
81
|
|
1275
|
-
- 2022/
|
1276
|
-
- 2022/
|
1277
|
-
- 2022/
|
1278
|
-
- 2022/
|
1279
|
-
- 2022/3/
|
82
|
+
- 2022/6/4 [v0.5.0] added subclasses of the block class and update_block API support
|
83
|
+
- 2022/5/19 [v0.4.1] added delete_block
|
84
|
+
- 2022/4/29 [v0.4.0] Change directory structure, TEST_IDs are moved from env.yml to TestConnection's constants, added retrieve_block spec, added append_block_children
|
85
|
+
- 2022/4/27 added Base#children
|
86
|
+
- 2022/3/27 [v0.3.3] create_child_page can receive a block for initialization.
|
87
|
+
- 2022/3/27 [v0.3.2] properties of a created child page are automatically assigned using the parent database.
|
88
|
+
- 2022/3/25 [v0.3.0] added create_child_database, update_database, add_property, rename_property and remove_property
|
89
|
+
- 2022/3/17 [v0.2.3] added template_mention objects, tools/an command
|
90
|
+
- 2022/3/16 [v0.2.2] added database.create_child_page and base.save instead of base.update/create
|
1280
91
|
- 2022/3/15 Fixed not to reload from API when all contents are loaded
|
1281
|
-
- 2022/3/14 Exclude notion-ruby-client, update Property values, update for Notion-Version 2022-02-22
|
92
|
+
- 2022/3/14 [v0.2.0] Exclude notion-ruby-client, update Property values, update for Notion-Version 2022-02-22
|
1282
93
|
- 2022/2/25 add_property_for_update -> assign_property, update README.md
|
1283
94
|
- 2022/2/20 add support for MultiSelectProperty
|
1284
95
|
- 2022/2/19 add support for SelectProperty
|
@@ -1289,18 +100,14 @@ textMentionObjects = RichTextArray.new "title", [TextObject.new("A TextObject"),
|
|
1289
100
|
- 2022/2/13 added Page#set_icon
|
1290
101
|
- 2022/2/13 First commit
|
1291
102
|
|
1292
|
-
##
|
103
|
+
## 4. Contributing
|
1293
104
|
|
1294
105
|
Bug reports and pull requests are welcome on GitHub at <https://github.com/hkob/notion_ruby_mapping>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/notion_ruby_mapping/blob/main/CODE_OF_CONDUCT.md).
|
1295
106
|
|
1296
|
-
##
|
107
|
+
## 5. License
|
1297
108
|
|
1298
109
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
1299
110
|
|
1300
|
-
##
|
111
|
+
## 6. Code of Conduct
|
1301
112
|
|
1302
113
|
Everyone interacting in the NotionRubyMapping project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/notion_ruby_mapping/blob/main/CODE_OF_CONDUCT.md).
|
1303
|
-
|
1304
|
-
## 10. Acknowledgements
|
1305
|
-
|
1306
|
-
The code depends on [notion-ruby-client](https://github.com/orbit-love/notion-ruby-client).
|