notion_ruby_mapping 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +1 -1
- data/README.md +494 -268
- data/env.yml.sample +7 -0
- data/lib/notion_ruby_mapping/base.rb +37 -30
- data/lib/notion_ruby_mapping/checkbox_property.rb +26 -0
- data/lib/notion_ruby_mapping/created_by_property.rb +21 -0
- data/lib/notion_ruby_mapping/created_time_property.rb +20 -0
- data/lib/notion_ruby_mapping/database.rb +8 -8
- data/lib/notion_ruby_mapping/date_base_property.rb +40 -38
- data/lib/notion_ruby_mapping/date_property.rb +42 -18
- data/lib/notion_ruby_mapping/email_property.rb +30 -1
- data/lib/notion_ruby_mapping/files_property.rb +40 -0
- data/lib/notion_ruby_mapping/formula_property.rb +18 -0
- data/lib/notion_ruby_mapping/last_edited_by_property.rb +21 -0
- data/lib/notion_ruby_mapping/last_edited_time_property.rb +20 -0
- data/lib/notion_ruby_mapping/list.rb +33 -2
- data/lib/notion_ruby_mapping/mention_object.rb +49 -0
- data/lib/notion_ruby_mapping/multi_select_property.rb +25 -6
- data/lib/notion_ruby_mapping/notion_cache.rb +126 -53
- data/lib/notion_ruby_mapping/number_property.rb +13 -8
- data/lib/notion_ruby_mapping/page.rb +5 -2
- data/lib/notion_ruby_mapping/payload.rb +10 -2
- data/lib/notion_ruby_mapping/people_property.rb +38 -0
- data/lib/notion_ruby_mapping/phone_number_property.rb +30 -1
- data/lib/notion_ruby_mapping/property.rb +79 -43
- data/lib/notion_ruby_mapping/property_cache.rb +31 -12
- data/lib/notion_ruby_mapping/query.rb +5 -2
- data/lib/notion_ruby_mapping/relation_property.rb +37 -0
- data/lib/notion_ruby_mapping/rich_text_object.rb +74 -0
- data/lib/notion_ruby_mapping/rich_text_property.rb +18 -0
- data/lib/notion_ruby_mapping/rollup_property.rb +29 -0
- data/lib/notion_ruby_mapping/select_property.rb +12 -6
- data/lib/notion_ruby_mapping/text_object.rb +89 -0
- data/lib/notion_ruby_mapping/text_property.rb +61 -0
- data/lib/notion_ruby_mapping/title_property.rb +18 -0
- data/lib/notion_ruby_mapping/url_property.rb +30 -1
- data/lib/notion_ruby_mapping/user_object.rb +38 -0
- data/lib/notion_ruby_mapping/version.rb +2 -1
- data/lib/notion_ruby_mapping.rb +3 -3
- data/notion_ruby_mapping.gemspec +3 -1
- metadata +40 -7
data/README.md
CHANGED
@@ -1,44 +1,67 @@
|
|
1
|
-
#
|
1
|
+
# notion_ruby_mapping
|
2
2
|
|
3
3
|
Notion Ruby mapping is currently under development.
|
4
4
|
|
5
5
|
Development note is here. → [Idea note of "notion_ruby_mapping"](https://www.notion.so/hkob/Idea-note-of-notion_ruby_mapping-3b0a3bb3c171438a830f9579d41df501)
|
6
6
|
|
7
7
|
## Table of Contents
|
8
|
-
|
8
|
+
|
9
|
+
|
10
|
+
<!-- @import "[TOC]" {cmd="toc" depthFrom=1 depthTo=6 orderedList=false} -->
|
11
|
+
|
12
|
+
<!-- code_chunk_output -->
|
13
|
+
|
14
|
+
- [notion\_ruby\_mapping](#notion_ruby_mapping)
|
9
15
|
- [Table of Contents](#table-of-contents)
|
10
16
|
- [1. Installation](#1-installation)
|
11
17
|
- [2. Example code](#2-example-code)
|
12
|
-
|
18
|
+
- [2.1 Set icon to all icon unsettled pages](#21-set-icon-to-all-icon-unsettled-pages)
|
19
|
+
- [2.2 Renumbering pages](#22-renumbering-pages)
|
20
|
+
- [2.3 Change title](#23-change-title)
|
21
|
+
- [Pattern 1 (replace existing text partially)](#pattern-1-replace-existing-text-partially)
|
22
|
+
- [Pattern 2 (replace all text)](#pattern-2-replace-all-text)
|
23
|
+
- [3. Preparation](#3-preparation)
|
13
24
|
- [3.1 Create a New Integration](#31-create-a-new-integration)
|
14
25
|
- [3.2 Create client](#32-create-client)
|
15
|
-
|
16
|
-
- [
|
17
|
-
|
18
|
-
- [
|
19
|
-
- [
|
20
|
-
- [
|
21
|
-
|
22
|
-
- [
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- [3
|
28
|
-
- [
|
29
|
-
- [
|
30
|
-
- [
|
31
|
-
- [
|
32
|
-
- [
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
26
|
+
- [4. Usage](#4-usage)
|
27
|
+
- [4.1 Page](#41-page)
|
28
|
+
- [4.1.1 Retrieve a page](#411-retrieve-a-page)
|
29
|
+
- [4.1.2 Update page properties](#412-update-page-properties)
|
30
|
+
- [4.1.3 Update other page information](#413-update-other-page-information)
|
31
|
+
- [4.1.4 other methods](#414-other-methods)
|
32
|
+
- [4.2 Page](#42-page)
|
33
|
+
- [4.2.1 Retrieve a database](#421-retrieve-a-database)
|
34
|
+
- [4.2.2 Query a database](#422-query-a-database)
|
35
|
+
- [4.2.2.1 Complex conditions](#4221-complex-conditions)
|
36
|
+
- [4.2.2.2 Sort criteria](#4222-sort-criteria)
|
37
|
+
- [4.2.3 Update database](#423-update-database)
|
38
|
+
- [4.3 List class](#43-list-class)
|
39
|
+
- [4.4 Block class](#44-block-class)
|
40
|
+
- [4.5 Property classes](#45-property-classes)
|
41
|
+
- [4.5.1 How to obtain Property object](#451-how-to-obtain-property-object)
|
42
|
+
- [4.5.2 Query object generator of property objects](#452-query-object-generator-of-property-objects)
|
43
|
+
- [4.5.3 create or update values for Page properties](#453-create-or-update-values-for-page-properties)
|
44
|
+
- [4.5.3.1 NumberProperty](#4531-numberproperty)
|
45
|
+
- [4.5.3.2 SelectProperty](#4532-selectproperty)
|
46
|
+
- [4.5.3.3 MultiSelectProperty](#4533-multiselectproperty)
|
47
|
+
- [4.5.3.4 DateProperty](#4534-dateproperty)
|
48
|
+
- [4.5.3.4 UrlProperty](#4534-urlproperty)
|
49
|
+
- [4.5.3.5 EmailProperty](#4535-emailproperty)
|
50
|
+
- [4.5.3.6 PhoneNumberProperty](#4536-phonenumberproperty)
|
51
|
+
- [4.5.3.7 PeopleProperty](#4537-peopleproperty)
|
52
|
+
- [4.5.3.8 TitleProperty, RichTextProperty](#4538-titleproperty-richtextproperty)
|
53
|
+
- [4.5.3.9 CheckboxProperty](#4539-checkboxproperty)
|
54
|
+
- [4.5.3.10 EmailProperty](#45310-emailproperty)
|
55
|
+
- [4.5.3.11 FilesProperty](#45311-filesproperty)
|
56
|
+
- [4.5.3.12 RelationProperty](#45312-relationproperty)
|
57
|
+
- [6. ChangeLog](#6-changelog)
|
58
|
+
- [6. Contributing](#6-contributing)
|
59
|
+
- [7. License](#7-license)
|
60
|
+
- [8. Code of Conduct](#8-code-of-conduct)
|
61
|
+
- [9. Acknowledgements](#9-acknowledgements)
|
62
|
+
|
63
|
+
<!-- /code_chunk_output -->
|
64
|
+
|
42
65
|
|
43
66
|
## 1. Installation
|
44
67
|
|
@@ -50,15 +73,22 @@ gem 'notion_ruby_mapping'
|
|
50
73
|
|
51
74
|
And then execute:
|
52
75
|
|
53
|
-
|
76
|
+
```shell
|
77
|
+
bundle install
|
78
|
+
```
|
54
79
|
|
55
80
|
Or install it yourself as:
|
56
81
|
|
57
|
-
|
82
|
+
```shell
|
83
|
+
gem install notion_ruby_mapping
|
84
|
+
```
|
58
85
|
|
59
86
|
## 2. Example code
|
60
87
|
|
88
|
+
### 2.1 Set icon to all icon unsettled pages
|
89
|
+
|
61
90
|
The following code sets a "💿" icon on all unset pages in the database.
|
91
|
+
|
62
92
|
```Ruby
|
63
93
|
require "notion_ruby_mapping"
|
64
94
|
|
@@ -69,7 +99,8 @@ database_id = ENV["DATABASE_ID"]
|
|
69
99
|
|
70
100
|
NotionCache.instance.create_client token
|
71
101
|
|
72
|
-
Database.
|
102
|
+
db = Database.new id: database_id
|
103
|
+
db.query_database.each do |page|
|
73
104
|
p page.set_icon(emoji: "💿").id unless page.icon
|
74
105
|
end
|
75
106
|
```
|
@@ -78,19 +109,50 @@ end
|
|
78
109
|
|---|---|
|
79
110
|
|![Before execution](images/pre_set_icon.png)|![After execution](images/post_set_icon.png)|
|
80
111
|
|
112
|
+
### 2.2 Renumbering pages
|
113
|
+
|
81
114
|
The following code sets serial numbers to the pages whose title is not empty in ascending order of titles.
|
115
|
+
|
82
116
|
```Ruby
|
83
|
-
|
84
|
-
|
117
|
+
db = Database.new id: database_id, assign: [RichTextProperty, "TextTitle"]
|
118
|
+
tp = db.properties["TextTitle"]
|
119
|
+
query = tp.filter_is_not_empty.ascending(tp)
|
120
|
+
db.query_database(tp.filter_is_not_empty.ascending(tp)).each.with_index(1) do |page, index|
|
85
121
|
page.properties["NumberTitle"].number = index
|
86
122
|
page.update
|
87
123
|
end
|
88
124
|
```
|
125
|
+
|
89
126
|
| After execution |
|
90
127
|
|-----------------------------------------------|
|
91
128
|
| ![After exuecution](images/serial_number.png) |
|
92
129
|
|
93
|
-
|
130
|
+
### 2.3 Change title
|
131
|
+
|
132
|
+
The following code update the page title.
|
133
|
+
|
134
|
+
#### Pattern 1 (replace existing text partially)
|
135
|
+
|
136
|
+
```Ruby
|
137
|
+
page = Page.find page_id # API access
|
138
|
+
print page.title # -> ABC\nDEF
|
139
|
+
tp = page.properties["Title"]
|
140
|
+
tp[1].text = "GHI"
|
141
|
+
page.update # API access
|
142
|
+
print page.title # -> ABC\nGHI
|
143
|
+
```
|
144
|
+
|
145
|
+
#### Pattern 2 (replace all text)
|
146
|
+
|
147
|
+
```Ruby
|
148
|
+
page = Page.new id: page_id, assign: [TitleProperty, "Title"]
|
149
|
+
tp = page.properties["Title"]
|
150
|
+
tp << TextObject.new("JKL")
|
151
|
+
page.update # API access
|
152
|
+
print page.title # -> JKL
|
153
|
+
```
|
154
|
+
|
155
|
+
## 3. Preparation
|
94
156
|
|
95
157
|
### 3.1 Create a New Integration
|
96
158
|
|
@@ -99,176 +161,143 @@ Please check [Notion documentation](https://developers.notion.com/docs#getting-s
|
|
99
161
|
### 3.2 Create client
|
100
162
|
|
101
163
|
Please create a client (notion-ruby-client) before you use the following class.
|
164
|
+
|
102
165
|
```Ruby
|
103
166
|
NotionCache.instance.create_client ENV["NOTION_API_TOKEN"]
|
104
167
|
```
|
105
168
|
|
106
|
-
|
169
|
+
## 4. Usage
|
170
|
+
|
171
|
+
### 4.1 Page
|
172
|
+
|
173
|
+
#### 4.1.1 Retrieve a page
|
107
174
|
|
108
|
-
|
175
|
+
`Page.find(id)` creates a Page object with `retrieving page API`.
|
176
|
+
The created object has page information generated from the JSON response.
|
109
177
|
|
110
178
|
```Ruby
|
111
|
-
|
179
|
+
page = Page.find "c01166c6-13ae-45cb-b968-18b4ef2f5a77" # Notion API call
|
112
180
|
```
|
113
181
|
|
114
|
-
|
115
|
-
|
182
|
+
`Page.new(id)` creates a Page object without the Notion API.
|
183
|
+
Since Page.new does not acquire property information, so you need to assign yourself.
|
116
184
|
|
117
185
|
```Ruby
|
118
|
-
|
119
|
-
|
186
|
+
# Assign some properties for update manually
|
187
|
+
# The argument of assign keyword is Array with the multiple pairs of PropertyClass and Property name
|
188
|
+
page = Page.new id: "c01166c6-13ae-45cb-b968-18b4ef2f5a77",
|
189
|
+
assign: [TitleProperty, "Title", NumberProperty, "NumberTitle"]
|
120
190
|
```
|
121
191
|
|
122
|
-
|
192
|
+
#### 4.1.2 Update page properties
|
123
193
|
|
124
|
-
Page
|
194
|
+
Page properties with values can be obtained from the retrieved page using `find`.
|
195
|
+
On the other hand, Page properties without values can be obtained from the property assigned page.
|
125
196
|
|
126
197
|
```Ruby
|
127
|
-
|
198
|
+
tp = page.properties["Title"] # TitleProperty
|
199
|
+
np = page.properties["Number"] # NumberProperty
|
128
200
|
```
|
129
201
|
|
130
|
-
|
131
|
-
|
202
|
+
Each property object can change values using corresponded methods.
|
203
|
+
After changing value, `will_update` flag of the property object also set to true.
|
204
|
+
These methods are explained in the section of each property object class.
|
132
205
|
|
133
206
|
```Ruby
|
134
|
-
|
135
|
-
|
207
|
+
to = tp[1] # TitleProperty has Array of TextObject
|
208
|
+
to.text = "ABC" # TextObject can set text by ".text="
|
209
|
+
# or tp[1].text = "ABC"
|
210
|
+
|
211
|
+
np.number = 3.14159
|
136
212
|
```
|
137
213
|
|
138
|
-
|
214
|
+
After update some properties, `page.update` method sends `update page API` and replace the page information using the response of API.
|
139
215
|
|
140
|
-
|
216
|
+
```Ruby
|
217
|
+
page.update # Notion API call
|
218
|
+
```
|
219
|
+
|
220
|
+
#### 4.1.3 Update other page information
|
221
|
+
|
222
|
+
`page.set_icon` can change the page icon using emoji or external url.
|
141
223
|
|
142
|
-
Gets a List object of Page objects contained in the database.
|
143
|
-
You can obtain filtered and ordered pages using Query object.
|
144
224
|
```Ruby
|
145
|
-
|
146
|
-
|
225
|
+
# both methods call Notion API
|
226
|
+
obj.set_icon emoji: "💿" # set emoji
|
227
|
+
obj.set_icon url: "https://cdn.profile-image.st-hatena.com/users/hkob/profile.png" # set external url
|
147
228
|
```
|
148
229
|
|
149
|
-
|
150
|
-
|
151
|
-
|
230
|
+
#### 4.1.4 other methods
|
231
|
+
|
232
|
+
- `page.title` returns plain_text string of `Title`.
|
233
|
+
- `page.icon` returns JSON hash for the page icon.
|
234
|
+
- `page[key]` returns a hash or an array object except "properties".
|
235
|
+
|
236
|
+
### 4.2 Page
|
237
|
+
|
238
|
+
#### 4.2.1 Retrieve a database
|
239
|
+
|
240
|
+
`Database.find(id)` creates a Database object with `retrieving database API`.
|
241
|
+
The created object has database information generated from the JSON response.
|
242
|
+
|
152
243
|
```Ruby
|
153
|
-
|
154
|
-
query = tp.filter_starts_with("A").ascending(tp)
|
155
|
-
pages = Database.query database_id, query
|
244
|
+
db = Database.find("c37a2c66-e3aa-4a0d-a447-73de3b80c253") # Notion API call
|
156
245
|
```
|
157
246
|
|
158
|
-
|
247
|
+
`Database.new(id)` creates a Database object without the Notion API.
|
248
|
+
Since Database.new does not acquire property information, so you need to assign yourself.
|
159
249
|
|
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
250
|
```Ruby
|
164
|
-
|
251
|
+
# assign some properties for update manually
|
252
|
+
db = Database.new id: "c37a2c66-e3aa-4a0d-a447-73de3b80c253",
|
253
|
+
assign: [TitleProperty, "Title", NumberProperty, "NumberTitle"]
|
165
254
|
```
|
166
255
|
|
167
|
-
|
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
|
256
|
+
#### 4.2.2 Query a database
|
184
257
|
|
185
|
-
|
258
|
+
`db.query_database` obtains a List object with Page objects contained in the database.
|
259
|
+
You can obtain filtered and ordered pages using Query object.
|
186
260
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
- CheckboxProperty
|
207
|
-
- filter_equals(value)
|
208
|
-
- filter_does_not_equal(value)
|
209
|
-
- SelectProperty
|
210
|
-
- filter_equals(value)
|
211
|
-
- filter_does_not_equal(value)
|
212
|
-
- filter_is_empty
|
213
|
-
- filter_is_not_empty
|
214
|
-
- MultiSelectProperty, PeopleProperty, CreatedByProperty, LastEditedByProperty
|
215
|
-
- filter_contains(value)
|
216
|
-
- filter_does_not_contain(value)
|
217
|
-
- filter_is_empty
|
218
|
-
- filter_is_not_empty
|
219
|
-
- DateProperty, CreatedTimeProperty, LastEditedTimeProperty
|
220
|
-
- filter_equals(value(Date / Time / DateTime / String))
|
221
|
-
- filter_does_not_equal(value(Date / Time / DateTime / String))
|
222
|
-
- filter_before(value(Date / Time / DateTime / String))
|
223
|
-
- filter_after(value(Date / Time / DateTime / String))
|
224
|
-
- filter_on_or_before(value(Date / Time / DateTime / String))
|
225
|
-
- filter_on_or_after(value(Date / Time / DateTime / String))
|
226
|
-
- filter_past_week
|
227
|
-
- filter_past_month
|
228
|
-
- filter_past_year
|
229
|
-
- filter_next_week
|
230
|
-
- filter_next_month
|
231
|
-
- filter_next_year
|
232
|
-
- FilesProperty
|
233
|
-
- filter_is_empty
|
234
|
-
- filter_is_not_empty
|
235
|
-
- FormulaProperty
|
236
|
-
- filter_equals(value(Date / Time / DateTime / String))
|
237
|
-
- filter_does_not_equal(value(Date / Time / DateTime / String))
|
238
|
-
- filter_before(value(Date / Time / DateTime / String))
|
239
|
-
- filter_after(value(Date / Time / DateTime / String))
|
240
|
-
- filter_on_or_before(value(Date / Time / DateTime / String))
|
241
|
-
- filter_on_or_after(value(Date / Time / DateTime / String))
|
242
|
-
- filter_past_week
|
243
|
-
- filter_past_month
|
244
|
-
- filter_past_year
|
245
|
-
- filter_next_week
|
246
|
-
- filter_next_month
|
247
|
-
- filter_next_year
|
248
|
-
- filter_contains(value)
|
249
|
-
- filter_does_not_contain(value)
|
250
|
-
- filter_starts_with(value)
|
251
|
-
- filter_ends_with(value)
|
252
|
-
- filter_greater_than(value)
|
253
|
-
- filter_less_than(value)
|
254
|
-
- filter_greater_than_or_equal_to(value)
|
255
|
-
- filter_less_than_or_equal_to(value)
|
256
|
-
- filter_is_empty
|
257
|
-
- filter_is_not_empty
|
261
|
+
```Ruby
|
262
|
+
# query_database method calls Notion API
|
263
|
+
db.query_database # retrieves all pages (no filter, no sort)
|
264
|
+
db.query_database query # retrieves using query
|
265
|
+
```
|
266
|
+
|
267
|
+
The query object can be generated from the Property objects included in the database object.
|
268
|
+
The Property object can be obtained from the retrieved or assigned database object like as the Page object.
|
269
|
+
|
270
|
+
`filter_xxxx` methods of the property objects generates a query object.
|
271
|
+
These methods are explained in the section of each property object class.
|
272
|
+
|
273
|
+
```Ruby
|
274
|
+
tp = db.properties["Title"]
|
275
|
+
query = tp.filter_starts_with("A").ascending(tp)
|
276
|
+
pages = db.query_database query
|
277
|
+
```
|
278
|
+
|
279
|
+
##### 4.2.2.1 Complex conditions
|
258
280
|
|
259
|
-
|
260
|
-
Complex filters can be generated `and` / `or` methods.
|
281
|
+
Complex filters can be generated `and` / `or` methods of the Query object.
|
261
282
|
Here are some sample scripts and the json parameters created from them.
|
262
283
|
|
263
284
|
```Ruby
|
264
285
|
# Prepare some sample properties
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
286
|
+
db = Database.new id: "sample database id",
|
287
|
+
assign: [
|
288
|
+
TitleProperty, "tp",
|
289
|
+
NumberProperty, "np",
|
290
|
+
CheckboxProperty, "cp",
|
291
|
+
LastEditedTimeProperty, "letp",
|
292
|
+
]
|
293
|
+
properties = db.properties # PropertyCache object
|
294
|
+
# PropertyCache object can receive [] or values_at methods.
|
295
|
+
# `values_at` method is useful when retrieving multiple properties at once.
|
296
|
+
(tp, np, cp, letp) = properties.values_at "tp", "np", "cp", "letp"
|
269
297
|
```
|
270
298
|
|
271
299
|
- query1: (A and B) filter
|
300
|
+
|
272
301
|
```Ruby
|
273
302
|
query1 = tp.filter_starts_with("start")
|
274
303
|
.and(np.filter_greater_than(100))
|
@@ -289,6 +318,7 @@ query1 = tp.filter_starts_with("start")
|
|
289
318
|
```
|
290
319
|
|
291
320
|
- query2: (A and B and C) filter
|
321
|
+
|
292
322
|
```Ruby
|
293
323
|
query2 = tp.filter_starts_with("start")
|
294
324
|
.and(np.filter_greater_than(100))
|
@@ -314,6 +344,7 @@ query2 = tp.filter_starts_with("start")
|
|
314
344
|
```
|
315
345
|
|
316
346
|
- query3: (A or B) filter
|
347
|
+
|
317
348
|
```Ruby
|
318
349
|
query3 = tp.filter_starts_with("start")
|
319
350
|
.or(np.filter_greater_than(100))
|
@@ -334,6 +365,7 @@ query3 = tp.filter_starts_with("start")
|
|
334
365
|
```
|
335
366
|
|
336
367
|
- query4: (A or B or C) filter
|
368
|
+
|
337
369
|
```Ruby
|
338
370
|
query4 = tp.filter_starts_with("start")
|
339
371
|
.or(np.filter_greater_than(100))
|
@@ -359,6 +391,7 @@ query4 = tp.filter_starts_with("start")
|
|
359
391
|
```
|
360
392
|
|
361
393
|
- query5: ((A and B) or C) filter
|
394
|
+
|
362
395
|
```Ruby
|
363
396
|
query5 = tp.filter_starts_with("start")
|
364
397
|
.and(np.filter_greater_than(100))
|
@@ -388,6 +421,7 @@ query5 = tp.filter_starts_with("start")
|
|
388
421
|
```
|
389
422
|
|
390
423
|
- query6: ((A or B) and C) filter
|
424
|
+
|
391
425
|
```Ruby
|
392
426
|
query6 = tp.filter_starts_with("start")
|
393
427
|
.or(np.filter_greater_than(100))
|
@@ -417,6 +451,7 @@ query6 = tp.filter_starts_with("start")
|
|
417
451
|
```
|
418
452
|
|
419
453
|
- query7: ((A and B) or (C and D)) filter
|
454
|
+
|
420
455
|
```Ruby
|
421
456
|
query7 = np.filter_greater_than(100).and(np.filter_less_than(200))
|
422
457
|
.or(np.filter_greater_than(300).and(np.filter_less_than(400)))
|
@@ -452,11 +487,13 @@ query7 = np.filter_greater_than(100).and(np.filter_less_than(200))
|
|
452
487
|
}
|
453
488
|
```
|
454
489
|
|
455
|
-
|
490
|
+
##### 4.2.2.2 Sort criteria
|
491
|
+
|
456
492
|
Sort criteria can be appended to an existing query object.
|
457
493
|
If you don't use the previous filters, you can generate by `Query.new`.
|
458
494
|
|
459
495
|
- sort criteria only
|
496
|
+
|
460
497
|
```Ruby
|
461
498
|
query8 = Query.new.ascending tp
|
462
499
|
query9 = Query.new.ascending letp
|
@@ -484,6 +521,7 @@ query12 = Query.new.ascending(tp).descending letp
|
|
484
521
|
```
|
485
522
|
|
486
523
|
- filter with sort
|
524
|
+
|
487
525
|
```Ruby
|
488
526
|
query13 = tp.filter_starts_with("A").ascending(tp)
|
489
527
|
|
@@ -494,134 +532,187 @@ query13 = tp.filter_starts_with("A").ascending(tp)
|
|
494
532
|
[{"property" => "tp", "direction" => "ascending"}]
|
495
533
|
```
|
496
534
|
|
497
|
-
|
535
|
+
#### 4.2.3 Update database
|
498
536
|
|
499
|
-
|
537
|
+
=== under construction ===
|
500
538
|
|
501
|
-
|
502
|
-
obj["icon"]
|
503
|
-
```
|
539
|
+
### 4.3 List class
|
504
540
|
|
505
|
-
|
506
|
-
|
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).
|
541
|
+
`db.query_database` and other API list results returns a List object.
|
542
|
+
The list object is an Enumerable object, so usually combines with `.each` method.
|
510
543
|
|
511
544
|
```Ruby
|
512
|
-
|
513
|
-
#
|
514
|
-
|
545
|
+
db.query_database(query).each do |page|
|
546
|
+
# exec some methods for a page object
|
547
|
+
end
|
515
548
|
```
|
516
549
|
|
517
|
-
|
518
|
-
The
|
550
|
+
Notion API returns only the first page-size objects.
|
551
|
+
The default page-size of this library is 100.
|
552
|
+
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.
|
553
|
+
Users do not have to worry about paging.
|
519
554
|
|
520
|
-
|
521
|
-
np = obj.properties["NumberTitle"]
|
522
|
-
```
|
555
|
+
### 4.4 Block class
|
523
556
|
|
524
|
-
|
557
|
+
=== under construction ===
|
525
558
|
|
526
|
-
|
527
|
-
You can set icon as emoji or external url.
|
559
|
+
### 4.5 Property classes
|
528
560
|
|
529
|
-
|
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
|
532
|
-
```
|
561
|
+
#### 4.5.1 How to obtain Property object
|
533
562
|
|
534
|
-
|
535
|
-
|
536
|
-
Page properties can update in the following three ways.
|
563
|
+
There are the following 17 XXXProperty classes corresponding to Notion databases.
|
537
564
|
|
538
|
-
|
565
|
+
1. TitleProperty
|
566
|
+
2. RichTextProperty
|
567
|
+
3. UrlProperty
|
568
|
+
4. EmailProperty
|
569
|
+
5. PhoneNumberProperty
|
570
|
+
6. NumberProperty
|
571
|
+
7. CheckboxProperty
|
572
|
+
8. SelectProperty
|
573
|
+
9. MultiSelectProperty
|
574
|
+
10. PeopleProperty
|
575
|
+
11. CreatedByProperty
|
576
|
+
12. LastEditedByProperty
|
577
|
+
13. DateProperty
|
578
|
+
14. CreatedTimeProperty
|
579
|
+
15. LastEditedTimeProperty
|
580
|
+
16. FilesProperty
|
581
|
+
17. FormulaProperty
|
539
582
|
|
540
|
-
|
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.
|
583
|
+
They are child classes of a `Property` class and generated from Page or Database objects.
|
544
584
|
|
545
585
|
```Ruby
|
546
|
-
page = Page.new
|
547
|
-
|
548
|
-
|
549
|
-
page.update # update page API call
|
550
|
-
print page
|
551
|
-
```
|
586
|
+
page = Page.new page_id, assign: [XXXProperty, "property_name"]
|
587
|
+
# or
|
588
|
+
page = Page.find page_id
|
552
589
|
|
553
|
-
|
590
|
+
xp = page.properties["property_name"]
|
591
|
+
# or
|
592
|
+
xp, yp = page.properties.values_at "xp_name", "yp_name"
|
593
|
+
```
|
554
594
|
|
555
|
-
|
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).
|
595
|
+
#### 4.5.2 Query object generator of property objects
|
560
596
|
|
561
|
-
|
562
|
-
page = Page.find first_page_id # retrieve page API call
|
563
|
-
property = page.properties["NumberTitle"]
|
564
|
-
property.number = 2022
|
565
|
-
page.update # update page API call
|
566
|
-
print page
|
567
|
-
```
|
597
|
+
The following methods for the Property objects generate a query object.
|
568
598
|
|
569
|
-
|
599
|
+
- TitleProperty, RichTextProperty, UrlProperty, EmailProperty, PhoneNumberProperty
|
600
|
+
- filter_equals(value)
|
601
|
+
- filter_does_not_equal(value)
|
602
|
+
- filter_contains(value)
|
603
|
+
- filter_does_not_contain(value)
|
604
|
+
- filter_starts_with(value)
|
605
|
+
- filter_ends_with(value)
|
606
|
+
- filter_is_empty
|
607
|
+
- filter_is_not_empty
|
608
|
+
- NumberProperty
|
609
|
+
- filter_equals(value)
|
610
|
+
- filter_does_not_equal(value)
|
611
|
+
- filter_greater_than(value)
|
612
|
+
- filter_less_than(value)
|
613
|
+
- filter_greater_than_or_equal_to(value)
|
614
|
+
- filter_less_than_or_equal_to(value)
|
615
|
+
- filter_is_empty
|
616
|
+
- filter_is_not_empty
|
617
|
+
- CheckboxProperty
|
618
|
+
- filter_equals(value)
|
619
|
+
- filter_does_not_equal(value)
|
620
|
+
- SelectProperty
|
621
|
+
- filter_equals(value)
|
622
|
+
- filter_does_not_equal(value)
|
623
|
+
- filter_is_empty
|
624
|
+
- filter_is_not_empty
|
625
|
+
- MultiSelectProperty, PeopleProperty, CreatedByProperty, LastEditedByProperty
|
626
|
+
- filter_contains(value)
|
627
|
+
- filter_does_not_contain(value)
|
628
|
+
- filter_is_empty
|
629
|
+
- filter_is_not_empty
|
630
|
+
- DateProperty, CreatedTimeProperty, LastEditedTimeProperty
|
631
|
+
- filter_equals(value(Date / Time / DateTime / String))
|
632
|
+
- filter_does_not_equal(value(Date / Time / DateTime / String))
|
633
|
+
- filter_before(value(Date / Time / DateTime / String))
|
634
|
+
- filter_after(value(Date / Time / DateTime / String))
|
635
|
+
- filter_on_or_before(value(Date / Time / DateTime / String))
|
636
|
+
- filter_on_or_after(value(Date / Time / DateTime / String))
|
637
|
+
- filter_past_week
|
638
|
+
- filter_past_month
|
639
|
+
- filter_past_year
|
640
|
+
- filter_next_week
|
641
|
+
- filter_next_month
|
642
|
+
- filter_next_year
|
643
|
+
- FilesProperty
|
644
|
+
- filter_is_empty
|
645
|
+
- filter_is_not_empty
|
646
|
+
- FormulaProperty
|
647
|
+
- filter_equals(value(Date / Time / DateTime / String))
|
648
|
+
- filter_does_not_equal(value(Date / Time / DateTime / String))
|
649
|
+
- filter_before(value(Date / Time / DateTime / String))
|
650
|
+
- filter_after(value(Date / Time / DateTime / String))
|
651
|
+
- filter_on_or_before(value(Date / Time / DateTime / String))
|
652
|
+
- filter_on_or_after(value(Date / Time / DateTime / String))
|
653
|
+
- filter_past_week
|
654
|
+
- filter_past_month
|
655
|
+
- filter_past_year
|
656
|
+
- filter_next_week
|
657
|
+
- filter_next_month
|
658
|
+
- filter_next_year
|
659
|
+
- filter_contains(value)
|
660
|
+
- filter_does_not_contain(value)
|
661
|
+
- filter_starts_with(value)
|
662
|
+
- filter_ends_with(value)
|
663
|
+
- filter_greater_than(value)
|
664
|
+
- filter_less_than(value)
|
665
|
+
- filter_greater_than_or_equal_to(value)
|
666
|
+
- filter_less_than_or_equal_to(value)
|
667
|
+
- filter_is_empty
|
668
|
+
- filter_is_not_empty
|
570
669
|
|
571
|
-
|
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).
|
670
|
+
#### 4.5.3 create or update values for Page properties
|
576
671
|
|
577
|
-
|
578
|
-
|
579
|
-
property = page.properties["NumberTitle"] # retrieve page API call (auto-load)
|
580
|
-
property.number = 12345
|
581
|
-
page.update # update page API call
|
582
|
-
print page
|
583
|
-
```
|
672
|
+
Retrieving Page object has XXXProperties with values.
|
673
|
+
On the other hand, Assigned Page object has also XXXProperties, but they don't have any information for pages.
|
584
674
|
|
585
|
-
|
675
|
+
XXXProperties can change property values by setter methods.
|
676
|
+
Since the setter method is different for each class, it will be explained separately.
|
586
677
|
|
587
|
-
|
678
|
+
##### 4.5.3.1 NumberProperty
|
588
679
|
|
589
680
|
NumberProperty can set a number by `.number=`.
|
590
681
|
|
591
682
|
```Ruby
|
592
683
|
np = page.properties["NumberTitle"]
|
593
|
-
np.number =
|
594
|
-
p np.
|
595
|
-
# Result => {"number" =>
|
684
|
+
np.number = 3.14
|
685
|
+
p np.property_values_json
|
686
|
+
# Result => => {"np"=>{"number"=>3.14, "type"=>"number"}}
|
596
687
|
```
|
597
688
|
|
598
|
-
|
689
|
+
##### 4.5.3.2 SelectProperty
|
599
690
|
|
600
691
|
NumberProperty can set a select name by `.select=`.
|
601
692
|
|
602
693
|
```Ruby
|
603
694
|
sp = page.properties["SelectTitle"]
|
604
695
|
sp.select = "Select 2"
|
605
|
-
p sp.
|
606
|
-
# Result => {"select" =>
|
696
|
+
p sp.property_values_json
|
697
|
+
# Result => {"sp"=>{"type"=>"select", "select"=>{"name"=>"Select 2"}}}
|
607
698
|
```
|
608
699
|
|
609
|
-
|
700
|
+
##### 4.5.3.3 MultiSelectProperty
|
610
701
|
|
611
702
|
MultiSelectProperty can set a select value or Array of select values by `.multi_select=`.
|
612
703
|
|
613
704
|
```Ruby
|
614
705
|
msp = page.properties["MultiSelectTitle"]
|
615
|
-
msp.
|
616
|
-
p msp.
|
617
|
-
# Result => {"multi_select" =>
|
706
|
+
msp.multi_select = "MS2"
|
707
|
+
p msp.property_values_json
|
708
|
+
# Result => {"msp"=>{"type"=>"multi_select", "multi_select"=>[{"name"=>"MS2"}]}}
|
618
709
|
|
619
710
|
msp.multi_select = %w[MS2 MS1]
|
620
|
-
p msp.
|
621
|
-
# Result => {"multi_select" =>
|
711
|
+
p msp.property_values_json
|
712
|
+
# Result => {"msp"=>{"type"=>"multi_select", "multi_select"=>[{"name"=>"MS2"}, {"name"=>"MS1"}]}}
|
622
713
|
```
|
623
714
|
|
624
|
-
|
715
|
+
##### 4.5.3.4 DateProperty
|
625
716
|
|
626
717
|
DateProperty can set a start_date or end_date by `.start_date=` or `end_date=`.
|
627
718
|
Date, Time, DateTime or String object can be used to the argument.
|
@@ -629,48 +720,183 @@ Date, Time, DateTime or String object can be used to the argument.
|
|
629
720
|
```Ruby
|
630
721
|
dp = page.properties["DateTitle"]
|
631
722
|
dp.start_date = Date.new(2022, 2, 22)
|
632
|
-
p dp.
|
633
|
-
# Result => {"
|
723
|
+
p dp.property_values_json
|
724
|
+
# Result => {"dp"=>{"type"=>"date", "date"=>{"start"=>"2022-02-22", "end"=>nil, "time_zone"=>nil}}}
|
634
725
|
|
635
726
|
dp.start_date = Time.new(2022, 2, 22, 1, 23, 45, "+09:00")
|
636
|
-
p dp.
|
637
|
-
# Result => {"start"
|
727
|
+
p dp.property_values_json
|
728
|
+
# Result =>{"dp"=>{"type"=>"date", "date"=>{"start"=>"2022-02-22T01:23:45+09:00", "end"=>nil, "time_zone"=>nil}}}
|
638
729
|
|
639
730
|
dp.start_date = DateTime.new(2022, 2, 23, 1, 23, 45, "+09:00")
|
640
|
-
p dp.
|
641
|
-
# Result => {"
|
731
|
+
p dp.property_values_json
|
732
|
+
# Result => {"dp"=>{"type"=>"date", "date"=>{"start"=>"2022-02-23T01:23:45+09:00", "end"=>nil, "time_zone"=>nil}}}
|
642
733
|
|
643
734
|
dp.start_date = Date.new(2022, 2, 20)
|
644
735
|
dp.end_date = Date.new(2022, 2, 22)
|
645
|
-
p dp.
|
646
|
-
# Result => {"
|
736
|
+
p dp.property_values_json
|
737
|
+
# Result => => {"dp"=>{"type"=>"date", "date"=>{"start"=>"2022-02-20", "end"=>"2022-02-22", "time_zone"=>nil}}}
|
647
738
|
|
648
739
|
dp.start_date = Time.new(2022, 2, 21, 1, 23, 45, "+09:00")
|
649
740
|
dp.end_date = Time.new(2022, 2, 22, 1, 23, 45, "+09:00")
|
650
|
-
p dp.
|
741
|
+
p dp.property_values_json
|
651
742
|
# Result => {"start" => "2022-02-21T01:23:45+09:00", "end" => "2022-02-22T01:23:45+09:00"}
|
652
743
|
|
653
744
|
dp.start_date = DateTime.new(2022, 2, 21, 1, 23, 45, "+09:00")
|
654
745
|
dp.end_date = DateTime.new(2022, 2, 22, 1, 23, 45, "+09:00")
|
655
|
-
p dp.
|
656
|
-
# result => {"
|
746
|
+
p dp.property_values_json
|
747
|
+
# result => {"dp"=>{"type"=>"date", "date"=>{"start"=>"2022-02-21T01:23:45+09:00", "end"=>nil, "time_zone"=>nil}}}
|
657
748
|
```
|
658
749
|
|
659
|
-
|
750
|
+
##### 4.5.3.4 UrlProperty
|
660
751
|
|
661
|
-
|
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.
|
752
|
+
UrlProperty can set a url by `.url=`.
|
664
753
|
|
665
754
|
```Ruby
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
755
|
+
up = page.properties["UrlTitle"]
|
756
|
+
up.url = "https://www.google.com/"
|
757
|
+
p up.property_values_json
|
758
|
+
# result => {"up"=>{"url"=>"https://www.google.com/", "type"=>"url"}}
|
759
|
+
```
|
760
|
+
|
761
|
+
##### 4.5.3.5 EmailProperty
|
762
|
+
|
763
|
+
EmailProperty can set an email by `.email=`.
|
764
|
+
|
765
|
+
```Ruby
|
766
|
+
ep = page.properties["MailTitle"]
|
767
|
+
ep.email = "https://www.google.com/"
|
768
|
+
p ep.property_values_json
|
769
|
+
# result => {"ep"=>{"email"=>"hkobhkob@gmail.com", "type"=>"email"}}
|
670
770
|
```
|
671
771
|
|
672
|
-
|
772
|
+
##### 4.5.3.6 PhoneNumberProperty
|
773
|
+
|
774
|
+
PhoneNumberProperty can set an phone number by `.phone_number=`.
|
775
|
+
|
776
|
+
```Ruby
|
777
|
+
pp = page.properties["TelTitle"]
|
778
|
+
pp.phone_number = "xx-xxxx-xxxx"
|
779
|
+
p pp.property_values_json
|
780
|
+
# result => {"pp"=>{"phone_number"=>"xx-xxxx-xxxx", "type"=>"phone_number"}}
|
781
|
+
```
|
782
|
+
|
783
|
+
##### 4.5.3.7 PeopleProperty
|
784
|
+
|
785
|
+
PeopleProperty can set an people by `.people=`.
|
786
|
+
PeopleProperty can set a user_id/UserObject value or Array of user_id/UserObject values by `.people=`.
|
787
|
+
|
788
|
+
```Ruby
|
789
|
+
pp = page.properties["UserTitle"]
|
790
|
+
pp.people = "user_id1"
|
791
|
+
p pp.property_values_json
|
792
|
+
# result => {"pp"=>{"type"=>"people", "people"=>[{"object"=>"user", "id"=>"user_id1"}]}}
|
793
|
+
|
794
|
+
pp.people = UserObject.new json: user1_json
|
795
|
+
p pp.property_values_json
|
796
|
+
# result => {"pp"=>{"type"=>"people", "people"=>[{"object"=>"user", "id"=>"user_id1_from_json"}]}}
|
797
|
+
```
|
798
|
+
|
799
|
+
```Ruby
|
800
|
+
pp.people = %w[user_id2 user_id3]
|
801
|
+
p pp.property_values_json
|
802
|
+
# result => {"pp"=>{"type"=>"people", "people"=>[{"object"=>"user", "id"=>"user_id2"}, {"object"=>"user", "id"=>"user_id3"}]}}
|
803
|
+
|
804
|
+
u2 = UserObject.new(json: user2_json)
|
805
|
+
u3 = UserObject.new(json: user3_json)
|
806
|
+
pp.people = [u2, u3]
|
807
|
+
p pp.property_values_json
|
808
|
+
# result => {"pp"=>{"type"=>"people", "people"=>[{"object"=>"user", "id"=>"user_id2_from_json"}, {"object"=>"user", "id"=>"user_id3_from_json"}]}}
|
809
|
+
```
|
810
|
+
|
811
|
+
##### 4.5.3.8 TitleProperty, RichTextProperty
|
812
|
+
|
813
|
+
TextProperty's subclasses (TitleProperty, RichTextProperty) have an array of TextObject objects.
|
814
|
+
`[]` method returns an existing TextObject.
|
815
|
+
The obtained TextObject can be set text by `.text=`.
|
816
|
+
|
817
|
+
```Ruby
|
818
|
+
pp = page.properties["Title"]
|
819
|
+
tp[0].text = "ABC\n"
|
820
|
+
p tp.property_values_json
|
821
|
+
# result => {"tp"=>{"type"=>"title", "title"=>[{"type"=>"text", "text"=>{"content"=>"ABC\n", "link"=>nil}, "plain_text"=>"ABC\n", "href"=>nil}]}}
|
822
|
+
```
|
823
|
+
|
824
|
+
`<<` method appends a new TextObject or a String.
|
825
|
+
```Ruby
|
826
|
+
to = TextObject.new "DEF"
|
827
|
+
to.bold = true
|
828
|
+
to.italic = true
|
829
|
+
to.strikethrough = true
|
830
|
+
to.underline = true
|
831
|
+
to.code = true
|
832
|
+
to.color = "default"
|
833
|
+
tp << to
|
834
|
+
p tp.property_values_json
|
835
|
+
# 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"}}]}}
|
836
|
+
```
|
837
|
+
|
838
|
+
`delete_at(index)` method remove a TextObject at index.
|
839
|
+
```Ruby
|
840
|
+
tp.delete_at 1
|
841
|
+
tp << "GHI"
|
842
|
+
p tp.property_values_json
|
843
|
+
# 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}]}}
|
844
|
+
```
|
845
|
+
|
846
|
+
##### 4.5.3.9 CheckboxProperty
|
847
|
+
|
848
|
+
PeopleProperty can set a boolean value by `.checkbox=`.
|
849
|
+
```Ruby
|
850
|
+
cp = page.properties["CheckboxTitle"]
|
851
|
+
cp.checkbox = true
|
852
|
+
p cp.property_values_json
|
853
|
+
# result => {"cp"=>{"checkbox"=>true, "type"=>"checkbox"}}
|
854
|
+
```
|
855
|
+
|
856
|
+
##### 4.5.3.10 EmailProperty
|
857
|
+
|
858
|
+
EmailProperty can set an email address by `.email=`.
|
859
|
+
```Ruby
|
860
|
+
ep = page.properties["MailTitle"]
|
861
|
+
ep.email = "hkobhkob@gmail.com"
|
862
|
+
p ep.property_values_json
|
863
|
+
# result => {"ep"=>{"email"=>"hkobhkob@gmail.com", "type"=>"email"}}
|
864
|
+
```
|
865
|
+
|
866
|
+
##### 4.5.3.11 FilesProperty
|
867
|
+
|
868
|
+
FilesProperty can set an external url or Array of external urls by `.files=`.
|
869
|
+
|
870
|
+
```Ruby
|
871
|
+
fp = page.properties["FilesTitle"]
|
872
|
+
fp.files = "F1"
|
873
|
+
p fp.property_values_json
|
874
|
+
# Result => {"fp"=>{"files"=>[{"name"=>"F1", "type"=>"external", "external"=>{"url"=>"F1"}}], "type"=>"files"}}
|
875
|
+
|
876
|
+
fp.files = %w[F2 F3]
|
877
|
+
p fp.property_values_json
|
878
|
+
# Result => {"fp"=>{"files"=>[{"name"=>"F2", "type"=>"external", "external"=>{"url"=>"F2"}}, {"name"=>"F3", "type"=>"external", "external"=>{"url"=>"F3"}}], "type"=>"files"}}
|
879
|
+
```
|
880
|
+
|
881
|
+
##### 4.5.3.12 RelationProperty
|
882
|
+
|
883
|
+
RelationProperty can set an relation's page_id or Array of relation's page_ids by `.relation=`.
|
884
|
+
|
885
|
+
```Ruby
|
886
|
+
rp = page.properties["RelationTitle"]
|
887
|
+
rp.relation = "R1"
|
888
|
+
p rp.property_values_json
|
889
|
+
# Result => {"rp"=>{"type"=>"relation", "relation"=>[{"id"=>"R1"}]}}
|
890
|
+
|
891
|
+
rp.relation = %w[R2 R3]
|
892
|
+
p rp.property_values_json
|
893
|
+
# Result => {"rp"=>{"type"=>"relation", "relation"=>[{"id"=>"R2"}, {"id"=>"R3"}]}}
|
894
|
+
```
|
895
|
+
|
896
|
+
|
897
|
+
## 6. ChangeLog
|
673
898
|
|
899
|
+
- 2022/3/14 Exclude notion-ruby-client, update Property values, update for Notion-Version 2022-02-22
|
674
900
|
- 2022/2/25 add_property_for_update -> assign_property, update README.md
|
675
901
|
- 2022/2/20 add support for MultiSelectProperty
|
676
902
|
- 2022/2/19 add support for SelectProperty
|
@@ -681,18 +907,18 @@ end
|
|
681
907
|
- 2022/2/13 added Page#set_icon
|
682
908
|
- 2022/2/13 First commit
|
683
909
|
|
684
|
-
##
|
910
|
+
## 6. Contributing
|
685
911
|
|
686
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/hkob/notion_ruby_mapping
|
912
|
+
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).
|
687
913
|
|
688
|
-
##
|
914
|
+
## 7. License
|
689
915
|
|
690
916
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
691
917
|
|
692
|
-
##
|
918
|
+
## 8. Code of Conduct
|
693
919
|
|
694
920
|
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).
|
695
921
|
|
696
|
-
##
|
922
|
+
## 9. Acknowledgements
|
697
923
|
|
698
924
|
The code depends on [notion-ruby-client](https://github.com/orbit-love/notion-ruby-client).
|