notion_ruby_mapping 0.4.1 → 0.5.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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -14
  3. data/examples/change_title.md +1 -1
  4. data/examples/renumbering_pages.md +3 -3
  5. data/examples/set_icon_to_all_icon_unsettled_pages.md +4 -4
  6. data/lib/notion_ruby_mapping/blocks/base.rb +11 -13
  7. data/lib/notion_ruby_mapping/blocks/block.rb +67 -487
  8. data/lib/notion_ruby_mapping/blocks/bookmark_block.rb +11 -0
  9. data/lib/notion_ruby_mapping/blocks/breadcrumb_block.rb +19 -0
  10. data/lib/notion_ruby_mapping/blocks/bulleted_list_item_block.rb +11 -0
  11. data/lib/notion_ruby_mapping/blocks/callout_block.rb +82 -0
  12. data/lib/notion_ruby_mapping/blocks/child_base_block.rb +21 -0
  13. data/lib/notion_ruby_mapping/blocks/child_database_block.rb +11 -0
  14. data/lib/notion_ruby_mapping/blocks/child_page_block.rb +11 -0
  15. data/lib/notion_ruby_mapping/blocks/code_block.rb +50 -0
  16. data/lib/notion_ruby_mapping/blocks/column_block.rb +29 -0
  17. data/lib/notion_ruby_mapping/blocks/column_list_block.rb +33 -0
  18. data/lib/notion_ruby_mapping/blocks/database.rb +7 -1
  19. data/lib/notion_ruby_mapping/blocks/divider_block.rb +19 -0
  20. data/lib/notion_ruby_mapping/blocks/embed_block.rb +11 -0
  21. data/lib/notion_ruby_mapping/blocks/equation_block.rb +43 -0
  22. data/lib/notion_ruby_mapping/blocks/file_base_block.rb +50 -0
  23. data/lib/notion_ruby_mapping/blocks/file_block.rb +11 -0
  24. data/lib/notion_ruby_mapping/blocks/heading1_block.rb +18 -0
  25. data/lib/notion_ruby_mapping/blocks/heading2_block.rb +18 -0
  26. data/lib/notion_ruby_mapping/blocks/heading3_block.rb +18 -0
  27. data/lib/notion_ruby_mapping/blocks/image_block.rb +11 -0
  28. data/lib/notion_ruby_mapping/blocks/link_preview_block.rb +16 -0
  29. data/lib/notion_ruby_mapping/blocks/link_to_page_block.rb +40 -0
  30. data/lib/notion_ruby_mapping/blocks/list.rb +2 -3
  31. data/lib/notion_ruby_mapping/blocks/numbered_list_item_block.rb +11 -0
  32. data/lib/notion_ruby_mapping/blocks/page.rb +6 -0
  33. data/lib/notion_ruby_mapping/blocks/paragraph_block.rb +11 -0
  34. data/lib/notion_ruby_mapping/blocks/pdf_block.rb +11 -0
  35. data/lib/notion_ruby_mapping/blocks/quote_block.rb +11 -0
  36. data/lib/notion_ruby_mapping/blocks/synced_block.rb +44 -0
  37. data/lib/notion_ruby_mapping/blocks/table_block.rb +50 -0
  38. data/lib/notion_ruby_mapping/blocks/table_of_contents_block.rb +34 -0
  39. data/lib/notion_ruby_mapping/blocks/table_row_block.rb +34 -0
  40. data/lib/notion_ruby_mapping/blocks/template_block.rb +34 -0
  41. data/lib/notion_ruby_mapping/blocks/text_sub_block_color_base_block.rb +45 -0
  42. data/lib/notion_ruby_mapping/blocks/to_do_block.rb +42 -0
  43. data/lib/notion_ruby_mapping/blocks/toggle_block.rb +11 -0
  44. data/lib/notion_ruby_mapping/blocks/toggle_heading1_block.rb +11 -0
  45. data/lib/notion_ruby_mapping/blocks/toggle_heading2_block.rb +11 -0
  46. data/lib/notion_ruby_mapping/blocks/toggle_heading3_block.rb +11 -0
  47. data/lib/notion_ruby_mapping/blocks/url_base_block.rb +34 -0
  48. data/lib/notion_ruby_mapping/blocks/url_caption_base_block.rb +46 -0
  49. data/lib/notion_ruby_mapping/blocks/video_block.rb +11 -0
  50. data/lib/notion_ruby_mapping/controllers/notion_cache.rb +26 -20
  51. data/lib/notion_ruby_mapping/controllers/payload.rb +32 -18
  52. data/lib/notion_ruby_mapping/controllers/query.rb +1 -1
  53. data/lib/notion_ruby_mapping/controllers/rich_text_array.rb +13 -2
  54. data/lib/notion_ruby_mapping/objects/rich_text_object.rb +2 -5
  55. data/lib/notion_ruby_mapping/properties/created_by_property.rb +1 -0
  56. data/lib/notion_ruby_mapping/properties/date_base_property.rb +24 -11
  57. data/lib/notion_ruby_mapping/properties/email_property.rb +1 -2
  58. data/lib/notion_ruby_mapping/properties/files_property.rb +1 -1
  59. data/lib/notion_ruby_mapping/properties/formula_property.rb +1 -1
  60. data/lib/notion_ruby_mapping/properties/multi_select_property.rb +2 -0
  61. data/lib/notion_ruby_mapping/properties/phone_number_property.rb +0 -1
  62. data/lib/notion_ruby_mapping/properties/select_property.rb +2 -1
  63. data/lib/notion_ruby_mapping/properties/url_property.rb +0 -2
  64. data/lib/notion_ruby_mapping/version.rb +1 -1
  65. data/lib/notion_ruby_mapping.rb +8 -1
  66. metadata +41 -2
