notion_ruby_mapping 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/notion_ruby_mapping/blocks/base.rb +51 -37
- data/lib/notion_ruby_mapping/blocks/block.rb +13 -13
- data/lib/notion_ruby_mapping/blocks/bookmark_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/breadcrumb_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/bulleted_list_item_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/callout_block.rb +10 -10
- data/lib/notion_ruby_mapping/blocks/child_base_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/child_database_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/child_page_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/code_block.rb +7 -7
- data/lib/notion_ruby_mapping/blocks/column_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/column_list_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/database.rb +5 -5
- data/lib/notion_ruby_mapping/blocks/divider_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/embed_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/equation_block.rb +5 -5
- data/lib/notion_ruby_mapping/blocks/file_base_block.rb +15 -3
- data/lib/notion_ruby_mapping/blocks/file_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/heading1_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/heading2_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/heading3_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/image_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/link_preview_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/link_to_page_block.rb +5 -5
- data/lib/notion_ruby_mapping/blocks/list.rb +21 -21
- data/lib/notion_ruby_mapping/blocks/numbered_list_item_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/page.rb +8 -8
- data/lib/notion_ruby_mapping/blocks/paragraph_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/pdf_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/quote_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/synced_block.rb +5 -5
- data/lib/notion_ruby_mapping/blocks/table_block.rb +8 -8
- data/lib/notion_ruby_mapping/blocks/table_of_contents_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/table_row_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/template_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/text_sub_block_color_base_block.rb +4 -4
- data/lib/notion_ruby_mapping/blocks/to_do_block.rb +4 -4
- data/lib/notion_ruby_mapping/blocks/toggle_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/toggle_heading1_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/toggle_heading2_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/toggle_heading3_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/url_base_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/url_caption_base_block.rb +4 -4
- data/lib/notion_ruby_mapping/blocks/video_block.rb +2 -2
- data/lib/notion_ruby_mapping/controllers/mermaid.rb +2 -5
- data/lib/notion_ruby_mapping/controllers/mermaid_database.rb +29 -32
- data/lib/notion_ruby_mapping/controllers/notion_cache.rb +68 -2
- data/lib/notion_ruby_mapping/controllers/payload.rb +29 -11
- data/lib/notion_ruby_mapping/controllers/property_cache.rb +8 -9
- data/lib/notion_ruby_mapping/controllers/query.rb +14 -14
- data/lib/notion_ruby_mapping/controllers/search.rb +5 -5
- data/lib/notion_ruby_mapping/objects/comment_object.rb +2 -2
- data/lib/notion_ruby_mapping/objects/emoji_object.rb +3 -3
- data/lib/notion_ruby_mapping/objects/equation_object.rb +3 -3
- data/lib/notion_ruby_mapping/objects/file_object.rb +44 -21
- data/lib/notion_ruby_mapping/objects/file_upload_object.rb +78 -0
- data/lib/notion_ruby_mapping/objects/mention_object.rb +43 -43
- data/lib/notion_ruby_mapping/objects/rich_text_object.rb +43 -43
- data/lib/notion_ruby_mapping/objects/text_object.rb +5 -5
- data/lib/notion_ruby_mapping/objects/user_object.rb +4 -4
- data/lib/notion_ruby_mapping/properties/button_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/checkbox_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/created_by_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/created_time_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/date_base_property.rb +15 -14
- data/lib/notion_ruby_mapping/properties/date_property.rb +16 -16
- data/lib/notion_ruby_mapping/properties/email_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/files_property.rb +14 -12
- data/lib/notion_ruby_mapping/properties/formula_property.rb +7 -7
- data/lib/notion_ruby_mapping/properties/last_edited_by_property.rb +4 -3
- data/lib/notion_ruby_mapping/properties/last_edited_time_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/multi_select_property.rb +15 -15
- data/lib/notion_ruby_mapping/properties/number_property.rb +9 -9
- data/lib/notion_ruby_mapping/properties/people_property.rb +7 -7
- data/lib/notion_ruby_mapping/properties/phone_number_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/property.rb +55 -56
- data/lib/notion_ruby_mapping/properties/relation_property.rb +17 -18
- data/lib/notion_ruby_mapping/properties/rich_text_property.rb +5 -5
- data/lib/notion_ruby_mapping/properties/rollup_property.rb +15 -15
- data/lib/notion_ruby_mapping/properties/select_property.rb +14 -14
- data/lib/notion_ruby_mapping/properties/status_property.rb +5 -5
- data/lib/notion_ruby_mapping/properties/text_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/title_property.rb +7 -7
- data/lib/notion_ruby_mapping/properties/unique_id_property.rb +4 -4
- data/lib/notion_ruby_mapping/properties/url_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/verification_property.rb +3 -3
- data/lib/notion_ruby_mapping/version.rb +1 -1
- data/lib/notion_ruby_mapping.rb +1 -1
- data/notion_ruby_mapping.gemspec +2 -0
- metadata +35 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac7180c69212c47d60456deee3790f5cdd2b7f2074f7c5e244ccf2aae102b371
|
4
|
+
data.tar.gz: d7c88e0ab4d4afdb30cf1d95d285ea2f4a533353886bd0d33c9a3eea5e19ea35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e5aec4c569a646464f20f57a96c6cb714425faacd96d3be8f1413f67531d4c887e2fc5f21f5bfabe95a2614fdc31abed5e638337b64269ad460b99c089ffd78
|
7
|
+
data.tar.gz: 54639e4104e52699c1b26b92e07b934f6902a74210ef7652f79ce2db420e611e91bc61bcd6dffef48aeda2360a0fda2c165d5b967638ca9816aed2e96f80f066
|
@@ -10,13 +10,13 @@ module NotionRubyMapping
|
|
10
10
|
def initialize(json: nil, id: nil, assign: [], parent: nil)
|
11
11
|
@nc = NotionCache.instance
|
12
12
|
@json = json
|
13
|
-
@id = @nc.hex_id(id || @json && @json[
|
14
|
-
@archived = @json && @json[
|
15
|
-
@has_children = @json && @json[
|
13
|
+
@id = @nc.hex_id(id || @json && @json["id"])
|
14
|
+
@archived = @json && @json["archived"]
|
15
|
+
@has_children = @json && @json["has_children"]
|
16
16
|
@new_record = true unless parent.nil?
|
17
17
|
raise StandardError, "Unknown id" if !is_a?(List) && !is_a?(Block) && @id.nil? && parent.nil?
|
18
18
|
|
19
|
-
@payload = Payload.new(!is_a?(Block) && parent && {parent
|
19
|
+
@payload = Payload.new(!is_a?(Block) && parent && {"parent" => parent})
|
20
20
|
@property_cache = nil
|
21
21
|
@created_time = nil
|
22
22
|
@last_edited_time = nil
|
@@ -30,14 +30,14 @@ module NotionRubyMapping
|
|
30
30
|
# @param [Hash, Notion::Messages] json
|
31
31
|
# @return [NotionRubyMapping::Base]
|
32
32
|
def self.create_from_json(json)
|
33
|
-
case json[
|
34
|
-
when
|
33
|
+
case json["object"]
|
34
|
+
when "page"
|
35
35
|
Page.new json: json
|
36
|
-
when
|
36
|
+
when "database"
|
37
37
|
Database.new json: json
|
38
|
-
when
|
38
|
+
when "list"
|
39
39
|
List.new json: json
|
40
|
-
when
|
40
|
+
when "block"
|
41
41
|
Block.decode_block json
|
42
42
|
else
|
43
43
|
raise StandardError, json.inspect
|
@@ -110,7 +110,7 @@ module NotionRubyMapping
|
|
110
110
|
reload
|
111
111
|
end
|
112
112
|
case key
|
113
|
-
when
|
113
|
+
when "properties"
|
114
114
|
properties
|
115
115
|
else
|
116
116
|
@json[key]
|
@@ -133,15 +133,15 @@ module NotionRubyMapping
|
|
133
133
|
block.block_json
|
134
134
|
end,
|
135
135
|
}
|
136
|
-
json[
|
136
|
+
json["after"] = after if after
|
137
137
|
if dry_run
|
138
138
|
path = @nc.append_block_children_page_path(id)
|
139
139
|
self.class.dry_run_script :patch, path, json
|
140
140
|
else
|
141
141
|
response = @nc.append_block_children_request @id, json
|
142
|
-
raise StandardError, response unless response[
|
142
|
+
raise StandardError, response unless response["results"]
|
143
143
|
|
144
|
-
answers = response[
|
144
|
+
answers = response["results"].map { |sub_json| Block.create_from_json sub_json }
|
145
145
|
only_one ? answers.first : answers
|
146
146
|
end
|
147
147
|
end
|
@@ -166,12 +166,12 @@ module NotionRubyMapping
|
|
166
166
|
# @return [NotionRubyMapping::Property] generated property
|
167
167
|
def assign_property(klass, title)
|
168
168
|
@property_cache ||= PropertyCache.new({},
|
169
|
-
base_type: database? ?
|
169
|
+
base_type: database? ? "database" : "page",
|
170
170
|
page_id: page? ? @id : nil)
|
171
171
|
property = if database?
|
172
|
-
klass.new(title, will_update: new_record?, base_type:
|
172
|
+
klass.new(title, will_update: new_record?, base_type: "database")
|
173
173
|
else
|
174
|
-
klass.new(title, will_update: true, base_type:
|
174
|
+
klass.new(title, will_update: true, base_type: "page", property_cache: @property_cache)
|
175
175
|
end
|
176
176
|
@property_cache.add_property property
|
177
177
|
property
|
@@ -193,13 +193,18 @@ module NotionRubyMapping
|
|
193
193
|
@children
|
194
194
|
else
|
195
195
|
response = @nc.block_children_request @id, query.query_string
|
196
|
-
@children = List.new json: response, type:
|
196
|
+
@children = List.new json: response, type: "parent", value: self, query: query
|
197
197
|
end
|
198
198
|
end
|
199
199
|
|
200
|
+
# @return [Hash, nil] obtained Hash
|
201
|
+
def cover
|
202
|
+
self["cover"]
|
203
|
+
end
|
204
|
+
|
200
205
|
# @return [NotionRubyMapping::CreatedTimeProperty]
|
201
206
|
def created_time
|
202
|
-
@created_time ||= CreatedTimeProperty.new("__timestamp__", json: self[
|
207
|
+
@created_time ||= CreatedTimeProperty.new("__timestamp__", json: self["created_time"])
|
203
208
|
end
|
204
209
|
|
205
210
|
# @return [TrueClass, FalseClass] true if Database object
|
@@ -210,7 +215,7 @@ module NotionRubyMapping
|
|
210
215
|
# @return [Hash, nil] obtained Hash
|
211
216
|
# @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#e13d526bd709451e9b06fd32e8d07fcd
|
212
217
|
def icon
|
213
|
-
self[
|
218
|
+
self["icon"]
|
214
219
|
end
|
215
220
|
|
216
221
|
# @return [String (frozen)]
|
@@ -220,12 +225,12 @@ module NotionRubyMapping
|
|
220
225
|
|
221
226
|
# @return [Hash] json properties
|
222
227
|
def json_properties
|
223
|
-
@json && @json[
|
228
|
+
@json && @json["properties"]
|
224
229
|
end
|
225
230
|
|
226
231
|
# @return [NotionRubyMapping::LastEditedTimeProperty]
|
227
232
|
def last_edited_time
|
228
|
-
@last_edited_time ||= LastEditedTimeProperty.new("__timestamp__", json: self[
|
233
|
+
@last_edited_time ||= LastEditedTimeProperty.new("__timestamp__", json: self["last_edited_time"])
|
229
234
|
end
|
230
235
|
|
231
236
|
# @return [Boolean] true if new record
|
@@ -241,16 +246,16 @@ module NotionRubyMapping
|
|
241
246
|
|
242
247
|
# @param [Boolean] dry_run true if dry_run
|
243
248
|
def parent(dry_run: false)
|
244
|
-
parent_json = @json && @json[
|
249
|
+
parent_json = @json && @json["parent"]
|
245
250
|
raise StandardError, "Unknown parent" if parent_json.nil?
|
246
251
|
|
247
|
-
type = parent_json[
|
252
|
+
type = parent_json["type"]
|
248
253
|
klass = case type
|
249
|
-
when
|
254
|
+
when "database_id"
|
250
255
|
Database
|
251
|
-
when
|
256
|
+
when "page_id"
|
252
257
|
Page
|
253
|
-
when
|
258
|
+
when "block_id"
|
254
259
|
Block
|
255
260
|
else
|
256
261
|
raise StandardError, "List does not have any parent"
|
@@ -259,10 +264,10 @@ module NotionRubyMapping
|
|
259
264
|
end
|
260
265
|
|
261
266
|
def parent_id
|
262
|
-
parent_json = @json && @json[
|
267
|
+
parent_json = @json && @json["parent"]
|
263
268
|
raise StandardError, "Unknown parent" if parent_json.nil?
|
264
269
|
|
265
|
-
parent_json[parent_json[
|
270
|
+
parent_json[parent_json["type"]]
|
266
271
|
end
|
267
272
|
|
268
273
|
# @return [NotionRubyMapping::PropertyCache] get or created PropertyCache object
|
@@ -275,7 +280,7 @@ module NotionRubyMapping
|
|
275
280
|
reload
|
276
281
|
end
|
277
282
|
@property_cache = PropertyCache.new json_properties,
|
278
|
-
base_type: database? ?
|
283
|
+
base_type: database? ? "database" : "page",
|
279
284
|
page_id: page? ? @id : nil
|
280
285
|
end
|
281
286
|
@property_cache
|
@@ -294,13 +299,13 @@ module NotionRubyMapping
|
|
294
299
|
|
295
300
|
# @return [NotionRubyMapping::Base]
|
296
301
|
def restore_from_json
|
297
|
-
return if (ps = @json[
|
302
|
+
return if (ps = @json["properties"]).nil?
|
298
303
|
|
299
304
|
properties.json = json_properties
|
300
305
|
return unless is_a?(Page) || is_a?(Database)
|
301
306
|
|
302
307
|
ps.each do |key, json|
|
303
|
-
if json[
|
308
|
+
if json["type"]
|
304
309
|
properties[key].update_from_json json
|
305
310
|
else
|
306
311
|
properties[key]&.clear_will_update
|
@@ -323,13 +328,22 @@ module NotionRubyMapping
|
|
323
328
|
end
|
324
329
|
end
|
325
330
|
|
326
|
-
# @param [String]
|
327
|
-
# @param [String]
|
331
|
+
# @param [String, nil] url
|
332
|
+
# @param [String, nil] file_upload_object
|
333
|
+
# @return [NotionRubyMapping::Base]
|
334
|
+
def set_cover(url: nil, file_upload_object: nil)
|
335
|
+
@payload.set_cover(url: url, file_upload_object: file_upload_object) if page? || database?
|
336
|
+
self
|
337
|
+
end
|
338
|
+
|
339
|
+
# @param [String, nil] emoji
|
340
|
+
# @param [String, nil] url
|
341
|
+
# @param [FileUploadObject, nil] file_upload_object
|
328
342
|
# @return [NotionRubyMapping::Base]
|
329
343
|
# @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#62eea67af7824496820c6bb903503540
|
330
344
|
# @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#e13d526bd709451e9b06fd32e8d07fcd
|
331
|
-
def set_icon(emoji: nil, url: nil)
|
332
|
-
@payload.set_icon(emoji: emoji, url: url) if page? || database?
|
345
|
+
def set_icon(emoji: nil, url: nil, file_upload_object: nil)
|
346
|
+
@payload.set_icon(emoji: emoji, url: url, file_upload_object: file_upload_object) if page? || database?
|
333
347
|
self
|
334
348
|
end
|
335
349
|
|
@@ -341,13 +355,13 @@ module NotionRubyMapping
|
|
341
355
|
# @param [Hash] json
|
342
356
|
# @return [NotionRubyMapping::Base]
|
343
357
|
def update_json(json)
|
344
|
-
unless json[
|
358
|
+
unless json["object"] != "error" && (@json.nil? || @json["type"] == json["type"])
|
345
359
|
raise StandardError,
|
346
360
|
json.inspect
|
347
361
|
end
|
348
362
|
|
349
363
|
@json = json
|
350
|
-
@id = @nc.hex_id(@json[
|
364
|
+
@id = @nc.hex_id(@json["id"])
|
351
365
|
restore_from_json
|
352
366
|
self
|
353
367
|
end
|
@@ -15,7 +15,6 @@ module NotionRubyMapping
|
|
15
15
|
attr_reader :can_have_children, :can_append, :type, :rich_text_array, :url, :caption, :color, :language
|
16
16
|
|
17
17
|
def self.type2class(type, has_children = false)
|
18
|
-
type_sym = type.to_sym
|
19
18
|
@type2class ||= {
|
20
19
|
false => {
|
21
20
|
bookmark: BookmarkBlock,
|
@@ -56,17 +55,17 @@ module NotionRubyMapping
|
|
56
55
|
heading_3: ToggleHeading3Block,
|
57
56
|
},
|
58
57
|
}
|
59
|
-
@klass = @type2class[has_children][
|
58
|
+
@klass = @type2class[has_children][type.to_sym] || @type2class[false][type.to_sym] || Block
|
60
59
|
end
|
61
60
|
|
62
61
|
def self.decode_block(json)
|
63
|
-
type2class(json[
|
62
|
+
type2class(json["type"], json["has_children"]).new json: json
|
64
63
|
end
|
65
64
|
|
66
65
|
# @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#298916c7c379424682f39ff09ee38544
|
67
66
|
# @param [String] id
|
68
67
|
# @param [Boolean] dry_run true if dry_run
|
69
|
-
# @return [NotionRubyMapping::Block]
|
68
|
+
# @return [String, NotionRubyMapping::Block]
|
70
69
|
def self.find(id, dry_run: false)
|
71
70
|
nc = NotionCache.instance
|
72
71
|
block_id = Base.block_id id
|
@@ -87,30 +86,30 @@ module NotionRubyMapping
|
|
87
86
|
# @param [Boolean] not_update false when update
|
88
87
|
# @return [Hash{String (frozen)->Hash}]
|
89
88
|
def block_json(not_update: true)
|
90
|
-
ans = {type
|
91
|
-
ans[
|
92
|
-
ans[
|
89
|
+
ans = {"type" => type}
|
90
|
+
ans["object"] = "block"
|
91
|
+
ans["archived"] = true if @archived
|
93
92
|
ans
|
94
93
|
end
|
95
94
|
|
96
95
|
# @return [Hash{String (frozen)->Array<Hash{String (frozen)->Hash}>}]
|
97
96
|
def children_block_json
|
98
|
-
{children
|
97
|
+
{"children" => [block_json]}
|
99
98
|
end
|
100
99
|
|
101
100
|
# @return [NotionRubyMapping::RichTextArray]
|
102
101
|
def decode_block_caption
|
103
|
-
@caption = RichTextArray.new
|
102
|
+
@caption = RichTextArray.new "caption", json: @json[type]["caption"] if @json[type]["caption"]
|
104
103
|
end
|
105
104
|
|
106
105
|
# @return [String]
|
107
106
|
def decode_color
|
108
|
-
@color = @json[type][
|
107
|
+
@color = @json[type]["color"]
|
109
108
|
end
|
110
109
|
|
111
110
|
# @return [NotionRubyMapping::RichTextArray]
|
112
111
|
def decode_block_rich_text_array
|
113
|
-
@rich_text_array = RichTextArray.new
|
112
|
+
@rich_text_array = RichTextArray.new "rich_text", json: @json[type]["rich_text"]
|
114
113
|
end
|
115
114
|
|
116
115
|
# @param [Boolean] dry_run true if dry_run
|
@@ -129,7 +128,8 @@ module NotionRubyMapping
|
|
129
128
|
if dry_run
|
130
129
|
dry_run_script :patch, @nc.block_path(@id), :update_block_json
|
131
130
|
else
|
132
|
-
|
131
|
+
@json = @nc.update_block_request(@id, update_block_json)
|
132
|
+
update_file_object_from_json(@json) if is_a? FileBaseBlock
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
@@ -148,7 +148,7 @@ module NotionRubyMapping
|
|
148
148
|
# @param [String, Symbol] type
|
149
149
|
# @param [String] color
|
150
150
|
def rich_text_array_and_color(type, text_info, color = "default")
|
151
|
-
@rich_text_array = RichTextArray.rich_text_array type
|
151
|
+
@rich_text_array = RichTextArray.rich_text_array type, text_info
|
152
152
|
@color = color
|
153
153
|
self
|
154
154
|
end
|
@@ -15,7 +15,7 @@ module NotionRubyMapping
|
|
15
15
|
decode_block_rich_text_array
|
16
16
|
decode_color
|
17
17
|
else
|
18
|
-
rich_text_array_and_color
|
18
|
+
rich_text_array_and_color "rich_text", text_info, color
|
19
19
|
@emoji = EmojiObject.emoji_object emoji if emoji
|
20
20
|
@file_object = FileObject.file_object file_url if file_url
|
21
21
|
add_sub_blocks sub_blocks
|
@@ -32,10 +32,10 @@ module NotionRubyMapping
|
|
32
32
|
def block_json(not_update: true)
|
33
33
|
ans = super
|
34
34
|
ans[type] = @rich_text_array.update_property_schema_json not_update
|
35
|
-
ans[type][
|
36
|
-
ans[type][
|
37
|
-
ans[type][
|
38
|
-
ans[type][
|
35
|
+
ans[type]["color"] = @color
|
36
|
+
ans[type]["icon"] = @emoji.property_values_json if @emoji
|
37
|
+
ans[type]["icon"] = @file_object.property_values_json if @file_object
|
38
|
+
ans[type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
|
39
39
|
ans
|
40
40
|
end
|
41
41
|
|
@@ -43,7 +43,7 @@ module NotionRubyMapping
|
|
43
43
|
# @see https://www.notion.so/hkob/CalloutBlock-0eb8b64bea664bc89fad706a866a6e26#b3598e385c2d4a23ada506441a7f0f32
|
44
44
|
def color=(new_color)
|
45
45
|
@color = new_color
|
46
|
-
@payload.add_update_block_key
|
46
|
+
@payload.add_update_block_key "color"
|
47
47
|
end
|
48
48
|
|
49
49
|
# @return [String, nil]
|
@@ -57,7 +57,7 @@ module NotionRubyMapping
|
|
57
57
|
def emoji=(emoji)
|
58
58
|
@emoji = EmojiObject.emoji_object emoji
|
59
59
|
@file_object = nil
|
60
|
-
@payload.add_update_block_key
|
60
|
+
@payload.add_update_block_key "icon"
|
61
61
|
end
|
62
62
|
|
63
63
|
# @return [String]
|
@@ -71,12 +71,12 @@ module NotionRubyMapping
|
|
71
71
|
def file_url=(url)
|
72
72
|
@file_object = FileObject.file_object url
|
73
73
|
@emoji = nil
|
74
|
-
@payload.add_update_block_key
|
74
|
+
@payload.add_update_block_key "icon"
|
75
75
|
end
|
76
76
|
|
77
|
-
# @return [
|
77
|
+
# @return [String]
|
78
78
|
def type
|
79
|
-
|
79
|
+
"callout"
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -5,7 +5,7 @@ module NotionRubyMapping
|
|
5
5
|
class ChildBaseBlock < Block
|
6
6
|
def initialize(json: nil, id: nil, parent: nil)
|
7
7
|
super
|
8
|
-
@title = @json[type][
|
8
|
+
@title = @json[type]["title"]
|
9
9
|
@can_append = false
|
10
10
|
@can_append = false
|
11
11
|
end
|
@@ -14,7 +14,7 @@ module NotionRubyMapping
|
|
14
14
|
# @return [Hash{String (frozen)->Hash}]
|
15
15
|
def block_json(not_update: true)
|
16
16
|
ans = super
|
17
|
-
ans[type] = {title
|
17
|
+
ans[type] = {"title" => @title}
|
18
18
|
ans
|
19
19
|
end
|
20
20
|
end
|
@@ -3,13 +3,13 @@
|
|
3
3
|
module NotionRubyMapping
|
4
4
|
# Notion block
|
5
5
|
class ChildDatabaseBlock < ChildBaseBlock
|
6
|
-
# @return [
|
6
|
+
# @return [String]
|
7
7
|
def type
|
8
|
-
|
8
|
+
"child_database"
|
9
9
|
end
|
10
10
|
|
11
11
|
def title
|
12
|
-
@json[type][
|
12
|
+
@json[type]["title"]
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -3,13 +3,13 @@
|
|
3
3
|
module NotionRubyMapping
|
4
4
|
# Notion block
|
5
5
|
class ChildPageBlock < ChildBaseBlock
|
6
|
-
# @return [
|
6
|
+
# @return [String]
|
7
7
|
def type
|
8
|
-
|
8
|
+
"child_page"
|
9
9
|
end
|
10
10
|
|
11
11
|
def title
|
12
|
-
@json[type][
|
12
|
+
@json[type]["title"]
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -12,10 +12,10 @@ module NotionRubyMapping
|
|
12
12
|
if @json
|
13
13
|
decode_block_rich_text_array
|
14
14
|
decode_block_caption
|
15
|
-
@language = json[type][
|
15
|
+
@language = json[type]["language"] || "shell"
|
16
16
|
else
|
17
|
-
rich_text_array_and_color
|
18
|
-
@caption = RichTextArray.rich_text_array
|
17
|
+
rich_text_array_and_color "rich_text", text_info
|
18
|
+
@caption = RichTextArray.rich_text_array "caption", caption
|
19
19
|
@language = language
|
20
20
|
end
|
21
21
|
end
|
@@ -32,19 +32,19 @@ module NotionRubyMapping
|
|
32
32
|
ans[type] = @rich_text_array.update_property_schema_json(not_update).merge(
|
33
33
|
@caption.update_property_schema_json(not_update),
|
34
34
|
)
|
35
|
-
ans[type][
|
35
|
+
ans[type]["language"] = @language
|
36
36
|
ans
|
37
37
|
end
|
38
38
|
|
39
39
|
# @param [String] new_language
|
40
40
|
def language=(new_language)
|
41
41
|
@language = new_language
|
42
|
-
@payload.add_update_block_key
|
42
|
+
@payload.add_update_block_key "language"
|
43
43
|
end
|
44
44
|
|
45
|
-
# @return [
|
45
|
+
# @return [String]
|
46
46
|
def type
|
47
|
-
|
47
|
+
"code"
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -12,9 +12,9 @@ module NotionRubyMapping
|
|
12
12
|
@can_append = false
|
13
13
|
end
|
14
14
|
|
15
|
-
# @return [
|
15
|
+
# @return [String]
|
16
16
|
def type
|
17
|
-
|
17
|
+
"column"
|
18
18
|
end
|
19
19
|
|
20
20
|
# @param [Boolean] not_update false when update
|
@@ -22,7 +22,7 @@ module NotionRubyMapping
|
|
22
22
|
def block_json(not_update: true)
|
23
23
|
ans = super
|
24
24
|
ans[type] = {}
|
25
|
-
ans[type][
|
25
|
+
ans[type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
|
26
26
|
ans
|
27
27
|
end
|
28
28
|
end
|
@@ -18,7 +18,7 @@ module NotionRubyMapping
|
|
18
18
|
|
19
19
|
# @return [String (frozen)]
|
20
20
|
def type
|
21
|
-
|
21
|
+
"column_list"
|
22
22
|
end
|
23
23
|
|
24
24
|
# @param [Boolean] not_update false when update
|
@@ -26,7 +26,7 @@ module NotionRubyMapping
|
|
26
26
|
def block_json(not_update: true)
|
27
27
|
ans = super
|
28
28
|
ans[type] = {}
|
29
|
-
ans[type][
|
29
|
+
ans[type]["children"] = @columns.map(&:block_json) if @columns
|
30
30
|
ans
|
31
31
|
end
|
32
32
|
end
|
@@ -42,7 +42,7 @@ module NotionRubyMapping
|
|
42
42
|
# @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#c217ce78020a4de79b720790fce3092d
|
43
43
|
def build_child_page(*assign)
|
44
44
|
assign = properties.map { |p| [p.class, p.name] }.flatten if assign.empty?
|
45
|
-
page = Page.new assign: assign, parent: {database_id
|
45
|
+
page = Page.new assign: assign, parent: {"database_id" => @id}
|
46
46
|
pp = page.properties
|
47
47
|
pp.clear_will_update
|
48
48
|
yield page, pp if block_given?
|
@@ -55,7 +55,7 @@ module NotionRubyMapping
|
|
55
55
|
# @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#c217ce78020a4de79b720790fce3092d
|
56
56
|
def create_child_page(*assign, dry_run: false)
|
57
57
|
assign = properties.map { |p| [p.class, p.name] }.flatten if assign.empty?
|
58
|
-
page = Page.new assign: assign, parent: {database_id
|
58
|
+
page = Page.new assign: assign, parent: {"database_id" => @id}
|
59
59
|
pp = page.properties
|
60
60
|
pp.clear_will_update
|
61
61
|
yield page, pp if block_given?
|
@@ -65,12 +65,12 @@ module NotionRubyMapping
|
|
65
65
|
# @return [NotionRubyMapping::RichTextArray]
|
66
66
|
# @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#217a7d988c404d68b270c4874a9117b4
|
67
67
|
def database_title
|
68
|
-
@database_title ||= RichTextArray.new
|
68
|
+
@database_title ||= RichTextArray.new "title", json: (self["title"]), will_update: new_record?
|
69
69
|
end
|
70
70
|
|
71
71
|
# @return [NotionRubyMapping::RichTextArray]
|
72
72
|
def description
|
73
|
-
RichTextArray.new
|
73
|
+
RichTextArray.new "description", json: self["description"]
|
74
74
|
end
|
75
75
|
|
76
76
|
# @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
|
@@ -80,7 +80,7 @@ module NotionRubyMapping
|
|
80
80
|
|
81
81
|
# @return [Boolean]
|
82
82
|
def is_inline
|
83
|
-
self[
|
83
|
+
self["is_inline"]
|
84
84
|
end
|
85
85
|
|
86
86
|
# @param [Boolean] flag
|
@@ -8,7 +8,7 @@ module NotionRubyMapping
|
|
8
8
|
def initialize(expression = nil, json: nil, id: nil, parent: nil)
|
9
9
|
super(json: json, id: id, parent: parent)
|
10
10
|
@equation_object = if @json
|
11
|
-
EquationObject.equation_object @json[type][
|
11
|
+
EquationObject.equation_object @json[type]["expression"]
|
12
12
|
else
|
13
13
|
EquationObject.equation_object expression
|
14
14
|
end
|
@@ -18,7 +18,7 @@ module NotionRubyMapping
|
|
18
18
|
# @return [Hash{String (frozen)->Hash}]
|
19
19
|
def block_json(not_update: true)
|
20
20
|
ans = super
|
21
|
-
ans[type] = {expression
|
21
|
+
ans[type] = {"expression" => @equation_object.expression}
|
22
22
|
ans
|
23
23
|
end
|
24
24
|
|
@@ -32,12 +32,12 @@ module NotionRubyMapping
|
|
32
32
|
# @see https://www.notion.so/hkob/EquationBlock-df0f823dc5ac41b798052f161dd6540c#f05e3b2c82914cea9f05e9e6644647e1
|
33
33
|
def expression=(new_expression)
|
34
34
|
@equation_object = EquationObject.equation_object new_expression
|
35
|
-
@payload.add_update_block_key
|
35
|
+
@payload.add_update_block_key "expression"
|
36
36
|
end
|
37
37
|
|
38
|
-
# @return [
|
38
|
+
# @return [String]
|
39
39
|
def type
|
40
|
-
|
40
|
+
"equation"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|