notion_ruby_mapping 0.3.2 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -1224
  3. data/env.yml.sample +0 -13
  4. data/lib/notion_ruby_mapping/{base.rb → blocks/base.rb} +166 -90
  5. data/lib/notion_ruby_mapping/blocks/block.rb +565 -0
  6. data/lib/notion_ruby_mapping/{database.rb → blocks/database.rb} +40 -9
  7. data/lib/notion_ruby_mapping/{list.rb → blocks/list.rb} +35 -3
  8. data/lib/notion_ruby_mapping/blocks/page.rb +71 -0
  9. data/lib/notion_ruby_mapping/{notion_cache.rb → controllers/notion_cache.rb} +134 -98
  10. data/lib/notion_ruby_mapping/{payload.rb → controllers/payload.rb} +0 -0
  11. data/lib/notion_ruby_mapping/{property_cache.rb → controllers/property_cache.rb} +21 -20
  12. data/lib/notion_ruby_mapping/{query.rb → controllers/query.rb} +26 -18
  13. data/lib/notion_ruby_mapping/{rich_text_array.rb → controllers/rich_text_array.rb} +26 -15
  14. data/lib/notion_ruby_mapping/objects/emoji_object.rb +40 -0
  15. data/lib/notion_ruby_mapping/objects/equation_object.rb +43 -0
  16. data/lib/notion_ruby_mapping/objects/file_object.rb +60 -0
  17. data/lib/notion_ruby_mapping/{mention_object.rb → objects/mention_object.rb} +11 -0
  18. data/lib/notion_ruby_mapping/{rich_text_object.rb → objects/rich_text_object.rb} +11 -0
  19. data/lib/notion_ruby_mapping/{text_object.rb → objects/text_object.rb} +0 -1
  20. data/lib/notion_ruby_mapping/{user_object.rb → objects/user_object.rb} +9 -4
  21. data/lib/notion_ruby_mapping/{checkbox_property.rb → properties/checkbox_property.rb} +3 -0
  22. data/lib/notion_ruby_mapping/{created_by_property.rb → properties/created_by_property.rb} +0 -0
  23. data/lib/notion_ruby_mapping/{created_time_property.rb → properties/created_time_property.rb} +1 -0
  24. data/lib/notion_ruby_mapping/properties/date_base_property.rb +122 -0
  25. data/lib/notion_ruby_mapping/{date_property.rb → properties/date_property.rb} +13 -0
  26. data/lib/notion_ruby_mapping/{email_property.rb → properties/email_property.rb} +1 -0
  27. data/lib/notion_ruby_mapping/{files_property.rb → properties/files_property.rb} +26 -13
  28. data/lib/notion_ruby_mapping/{formula_property.rb → properties/formula_property.rb} +4 -0
  29. data/lib/notion_ruby_mapping/{last_edited_by_property.rb → properties/last_edited_by_property.rb} +1 -0
  30. data/lib/notion_ruby_mapping/{last_edited_time_property.rb → properties/last_edited_time_property.rb} +1 -0
  31. data/lib/notion_ruby_mapping/{multi_property.rb → properties/multi_property.rb} +0 -0
  32. data/lib/notion_ruby_mapping/{multi_select_property.rb → properties/multi_select_property.rb} +2 -3
  33. data/lib/notion_ruby_mapping/{number_property.rb → properties/number_property.rb} +4 -0
  34. data/lib/notion_ruby_mapping/{people_property.rb → properties/people_property.rb} +8 -3
  35. data/lib/notion_ruby_mapping/{phone_number_property.rb → properties/phone_number_property.rb} +4 -0
  36. data/lib/notion_ruby_mapping/{property.rb → properties/property.rb} +33 -0
  37. data/lib/notion_ruby_mapping/{relation_property.rb → properties/relation_property.rb} +30 -10
  38. data/lib/notion_ruby_mapping/{rich_text_property.rb → properties/rich_text_property.rb} +0 -0
  39. data/lib/notion_ruby_mapping/{rollup_property.rb → properties/rollup_property.rb} +7 -0
  40. data/lib/notion_ruby_mapping/{select_property.rb → properties/select_property.rb} +6 -1
  41. data/lib/notion_ruby_mapping/{text_property.rb → properties/text_property.rb} +0 -0
  42. data/lib/notion_ruby_mapping/{title_property.rb → properties/title_property.rb} +0 -0
  43. data/lib/notion_ruby_mapping/{url_property.rb → properties/url_property.rb} +5 -0
  44. data/lib/notion_ruby_mapping/version.rb +1 -1
  45. data/lib/notion_ruby_mapping.rb +14 -7
  46. metadata +43 -40
  47. data/lib/notion_ruby_mapping/block.rb +0 -10
  48. data/lib/notion_ruby_mapping/date_base_property.rb +0 -75
  49. data/lib/notion_ruby_mapping/page.rb +0 -50
