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
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class CalloutBlock < Block
6
+ # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
7
+ # @param [String] emoji
8
+ # @param [String] file_url
9
+ # @param [String] color
10
+ # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
11
+ def initialize(text_info = nil, emoji: nil, file_url: nil, sub_blocks: nil, color: "default", json: nil, id: nil,
12
+ parent: nil)
13
+ super(json: json, id: id, parent: parent)
14
+ if @json
15
+ decode_block_rich_text_array
16
+ decode_color
17
+ else
18
+ rich_text_array_and_color "rich_text", text_info, color
19
+ @emoji = EmojiObject.emoji_object emoji if emoji
20
+ @file_object = FileObject.file_object file_url if file_url
21
+ add_sub_blocks sub_blocks
22
+ end
23
+ @can_have_children = true
24
+ end
25
+
26
+ # @see https://www.notion.so/hkob/CalloutBlock-0eb8b64bea664bc89fad706a866a6e26#db689d47cbcc44359a5ade17ca754cdd
27
+ # @see https://www.notion.so/hkob/CalloutBlock-0eb8b64bea664bc89fad706a866a6e26#4314e4d50617485f8d0fc3505c5b3e9b
28
+ attr_reader :color, :rich_text_array
29
+
30
+ # @param [Boolean] not_update false when update
31
+ # @return [Hash{String (frozen)->Hash}]
32
+ def block_json(not_update: true)
33
+ ans = super
34
+ ans[type] = @rich_text_array.update_property_schema_json not_update
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
+ ans
40
+ end
41
+
42
+ # @param [String] new_color
43
+ # @see https://www.notion.so/hkob/CalloutBlock-0eb8b64bea664bc89fad706a866a6e26#b3598e385c2d4a23ada506441a7f0f32
44
+ def color=(new_color)
45
+ @color = new_color
46
+ @payload.add_update_block_key "color"
47
+ end
48
+
49
+ # @return [String, nil]
50
+ # @see https://www.notion.so/hkob/CalloutBlock-0eb8b64bea664bc89fad706a866a6e26#611496b7fd96499882fad138ef248b04
51
+ def emoji
52
+ @emoji&.emoji
53
+ end
54
+
55
+ # @param [String] emoji
56
+ # @see https://www.notion.so/hkob/CalloutBlock-0eb8b64bea664bc89fad706a866a6e26#0bd030c398184f94b819358830c2e26d
57
+ def emoji=(emoji)
58
+ @emoji = EmojiObject.emoji_object emoji
59
+ @file_object = nil
60
+ @payload.add_update_block_key "icon"
61
+ end
62
+
63
+ # @return [String]
64
+ # @see https://www.notion.so/hkob/CalloutBlock-0eb8b64bea664bc89fad706a866a6e26#57a8fc88f2ee49f7963942ad30cbca04
65
+ def file_url
66
+ @file_object&.url
67
+ end
68
+
69
+ # @param [String] url
70
+ # @see https://www.notion.so/hkob/CalloutBlock-0eb8b64bea664bc89fad706a866a6e26#041dd676bbfb442699229486fd30370a
71
+ def file_url=(url)
72
+ @file_object = FileObject.file_object url
73
+ @emoji = nil
74
+ @payload.add_update_block_key "icon"
75
+ end
76
+
77
+ # @return [String (frozen)]
78
+ def type
79
+ "callout"
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class ChildBaseBlock < Block
6
+ def initialize(json: nil, id: nil, parent: nil)
7
+ super
8
+ @title = @json[type]["title"]
9
+ @can_append = false
10
+ @can_append = false
11
+ end
12
+
13
+ # @param [Boolean] not_update false when update
14
+ # @return [Hash{String (frozen)->Hash}]
15
+ def block_json(not_update: true)
16
+ ans = super
17
+ ans[type] = {"title" => @title}
18
+ ans
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class ChildDatabaseBlock < ChildBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "child_database"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class ChildPageBlock < ChildBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "child_page"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class CodeBlock < Block
6
+ # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
7
+ # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] caption
8
+ # @param [String] language
9
+ # @see https://www.notion.so/hkob/CodeBlock-3a25869f60394b3f902c1ed0bf5ce1c9#7777d9b785234278876d7bf6842dd8a2
10
+ def initialize(text_info = nil, caption: [], language: "shell", json: nil, id: nil, parent: nil)
11
+ super(json: json, id: id, parent: parent)
12
+ if @json
13
+ decode_block_rich_text_array
14
+ decode_block_caption
15
+ @language = json[type]["language"] || "shell"
16
+ else
17
+ rich_text_array_and_color "rich_text", text_info
18
+ @caption = RichTextArray.rich_text_array "caption", caption
19
+ @language = language
20
+ end
21
+ end
22
+
23
+ # @see https://www.notion.so/hkob/CodeBlock-3a25869f60394b3f902c1ed0bf5ce1c9#282b6ca100a14841b849ab24519647f3
24
+ # @see https://www.notion.so/hkob/CodeBlock-3a25869f60394b3f902c1ed0bf5ce1c9#6321da9df4f04ccdbddddcd93b1afbe2
25
+ # @see https://www.notion.so/hkob/CodeBlock-3a25869f60394b3f902c1ed0bf5ce1c9#9de0cd82fb594a3a8d12095d9e21ea8d
26
+ attr_reader :caption, :language, :rich_text_array
27
+
28
+ # @param [Boolean] not_update false when update
29
+ # @return [Hash{String (frozen)->Hash}]
30
+ def block_json(not_update: true)
31
+ ans = super
32
+ ans[type] = @rich_text_array.update_property_schema_json(not_update).merge(
33
+ @caption.update_property_schema_json(not_update),
34
+ )
35
+ ans[type]["language"] = @language
36
+ ans
37
+ end
38
+
39
+ # @param [String] new_language
40
+ def language=(new_language)
41
+ @language = new_language
42
+ @payload.add_update_block_key "language"
43
+ end
44
+
45
+ # @return [String (frozen)]
46
+ def type
47
+ "code"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class ColumnBlock < Block
6
+ # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
7
+ # @see https://www.notion.so/hkob/ColumnBlock-91cb314fc6594ff6b0c77c1eae6c7fab#4b4486cdf26a474eab1c92f9c6ea8a91
8
+ def initialize(sub_blocks = [], json: nil, id: nil, parent: nil)
9
+ super(json: json, id: id, parent: parent)
10
+ add_sub_blocks sub_blocks unless json
11
+ @can_have_children = true
12
+ @can_append = false
13
+ end
14
+
15
+ # @return [String (frozen)]
16
+ def type
17
+ "column"
18
+ end
19
+
20
+ # @param [Boolean] not_update false when update
21
+ # @return [Hash{String (frozen)->Hash}]
22
+ def block_json(not_update: true)
23
+ ans = super
24
+ ans[type] = {}
25
+ ans[type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
26
+ ans
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class ColumnListBlock < Block
6
+ # @param [Array<Array<NotionRubyMapping::Block, Array<NotionRubyMapping::Block>>>] array_of_sub_blocks
7
+ # @return [NotionRubyMapping::Block]
8
+ # @see https://www.notion.so/hkob/ColumnListBlock-78d12860099f4e7d89b65c446bd314ba#6e1c97e1b5da45038232f43994e4d7e5
9
+ def initialize(array_of_sub_blocks = [], json: nil, id: nil, parent: nil)
10
+ super(json: json, id: id, parent: parent)
11
+ unless json
12
+ raise StandardError, "The column_list must have at least 2 columns." if array_of_sub_blocks.count < 2
13
+
14
+ @columns = array_of_sub_blocks.map { |sub_blocks| ColumnBlock.new(sub_blocks) }
15
+ end
16
+ @can_have_children = true
17
+ end
18
+
19
+ # @return [String (frozen)]
20
+ def type
21
+ "column_list"
22
+ end
23
+
24
+ # @param [Boolean] not_update false when update
25
+ # @return [Hash{String (frozen)->Hash}]
26
+ def block_json(not_update: true)
27
+ ans = super
28
+ ans[type] = {}
29
+ ans[type]["children"] = @columns.map(&:block_json) if @columns
30
+ ans
31
+ end
32
+ end
33
+ end
@@ -17,6 +17,12 @@ module NotionRubyMapping
17
17
  end
18
18
  end
19
19
 
20
+ # @param [String] key
21
+ # @return [NotionRubyMapping::PropertyCache, Hash] obtained Page value or PropertyCache
22
+ def [](key)
23
+ get key
24
+ end
25
+
20
26
  # @param [Class] klass
21
27
  # @param [String] title
22
28
  # @return [NotionRubyMapping::Property]
@@ -76,7 +82,7 @@ module NotionRubyMapping
76
82
  if dry_run
77
83
  Base.dry_run_script :post, @nc.query_database_path(@id), query.query_json
78
84
  else
79
- response = @nc.database_query @id, query
85
+ response = @nc.database_query_request @id, query
80
86
  List.new json: response, database: self, query: query
81
87
  end
82
88
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class DividerBlock < Block
6
+ # @param [Boolean] not_update false when update
7
+ # @return [Hash{String (frozen)->Hash}]
8
+ def block_json(not_update: true)
9
+ ans = super
10
+ ans[type] = {}
11
+ ans
12
+ end
13
+
14
+ # @return [String (frozen)]
15
+ def type
16
+ "divider"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class EmbedBlock < UrlCaptionBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "embed"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class EquationBlock < Block
6
+ # @param [String, NotionRubyMapping::EquationObject] expression
7
+ # @see https://www.notion.so/hkob/EquationBlock-df0f823dc5ac41b798052f161dd6540c#cfcd2ceb77194c0e915500b429e8b91b
8
+ def initialize(expression = nil, json: nil, id: nil, parent: nil)
9
+ super(json: json, id: id, parent: parent)
10
+ @equation_object = if @json
11
+ EquationObject.equation_object @json[type]["expression"]
12
+ else
13
+ EquationObject.equation_object expression
14
+ end
15
+ end
16
+
17
+ # @param [Boolean] not_update false when update
18
+ # @return [Hash{String (frozen)->Hash}]
19
+ def block_json(not_update: true)
20
+ ans = super
21
+ ans[type] = {"expression" => @equation_object.expression}
22
+ ans
23
+ end
24
+
25
+ # @return [String]
26
+ # @see https://www.notion.so/hkob/EquationBlock-df0f823dc5ac41b798052f161dd6540c#da3e9d93ffac4d84854be3342b4bf3fe
27
+ def expression
28
+ @equation_object&.expression
29
+ end
30
+
31
+ # @param [String] new_expression
32
+ # @see https://www.notion.so/hkob/EquationBlock-df0f823dc5ac41b798052f161dd6540c#f05e3b2c82914cea9f05e9e6644647e1
33
+ def expression=(new_expression)
34
+ @equation_object = EquationObject.equation_object new_expression
35
+ @payload.add_update_block_key "expression"
36
+ end
37
+
38
+ # @return [String (frozen)]
39
+ def type
40
+ "equation"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class FileBaseBlock < Block
6
+ # @param [String, nil] url
7
+ # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>, nil] caption
8
+ # @see https://www.notion.so/hkob/FileBlock-08f2aa6948364d00b92beacaac9a619c#ace53d2e6ff2404f937179ae1e966e98
9
+ # @see https://www.notion.so/hkob/ImageBlock-806b3d2a9a2c4bf5a5aca6e3fbc8a7e2#4cb790b8b5c847acab4341d55e4fa66a
10
+ def initialize(url = nil, caption: [], json: nil, id: nil, parent: nil)
11
+ super(json: json, id: id, parent: parent)
12
+ if @json
13
+ @file_object = FileObject.new json: @json[type]
14
+ decode_block_caption
15
+ @can_append = @file_object.external?
16
+ else
17
+ @file_object = FileObject.file_object url
18
+ @caption = RichTextArray.rich_text_array "caption", caption
19
+ end
20
+ end
21
+
22
+ # @see https://www.notion.so/hkob/FileBlock-08f2aa6948364d00b92beacaac9a619c#158487a7e1644fae8778dcff59869356
23
+ # @see https://www.notion.so/hkob/ImageBlock-806b3d2a9a2c4bf5a5aca6e3fbc8a7e2#19a4aa3e06514bbe84be9d3b8a45a20f
24
+ attr_reader :caption
25
+
26
+ # @param [Boolean] not_update false when update
27
+ # @return [Hash{String (frozen)->Hash}]
28
+ def block_json(not_update: true)
29
+ ans = super
30
+ ans[type] = @file_object.property_values_json
31
+ ans[type].merge! @caption.update_property_schema_json(not_update) if @caption
32
+ ans
33
+ end
34
+
35
+ # @return [String]
36
+ # @see https://www.notion.so/hkob/FileBlock-08f2aa6948364d00b92beacaac9a619c#d3e7d31b7b274955aa7603163867fa57
37
+ # @see https://www.notion.so/hkob/ImageBlock-806b3d2a9a2c4bf5a5aca6e3fbc8a7e2#01e1883119f14c5f9f7f6823793e72ec
38
+ def url
39
+ @file_object&.url
40
+ end
41
+
42
+ # @param [String] url
43
+ # @see https://www.notion.so/hkob/FileBlock-08f2aa6948364d00b92beacaac9a619c#23497b8eb2214c45b3d5881796f984cb
44
+ # @see https://www.notion.so/hkob/ImageBlock-806b3d2a9a2c4bf5a5aca6e3fbc8a7e2#61598d260b6140f2a359f7d22ea2548a
45
+ def url=(url)
46
+ @file_object.url = url
47
+ @payload.add_update_block_key "external"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class FileBlock < FileBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "file"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class Heading1Block < TextSubBlockColorBaseBlock
6
+ # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>, nil] text_info
7
+ # @param [String] color
8
+ def initialize(text_info = nil, color: nil, json: nil, id: nil, parent: nil)
9
+ super(text_info, color: color, json: json, id: id, parent: parent)
10
+ @can_have_children = false
11
+ end
12
+
13
+ # @return [String (frozen)]
14
+ def type
15
+ "heading_1"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class Heading2Block < TextSubBlockColorBaseBlock
6
+ # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
7
+ # @param [String] color
8
+ def initialize(text_info = nil, color: nil, json: nil, id: nil, parent: nil)
9
+ super(text_info, color: color, json: json, id: id, parent: parent)
10
+ @can_have_children = false
11
+ end
12
+
13
+ # @return [String (frozen)]
14
+ def type
15
+ "heading_2"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class Heading3Block < TextSubBlockColorBaseBlock
6
+ # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
7
+ # @param [String] color
8
+ def initialize(text_info = nil, color: nil, json: nil, id: nil, parent: nil)
9
+ super(text_info, color: color, json: json, id: id, parent: parent)
10
+ @can_have_children = false
11
+ end
12
+
13
+ # @return [String (frozen)]
14
+ def type
15
+ "heading_3"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class ImageBlock < FileBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "image"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class LinkPreviewBlock < UrlBaseBlock
6
+ def initialize(url = nil, json: nil, id: nil, parent: nil)
7
+ super
8
+ @can_append = false
9
+ end
10
+
11
+ # @return [String (frozen)]
12
+ def type
13
+ "link_preview"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class LinkToPageBlock < Block
6
+ # @param [String] page_id
7
+ # @param [String] database_id
8
+ # @see https://www.notion.so/hkob/LinkToPageBlock-e6d09d4742a24fb6bf1101b14a288ff5#d46a2f4288b04cbdbd1b4679f70b7642
9
+ def initialize(page_id: nil, database_id: nil, json: nil, id: nil, parent: nil)
10
+ super(json: json, id: id, parent: parent)
11
+ if @json
12
+ @page_id, @database_id = @json[type].values_at(*%w[page_id database_id])
13
+ else
14
+ @page_id = page_id
15
+ @database_id = database_id
16
+ end
17
+ end
18
+
19
+ # @see https://www.notion.so/hkob/LinkToPageBlock-e6d09d4742a24fb6bf1101b14a288ff5#f0ccbad5a94248baa658efc26d9c0ca3
20
+ # @see https://www.notion.so/hkob/LinkToPageBlock-e6d09d4742a24fb6bf1101b14a288ff5#1444263ecc7d402c8a18f4dd32a14956
21
+ attr_reader :database_id, :page_id
22
+
23
+ # @param [Boolean] not_update false when update
24
+ # @return [Hash{String (frozen)->Hash}]
25
+ def block_json(not_update: true)
26
+ ans = super
27
+ ans[type] = if @page_id
28
+ {"type" => "page_id", "page_id" => @page_id}
29
+ else
30
+ {"type" => "database_id", "database_id" => @database_id}
31
+ end
32
+ ans
33
+ end
34
+
35
+ # @return [String (frozen)]
36
+ def type
37
+ "link_to_page"
38
+ end
39
+ end
40
+ end
@@ -17,7 +17,6 @@ module NotionRubyMapping
17
17
  end
18
18
  attr_reader :has_more
19
19
 
20
-
21
20
  # @return [NotionRubyMapping::List, Enumerator]
22
21
  # @see https://www.notion.so/hkob/List-9a0b32335e0d48849a785ce5e162c760#12e1c261a0944a4095776b7515bef4a1
23
22
  def each
@@ -56,7 +55,7 @@ module NotionRubyMapping
56
55
  unless @has_content # re-exec
57
56
  unless @load_all_contents
58
57
  @query.start_cursor = nil
59
- @json = @database.query_database @query
58
+ @json = @nc.database_query_request @database.id, @query
60
59
  @has_more = @json["has_more"]
61
60
  end
62
61
  @index = 0
@@ -71,7 +70,7 @@ module NotionRubyMapping
71
70
  elsif @has_more
72
71
  if @database
73
72
  @query.start_cursor = @json["next_cursor"]
74
- @json = @database.query_database @query
73
+ @json = @nc.database_query_request @database.id, @query
75
74
  @index = 0
76
75
  @has_more = @json["has_more"]
77
76
  else
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class NumberedListItemBlock < TextSubBlockColorBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "numbered_list_item"
9
+ end
10
+ end
11
+ end
@@ -17,6 +17,12 @@ module NotionRubyMapping
17
17
  end
18
18
  end
19
19
 
20
+ # @param [String] key
21
+ # @return [NotionRubyMapping::PropertyCache, Hash] obtained Page value or PropertyCache
22
+ def [](key)
23
+ get key
24
+ end
25
+
20
26
  # @param [String] title
21
27
  # @param [Array<String, Property>] assigns
22
28
  # @return [NotionRubyMapping::Database]
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class ParagraphBlock < TextSubBlockColorBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "paragraph"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class PdfBlock < FileBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "pdf"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class QuoteBlock < TextSubBlockColorBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "quote"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class SyncedBlock < Block
6
+ # @param [String] block_id
7
+ # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
8
+ def initialize(block_id: nil, sub_blocks: nil, json: nil, id: nil, parent: nil)
9
+ super json: json, id: id, parent: parent
10
+ if @json
11
+ synced_from = @json[type]["synced_from"]
12
+ @block_id = synced_from && @nc.hex_id(synced_from["block_id"])
13
+ else
14
+ @block_id = block_id
15
+ add_sub_blocks sub_blocks
16
+ end
17
+ @can_have_children = @block_id.nil?
18
+ end
19
+
20
+ attr_reader :block_id
21
+
22
+ def block_json(not_update: true)
23
+ ans = super
24
+ ans[type] = {"synced_from" => @block_id ? {"type" => "block_id", "block_id" => @nc.hex_id(@block_id)} : nil}
25
+ ans[type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
26
+ ans
27
+ end
28
+
29
+ # @return [Boolean] true if synced_block & block_id is nil
30
+ def synced_block_original?
31
+ @block_id.nil?
32
+ end
33
+
34
+ # @return [NotionRubyMapping::SyncedBlock]
35
+ def synced_block_original
36
+ @block_id && Block.find(@block_id)
37
+ end
38
+
39
+ # @return [String, nil]
40
+ def synced_block_original_id
41
+ @block_id
42
+ end
43
+
44
+ # @return [String (frozen)]
45
+ def type
46
+ "synced_block"
47
+ end
48
+ end
49
+ end