notion_ruby_mapping 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d1a29ab30d2bd0631a41516611cf406c86fc4940b11335b0a3f677b31d4c4ea
4
- data.tar.gz: 133ad7c09465c229b0894fd6dcd36e7d722f4f1cffa995c43b87fae4b6362d9e
3
+ metadata.gz: 5aef3ce3be5f734faf9803496c1196e715ad8513fbabc143abe43b4d4780a274
4
+ data.tar.gz: 1384fc70512cc6a396693fb7a37f8a80311bac85e26616a22ea8a5b3c491e28e
5
5
  SHA512:
6
- metadata.gz: 26ec1318e3df00a79a058798c2bbe5ae722cbe87fcc4191f3e0c00bed5e0a13880906e697d5f5e92d06159625a23c5a0736d91c577edd38c97f512f8a1e22f36
7
- data.tar.gz: f09480ff8c3c38af9a7b284b97b903fcea59c99f50815285c93e61127e82b85edecad549442d566a914bcd51884139e05a93588beeeb59683749072ce98a8542
6
+ metadata.gz: cf783b7b53434fefb0f556a9f0fd17ca4dc4bac220e90bb609abf454a1e05ec0de37f4937998cd04fc34c037e87bea9ca3c454593a53a1a0de7998fea7009c9f
7
+ data.tar.gz: ea70aa30d1f9d082cab295320d79b4a975a67255fc61ce4956379e98ca4b4996093ac9e0b1c19e80815b233792be5ff5d29b50a49115d0d1e68461237dfefdfd
data/README.md CHANGED
@@ -6,25 +6,41 @@ Development note is here. → [Idea note of "notion_ruby_mapping"](https://www.n
6
6
 
7
7
  ## Table of Contents
8
8
  - [NotionRubyMapping](#notionrubymapping)
9
- - [Installation](#installation)
10
- - [Example code](#example-code)
11
- - [Usage](#usage)
12
- - [Create a New Integration](#create-a-new-integration)
13
- - [Create client](#create-client)
14
- - [Classes](#classes)
15
- - [Base class](#base-class)
16
- - [Database class](#database-class)
17
- - [Query class](#query-class)
18
- - [Page class](#page-class)
19
- - [List class](#list-class)
20
- - [Block class](#block-class)
21
- - [ChangeLog](#changelog)
22
- - [Contributing](#contributing)
23
- - [License](#license)
24
- - [Code of Conduct](#code-of-conduct)
25
- - [Acknowledgements](#acknowledgements)
26
-
27
- ## Installation
9
+ - [Table of Contents](#table-of-contents)
10
+ - [1. Installation](#1-installation)
11
+ - [2. Example code](#2-example-code)
12
+ - [3. Usage](#3-usage)
13
+ - [3.1 Create a New Integration](#31-create-a-new-integration)
14
+ - [3.2 Create client](#32-create-client)
15
+ - [3.3 Retrieve a database](#33-retrieve-a-database)
16
+ - [3.4 Retrieve a page](#34-retrieve-a-page)
17
+ - [3.5 Query a database](#35-query-a-database)
18
+ - [3.5.1 A simple example](#351-a-simple-example)
19
+ - [3.5.2 Property classes](#352-property-classes)
20
+ - [3.5.3 Query object generator of property objects](#353-query-object-generator-of-property-objects)
21
+ - [3.5.4 Complex conditions](#354-complex-conditions)
22
+ - [3.5.5 Sort criteria](#355-sort-criteria)
23
+ - [3.6 Access the database or page values and properties](#36-access-the-database-or-page-values-and-properties)
24
+ - [3.7 Set icon (Database / Page)](#37-set-icon-database--page)
25
+ - [3.8 Update page property values](#38-update-page-property-values)
26
+ - [3.8.1 Assign property and update it (fastest: one API call only)](#381-assign-property-and-update-it-fastest-one-api-call-only)
27
+ - [3.8.2 Update the loaded page (easy but slow: two API calls)](#382-update-the-loaded-page-easy-but-slow-two-api-calls)
28
+ - [3.8.3 Update the unloaded page with auto-load (easy but slow: two API calls)](#383-update-the-unloaded-page-with-auto-load-easy-but-slow-two-api-calls)
29
+ - [3.8.4 Explanation of how to update each property](#384-explanation-of-how-to-update-each-property)
30
+ - [3.8.4.1 NumberProperty](#3841-numberproperty)
31
+ - [3.8.4.2 SelectProperty](#3842-selectproperty)
32
+ - [3.8.4.3 MultiSelectProperty](#3843-multiselectproperty)
33
+ - [3.8.4.4 DateProperty](#3844-dateproperty)
34
+ - [3.9 Iteration of list object](#39-iteration-of-list-object)
35
+ - [4. ChangeLog](#4-changelog)
36
+ - [5. Contributing](#5-contributing)
37
+ - [6. License](#6-license)
38
+ - [7. Code of Conduct](#7-code-of-conduct)
39
+ - [8. Acknowledgements](#8-acknowledgements)
40
+
41
+ <!-- @import "[TOC]" {cmd="toc" depthFrom=2 depthTo=4 orderedList=false} -->
42
+
43
+ ## 1. Installation
28
44
 
29
45
  Add this line to your application's Gemfile:
30
46
 
@@ -40,7 +56,7 @@ Or install it yourself as:
40
56
 
41
57
  $ gem install notion_ruby_mapping
42
58
 
43
- ## Example code
59
+ ## 2. Example code
44
60
 
45
61
  The following code sets a "💿" icon on all unset pages in the database.
46
62
  ```Ruby
@@ -74,45 +90,54 @@ end
74
90
  |-----------------------------------------------|
75
91
  | ![After exuecution](images/serial_number.png) |
76
92
 
77
- ## Usage
93
+ ## 3. Usage
78
94
 
79
- ### Create a New Integration
95
+ ### 3.1 Create a New Integration
80
96
 
81
97
  Please check [Notion documentation](https://developers.notion.com/docs#getting-started).
82
98
 
83
- ### Create client
99
+ ### 3.2 Create client
84
100
 
101
+ Please create a client (notion-ruby-client) before you use the following class.
85
102
  ```Ruby
86
103
  NotionCache.instance.create_client ENV["NOTION_API_TOKEN"]
87
104
  ```
88
- Please create a client (notion-ruby-client) before you use the following class.
89
105
 
90
- ### Classes
106
+ ### 3.3 Retrieve a database
91
107
 
92
- #### Base class (Abstract class for Database / Page / Block / List)
108
+ Database.find(id) creates a Database object from the results of Notion API.
93
109
 
94
- - Set icon (only Database / Page)
110
+ ```Ruby
111
+ db = Database.find("c37a2c66-e3aa-4a0d-a447-73de3b80c253")
112
+ ```
113
+
114
+ Database.new(id) creates a Database object without accessing to Notion.
115
+ If you want to retrieve the contents after creation, please use a `reload` method.
95
116
 
96
117
  ```Ruby
97
- obj.set_icon emoji: "💿" # set emoji
98
- obj.set_icon url: "https://cdn.profile-image.st-hatena.com/users/hkob/profile.png" # set external url
118
+ db = Database.new("c37a2c66-e3aa-4a0d-a447-73de3b80c253")
119
+ db.reload
99
120
  ```
100
121
 
101
- - Get values and properties
122
+ ### 3.4 Retrieve a page
123
+
124
+ Page.find(id) creates a Page object from the results of Notion API.
102
125
 
103
126
  ```Ruby
104
- obj.icon # obtain icon json
105
- obj["icon"] # same as obj.icon
106
- obj.properties["NumberTitle"]
127
+ page = Page.find("c01166c6-13ae-45cb-b968-18b4ef2f5a77")
107
128
  ```
108
129
 
109
- #### Database class
130
+ Page.new(id) creates a Page object without accessing to Notion.
131
+ If you want to retrieve the contents after creation, please use a `reload` method.
110
132
 
111
- - Retrieve a database
112
133
  ```Ruby
113
- db = Database.find("c37a2c66-e3aa-4a0d-a447-73de3b80c253")
134
+ page = Page.new("c01166c6-13ae-45cb-b968-18b4ef2f5a77")
135
+ page.reload
114
136
  ```
115
- - Query a database
137
+
138
+ ### 3.5 Query a database
139
+
140
+ #### 3.5.1 A simple example
116
141
 
117
142
  Gets a List object of Page objects contained in the database.
118
143
  You can obtain filtered and ordered pages using Query object.
@@ -121,8 +146,6 @@ Database.query("c37a2c66-e3aa-4a0d-a447-73de3b80c253") # retrieves all pages
121
146
  Database.query("c37a2c66-e3aa-4a0d-a447-73de3b80c253", query) # retrieves using query
122
147
  ```
123
148
 
124
- #### Query class and related *Property class
125
-
126
149
  Query object can be generated from the following Property objects.
127
150
  For example, in order to obtain the pages whose title starts with "A" and ordered by ascending,
128
151
  the following code can be used.
@@ -132,6 +155,35 @@ query = tp.filter_starts_with("A").ascending(tp)
132
155
  pages = Database.query database_id, query
133
156
  ```
134
157
 
158
+ #### 3.5.2 Property classes
159
+
160
+ There are the following 17 XXXProperty classes corresponding to Notion databases.
161
+ They are child classes of a `Property` class
162
+ and these constructor method has a common form where the first argument is the property name.
163
+ ```Ruby
164
+ xp = XXXProperty.new "property name"
165
+ ```
166
+
167
+ 1. TitleProperty
168
+ 2. RichTextProperty
169
+ 3. UrlProperty
170
+ 4. EmailProperty
171
+ 5. PhoneNumberProperty
172
+ 6. NumberProperty
173
+ 7. CheckboxProperty
174
+ 8. SelectProperty
175
+ 9. MultiSelectProperty
176
+ 10. PeopleProperty
177
+ 11. CreatedByProperty
178
+ 12. LastEditedByProperty
179
+ 13. DateProperty
180
+ 14. CreatedTimeProperty
181
+ 15. LastEditedTimeProperty
182
+ 16. FilesProperty
183
+ 17. FormulaProperty
184
+
185
+ #### 3.5.3 Query object generator of property objects
186
+
135
187
  The following methods for the Property objects generate a query object.
136
188
  - TitleProperty, RichTextProperty, UrlProperty, EmailProperty, PhoneNumberProperty
137
189
  - filter_equals(value)
@@ -204,16 +256,19 @@ The following methods for the Property objects generate a query object.
204
256
  - filter_is_empty
205
257
  - filter_is_not_empty
206
258
 
259
+ #### 3.5.4 Complex conditions
207
260
  Complex filters can be generated `and` / `or` methods.
261
+ Here are some sample scripts and the json parameters created from them.
262
+
208
263
  ```Ruby
209
- # Prepare sample properties
264
+ # Prepare some sample properties
210
265
  tp = TitleProperty.new "tp"
211
266
  np = NumberProperty.new "np"
212
267
  cp = CheckboxProperty.new "cp"
213
268
  letp = LastEditedTimeProperty.new "letp"
214
269
  ```
215
270
 
216
- - (A and B) filter
271
+ - query1: (A and B) filter
217
272
  ```Ruby
218
273
  query1 = tp.filter_starts_with("start")
219
274
  .and(np.filter_greater_than(100))
@@ -233,7 +288,7 @@ query1 = tp.filter_starts_with("start")
233
288
  }
234
289
  ```
235
290
 
236
- - (A and B and C) filter
291
+ - query2: (A and B and C) filter
237
292
  ```Ruby
238
293
  query2 = tp.filter_starts_with("start")
239
294
  .and(np.filter_greater_than(100))
@@ -258,7 +313,7 @@ query2 = tp.filter_starts_with("start")
258
313
  }
259
314
  ```
260
315
 
261
- - (A or B) filter
316
+ - query3: (A or B) filter
262
317
  ```Ruby
263
318
  query3 = tp.filter_starts_with("start")
264
319
  .or(np.filter_greater_than(100))
@@ -278,7 +333,7 @@ query3 = tp.filter_starts_with("start")
278
333
  }
279
334
  ```
280
335
 
281
- - (A or B or C) filter
336
+ - query4: (A or B or C) filter
282
337
  ```Ruby
283
338
  query4 = tp.filter_starts_with("start")
284
339
  .or(np.filter_greater_than(100))
@@ -303,7 +358,7 @@ query4 = tp.filter_starts_with("start")
303
358
  }
304
359
  ```
305
360
 
306
- - ((A and B) or C) filter
361
+ - query5: ((A and B) or C) filter
307
362
  ```Ruby
308
363
  query5 = tp.filter_starts_with("start")
309
364
  .and(np.filter_greater_than(100))
@@ -332,7 +387,7 @@ query5 = tp.filter_starts_with("start")
332
387
  }
333
388
  ```
334
389
 
335
- - ((A or B) and C) filter
390
+ - query6: ((A or B) and C) filter
336
391
  ```Ruby
337
392
  query6 = tp.filter_starts_with("start")
338
393
  .or(np.filter_greater_than(100))
@@ -361,7 +416,7 @@ query6 = tp.filter_starts_with("start")
361
416
  }
362
417
  ```
363
418
 
364
- - ((A and B) or (C and D)) filter
419
+ - query7: ((A and B) or (C and D)) filter
365
420
  ```Ruby
366
421
  query7 = np.filter_greater_than(100).and(np.filter_less_than(200))
367
422
  .or(np.filter_greater_than(300).and(np.filter_less_than(400)))
@@ -397,7 +452,11 @@ query7 = np.filter_greater_than(100).and(np.filter_less_than(200))
397
452
  }
398
453
  ```
399
454
 
400
- - sort criteria
455
+ #### 3.5.5 Sort criteria
456
+ Sort criteria can be appended to an existing query object.
457
+ If you don't use the previous filters, you can generate by `Query.new`.
458
+
459
+ - sort criteria only
401
460
  ```Ruby
402
461
  query8 = Query.new.ascending tp
403
462
  query9 = Query.new.ascending letp
@@ -435,116 +494,184 @@ query13 = tp.filter_starts_with("A").ascending(tp)
435
494
  [{"property" => "tp", "direction" => "ascending"}]
436
495
  ```
437
496
 
438
- #### Page class
497
+ ### 3.6 Access the database or page values and properties
498
+
499
+ Database or Page values can be accessed by [] access with keywords.
439
500
 
440
- - Retrieve a page
441
501
  ```Ruby
442
- page = Page.find("c01166c6-13ae-45cb-b968-18b4ef2f5a77")
502
+ obj["icon"]
503
+ ```
504
+
505
+ Almost values returns a hash or an array object except "properties".
506
+ `obj["properties"]` or `obj.properties` returns a PropertyCache object.
507
+ The PropertyCache object is created from json information on the first access and is cached to the Page or Database object.
508
+ If page or database object is generated by `.new` method, the object don't have json information.
509
+ In this case, the `.properties` method calls `reload` method automatically, then it creates the PropertyCache object from the loaded json information (called auto-load function).
510
+
511
+ ```Ruby
512
+ obj["properties"]
513
+ # or
514
+ obj.properties
515
+ ```
516
+
517
+ Each Property object is obtained by [] access with the property name.
518
+ The Property object is also created on the first access and is cached to the PropertyCache object.
519
+
520
+ ```Ruby
521
+ np = obj.properties["NumberTitle"]
522
+ ```
523
+
524
+ ## 3.7 Set icon (Database / Page)
525
+
526
+ Database or Page icon can update by `obj.set_icon` method.
527
+ You can set icon as emoji or external url.
528
+
529
+ ```Ruby
530
+ obj.set_icon emoji: "💿" # set emoji
531
+ obj.set_icon url: "https://cdn.profile-image.st-hatena.com/users/hkob/profile.png" # set external url
443
532
  ```
444
533
 
445
- - Update values and properties
534
+ ## 3.8 Update page property values
446
535
 
447
536
  Page properties can update in the following three ways.
448
537
 
449
- 1. update the property directory (fastest: one API call only)
538
+ ### 3.8.1 Assign property and update it (fastest: one API call only)
539
+
540
+ This is the fastest way using an empty Page object.
541
+ `page.assign_property` generates an empty PropertyCache and an empty XXXProperty.
542
+ After updating the property value, please call `page.update`.
543
+ Notion API will be called using a JSON payload generated from the PropertyCache object.
544
+
450
545
  ```Ruby
451
546
  page = Page.new id: page_id
452
- np = NumberProperty.new "NumberTitle", number: 3.14
453
- page.add_property_for_update np
547
+ property = page.assign_property NumberProperty, "NumberTitle"
548
+ property.number = 2022
454
549
  page.update # update page API call
455
550
  print page
456
551
  ```
457
552
 
458
- 2. update the loaded page (easy but slow: two API call)
553
+ ### 3.8.2 Update the loaded page (easy but slow: two API calls)
554
+
555
+ This is an easiest way using a loaded Page object.
556
+ A PropertyCache object is automatically generated by `page.properties`.
557
+ After updating the property value, please call `page.update`.
558
+ Notion API will be called using a JSON payload generated from the PropertyCache object.
559
+ There are two API calls (find and update).
560
+
459
561
  ```Ruby
460
562
  page = Page.find first_page_id # retrieve page API call
461
- page.properties["NumberTitle"].number = 2022
563
+ property = page.properties["NumberTitle"]
564
+ property.number = 2022
462
565
  page.update # update page API call
463
566
  print page
464
567
  ```
465
568
 
466
- 3. update the unloaded page using autoload (easy but slow: two API call)
569
+ ### 3.8.3 Update the unloaded page with auto-load (easy but slow: two API calls)
570
+
571
+ This is also an easiest way using an auto-load function of the Page object.
572
+ A PropertyCache object is automatically generated by `page.properties` using the auto-load function of page objects.
573
+ After updating the property value, please call `page.update`.
574
+ Notion API will be called using a JSON payload generated from the PropertyCache object.
575
+ There are also two API calls (find and update).
576
+
467
577
  ```Ruby
468
578
  page = Page.new id: first_page_id
469
- page.properties["NumberTitle"].number = 12345 # retrieve page API call (autoload)
579
+ property = page.properties["NumberTitle"] # retrieve page API call (auto-load)
580
+ property.number = 12345
470
581
  page.update # update page API call
471
582
  print page
472
583
  ```
473
584
 
474
- - Retrieve block children (List object)
475
- ```Ruby
476
- children = page.children
477
- ```
585
+ ### 3.8.4 Explanation of how to update each property
586
+
587
+ #### 3.8.4.1 NumberProperty
478
588
 
479
- #### List class
589
+ NumberProperty can set a number by `.number=`.
480
590
 
481
- - access for each components
482
591
  ```Ruby
483
- list.each do |obj| # obj's class is Page or Block
484
- # do something
485
- end
592
+ np = page.properties["NumberTitle"]
593
+ np.number = 456
594
+ p np.create_json
595
+ # Result => {"number" => 456}
486
596
  ```
487
597
 
488
- #### Block class
489
-
490
- Not implemented
598
+ #### 3.8.4.2 SelectProperty
491
599
 
492
- #### NumberProperty class
600
+ NumberProperty can set a select name by `.select=`.
493
601
 
494
- - constructor
495
602
  ```Ruby
496
- np = NumberProperty.new "np", number: 123
603
+ sp = page.properties["SelectTitle"]
604
+ sp.select = "Select 2"
605
+ p sp.create_json
606
+ # Result => {"select" => {"name" => "Select 2"}}
497
607
  ```
498
608
 
499
- - set value
500
- ```Ruby
501
- np.number = 456 # number <- 456 and will_update <- true
502
- ```
609
+ #### 3.8.4.3 MultiSelectProperty
610
+
611
+ MultiSelectProperty can set a select value or Array of select values by `.multi_select=`.
503
612
 
504
- - create json
505
613
  ```Ruby
506
- np.create_json # {"number" => 456}
614
+ msp = page.properties["MultiSelectTitle"]
615
+ msp.select = "MS2"
616
+ p msp.create_json
617
+ # Result => {"multi_select" => [{"name" => "MS2"}]}
618
+
619
+ msp.multi_select = %w[MS2 MS1]
620
+ p msp.create_json
621
+ # Result => {"multi_select" => [{"name" => "MS2"}, {"name" => "MS1"}]}
507
622
  ```
508
623
 
509
- #### SelectProperty class
624
+ #### 3.8.4.4 DateProperty
510
625
 
511
- - constructor
512
- ```Ruby
513
- sp = SelectProperty.new "sp", select: "Select 1"
514
- ```
626
+ DateProperty can set a start_date or end_date by `.start_date=` or `end_date=`.
627
+ Date, Time, DateTime or String object can be used to the argument.
515
628
 
516
- - set value
517
629
  ```Ruby
518
- sp.select = "Select 2" # select <- "Select 2" and will_update <- true
519
- ```
630
+ dp = page.properties["DateTitle"]
631
+ dp.start_date = Date.new(2022, 2, 22)
632
+ p dp.create_json
633
+ # Result => {"start" => "2022-02-22"}
520
634
 
521
- - create json
522
- ```Ruby
523
- sp.create_json # {"select" => {"name" => "Select 2"}}
524
- ```
635
+ dp.start_date = Time.new(2022, 2, 22, 1, 23, 45, "+09:00")
636
+ p dp.create_json
637
+ # Result => {"start" => "2022-02-22T01:23:45+09:00"}
525
638
 
526
- #### MultiSelectProperty class
639
+ dp.start_date = DateTime.new(2022, 2, 23, 1, 23, 45, "+09:00")
640
+ p dp.create_json
641
+ # Result => {"start" => "2022-02-23T01:23:45+09:00"}
527
642
 
528
- - constructor
529
- ```Ruby
530
- msp1 = MultiSelectProperty.new "msp1", multi_select: "MS1" # Single value
531
- msp2 = MultiSelectProperty.new "msp2", multi_select: %w[MS1 MS2] # Multi values
532
- ```
643
+ dp.start_date = Date.new(2022, 2, 20)
644
+ dp.end_date = Date.new(2022, 2, 22)
645
+ p dp.create_json
646
+ # Result => {"start" => "2022-02-20", "end" => "2022-02-22"}
533
647
 
534
- - set value
535
- ```Ruby
536
- msp1.multi_select = %w[MS2 MS1] # multi_select <- ["MS1", "MS2"] and will_update <- true
537
- msp2.select = "MS2" # multi_select <- "MS2" and will_update <- true
648
+ dp.start_date = Time.new(2022, 2, 21, 1, 23, 45, "+09:00")
649
+ dp.end_date = Time.new(2022, 2, 22, 1, 23, 45, "+09:00")
650
+ p dp.create_json
651
+ # Result => {"start" => "2022-02-21T01:23:45+09:00", "end" => "2022-02-22T01:23:45+09:00"}
652
+
653
+ dp.start_date = DateTime.new(2022, 2, 21, 1, 23, 45, "+09:00")
654
+ dp.end_date = DateTime.new(2022, 2, 22, 1, 23, 45, "+09:00")
655
+ p dp.create_json
656
+ # result => {"start" => "2022-02-21T01:23:45+09:00", "end" => "2022-02-22T01:23:45+09:00"}
538
657
  ```
539
658
 
540
- - create json
659
+ ### 3.9 Iteration of list object
660
+
661
+ Some methods like as `Database.query` return a list object.
662
+ Since the list object also has a json array object, `Enumerable` module is implemented.
663
+ Each iteration creates a Page or Block object and calls the block with it as an argument.
664
+
541
665
  ```Ruby
542
- msp1.create_json # {"multi_select" => [{"name" => "MS2"}, {"name" => "MS1"}]}
543
- msp2.create_json # {"multi_select" => [{"name" => "MS2"}]}
666
+ pages = Database.query("c37a2c66-e3aa-4a0d-a447-73de3b80c253") # retrieves all pages
667
+ pages.each do |page| # obj's class is Page or Block
668
+ page.set_icon(emoji: "💿") unless page["icon"]
669
+ end
544
670
  ```
545
671
 
546
- ## ChangeLog
672
+ ## 4. ChangeLog
547
673
 
674
+ - 2022/2/25 add_property_for_update -> assign_property, update README.md
548
675
  - 2022/2/20 add support for MultiSelectProperty
549
676
  - 2022/2/19 add support for SelectProperty
550
677
  - 2022/2/17 added Page#properties, Page#add_property_for_update, Page#update
@@ -554,18 +681,18 @@ msp2.create_json # {"multi_select" => [{"name" => "MS2"}]}
554
681
  - 2022/2/13 added Page#set_icon
555
682
  - 2022/2/13 First commit
556
683
 
557
- ## Contributing
684
+ ## 5. Contributing
558
685
 
559
686
  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).
560
687
 
561
- ## License
688
+ ## 6. License
562
689
 
563
690
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
564
691
 
565
- ## Code of Conduct
692
+ ## 7. Code of Conduct
566
693
 
567
694
  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).
568
695
 
569
- ## Acknowledgements
696
+ ## 8. Acknowledgements
570
697
 
571
- The code depends on [notion-ruby-client](https://github.com/orbit-love/notion-ruby-client).
698
+ The code depends on [notion-ruby-client](https://github.com/orbit-love/notion-ruby-client).
@@ -91,7 +91,7 @@ module NotionRubyMapping
91
91
  end
92
92
  self
93
93
  end
94
-
94
+
95
95
  # @param [String] key
96
96
  # @return [NotionRubyMapping::PropertyCache, Hash] obtained Page value or PropertyCache
97
97
  def [](key)
@@ -116,10 +116,23 @@ module NotionRubyMapping
116
116
  # @param [Property] property Property object for udpate or create
117
117
  # @return [NotionRubyMapping::Base]
118
118
  def add_property_for_update(property)
119
- properties.add_property property, will_update: true
119
+ @property_cache ||= PropertyCache.new {}
120
+ @property_cache.add_property property, will_update: true
120
121
  self
121
122
  end
122
123
 
124
+ # @param [Class] klass
125
+ # @param [String] title
126
+ # @return [Property] generated property
127
+ def assign_property(klass, title)
128
+ @property_cache ||= PropertyCache.new {}
129
+
130
+ property = klass.new(title)
131
+ property.will_update = true
132
+ @property_cache.add_property property
133
+ property
134
+ end
135
+
123
136
  # @return [Hash] created json
124
137
  def create_json
125
138
  payload.create_json @property_cache&.create_json
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion_ruby_mapping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroyuki KOBAYASHI
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-21 00:00:00.000000000 Z
11
+ date: 2022-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: notion-ruby-client