notion_ruby_mapping 0.4.0 → 0.5.1

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