@@ -5,12 +5,62 @@ module NotionRubyMapping
5
5
  class Block < Base
6
6
  ### Public announced methods
7
7
 
8
+ # @see https://www.notion.so/hkob/BreadcrumbBlock-3d0905b858524cdd8c868f80fd5d089a#d3b517be0c4b4825bed98206ce3ef41a
9
+ # @see https://www.notion.so/hkob/DividerBlock-d943b964dc4d4eff8f1d24ee0684e29e#f0ac8179c9a044bf95b87de1eb338413
8
10
  def initialize(json: nil, id: nil, parent: nil)
9
11
  super
10
12
  @can_have_children = false
11
13
  @can_append = true
12
14
  end
13
- attr_reader :can_have_children, :can_append, :type
15
+ attr_reader :can_have_children, :can_append, :type, :rich_text_array, :url, :caption, :color, :language
16
+
17
+ def self.type2class(type, has_children = false)
18
+ @type2class ||= {
19
+ false => {
20
+ "bookmark" => BookmarkBlock,
21
+ "breadcrumb" => BreadcrumbBlock,
22
+ "bulleted_list_item" => BulletedListItemBlock,
23
+ "callout" => CalloutBlock,
24
+ "child_database" => ChildDatabaseBlock,
25
+ "child_page" => ChildPageBlock,
26
+ "code" => CodeBlock,
27
+ "column" => ColumnBlock,
28
+ "column_list" => ColumnListBlock,
29
+ "divider" => DividerBlock,
30
+ "embed" => EmbedBlock,
31
+ "equation" => EquationBlock,
32
+ "file" => FileBlock,
33
+ "heading_1" => Heading1Block,
34
+ "heading_2" => Heading2Block,
35
+ "heading_3" => Heading3Block,
36
+ "image" => ImageBlock,
37
+ "link_preview" => LinkPreviewBlock,
38
+ "link_to_page" => LinkToPageBlock,
39
+ "numbered_list_item" => NumberedListItemBlock,
40
+ "paragraph" => ParagraphBlock,
41
+ "pdf" => PdfBlock,
42
+ "quote" => QuoteBlock,
43
+ "synced_block" => SyncedBlock,
44
+ "table" => TableBlock,
45
+ "table_row" => TableRowBlock,
46
+ "table_of_contents" => TableOfContentsBlock,
47
+ "template" => TemplateBlock,
48
+ "to_do" => ToDoBlock,
49
+ "toggle" => ToggleBlock,
50
+ "video" => VideoBlock,
51
+ },
52
+ true => {
53
+ "heading_1" => ToggleHeading1Block,
54
+ "heading_2" => ToggleHeading2Block,
55
+ "heading_3" => ToggleHeading3Block,
56
+ }
57
+ }
58
+ @klass = @type2class[has_children][type] || @type2class[false][type] || Block
59
+ end
60
+
61
+ def self.decode_block(json)
62
+ type2class(json["type"], json["has_children"]).new json: json
63
+ end
14
64
 