data/README.md CHANGED
@@ -9,74 +9,17 @@ Development note is here. → [Idea note of "notion_ruby_mapping"](https://www.n
9
9
  - [notion_ruby_mapping](#notion_ruby_mapping)
10
10
  - [Table of Contents](#table-of-contents)
11
11
  - [1. Installation](#1-installation)
12
- - [2. Example code](#2-example-code)
13
- - [3. Preparation](#3-preparation)
14
- - [3.1 Create a New Integration](#31-create-a-new-integration)
15
- - [3.2 Create client](#32-create-client)
16
- - [4. Usage](#4-usage)
17
- - [4.1 Page](#41-page)
18
- - [4.1.1 Retrieve a page](#411-retrieve-a-page)
19
- - [4.1.2 Update page properties](#412-update-page-properties)
20
- - [4.1.3 Update other page information](#413-update-other-page-information)
21
- - [4.1.4 other methods](#414-other-methods)
22
- - [4.2 Database](#42-database)
23
- - [4.2.1 Retrieve a database](#421-retrieve-a-database)
24
- - [4.2.2 Query a database](#422-query-a-database)
25
- - [4.2.2.1 Complex conditions](#4221-complex-conditions)
26
- - [4.2.2.2 Sort criteria](#4222-sort-criteria)
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)
12
+ - [2. How to use](#2-how-to-use)
13
+ - [2.1 Create a New Integration](#21-create-a-new-integration)
14
+ - [2.2 Create client](#22-create-client)
15
+ - [2.3 Sample codes](#23-sample-codes)
16
+ - [2.4. Another example code (Use case)](#24-another-example-code-use-case)
17
+ - [2.5 API reference](#25-api-reference)
18
+ - [3. ChangeLog](#3-changelog)
19
+ - [4. Contributing](#4-contributing)
20
+ - [5. License](#5-license)
21
+ - [6. Code of Conduct](#6-code-of-conduct)
22
+ - [7. Acknowledgements](#7-acknowledgements)
80
23
 
81
24
  ## 1. Installation
82
25
 
@@ -98,1176 +41,43 @@ Or install it yourself as:
98
41
  gem install notion_ruby_mapping
99
42
  ```
100
43
 
101
- ## 2. Example code
44
+ ## 2. How to use
102
45
 
103
- 1. [Set icon to all icon unsettled pages](examples/set_icon_to_all_icon_unsettled_pages.md)
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
46
+ ### 2.1 Create a New Integration
110
47
 
111
48
  Please check [Notion documentation](https://developers.notion.com/docs#getting-started).
112
49
 
113
- ### 3.2 Create client
50
+ ### 2.2 Create client
114
51
 
115
52
  Please create a client (notion-ruby-client) before you use the following class.
116
53
 
117
54
  ```Ruby
118
- NotionCache.instance.create_client "Secret_XXXXXXXXXXXXXXXXXXXX" # write directly
55
+ NotionCache.instance.create_client "secret_XXXXXXXXXXXXXXXXXXXX" # write directly
119
56
  NotionCache.instance.create_client ENV["NOTION_API_TOKEN"] # from environment
120
57
  ```
121
58
 
122
- ## 4. Usage
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.
530
-
531
- ```Ruby
532
- page = db.create_child_page
533
- page.properties["Name"] << "New Page"
534
- page.save
535
- ```
536
-
537
- - result of dry run
538
-
539
- ```bash
540
- #!/bin/sh
541
- curl -X POST 'https://api.notion.com/v1/pages'\
542
- -H 'Notion-Version: 2022-02-22'\
543
- -H 'Authorization: Bearer '"$NOTION_API_KEY"''\
544
- -H 'Content-Type: application/json'\
545
- --data '{"properties":{"Name":{"type":"title","title":[{"type":"text","text":{"content":"New Page","link":null},"plain_text":"New Page","href":null}]}},"parent":{"database_id":"c37a2c66e3aa4a0da44773de3b80c253"}}'⏎
546
- ```
547
-
548
- #### 4.2.4 Create database
549
-
550
- `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.
551
-
552
- ```Ruby
553
- page = Page.find "a sample page id"
554
- db = parent_page.create_child_database "New database title",
555
- CheckboxProperty, "Checkbox",
556
- CreatedByProperty, "CreatedBy",
557
- CreatedTimeProperty, "CreatedTime",
558
- DateProperty, "Date",
559
- EmailProperty, "Email",
560
- FilesProperty, "Files",
561
- FormulaProperty, "Formula",
562
- LastEditedByProperty, "LastEditedBy",
563
- LastEditedTimeProperty, "LastEditedTime",
564
- MultiSelectProperty, "MultiSelect",
565
- NumberProperty, "Number",
566
- PeopleProperty, "People",
567
- PhoneNumberProperty, "PhoneNumber",
568
- RelationProperty, "Relation",
569
- RollupProperty, "Rollup",
570
- RichTextProperty, "RichText",
571
- SelectProperty, "Select",
572
- TitleProperty, "Title",
573
- UrlProperty, "Url"
574
- fp, msp, np, rp, rup, sp = db.properties.values_at "Formula", "MultiSelect", "Number", "Relation", "Rollup", "Select"
575
- fp.formula_expression = "now()"
576
- msp.add_multi_select_options name: "MS1", color: "orange"
577
- msp.add_multi_select_options name: "MS2", color: "green"
578
- np.format = "yen"
579
- rp.replace_relation_database database_id: tc.database_id
580
- rup.relation_property_name = "Relation"
581
- rup.rollup_property_name = "NumberTitle"
582
- rup.function = "sum"
583
- sp.add_select_options name: "S1", color: "yellow"
584
- sp.add_select_options name: "S2", color: "default"
585
- db.set_icon emoji: "🎉"
586
- db.save
587
- ```
588
-
589
- #### 4.2.5 Update database properties
590
-
591
- `save` method updates existing database properties. The database needs to be retrieved using `find` to prevent existing settings from disappearing.
592
-
593
- ```Ruby
594
- db = Database.find "c7697137d49f49c2bbcdd6a665c4f921"
595
- fp, msp, np, rp, rup, sp = db.properties.values_at "Formula", "MultiSelect", "Number", "Relation", "Rollup", "Select"
596
- fp.formula_expression = "pi"
597
- msp.add_multi_select_options name: "MS3", color: "blue"
598
- np.format = "percent"
599
- rp.replace_relation_database database_id: tc.database_id, synced_property_name: "Renamed table"
600
- rup.function = "average"
601
- sp.add_select_options name: "S3", color: "red"
602
- db.set_icon emoji: "🎉"
603
- db.database_title << "(Added)"
604
- db.save
605
- ```
606
-
607
- #### 4.2.6 Add a database property
608
-
609
- `add_property` can add a database property.
610
-
611
- ```Ruby
612
- db = Database.find "c7697137d49f49c2bbcdd6a665c4f921"
613
- db.add_property NumberProperty, "added number property" do |np|
614
- np.format = "euro" # arrange option
615
- end
616
- db.add_property UrlProperty, "added url property" # UrlProperty has no option
617
- db.save
618
- ```
619
-
620
- - result of dry run
621
-
622
- ```bash
623
- #!/bin/sh
624
- curl -X PATCH 'https://api.notion.com/v1/databases/c7697137d49f49c2bbcdd6a665c4f921'\
625
- -H 'Notion-Version: 2022-02-22'\
626
- -H 'Authorization: Bearer '"$NOTION_API_KEY"''\
627
- -H 'Content-Type: application/json'\
628
- --data '{"properties":{"added number property":{"number":{"format":"euro"}},"added url property":{"url":{}}}}'⏎
629
- ```
630
-
631
- #### 4.2.7 Rename a database property
632
-
633
- `rename_property` can rename a database property.
634
-
635
- ```Ruby
636
- properties = db.properties
637
- properties["added number property"].new_name = "renamed number property"
638
- properties["added url property"].new_name = "renamed url property"
639
- db.save
640
- ```
641
-
642
- - result of dry run
643
-
644
- ```bash
645
- #!/bin/sh
646
- curl -X PATCH 'https://api.notion.com/v1/databases/c7697137d49f49c2bbcdd6a665c4f921'\
647
- -H 'Notion-Version: 2022-02-22'\
648
- -H 'Authorization: Bearer '"$NOTION_API_KEY"''\
649
- -H 'Content-Type: application/json'\
650
- --data '{"properties":{"added number property":{"name":"renamed number property"},"added url property":{"name":"renamed url property"}}}'
651
- ```
652
-
653
- #### 4.2.8 Remove database properties
654
-
655
- `remove_properties' can remove some database properties.
656
-
657
- ```Ruby
658
- db.remove_property "renamed number property", "renamed url property"
659
- ```
660
-
661
- - result of dry run
662
-
663
- ```bash
664
- #!/bin/sh
665
- curl -X PATCH 'https://api.notion.com/v1/databases/c7697137d49f49c2bbcdd6a665c4f921'\
666
- -H 'Notion-Version: 2022-02-22'\
667
- -H 'Authorization: Bearer '"$NOTION_API_KEY"''\
668
- -H 'Content-Type: application/json'\
669
- --data '{"properties":{"renamed number property":null,"renamed url property":null}}'
670
- ```
671
-
672
- #### 4.2.9 other methods
673
-
674
- - `Database.find id, dry_run: true` create shell script for verification.
675
- - `db.save` call Notion API, and so on and replace object information.
676
- - `db.save dry_run: true` create shell script for verification.
677
- - `db.new_record?` returns true if the database was generated by `create_child_database`.
678
- - `db.database_title` returns plain_text string of `Database`.
679
- - `db.title` returns plain_text string of `TitleProperty`.
680
- - `db.icon` returns JSON hash for the page icon.
681
- - `db[key]` returns a hash or an array object except "properties".
682
- - `db.created_time` returns CreatedTimeProperty for filter
683
- - `db.last_edited_time` returns LastEditedTimeProperty for filter
684
-
685
- ### 4.3 List class
686
-
687
- `db.query_database` and other API list results returns a List object.
688
- The list object is an Enumerable object, so usually combines with `.each` method.
689
-
690
- ```Ruby
691
- db.query_database(query).each do |page|
692
- # exec some methods for a page object
693
- end
694
- ```
695
-
696
- Notion API returns only the first page-size objects.
697
- The default page-size of this library is 100.
698
- 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.
699
- Users do not have to worry about paging.
700
-
701
- ### 4.4 Block class
702
-
703
- === under construction ===
704
-
705
- ### 4.5 Property classes
706
-
707
- #### 4.5.1 How to obtain Property object
708
-
709
- There are the following 17 XXXProperty classes corresponding to Notion databases.
710
-
711
- 1. TitleProperty
712
- 2. RichTextProperty
713
- 3. UrlProperty
714
- 4. EmailProperty
715
- 5. PhoneNumberProperty
716
- 6. NumberProperty
717
- 7. CheckboxProperty
718
- 8. SelectProperty
719
- 9. MultiSelectProperty
720
- 10. PeopleProperty
721
- 11. CreatedByProperty
722
- 12. LastEditedByProperty
723
- 13. DateProperty
724
- 14. CreatedTimeProperty
725
- 15. LastEditedTimeProperty
726
- 16. FilesProperty
727
- 17. FormulaProperty
728
-
729
- They are child classes of a `Property` class and generated from Page or Database objects.
730
-
731
- ```Ruby
732
- page = Page.new page_id, assign: [XXXProperty, "property_name"]
733
- # or
734
- page = Page.find page_id
735
-
736
- xp = page.properties["property_name"]
737
- # or
738
- xp, yp = page.properties.values_at "xp_name", "yp_name"
739
- ```
740
-
741
- Page properties and database properties are objects of the same class, but there are methods for page properties and methods for database properties.
59
+ ### 2.3 Sample codes
742
60
 
743
- #### 4.5.2 Query object generator of property objects
61
+ 1. [Database and page access sample](https://www.notion.so/hkob/Database-and-page-access-sample-d30033e707194faf995741167eb2b6f8)
62
+ 1. [Append block children sample](https://www.notion.so/hkob/Append-block-children-sample-3867910a437340be931cf7f2c06443c6)
744
63
 
745
- The following methods for the Property objects generate a query object. These methods can be used for page properties and database properties.
64
+ ### 2.4. Another example code (Use case)
746
65
 
747
- - TitleProperty, RichTextProperty, UrlProperty, EmailProperty, PhoneNumberProperty
748
- - filter_equals(value)
749
- - filter_does_not_equal(value)
750
- - filter_contains(value)
751
- - filter_does_not_contain(value)
752
- - filter_starts_with(value)
753
- - filter_ends_with(value)
754
- - filter_is_empty
755
- - filter_is_not_empty
756
- - NumberProperty
757
- - filter_equals(value)
758
- - filter_does_not_equal(value)
759
- - filter_greater_than(value)
760
- - filter_less_than(value)
761
- - filter_greater_than_or_equal_to(value)
762
- - filter_less_than_or_equal_to(value)
763
- - filter_is_empty
764
- - filter_is_not_empty
765
- - CheckboxProperty
766
- - filter_equals(value)
767
- - filter_does_not_equal(value)
768
- - SelectProperty
769
- - filter_equals(value)
770
- - filter_does_not_equal(value)
771
- - filter_is_empty
772
- - filter_is_not_empty
773
- - MultiSelectProperty, PeopleProperty, CreatedByProperty, LastEditedByProperty
774
- - filter_contains(value)
775
- - filter_does_not_contain(value)
776
- - filter_is_empty
777
- - filter_is_not_empty
778
- - DateProperty, CreatedTimeProperty, LastEditedTimeProperty
779
- - filter_equals(value(Date / Time / DateTime / String))
780
- - filter_does_not_equal(value(Date / Time / DateTime / String))
781
- - filter_before(value(Date / Time / DateTime / String))
782
- - filter_after(value(Date / Time / DateTime / String))
783
- - filter_on_or_before(value(Date / Time / DateTime / String))
784
- - filter_on_or_after(value(Date / Time / DateTime / String))
785
- - filter_past_week
786
- - filter_past_month
787
- - filter_past_year
788
- - filter_next_week
789
- - filter_next_month
790
- - filter_next_year
791
- - FilesProperty
792
- - filter_is_empty
793
- - filter_is_not_empty
794
- - FormulaProperty
795
- - filter_equals(value(Date / Time / DateTime / String))
796
- - filter_does_not_equal(value(Date / Time / DateTime / String))
797
- - filter_before(value(Date / Time / DateTime / String))
798
- - filter_after(value(Date / Time / DateTime / String))
799
- - filter_on_or_before(value(Date / Time / DateTime / String))
800
- - filter_on_or_after(value(Date / Time / DateTime / String))
801
- - filter_past_week
802
- - filter_past_month
803
- - filter_past_year
804
- - filter_next_week
805
- - filter_next_month
806
- - filter_next_year
807
- - filter_contains(value)
808
- - filter_does_not_contain(value)
809
- - filter_starts_with(value)
810
- - filter_ends_with(value)
811
- - filter_greater_than(value)
812
- - filter_less_than(value)
813
- - filter_greater_than_or_equal_to(value)
814
- - filter_less_than_or_equal_to(value)
815
- - filter_is_empty
816
- - filter_is_not_empty
817
-
818
- #### 4.5.3 create or update values for Page properties
819
-
820
- 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.
821
-
822
- XXXProperties can change property values by setter methods. Since the setter method is different for each class, it will be explained separately.
823
-
824
- ##### 4.5.3.1 NumberProperty
825
-
826
- NumberProperty can set a number by `.number=`.
827
-
828
- ```Ruby
829
- np = page.properties["NumberTitle"]
830
- np.number = 3.14
831
- p np.property_values_json
832
- # Result => => {"np"=>{"number"=>3.14, "type"=>"number"}}
833
- ```
834
-
835
- ##### 4.5.3.2 SelectProperty
836
-
837
- SelectProperty can set a select name by `.select=`.
838
-
839
- ```Ruby
840
- sp = page.properties["SelectTitle"]
841
- sp.select = "Select 2"
842
- p sp.property_values_json
843
- # Result => {"sp"=>{"type"=>"select", "select"=>{"name"=>"Select 2"}}}
844
- ```
845
-
846
- ##### 4.5.3.3 MultiSelectProperty
847
-
848
- MultiSelectProperty can set a select value or Array of select values by `.multi_select=`.
849
-
850
- ```Ruby
851
- msp = page.properties["MultiSelectTitle"]
852
- msp.multi_select = "MS2"
853
- p msp.property_values_json
854
- # Result => {"msp"=>{"type"=>"multi_select", "multi_select"=>[{"name"=>"MS2"}]}}
855
-
856
- msp.multi_select = %w[MS2 MS1]
857
- p msp.property_values_json
858
- # Result => {"msp"=>{"type"=>"multi_select", "multi_select"=>[{"name"=>"MS2"}, {"name"=>"MS1"}]}}
859
- ```
860
-
861
- ##### 4.5.3.4 DateProperty
862
-
863
- DateProperty can set a start_date or end_date by `.start_date=` or `end_date=`.
864
- Date, Time, DateTime or String object can be used to the argument.
865
-
866
- ```Ruby
867
- dp = page.properties["DateTitle"]
868
- dp.start_date = Date.new(2022, 2, 22)
869
- p dp.property_values_json
870
- # Result => {"dp"=>{"type"=>"date", "date"=>{"start"=>"2022-02-22", "end"=>nil, "time_zone"=>nil}}}
871
-
872
- dp.start_date = Time.new(2022, 2, 22, 1, 23, 45, "+09:00")
873
- p dp.property_values_json
874
- # Result =>{"dp"=>{"type"=>"date", "date"=>{"start"=>"2022-02-22T01:23:45+09:00", "end"=>nil, "time_zone"=>nil}}}
875
-
876
- dp.start_date = DateTime.new(2022, 2, 23, 1, 23, 45, "+09:00")
877
- p dp.property_values_json
878
- # Result => {"dp"=>{"type"=>"date", "date"=>{"start"=>"2022-02-23T01:23:45+09:00", "end"=>nil, "time_zone"=>nil}}}
879
-
880
- dp.start_date = Date.new(2022, 2, 20)
881
- dp.end_date = Date.new(2022, 2, 22)
882
- p dp.property_values_json
883
- # Result => => {"dp"=>{"type"=>"date", "date"=>{"start"=>"2022-02-20", "end"=>"2022-02-22", "time_zone"=>nil}}}
884
-
885
- dp.start_date = Time.new(2022, 2, 21, 1, 23, 45, "+09:00")
886
- dp.end_date = Time.new(2022, 2, 22, 1, 23, 45, "+09:00")
887
- p dp.property_values_json
888
- # Result => {"start" => "2022-02-21T01:23:45+09:00", "end" => "2022-02-22T01:23:45+09:00"}
889
-
890
- dp.start_date = DateTime.new(2022, 2, 21, 1, 23, 45, "+09:00")
891
- dp.end_date = DateTime.new(2022, 2, 22, 1, 23, 45, "+09:00")
892
- p dp.property_values_json
893
- # result => {"dp"=>{"type"=>"date", "date"=>{"start"=>"2022-02-21T01:23:45+09:00", "end"=>nil, "time_zone"=>nil}}}
894
- ```
895
-
896
- ##### 4.5.3.4 UrlProperty
897
-
898
- UrlProperty can set a url by `.url=`.
899
-
900
- ```Ruby
901
- up = page.properties["UrlTitle"]
902
- up.url = "https://www.google.com/"
903
- p up.property_values_json
904
- # result => {"up"=>{"url"=>"https://www.google.com/", "type"=>"url"}}
905
- ```
906
-
907
- ##### 4.5.3.5 EmailProperty
908
-
909
- EmailProperty can set an email by `.email=`.
910
-
911
- ```Ruby
912
- ep = page.properties["MailTitle"]
913
- ep.email = "https://www.google.com/"
914
- p ep.property_values_json
915
- # result => {"ep"=>{"email"=>"hkobhkob@gmail.com", "type"=>"email"}}
916
- ```
917
-
918
- ##### 4.5.3.6 PhoneNumberProperty
919
-
920
- PhoneNumberProperty can set an phone number by `.phone_number=`.
921
-
922
- ```Ruby
923
- pp = page.properties["TelTitle"]
924
- pp.phone_number = "xx-xxxx-xxxx"
925
- p pp.property_values_json
926
- # result => {"pp"=>{"phone_number"=>"xx-xxxx-xxxx", "type"=>"phone_number"}}
927
- ```
928
-
929
- ##### 4.5.3.7 PeopleProperty
930
-
931
- PeopleProperty can set an people by `.people=`.
932
- PeopleProperty can set a user_id/UserObject value or Array of user_id/UserObject values by `.people=`.
933
-
934
- ```Ruby
935
- pp = page.properties["UserTitle"]
936
- pp.people = "user_id1"
937
- p pp.property_values_json
938
- # result => {"pp"=>{"type"=>"people", "people"=>[{"object"=>"user", "id"=>"user_id1"}]}}
939
-
940
- pp.people = UserObject.new json: user1_json
941
- p pp.property_values_json
942
- # result => {"pp"=>{"type"=>"people", "people"=>[{"object"=>"user", "id"=>"user_id1_from_json"}]}}
943
- ```
944
-
945
- ```Ruby
946
- pp.people = %w[user_id2 user_id3]
947
- p pp.property_values_json
948
- # result => {"pp"=>{"type"=>"people", "people"=>[{"object"=>"user", "id"=>"user_id2"}, {"object"=>"user", "id"=>"user_id3"}]}}
949
-
950
- u2 = UserObject.new(json: user2_json)
951
- u3 = UserObject.new(json: user3_json)
952
- pp.people = [u2, u3]
953
- p pp.property_values_json
954
- # result => {"pp"=>{"type"=>"people", "people"=>[{"object"=>"user", "id"=>"user_id2_from_json"}, {"object"=>"user", "id"=>"user_id3_from_json"}]}}
955
- ```
956
-
957
- ##### 4.5.3.8 TitleProperty, RichTextProperty
958
-
959
- TextProperty's subclasses (TitleProperty, RichTextProperty) have an array of TextObject objects.
960
- `[]` method returns an existing TextObject.
961
- The obtained TextObject can be set text by `.text=`.
962
-
963
- ```Ruby
964
- pp = page.properties["Title"]
965
- tp[0].text = "ABC\n"
966
- p tp.property_values_json
967
- # result => {"tp"=>{"type"=>"title", "title"=>[{"type"=>"text", "text"=>{"content"=>"ABC\n", "link"=>nil}, "plain_text"=>"ABC\n", "href"=>nil}]}}
968
- ```
969
-
970
- `<<` method appends a new TextObject or a String.
971
-
972
- ```Ruby
973
- to = TextObject.new "DEF"
974
- to.bold = true
975
- to.italic = true
976
- to.strikethrough = true
977
- to.underline = true
978
- to.code = true
979
- to.color = "default"
980
- tp << to
981
- p tp.property_values_json
982
- # 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"}}]}}
983
- ```
984
-
985
- `delete_at(index)` method remove a TextObject at index.
986
-
987
- ```Ruby
988
- tp.delete_at 1
989
- tp << "GHI"
990
- p tp.property_values_json
991
- # 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}]}}
992
- ```
993
-
994
- ##### 4.5.3.9 CheckboxProperty
995
-
996
- CheckboxProperty can set a boolean value by `.checkbox=`.
997
-
998
- ```Ruby
999
- cp = page.properties["CheckboxTitle"]
1000
- cp.checkbox = true
1001
- p cp.property_values_json
1002
- # result => {"cp"=>{"checkbox"=>true, "type"=>"checkbox"}}
1003
- ```
1004
-
1005
- ##### 4.5.3.10 FilesProperty
1006
-
1007
- FilesProperty can set an external url or Array of external urls by `.files=`.
1008
-
1009
- ```Ruby
1010
- fp = page.properties["FilesTitle"]
1011
- fp.files = "F1"
1012
- p fp.property_values_json
1013
- # Result => {"fp"=>{"files"=>[{"name"=>"F1", "type"=>"external", "external"=>{"url"=>"F1"}}], "type"=>"files"}}
1014
-
1015
- fp.files = %w[F2 F3]
1016
- p fp.property_values_json
1017
- # Result => {"fp"=>{"files"=>[{"name"=>"F2", "type"=>"external", "external"=>{"url"=>"F2"}}, {"name"=>"F3", "type"=>"external", "external"=>{"url"=>"F3"}}], "type"=>"files"}}
1018
- ```
1019
-
1020
- ##### 4.5.3.11 RelationProperty
1021
-
1022
- RelationProperty can set an relation's page_id or Array of relation's page_ids by `.relation=`.
1023
-
1024
- ```Ruby
1025
- rp = page.properties["RelationTitle"]
1026
- rp.relation = "R1"
1027
- p rp.property_values_json
1028
- # Result => {"rp"=>{"type"=>"relation", "relation"=>[{"id"=>"R1"}]}}
1029
-
1030
- rp.relation = %w[R2 R3]
1031
- p rp.property_values_json
1032
- # Result => {"rp"=>{"type"=>"relation", "relation"=>[{"id"=>"R2"}, {"id"=>"R3"}]}}
1033
- ```
1034
-
1035
- #### 4.5.4 create or update values for Database properties
1036
-
1037
- 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.
1038
-
1039
- XXXProperties can change property values by setter methods. Since the setter method is different for each class, it will be explained separately.
1040
-
1041
- ##### 4.5.4.1 NumberProperty
1042
-
1043
- NumberProperty can set a format by `.format=`.
1044
-
1045
- ```Ruby
1046
- np = db.properties["NumberTitle"]
1047
- np.format = "percent"
1048
- print np.property_schema_json
1049
- # Result => {"NumberTitle"=>{"number"=>{"format"=>"percent"}}}
1050
- ```
1051
-
1052
- ##### 4.5.4.2 SelectProperty
1053
-
1054
- SelectProperty can add a new option by `.add_select_options`.
1055
-
1056
- ```Ruby
1057
- sp = db.properties["SelectTitle"]
1058
- sp.add_select_options name: "S3", color: "red"
1059
- print sp.property_schema_json
1060
- # 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"}]}}}
1061
- ```
1062
-
1063
- If you want to edit existing values, you should access `edit_select_options` array. It sets `will_update` flag to true.
1064
-
1065
- ```Ruby
1066
- sp.edit_select_options[0]["name"] = "new S1"
1067
- p sp.property_values_json
1068
- # 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"}]}}}⏎
1069
- ```
1070
-
1071
- ##### 4.5.4.3 MultiSelectProperty
1072
-
1073
- MultiSelectProperty can add a new option by `.add_multi_select_options`.
1074
-
1075
- ```Ruby
1076
- msp = db.properties["MultiSelectTitle"]
1077
- msp.add_multi_select_options name: "MS3", color: "blue"
1078
- print msp.property_schema_json
1079
- # 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"}]}}}
1080
- ```
1081
-
1082
- If you want to edit existing values, you should access `edit_multi_select_options` array. It sets `will_update` flag to true.
1083
-
1084
- ```Ruby
1085
- msp.edit_multi_select_options[0]["name"] = "new MS1"
1086
- p msp.property_values_json
1087
- # 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"}]}}}⏎
1088
- ```
1089
-
1090
- ##### 4.5.4.4 DateProperty
1091
-
1092
- DateProperty has no option.
1093
-
1094
- ```Ruby
1095
- dp = db.properties["DateTitle"]
1096
- print dp.property_schema_json
1097
- # Result => {"DateTitle"=>{"date"=>{}}}
1098
- ```
1099
-
1100
- ##### 4.5.4.4 UrlProperty
1101
-
1102
- UrlProperty has no option.
1103
-
1104
- ```Ruby
1105
- up = db.properties["UrlTitle"]
1106
- print up.property_schema_json
1107
- # Result => {"UrlTitle"=>{"url"=>{}}}
1108
- ```
1109
-
1110
- ##### 4.5.4.5 EmailProperty
1111
-
1112
- EmailProperty has no option.
1113
-
1114
- ```Ruby
1115
- ep = db.properties["MailTitle"]
1116
- print ep.property_schema_json
1117
- # Result => {"MailTitle"=>{"email"=>{}}}
1118
- ```
1119
-
1120
- ##### 4.5.4.6 PhoneNumberProperty
1121
-
1122
- PhoneNumberProperty has no option.
1123
-
1124
- ```Ruby
1125
- pp = db.properties["TelTitle"]
1126
- print ep.property_schema_json
1127
- # Result => {"TelTitle"=>{"phone_number"=>{}}}
1128
- ```
1129
-
1130
- ##### 4.5.4.7 PeopleProperty
1131
-
1132
- PeopleProperty has no option.
1133
-
1134
- ```Ruby
1135
- usp = db.properties["UserTitle"]
1136
- print usp.property_schema_json
1137
- # Result => {"UserTitle"=>{"people"=>{}}}
1138
- ```
1139
-
1140
- ##### 4.5.4.8 TitleProperty, RichTextProperty
1141
-
1142
- TitleProperty and RichTextProperty have no option.
1143
-
1144
- ```Ruby
1145
- tp, rtp = db.properties.values_at "Title", "TextTitle"
1146
- print tp.property_schema_json
1147
- # Result => {"Title"=>{"title"=>{}}}
1148
- print rtp.property_schema_json
1149
- # Result => {"TextTitle"=>{"rich_text"=>{}}}
1150
- ```
1151
-
1152
- ##### 4.5.4.9 CheckboxProperty
1153
-
1154
- CheckboxProperty has no option.
1155
-
1156
- ```Ruby
1157
- cp = db.properties["CheckboxTitle"]
1158
- print cp.property_schema_json
1159
- # Result => {"CheckboxTitle"=>{"checkbox"=>{}}}
1160
- ```
1161
-
1162
- ##### 4.5.4.10 FilesProperty
1163
-
1164
- FilesProperty has no option.
1165
-
1166
- ```Ruby
1167
- fp = db.properties["FilesTitle"]
1168
- print fp.property_schema_json
1169
- # Result => {"FilesTitle"=>{"files"=>{}}}
1170
- ```
1171
-
1172
- ##### 4.5.4.11 RelationProperty
1173
-
1174
- RelationProperty can set an relation's database_id by `.replace_relation_database`.
1175
-
1176
- ```Ruby
1177
- rp = db.properties["RelationTitle"]
1178
- rp.replace_relation_database database_id: "new database id"
1179
- p rp.property_values_json
1180
- # Result => {"Relation"=>{"relation"=>{"database_id"=>"new database id"}}}
1181
- ```
1182
-
1183
- ##### 4.5.4.12 RollupProperty
1184
-
1185
- RollupProperty can set rollup property name, relation property name and function by `.rollup_property_name=`, `relation_property_name=` and `function=`, respectively.
1186
-
1187
- ```Ruby
1188
- rup = db.properties["RollupTitle"]
1189
- rup.relation_property_name = "new relation property name"
1190
- rup.rollup_property_name = "new rollup property name"
1191
- rup.function = "average"
1192
- # Result => {"Rollup"=>{"rollup"=>{"function"=>"average", "relation_property_name"=>"new relation property name", "rollup_property_name"=>"new rollup property name"}}}
1193
- ```
1194
-
1195
- ## 5. XXXObjects and RichTextArray
1196
-
1197
- ### 5.1 RichTextObject
1198
-
1199
- RichTextObject is an abstract class for TextObject and MentionObject.
1200
- It can store a link and some annotations.
1201
-
1202
- There are common instance methods for its subclass objects.
1203
-
1204
- - plain_text=(value)
1205
- - bold=(flag)
1206
- - italic=(flag)
1207
- - strikethrough=(flag)
1208
- - underline=(flag)
1209
- - code=(flag)
1210
- - color=(color)
1211
-
1212
- ### 5.2 TextObject
1213
-
1214
- TextObject is a class for texts.
1215
- `TextObject.new(text)` creates a TextObject.
1216
- After creating or retrieving TextObject, `to.text=` replaces including text.
1217
-
1218
- ```Ruby
1219
- to = TextObject.new "first text"
1220
- to.text = "replaced text"
1221
- ```
1222
-
1223
- ### 5.3 MentionObject
1224
-
1225
- MentionObject is a class for mentions for user, page, database, date and template_mention.
1226
-
1227
- ```Ruby
1228
- mention_user = MentionObject.new user_id: "user_id", plain_text: "m_user"
1229
- mention_page = MentionObject.new page_id: "page_id", plain_text: "m_page"
1230
- mention_db = MentionObject.new database_id: "database_id", plain_text: "m_db"
1231
- mention_date = MentionObject.new start: "2022-03-17", plain_text: "m_date"
1232
- mention_today = MentionObject.new mention_template: "today"
1233
- mention_now = MentionObject.new mention_template: "now"
1234
- mention_user = MentionObject.new mention_template: "user"
1235
- ```
1236
-
1237
- ### 5.4 UserObject
1238
-
1239
- UserObject is a class for users.
1240
-
1241
- ```Ruby
1242
- u = User.new id: "user_id"
1243
- ```
1244
-
1245
- ### 5.5 RichTextArray
1246
-
1247
- Some properties and Database title have an array of RichTextObject. `RichTextArray` is the delegate class for the array of RichTextObject.
1248
- Moreover, some methods of TitleProperty, RichTextProperty and Database.title delegate to the included RichTextArray.
1249
-
1250
- #### 5.5.1 Constructor for RichTextArray
1251
-
1252
- RichTextArray can be created by a String, some Strings, a RichTextObject and some RichTextObjects. String values will convert to simple TextObjects.
1253
-
1254
- ```Ruby
1255
- nullString = RichTextArray.new "title"
1256
- aString = RichTextArray.new "title", text_objects: "A string"
1257
- twoStrings = RichTextArray.new "title", text_objects: %W[ABC\n DEF]
1258
- aTextObject = RichTextArray.new "title", text_objects: TextObject.new "A TextObject"
1259
- textMentionObjects = RichTextArray.new "title", [TextObject.new("A TextObject"), MentionObject.new(user_id: "ABC")]
1260
- ```
66
+ 1. [Set icon to all icon unsettled pages](examples/set_icon_to_all_icon_unsettled_pages.md)
67
+ 1. [Renumbering pages](examples/renumbering_pages.md)
68
+ 1. [Change title](examples/change_title.md)
1261
69
 
1262
- #### 5.5.2 Instance methods
70
+ ### 2.5 API reference
1263
71
 
1264
- - `rto << text_or_text_object`: append a text or RichTextObject
1265
- - `rto[0]`: obtain the object specified by the index
1266
- - `delete_at 0`: obtain the object specified by the index and delete from the array
1267
- - `full_text`: obtain joined plain text
72
+ 1. [Notion Ruby Mapping Public API reference](https://www.notion.so/hkob/Notion-Ruby-Mapping-Public-API-reference-4091aca15b664299b63e6253b7601fec)
1268
73
 
1269
- ## 6. ChangeLog
74
+ ## 3. ChangeLog
1270
75
 
76
+ - added append_block_children
77
+ - added retrieve_block spec
78
+ - 2022/4/29 Change directory structure, TEST_IDs are moved from env.yml to TestConnection's constants
79
+ - 2022/4/27 added Base#children
80
+ - 2022/3/27 create_child_page can receive a block for initialization.
1271
81
  - 2022/3/27 properties of a created child page are automatically assigned using the parent database.
1272
82
  - 2022/3/25 added create_child_database, update_database, add_property, rename_property and remove_property
1273
83
  - 2022/3/17 added template_mention objects, tools/an command
@@ -1284,18 +94,18 @@ textMentionObjects = RichTextArray.new "title", [TextObject.new("A TextObject"),
1284
94
  - 2022/2/13 added Page#set_icon
1285
95
  - 2022/2/13 First commit
1286
96
 
1287
- ## 7. Contributing
97
+ ## 4. Contributing
1288
98
 
1289
99
  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).
1290
100
 
1291
- ## 8. License
101
+ ## 5. License
1292
102
 
1293
103
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
1294
104
 
1295
- ## 9. Code of Conduct
105
+ ## 6. Code of Conduct
1296
106
 
1297
107
  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).
1298
108
 
1299
- ## 10. Acknowledgements
109
+ ## 7. Acknowledgements
1300
110
 
1301
111
  The code depends on [notion-ruby-client](https://github.com/orbit-love/notion-ruby-client).