notion_ruby_mapping 0.8.9 → 1.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/.rubocop.yml +12 -1
- data/lib/notion_ruby_mapping/blocks/base.rb +33 -33
- data/lib/notion_ruby_mapping/blocks/block.rb +48 -47
- 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 +6 -6
- 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 +2 -2
- data/lib/notion_ruby_mapping/blocks/file_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/heading1_block.rb +4 -4
- 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 +1 -1
- 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 -20
- data/lib/notion_ruby_mapping/blocks/numbered_list_item_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/page.rb +9 -10
- 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/discussion_thread.rb +1 -1
- data/lib/notion_ruby_mapping/controllers/mermaid_database.rb +34 -34
- data/lib/notion_ruby_mapping/controllers/notion_cache.rb +6 -8
- data/lib/notion_ruby_mapping/controllers/payload.rb +11 -11
- data/lib/notion_ruby_mapping/controllers/property_cache.rb +8 -7
- data/lib/notion_ruby_mapping/controllers/query.rb +10 -10
- data/lib/notion_ruby_mapping/controllers/search.rb +5 -6
- 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 +9 -9
- 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 +4 -4
- 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 +14 -13
- data/lib/notion_ruby_mapping/properties/date_property.rb +17 -17
- data/lib/notion_ruby_mapping/properties/email_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/files_property.rb +16 -13
- data/lib/notion_ruby_mapping/properties/formula_property.rb +7 -7
- data/lib/notion_ruby_mapping/properties/last_edited_by_property.rb +2 -2
- 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 +6 -6
- data/lib/notion_ruby_mapping/properties/phone_number_property.rb +4 -4
- data/lib/notion_ruby_mapping/properties/property.rb +78 -75
- data/lib/notion_ruby_mapping/properties/relation_property.rb +18 -17
- 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 +6 -6
- data/lib/notion_ruby_mapping/properties/unique_id_property.rb +3 -3
- 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/notion_ruby_mapping.gemspec +1 -2
- metadata +4 -22
- data/sig/notion_ruby_mapping.rbs +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d1066cd6c3332c90c8370e13f4cc52e9e729b29df0726ebad6279825d56f2a6
|
4
|
+
data.tar.gz: 85a67ad41b4ffb73578568e804c395b9fd0fb0f69ac6b535c3ddef0f8927e6e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3356a1466bae782aee4e51f6b14849e7c7a429b692bc0f6cb1108190d42f12231ca48975e3cd17cb271ac015d38f68d7aafd22edf9b6688e0e4ecd3ab7d59c8d
|
7
|
+
data.tar.gz: 4272a59512daad50200fb919483a2b36044fa5dd875c20289b90871a0e276b0771b3f6235eae94df09421afbf862f1fb8f8726a6efb0b11f79b0ade0dfbdab04
|
data/.rubocop.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require: rubocop-rspec
|
2
2
|
|
3
3
|
AllCops:
|
4
|
-
TargetRubyVersion:
|
4
|
+
TargetRubyVersion: 3.0
|
5
5
|
|
6
6
|
Style/StringLiterals:
|
7
7
|
Enabled: true
|
@@ -26,6 +26,17 @@ Style/TrailingCommaInArrayLiteral:
|
|
26
26
|
Style/TrailingCommaInHashLiteral:
|
27
27
|
EnforcedStyleForMultiline: comma
|
28
28
|
|
29
|
+
Naming/VariableNumber:
|
30
|
+
EnforcedStyle: snake_case
|
31
|
+
|
32
|
+
RSpec/NestedGroups:
|
33
|
+
Enabled: true
|
34
|
+
MaxNesting: 5
|
35
|
+
|
36
|
+
RSpec/MultipleMemoizedHelpers:
|
37
|
+
Enabled: true
|
38
|
+
Max: 8
|
39
|
+
|
29
40
|
Metrics/BlockLength:
|
30
41
|
Exclude:
|
31
42
|
- "Rakefile"
|
@@ -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 && {
|
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]&.to_sym
|
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
|
@@ -90,7 +90,7 @@ module NotionRubyMapping
|
|
90
90
|
self.class.dry_run_script :get, @nc.retrieve_comments_path(@id)
|
91
91
|
else
|
92
92
|
ans = {}
|
93
|
-
List.new(type:
|
93
|
+
List.new(type: "comment_parent", value: self,
|
94
94
|
json: @nc.retrieve_comments_request(@id, query),
|
95
95
|
query: query).each do |comment|
|
96
96
|
dt_id = comment.discussion_id
|
@@ -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]
|
@@ -128,20 +128,20 @@ module NotionRubyMapping
|
|
128
128
|
|
129
129
|
only_one = blocks.length == 1
|
130
130
|
json = {
|
131
|
-
|
131
|
+
children: Array(blocks).map do |block|
|
132
132
|
assert_parent_children_pair block
|
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
|
@@ -155,10 +155,10 @@ module NotionRubyMapping
|
|
155
155
|
return if block.can_append
|
156
156
|
|
157
157
|
bt = block.type
|
158
|
-
raise StandardError, "Internal file block can not append." if bt ==
|
158
|
+
raise StandardError, "Internal file block can not append." if bt == :file
|
159
159
|
|
160
|
-
raise StandardError, "Column block can only append column_list block" unless bt ==
|
161
|
-
block? && type ==
|
160
|
+
raise StandardError, "Column block can only append column_list block" unless bt == :column &&
|
161
|
+
block? && type == :column_list
|
162
162
|
end
|
163
163
|
|
164
164
|
# @param [NotionRubyMapping::Property] klass
|
@@ -199,7 +199,7 @@ module NotionRubyMapping
|
|
199
199
|
|
200
200
|
# @return [NotionRubyMapping::CreatedTimeProperty]
|
201
201
|
def created_time
|
202
|
-
@created_time ||= CreatedTimeProperty.new("__timestamp__", json: self[
|
202
|
+
@created_time ||= CreatedTimeProperty.new("__timestamp__", json: self[:created_time])
|
203
203
|
end
|
204
204
|
|
205
205
|
# @return [TrueClass, FalseClass] true if Database object
|
@@ -210,7 +210,7 @@ module NotionRubyMapping
|
|
210
210
|
# @return [Hash, nil] obtained Hash
|
211
211
|
# @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#e13d526bd709451e9b06fd32e8d07fcd
|
212
212
|
def icon
|
213
|
-
self[
|
213
|
+
self[:icon]
|
214
214
|
end
|
215
215
|
|
216
216
|
# @return [String (frozen)]
|
@@ -220,12 +220,12 @@ module NotionRubyMapping
|
|
220
220
|
|
221
221
|
# @return [Hash] json properties
|
222
222
|
def json_properties
|
223
|
-
@json && @json[
|
223
|
+
@json && @json[:properties]
|
224
224
|
end
|
225
225
|
|
226
226
|
# @return [NotionRubyMapping::LastEditedTimeProperty]
|
227
227
|
def last_edited_time
|
228
|
-
@last_edited_time ||= LastEditedTimeProperty.new("__timestamp__", json: self[
|
228
|
+
@last_edited_time ||= LastEditedTimeProperty.new("__timestamp__", json: self[:last_edited_time])
|
229
229
|
end
|
230
230
|
|
231
231
|
# @return [Boolean] true if new record
|
@@ -241,16 +241,16 @@ module NotionRubyMapping
|
|
241
241
|
|
242
242
|
# @param [Boolean] dry_run true if dry_run
|
243
243
|
def parent(dry_run: false)
|
244
|
-
parent_json = @json && @json[
|
244
|
+
parent_json = @json && @json[:parent]
|
245
245
|
raise StandardError, "Unknown parent" if parent_json.nil?
|
246
246
|
|
247
|
-
type = parent_json[
|
247
|
+
type = parent_json[:type]&.to_sym
|
248
248
|
klass = case type
|
249
|
-
when
|
249
|
+
when :database_id
|
250
250
|
Database
|
251
|
-
when
|
251
|
+
when :page_id
|
252
252
|
Page
|
253
|
-
when
|
253
|
+
when :block_id
|
254
254
|
Block
|
255
255
|
else
|
256
256
|
raise StandardError, "List does not have any parent"
|
@@ -259,10 +259,10 @@ module NotionRubyMapping
|
|
259
259
|
end
|
260
260
|
|
261
261
|
def parent_id
|
262
|
-
parent_json = @json && @json[
|
262
|
+
parent_json = @json && @json[:parent]
|
263
263
|
raise StandardError, "Unknown parent" if parent_json.nil?
|
264
264
|
|
265
|
-
parent_json[parent_json[
|
265
|
+
parent_json[parent_json[:type]]
|
266
266
|
end
|
267
267
|
|
268
268
|
# @return [NotionRubyMapping::PropertyCache] get or created PropertyCache object
|
@@ -294,13 +294,13 @@ module NotionRubyMapping
|
|
294
294
|
|
295
295
|
# @return [NotionRubyMapping::Base]
|
296
296
|
def restore_from_json
|
297
|
-
return if (ps = @json[
|
297
|
+
return if (ps = @json[:properties]).nil?
|
298
298
|
|
299
299
|
properties.json = json_properties
|
300
300
|
return unless is_a?(Page) || is_a?(Database)
|
301
301
|
|
302
302
|
ps.each do |key, json|
|
303
|
-
if json[
|
303
|
+
if json[:type]
|
304
304
|
properties[key].update_from_json json
|
305
305
|
else
|
306
306
|
properties[key]&.clear_will_update
|
@@ -341,13 +341,13 @@ module NotionRubyMapping
|
|
341
341
|
# @param [Hash] json
|
342
342
|
# @return [NotionRubyMapping::Base]
|
343
343
|
def update_json(json)
|
344
|
-
unless json[
|
344
|
+
unless json[:object] != "error" && (@json.nil? || @json[:type] == json[:type])
|
345
345
|
raise StandardError,
|
346
346
|
json.inspect
|
347
347
|
end
|
348
348
|
|
349
349
|
@json = json
|
350
|
-
@id = @nc.hex_id(@json[
|
350
|
+
@id = @nc.hex_id(@json[:id])
|
351
351
|
restore_from_json
|
352
352
|
self
|
353
353
|
end
|
@@ -15,51 +15,52 @@ 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
|
18
19
|
@type2class ||= {
|
19
20
|
false => {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
21
|
+
bookmark: BookmarkBlock,
|
22
|
+
breadcrumb: BreadcrumbBlock,
|
23
|
+
bulleted_list_item: BulletedListItemBlock,
|
24
|
+
callout: CalloutBlock,
|
25
|
+
child_database: ChildDatabaseBlock,
|
26
|
+
child_page: ChildPageBlock,
|
27
|
+
code: CodeBlock,
|
28
|
+
column: ColumnBlock,
|
29
|
+
column_list: ColumnListBlock,
|
30
|
+
divider: DividerBlock,
|
31
|
+
embed: EmbedBlock,
|
32
|
+
equation: EquationBlock,
|
33
|
+
file: FileBlock,
|
34
|
+
heading_1: Heading1Block,
|
35
|
+
heading_2: Heading2Block,
|
36
|
+
heading_3: Heading3Block,
|
37
|
+
image: ImageBlock,
|
38
|
+
link_preview: LinkPreviewBlock,
|
39
|
+
link_to_page: LinkToPageBlock,
|
40
|
+
numbered_list_item: NumberedListItemBlock,
|
41
|
+
paragraph: ParagraphBlock,
|
42
|
+
pdf: PdfBlock,
|
43
|
+
quote: QuoteBlock,
|
44
|
+
synced_block: SyncedBlock,
|
45
|
+
table: TableBlock,
|
46
|
+
table_row: TableRowBlock,
|
47
|
+
table_of_contents: TableOfContentsBlock,
|
48
|
+
template: TemplateBlock,
|
49
|
+
to_do: ToDoBlock,
|
50
|
+
toggle: ToggleBlock,
|
51
|
+
video: VideoBlock,
|
51
52
|
},
|
52
53
|
true => {
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
}
|
54
|
+
heading_1: ToggleHeading1Block,
|
55
|
+
heading_2: ToggleHeading2Block,
|
56
|
+
heading_3: ToggleHeading3Block,
|
57
|
+
},
|
57
58
|
}
|
58
|
-
@klass = @type2class[has_children][
|
59
|
+
@klass = @type2class[has_children][type_sym] || @type2class[false][type_sym] || Block
|
59
60
|
end
|
60
61
|
|
61
62
|
def self.decode_block(json)
|
62
|
-
type2class(json[
|
63
|
+
type2class(json[:type], json[:has_children]).new json: json
|
63
64
|
end
|
64
65
|
|
65
66
|
# @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#298916c7c379424682f39ff09ee38544
|
@@ -80,36 +81,36 @@ module NotionRubyMapping
|
|
80
81
|
# @return [NotionRubyMapping::Block, String]
|
81
82
|
# @param [Array<Block>] blocks
|
82
83
|
def append_after(*blocks, dry_run: false)
|
83
|
-
parent.append_block_children
|
84
|
+
parent.append_block_children(*blocks, after: id, dry_run: dry_run)
|
84
85
|
end
|
85
86
|
|
86
87
|
# @param [Boolean] not_update false when update
|
87
88
|
# @return [Hash{String (frozen)->Hash}]
|
88
89
|
def block_json(not_update: true)
|
89
|
-
ans = {
|
90
|
-
ans[
|
91
|
-
ans[
|
90
|
+
ans = {type: type.to_s}
|
91
|
+
ans[:object] = "block"
|
92
|
+
ans[:archived] = true if @archived
|
92
93
|
ans
|
93
94
|
end
|
94
95
|
|
95
96
|
# @return [Hash{String (frozen)->Array<Hash{String (frozen)->Hash}>}]
|
96
97
|
def children_block_json
|
97
|
-
{
|
98
|
+
{children: [block_json]}
|
98
99
|
end
|
99
100
|
|
100
101
|
# @return [NotionRubyMapping::RichTextArray]
|
101
102
|
def decode_block_caption
|
102
|
-
@caption = RichTextArray.new
|
103
|
+
@caption = RichTextArray.new :caption, json: @json[type][:caption]
|
103
104
|
end
|
104
105
|
|
105
106
|
# @return [String]
|
106
107
|
def decode_color
|
107
|
-
@color = @json[type][
|
108
|
+
@color = @json[type][:color]
|
108
109
|
end
|
109
110
|
|
110
111
|
# @return [NotionRubyMapping::RichTextArray]
|
111
112
|
def decode_block_rich_text_array
|
112
|
-
@rich_text_array = RichTextArray.new
|
113
|
+
@rich_text_array = RichTextArray.new :rich_text, json: @json[type][:rich_text]
|
113
114
|
end
|
114
115
|
|
115
116
|
# @param [Boolean] dry_run true if dry_run
|
@@ -144,10 +145,10 @@ module NotionRubyMapping
|
|
144
145
|
@can_have_children = true
|
145
146
|
end
|
146
147
|
|
147
|
-
# @param [String] type
|
148
|
+
# @param [String, Symbol] type
|
148
149
|
# @param [String] color
|
149
150
|
def rich_text_array_and_color(type, text_info, color = "default")
|
150
|
-
@rich_text_array = RichTextArray.rich_text_array type, text_info
|
151
|
+
@rich_text_array = RichTextArray.rich_text_array type.to_sym, text_info
|
151
152
|
@color = color
|
152
153
|
self
|
153
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 [Symbol]
|
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] = {
|
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 [Symbol]
|
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 [Symbol]
|
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 [Symbol]
|
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 [Symbol]
|
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: {
|
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: {
|
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
|
@@ -107,7 +107,7 @@ module NotionRubyMapping
|
|
107
107
|
Base.dry_run_script :post, @nc.query_database_path(@id), query.query_json
|
108
108
|
else
|
109
109
|
response = @nc.database_query_request @id, query
|
110
|
-
List.new json: response, type:
|
110
|
+
List.new json: response, type: "database", value: self, query: query
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|