15
65
  # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#298916c7c379424682f39ff09ee38544
16
66
  # @param [String] id
@@ -24,254 +74,33 @@ module NotionRubyMapping
24
74
  end
25
75
  end
26
76
 
27
- # @return [Hash{String (frozen)->String (frozen) | Array}, nil]
28
- def block_json
29
- ans = {"type" => @type}
77
+ # @param [Boolean] not_update false when update
78
+ # @return [Hash{String (frozen)->Hash}]
79
+ def block_json(not_update: true)
80
+ ans = {"type" => type}
30
81
  ans["object"] = "block"
31
82
  ans["archived"] = true if @archived
32
- ans["has_children"] = true if @has_children
33
- case @type
34
- when "bookmark", "embed"
35
- @caption.will_update = true
36
- ans[@type] = @caption.update_property_schema_json
37
- ans[@type]["url"] = @url
38
- when "breadcrumb", "divider"
39
- ans[@type] = {}
40
- when "callout"
41
- @rich_text_array.will_update = true
42
- ans[@type] = @rich_text_array.update_property_schema_json
43
- ans[@type]["color"] = @color
44
- ans[@type]["icon"] = @emoji.property_values_json if @emoji
45
- ans[@type]["icon"] = @file.property_values_json if @file
46
- ans[@type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
47
- when "child_database", "child_page"
48
- ans[@type] = {"title" => @title}
49
- when "code"
50
- @rich_text_array.will_update = true
51
- @caption.will_update = true
52
- ans[@type] = @rich_text_array.update_property_schema_json.merge @caption.update_property_schema_json
53
- ans[@type]["language"] = @language
54
- when "column"
55
- ans[@type] = {}
56
- ans[@type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
57
- @can_append = false
58
- when "column_list"
59
- ans[@type] = {}
60
- ans[@type]["children"] = @columns.map(&:block_json) if @columns
61
- when "paragraph", "bulleted_list_item", "heading_1", "heading_2", "heading_3", "numbered_list_item", "quote",
62
- "toggle"
63
- @rich_text_array.will_update = true
64
- ans[@type] = @rich_text_array.update_property_schema_json
65
- ans[@type]["color"] = @color
66
- ans[@type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
67
- when "equation"
68
- ans[@type] = {"expression" => @equation_object.expression}
69
- when "file", "image", "pdf", "video"
70
- @caption.will_update = true if @caption
71
- ans[@type] = @file_object.property_values_json
72
- ans[@type].merge! @caption.update_property_schema_json if @caption
73
- when "link_preview"
74
- ans[@type] = {"url" => @url}
75
- when "link_to_page"
76
- ans[@type] = if @page_id
77
- {"type" => "page_id", "page_id" => @page_id}
78
- else
79
- {"type" => "database_id", "database_id" => @database_id}
80
- end
81
- when "synced_block"
82
- ans[@type] = {"synced_from" => @block_id ? {"type" => "block_id", "block_id" => @block_id} : nil}
83
- ans[@type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
84
- when "table"
85
- ans[@type] = {
86
- "has_column_header" => @has_column_header,
87
- "has_row_header" => @has_row_header,
88
- "table_width" => @table_width,
89
- }
90
- ans[@type]["children"] = @table_rows.map(&:block_json) if @table_rows
91
- when "table_of_contents"
92
- ans[@type] = {"color" => @color}
93
- when "table_row"
94
- ans[@type] = {"cells" => @cells.map { |cell| Array(cell).map(&:property_values_json) }}
95
- when "template"
96
- @rich_text_array.will_update = true
97
- ans[@type] = @rich_text_array.update_property_schema_json
98
- ans[@type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
99
- when "to_do"
100
- @rich_text_array.will_update = true
101
- ans[@type] = @rich_text_array.update_property_schema_json
102
- ans[@type]["checked"] = @checked
103
- ans[@type]["color"] = @color
104
- ans[@type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
105
- else
106
- print "not yet implemented"
107
- end
108
83
  ans
109
84
  end
110
85
 
111
- # @param [Sting] url
112
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] caption
113
- # @return [NotionRubyMapping::Block]
114
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#ff5299524c434c27bd79e4d942922928
115
- def bookmark(url, caption: [])
116
- @type = __method__.to_s
117
- @url = url
118
- @caption = RichTextArray.rich_text_array "caption", caption
119
- self
120
- end
121
-
122
- # @return [NotionRubyMapping::Block]
123
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#f0a9dc4e0823485abe5b76051053e877
124
- def breadcrumb
125
- @type = __method__.to_s
126
- self
127
- end
128
-
129
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
130
- # @param [String] color
131
- # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
132
- # @return [NotionRubyMapping::Block]
133
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#a97ff4121e724ee1aa45e194d0a76099
134
- def bulleted_list_item(text_info, sub_blocks: nil, color: "default")
135
- @type = __method__.to_s
136
- rich_text_array_and_color "rich_text", text_info, color
137
- add_sub_blocks sub_blocks
138
- self
139
- end
140
-
141
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
142
- # @param [String] emoji
143
- # @param [String] file_url
144
- # @param [String] color
145
- # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
146
- # @return [NotionRubyMapping::Block]
147
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#39b874d7b97749a49eebb9a5f48747a1
148
- def callout(text_info, emoji: nil, file_url: nil, sub_blocks: nil, color: "default")
149
- @type = __method__.to_s
150
- rich_text_array_and_color "rich_text", text_info, color
151
- @emoji = EmojiObject.emoji_object emoji if emoji
152
- @file = FileObject.file_object file_url if file_url
153
- add_sub_blocks sub_blocks
154
- self
155
- end
156
-
157
86
  # @return [Hash{String (frozen)->Array<Hash{String (frozen)->Hash}>}]
158
87
  def children_block_json
159
88
  {"children" => [block_json]}
160
89
  end
161
90
 
162
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
163
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] caption
164
- # @param [String] language
165
- # @return [NotionRubyMapping::Block]
166
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#90f1ebf5ca3f4b479471e6a76ef8c169
167
- def code(text_info, caption: [], language: "shell")
168
- @type = __method__.to_s
169
- rich_text_array_and_color "rich_text", text_info
170
- @caption = RichTextArray.rich_text_array "caption", caption
171
- @language = language
172
- self
173
- end
174
-
175
- # @return [NotionRubyMapping::Block]
176
- # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
177
- # @note created by column_list only
178
- def column(sub_blocks)
179
- @type = __method__.to_s
180
- add_sub_blocks sub_blocks
181
- self
182
- end
183
-
184
- # @param [Array<Array<NotionRubyMapping::Block, Array<NotionRubyMapping::Block>>>] array_of_sub_blocks
185
- # @return [NotionRubyMapping::Block]
186
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#5413288d6d2b4f0f8fe331b0e8e643ca
187
- def column_list(array_of_sub_blocks)
188
- @type = __method__.to_s
189
- raise StandardError, "The column_list must have at least 2 columns." if array_of_sub_blocks.count < 2
190
-
191
- @columns = array_of_sub_blocks.map { |sub_blocks| Block.new.column(sub_blocks) }
192
- self
193
- end
194
-
195
- # @return [NotionRubyMapping::Block]
196
- def decode_block
197
- @type = @json["type"]
198
- sub_json = @json[@type]
199
- case @type
200
- when "bookmark", "embed"
201
- @url = sub_json["url"]
202
- decode_block_caption
203
- when "bulleted_list_item", "paragraph", "numbered_list_item", "toggle", "heading_1", "heading_2", "heading_3"
204
- decode_block_rich_text_array
205
- decode_color
206
- @can_have_children = true
207
- when "quote"
208
- decode_block_rich_text_array
209
- decode_color
210
- @can_have_children = true
211
- when "callout"
212
- decode_block_rich_text_array
213
- decode_color
214
- @can_have_children = true
215
- when "child_database", "child_page"
216
- @title = sub_json["title"]
217
- @can_append = false
218
- when "code"
219
- decode_block_rich_text_array
220
- decode_block_caption
221
- @language = sub_json["language"] || "shell"
222
- when "equation"
223
- @equation_object = EquationObject.equation_object sub_json["expression"]
224
- when "file", "image", "pdf", "video"
225
- @file_object = FileObject.new json: sub_json
226
- decode_block_caption
227
- @can_append = @file_object.external?
228
- when "link_preview"
229
- @url = sub_json["url"]
230
- @can_append = false
231
- when "link_to_page"
232
- @page_id, @database_id = sub_json.values_at(*%w[page_id database_id])
233
- when "synced_block"
234
- @block_id = sub_json["synced_from"] && sub_json["synced_from"]["block_id"]
235
- @can_have_children = @block_id.nil?
236
- when "table"
237
- @has_column_header = sub_json["has_column_header"]
238
- @has_row_header = sub_json["has_row_header"]
239
- @table_width = sub_json["table_width"]
240
- @can_have_children = true
241
- when "table_of_contents"
242
- decode_color
243
- when "table_row"
244
- print sub_json["cells"]
245
- @cells = sub_json["cells"].map { |cell| cell.map { |to| RichTextObject.create_from_json to } }
246
- when "template"
247
- decode_block_rich_text_array
248
- @can_have_children = true
249
- when "to_do"
250
- decode_block_rich_text_array
251
- decode_color
252
- @checked = sub_json["checked"]
253
- @can_have_children = true
254
- else
255
- print "not yet implemented"
256
- end
257
- @has_children = @json["has_children"] == "true"
258
- @archived = @json["archived"] == "true"
259
- self
260
- end
261
-
262
91
  # @return [NotionRubyMapping::RichTextArray]
263
92
  def decode_block_caption
264
- @caption = RichTextArray.new "caption", json: @json[@type]["caption"]
93
+ @caption = RichTextArray.new "caption", json: @json[type]["caption"]
265
94
  end
266
95
 
267
96
  # @return [String]
268
97
  def decode_color
269
- @color = @json[@type]["color"]
98
+ @color = @json[type]["color"]
270
99
  end
271
100
 
272
101
  # @return [NotionRubyMapping::RichTextArray]
273
102
  def decode_block_rich_text_array
274
- @rich_text_array = RichTextArray.new "rich_text", json: @json[@type]["rich_text"]
103
+ @rich_text_array = RichTextArray.new "rich_text", json: @json[type]["rich_text"]
275
104
  end
276
105
 
277
106
  # @param [Boolean] dry_run
@@ -284,267 +113,18 @@ module NotionRubyMapping
284
113
  end
285
114
  end
286
115
 
287
- # @return [NotionRubyMapping::Block]
288
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#fe58d26468e04b38b8ae730e4f0c74ae
289
- def divider
290
- @type = __method__.to_s
291
- self
292
- end
293
-
294
- # @param [String] url
295
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] caption
296
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#1a69571806c24035b93adec8c8480d87
297
- def embed(url, caption: [])
298
- @type = __method__.to_s
299
- @url = url
300
- @caption = RichTextArray.rich_text_array "caption", caption
301
- self
302
- end
303
-
304
- # @param [String, NotionRubyMapping::EquationObject] expression
305
- # @return [NotionRubyMapping::Block]
306
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#7e284283779c443a9e26a7bfd10f1b98
307
- def equation(expression)
308
- @type = __method__.to_s
309
- @equation_object = EquationObject.equation_object expression
310
- self
311
- end
312
-
313
- # @param [String] url
314
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] caption
315
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#6177fa62ef1e408ca498ebe8d8580d65
316
- def file(url, caption: [])
317
- @type = __method__.to_s
318
- @file_object = FileObject.file_object url
319
- @caption = RichTextArray.rich_text_array "caption", caption
320
- self
321
- end
322
-
323
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
324
- # @param [String] color
325
- # @return [NotionRubyMapping::Block]
326
- def heading_1(text_info, color: "default")
327
- @type = __method__.to_s
328
- rich_text_array_and_color "rich_text", text_info, color
329
- @can_have_children = true
330
- self
331
- end
332
-
333
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
334
- # @param [String] color
335
- # @return [NotionRubyMapping::Block]
336
- def heading_2(text_info, color: "default")
337
- @type = __method__.to_s
338
- rich_text_array_and_color "rich_text", text_info, color
339
- @can_have_children = true
340
- self
341
- end
342
-
343
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
344
- # @param [String] color
345
- # @return [NotionRubyMapping::Block]
346
- def heading_3(text_info, color: "default")
347
- @type = __method__.to_s
348
- rich_text_array_and_color "rich_text", text_info, color
349
- @can_have_children = true
350
- self
351
- end
352
-
353
- # @param [String] url
354
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] caption
355
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#7aad77515ce14e3bbc7e0a7a5427820b
356
- def image(url, caption: [])
357
- @type = __method__.to_s
358
- @file_object = FileObject.file_object url
359
- @caption = RichTextArray.rich_text_array "caption", caption
360
- self
361
- end
362
-
363
- # @param [String] page_id
364
- # @param [String] database_id
365
- # @return [NotionRubyMapping::Block]
366
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#aabda81c11a949d5ba2e73cf9b50d0ad
367
- def link_to_page(page_id: nil, database_id: nil)
368
- raise StandardError, "page_id or database_id is required." if page_id.nil? && database_id.nil?
369
-
370
- @type = __method__.to_s
371
- @page_id = page_id
372
- @database_id = database_id
373
- self
374
- end
375
-
376
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
377
- # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
378
- # @param [String] color
379
- # @return [NotionRubyMapping::Block]
380
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#186bfd02b51946bcbc732063e6c3af1c
381
- def numbered_list_item(text_info, sub_blocks: nil, color: "default")
382
- @type = __method__.to_s
383
- rich_text_array_and_color "rich_text", text_info, color
384
- add_sub_blocks sub_blocks
385
- self
386
- end
387
-
388
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
389
- # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
390
- # @param [String] color
391
- # @return [NotionRubyMapping::Block]
392
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#f3c4fd6a1578429680a5921cbe03c560
393
- def paragraph(text_info, sub_blocks: nil, color: "default")
394
- @type = __method__.to_s
395
- rich_text_array_and_color "rich_text", text_info, color
396
- add_sub_blocks sub_blocks
397
- self
398
- end
399
-
400
- # @param [String] url
401
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#cd22a466ded048f686ad1f201588d42a
402
- def pdf(url)
403
- @type = __method__.to_s
404
- @file_object = FileObject.file_object url
405
- self
406
- end
407
-
408
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
409
- # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
410
- # @param [String] color
411
- # @return [NotionRubyMapping::Block]
412
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#0a1ed3fc49d544d18606b84d59727b27
413
- def quote(text_info, sub_blocks: nil, color: "default")
414
- @type = __method__.to_s
415
- rich_text_array_and_color "rich_text", text_info, color
416
- add_sub_blocks sub_blocks
417
- self
418
- end
419
-
420
- # @param [Array<Block>] sub_blocks
421
- # @param [String] block_id
422
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#69fa1e60d151454aac3c7209a1c41793
423
- def synced_block(sub_blocks: nil, block_id: nil)
424
- raise StandardError, "blocks or block_id cannot set at the same time." if !sub_blocks.nil? && !block_id.nil?
425
-
426
- @type = __method__.to_s
427
- @sub_blocks = Array(sub_blocks) if sub_blocks
428
- @block_id = block_id
429
- @can_have_children = @block_id.nil?
430
- self
431
- end
432
-
433
- # @return [Boolean] true if synced_block & block_id is nil
434
- def synced_block_original?
435
- @type == "synced_block" && @block_id.nil?
436
- end
437
-
438
- def table(table_width:, has_column_header: false, has_row_header: false, table_rows: nil)
439
- @type = __method__.to_s
440
- @table_width = table_width
441
- @has_column_header = has_column_header
442
- @has_row_header = has_row_header
443
- if table_rows
444
- @table_rows = table_rows.map do |table_row|
445
- Block.new.table_row table_row, @table_width
446
- end
447
- end
448
- self
449
- end
450
-
451
- # @param [String] color
452
- # @return [NotionRubyMapping::Block]
453
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#272b41e76bef4f3d8e7386369475910e
454
- def table_of_contents(color: "default")
455
- @type = __method__.to_s
456
- @color = color
457
- self
458
- end
459
-
460
- # @param [Array<String, Array<String>, TextObject, Array<TextObject>>] array_array_of_text_objects
461
- # @return [NotionRubyMapping::Block]
462
- def table_row(array_array_of_text_objects, table_width)
463
- @type = __method__.to_s
464
- cc = array_array_of_text_objects.count
465
- raise StandardError, "table width must be #{table_width} (given array size is #{cc}" unless table_width == cc
466
-
467
- @cells = array_array_of_text_objects.map do |cell|
468
- Array(cell).map { |text_info| TextObject.text_object text_info }
116
+ # @return [NotionRubyMapping::Base, String]
117
+ def update(dry_run: false)
118
+ if dry_run
119
+ dry_run_script :patch, @nc.block_path(@id), :update_block_json
120
+ else
121
+ update_json @nc.update_block_request(@id, update_block_json)
469
122
  end
470
- self
471
- end
472
-
473
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
474
- # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
475
- # @return [NotionRubyMapping::Block]
476
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#840eefedd571423e8532ab9042cc0fc1
477
- def template(text_info, sub_blocks: nil)
478
- @type = __method__.to_s
479
- rich_text_array_and_color "rich_text", text_info, nil
480
- add_sub_blocks sub_blocks
481
- self
482
- end
483
-
484
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
485
- # @param [Boolean] checked
486
- # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
487
- # @param [String] color
488
- # @return [NotionRubyMapping::Block]
489
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#386e74f3760b43b49a1c3316532f252d
490
- def to_do(text_info, checked: false, sub_blocks: nil, color: "default")
491
- @type = __method__.to_s
492
- rich_text_array_and_color "rich_text", text_info, color
493
- add_sub_blocks sub_blocks
494
- @checked = checked
495
- self
496
- end
497
-
498
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
499
- # @param [Boolean] checked
500
- # @param [String] color
501
- # @return [NotionRubyMapping::Block]
502
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#5a156ee95d0f4a7a83689f7ce5830296
503
- def toggle(text_info, checked: false, sub_blocks: nil, color: "default")
504
- @type = __method__.to_s
505
- rich_text_array_and_color "rich_text", text_info, color
506
- @checked = checked
507
- add_sub_blocks sub_blocks
508
- self
509
- end
510
-
511
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
512
- # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
513
- # @param [String] color
514
- # @return [NotionRubyMapping::Block]
515
- # @see
516
- def toggle_heading_1(text_info, sub_blocks:, color: "default")
517
- heading_1 text_info, color: color
518
- add_sub_blocks sub_blocks
519
- self
520
123
  end
521
124
 
522
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
523
- # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
524
- # @param [String] color
525
- # @return [NotionRubyMapping::Block]
526
- def toggle_heading_2(text_info, sub_blocks:, color: "default")
527
- heading_2 text_info, color: color
528
- add_sub_blocks sub_blocks
529
- self
530
- end
531
-
532
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
533
- # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
534
- # @param [String] color
535
- # @return [NotionRubyMapping::Block]
536
- def toggle_heading_3(text_info, sub_blocks:, color: "default")
537
- heading_3 text_info, color: color
538
- add_sub_blocks sub_blocks
539
- self
540
- end
541
-
542
- # @param [String] url
543
- # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#7aad77515ce14e3bbc7e0a7a5427820b
544
- def video(url)
545
- @type = __method__.to_s
546
- @file_object = FileObject.file_object url
547
- self
125
+ # @return [Hash]
126
+ def update_block_json
127
+ @payload.update_block_json type, block_json(not_update: false)
548
128
  end
549
129
 
550
130
  protected
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class BookmarkBlock < UrlCaptionBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "bookmark"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class BreadcrumbBlock < Block
6
+ # @return [String (frozen)]
7
+ def type
8
+ "breadcrumb"
9
+ end
10
+
11
+ # @param [Boolean] not_update false when update
12
+ # @return [Hash{String (frozen)->Hash}]
13
+ def block_json(not_update: true)
14
+ ans = super
15
+ ans[type] = {}
16
+ ans
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class BulletedListItemBlock < TextSubBlockColorBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "bulleted_list_item"
9
+ end
10
+ end
11
+ end