notion_ruby_mapping 3.0.6 → 4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a52b1e5d063d287acdc0bb5bfa88f48c666c3f8d550115db524cc4243dda5cc6
4
- data.tar.gz: 4d38fd4b35fb0ac10c0302d04d726aaa5f43672e46c32700c8758ee5d481b406
3
+ metadata.gz: 9dad5c3579a84ff3dd64c56a20d58e1c8bdcd605d6d956b7a97f3a6120bee28a
4
+ data.tar.gz: fffec11062ce3e152350cda495ad33b13baf2697abb7db308b4755e66710654e
5
5
  SHA512:
6
- metadata.gz: e2c267cbffaa97b9cb1c70f9b254c7e1976dd7956bb9359929d151905b82ee0ef459d75e585943765022aa921d5ec91176a40459b10b072a0feac00ef07da9bf
7
- data.tar.gz: b8b05c7683b1bb6969db57dfce0656cf1c92529ec7167a5f9250c1cf80453e44df8dc7fc55501c4fab6515b3b10587e1d247c2aec9049eac4f520fdb7053b9d2
6
+ metadata.gz: bc60d84f2634660338b0ffee697539e9063b4e46e079c5a107724f1acd782e466bbc27b80561b710dcaf2a9878194a5b0a77bcf52edf4028e142d3b24a636767
7
+ data.tar.gz: d7e39e143665cd7c51ebd8008e727aacdaee9ee936f043017c7e163b4db078c253a189dc391baead83061b1ae0656a9c33c5d278e5269e6f2b871a774c061c16
@@ -7,11 +7,15 @@ module NotionRubyMapping
7
7
  # @param [Hash, nil] json
8
8
  # @param [String, nil] id
9
9
  # @param [Array<Property, Class, String>] assign
10
- def initialize(json: nil, id: nil, assign: [], parent: nil, template_page: nil, position: nil)
10
+ # @param [Block, nil] parent
11
+ # @param [String, nil] template_page
12
+ # @param [String, nil] position
13
+ # @param [String, nil] markdown
14
+ def initialize(json: nil, id: nil, assign: [], parent: nil, template_page: nil, position: nil, markdown: nil)
11
15
  @nc = NotionCache.instance
12
16
  @json = json
13
17
  @id = @nc.hex_id(id || @json && @json["id"])
14
- @archived = @json && @json["archived"]
18
+ @in_trash = @json && @json["in_trash"]
15
19
  @has_children = @json && @json["has_children"]
16
20
  @new_record = true unless parent.nil?
17
21
  raise StandardError, "Unknown id" if !is_a?(List) && !is_a?(Block) && @id.nil? && parent.nil?
@@ -28,6 +32,7 @@ module NotionRubyMapping
28
32
  elsif position
29
33
  payload_json["position"] = {"type" => "after_block", "after_block" => {"id" => position}}
30
34
  end
35
+ payload_json["markdown"] = markdown if markdown
31
36
  @payload = Payload.new(payload_json)
32
37
  @property_cache = nil
33
38
  @created_time = nil
@@ -37,13 +42,13 @@ module NotionRubyMapping
37
42
  assign.each_slice(2) { |(klass, key)| assign_property(klass, key) }
38
43
  @json ||= {}
39
44
  end
40
- attr_reader :json, :id, :archived, :has_children
45
+ attr_reader :json, :id, :in_trash, :has_children
41
46
 
42
47
  # @param [Hash, Notion::Messages] json
43
48
  # @return [NotionRubyMapping::Base]
44
49
  def self.create_from_json(json)
45
50
  case json["object"]
46
- when "page"
51
+ when "page", "page_markdown"
47
52
  Page.new json: json
48
53
  when "data_source"
49
54
  DataSource.new json: json
@@ -140,12 +145,12 @@ module NotionRubyMapping
140
145
  end
141
146
 
142
147
  # @param [Array<Block>] blocks
143
- # @param [String, nil] after block id of previous block
148
+ # @param [String, nil] position block id of previous block, start, or end
144
149
  # @param [Boolean] dry_run true if dry_run
145
150
  # @return [NotionRubyMapping::Block, String]
146
151
  # @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#44bbf83d852c419485c5efe9fe1558fb
147
152
  # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#2c47f7fedae543cf8566389ba1677132
148
- def append_block_children(*blocks, after: nil, dry_run: false)
153
+ def append_block_children(*blocks, position: nil, dry_run: false)
149
154
  raise StandardError, "This block can have no children." unless page? || (block? && can_have_children)
150
155
 
151
156
  only_one = blocks.length == 1
@@ -155,7 +160,11 @@ module NotionRubyMapping
155
160
  block.block_json
156
161
  end,
157
162
  }
158
- json["after"] = after if after
163
+ if %w[start end].include? position
164
+ json["position"] = {"type" => position}
165
+ elsif position
166
+ json["position"] = {"type" => "after_block", "after_block" => {"id" => position}}
167
+ end
159
168
  if dry_run
160
169
  path = @nc.append_block_children_page_path(id)
161
170
  self.class.dry_run_script :patch, path, json
@@ -266,6 +275,11 @@ module NotionRubyMapping
266
275
  @last_edited_time ||= LastEditedTimeProperty.new("__timestamp__", json: self["last_edited_time"])
267
276
  end
268
277
 
278
+ # @return [String]
279
+ def markdown
280
+ @json && @json["markdown"]
281
+ end
282
+
269
283
  # @return [Boolean] true if new record
270
284
  # @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#307af6e40d3840c59f8a82513a572d51
271
285
  def new_record?
@@ -34,6 +34,7 @@ module NotionRubyMapping
34
34
  heading_1: Heading1Block,
35
35
  heading_2: Heading2Block,
36
36
  heading_3: Heading3Block,
37
+ heading_4: Heading4Block,
37
38
  image: ImageBlock,
38
39
  link_preview: LinkPreviewBlock,
39
40
  link_to_page: LinkToPageBlock,
@@ -53,6 +54,7 @@ module NotionRubyMapping
53
54
  heading_1: ToggleHeading1Block,
54
55
  heading_2: ToggleHeading2Block,
55
56
  heading_3: ToggleHeading3Block,
57
+ heading_4: ToggleHeading4Block,
56
58
  },
57
59
  }
58
60
  @klass = @type2class[has_children][type.to_sym] || @type2class[false][type.to_sym] || Block
@@ -80,7 +82,7 @@ module NotionRubyMapping
80
82
  # @return [NotionRubyMapping::Block, String]
81
83
  # @param [Array<Block>] blocks
82
84
  def append_after(*blocks, dry_run: false)
83
- parent.append_block_children(*blocks, after: id, dry_run: dry_run)
85
+ parent.append_block_children(*blocks, position: id, dry_run: dry_run)
84
86
  end
85
87
 
86
88
  # @param [Boolean] not_update false when update
@@ -88,7 +90,7 @@ module NotionRubyMapping
88
90
  def block_json(not_update: true)
89
91
  ans = {"type" => type}
90
92
  ans["object"] = "block"
91
- ans["archived"] = true if @archived
93
+ ans["in_trash"] = true if @in_trash
92
94
  ans
93
95
  end
94
96
 
@@ -40,9 +40,12 @@ module NotionRubyMapping
40
40
  # @param [Array<Property, Class, String>] assign
41
41
  # @return [NotionRubyMapping::Base]
42
42
  # @see https://www.notion.so/hkob/DataSource-1462b24502424539a4231bedc07dc2f5#c217ce78020a4de79b720790fce3092d
43
- def build_child_page(*assign, template_page: nil)
43
+ # @param [String, NilClass] template_page
44
+ # @param [String, NilClass] markdown
45
+ def build_child_page(*assign, template_page: nil, markdown: nil)
44
46
  assign = properties.map { |p| [p.class, p.name] }.flatten if assign.empty?
45
- page = Page.new assign: assign, parent: {"data_source_id" => @id}, template_page: template_page
47
+ page = Page.new assign: assign, parent: {"data_source_id" => @id}, template_page: template_page,
48
+ markdown: markdown
46
49
  pp = page.properties
47
50
  pp.clear_will_update
48
51
  yield page, pp if block_given?
@@ -50,12 +53,15 @@ module NotionRubyMapping
50
53
  end
51
54
 
52
55
  # @param [Array<Property, Class, String>] assign
56
+ # @param [String, NilClass] template_page
57
+ # @param [String, NilClass] markdown
53
58
  # @param [Boolean] dry_run true if dry_run
54
59
  # @return [NotionRubyMapping::Base]
55
60
  # @see https://www.notion.so/hkob/DataSource-1462b24502424539a4231bedc07dc2f5#c217ce78020a4de79b720790fce3092d
56
- def create_child_page(*assign, template_page: nil, dry_run: false)
61
+ def create_child_page(*assign, template_page: nil, markdown: nil, dry_run: false)
57
62
  assign = properties.map { |p| [p.class, p.name] }.flatten if assign.empty?
58
- page = Page.new assign: assign, parent: {"data_source_id" => @id}, template_page: template_page
63
+ page = Page.new assign: assign, parent: {"data_source_id" => @id}, template_page: template_page,
64
+ markdown: markdown
59
65
  pp = page.properties
60
66
  pp.clear_will_update
61
67
  yield page, pp if block_given?
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class Heading4Block < 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]
14
+ def type
15
+ "heading_4"
16
+ end
17
+
18
+ # @param [Boolean] not_update false when update
19
+ # @return [Hash{String (frozen)->Hash}]
20
+ def block_json(not_update: true)
21
+ ans = super
22
+ ans[type]["is_toggleable"] = false
23
+ ans
24
+ end
25
+ end
26
+ end
@@ -60,9 +60,12 @@ module NotionRubyMapping
60
60
  end
61
61
 
62
62
  # @return [NotionRubyMapping::Base]
63
- def build_child_page(template_page: nil, position: nil)
63
+ # @param [String, NilClass] template_page
64
+ # @param [String, NilClass] position
65
+ # @param [String, NilClass] markdown
66
+ def build_child_page(template_page: nil, position: nil, markdown: nil)
64
67
  page = Page.new assign: [TitleProperty, "title"], parent: {"type" => "page_id", "page_id" => @id},
65
- template_page: template_page, position: position
68
+ template_page: template_page, position: position, markdown: markdown
66
69
  pp = page.properties
67
70
  pp.clear_will_update
68
71
  yield page, pp if block_given?
@@ -71,15 +74,32 @@ module NotionRubyMapping
71
74
 
72
75
  # @param [Boolean] dry_run true if dry_run
73
76
  # @return [NotionRubyMapping::Base]
74
- def create_child_page(template_page: nil, position: nil, dry_run: false)
77
+ # @param [String, NilClass] template_page
78
+ # @param [String, NilClass] position
79
+ # @param [String, NilClass] markdown
80
+ def create_child_page(template_page: nil, position: nil, markdown: nil, dry_run: false)
75
81
  page = Page.new assign: [TitleProperty, "title"], parent: {"type" => "page_id", "page_id" => @id},
76
- template_page: template_page, position: position
82
+ template_page: template_page, position: position, markdown: markdown
77
83
  pp = page.properties
78
84
  pp.clear_will_update
79
85
  yield page, pp if block_given?
80
86
  page.save dry_run: dry_run
81
87
  end
82
88
 
89
+ # @param [String] markdown
90
+ # @param [String, NilClass] after
91
+ # @param [Boolean] dry_run
92
+ # @return [String, NotionRubyMapping::Base]
93
+ def insert_markdown(markdown, after: nil, dry_run: false)
94
+ json = {"type" => "insert_content", "insert_content" => {"content" => markdown}}
95
+ json["insert_content"]["after"] = after if after
96
+ if dry_run
97
+ self.class.dry_run_script :patch, @nc.markdown_page_path(@id), json
98
+ else
99
+ update_json @nc.markdown_page_request(@id, json)
100
+ end
101
+ end
102
+
83
103
  # @param [Page, DataSource] page_or_data_source
84
104
  # @param [Boolean] dry_run true if dry_run
85
105
  # @return [NotionRubyMapping::Page, String]
@@ -98,6 +118,21 @@ module NotionRubyMapping
98
118
  @json["public_url"]
99
119
  end
100
120
 
121
+ # @param [String] replace
122
+ # @param [String] replace_range
123
+ # @param [Boolean] dry_run
124
+ # @return [String, NotionRubyMapping::Base]
125
+ def replace_markdown(replace, replace_range, allow_deleting_content: nil, dry_run: false)
126
+ json = {"type" => "replace_content_range",
127
+ "replace_content_range" => {"content" => replace, "content_range" => replace_range}}
128
+ json["replace_content_range"]["allow_deleting_content"] = true if allow_deleting_content
129
+ if dry_run
130
+ self.class.dry_run_script :patch, @nc.markdown_page_path(@id), json
131
+ else
132
+ update_json @nc.markdown_page_request(@id, json)
133
+ end
134
+ end
135
+
101
136
  # @return [String] title
102
137
  # @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#2ff7209055f346fbbda454cdbb40b1c8
103
138
  def title
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class ToggleHeading4Block < TextSubBlockColorBaseBlock
6
+ # @return [String]
7
+ def type
8
+ "heading_4"
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]["is_toggleable"] = true
16
+ ans
17
+ end
18
+ end
19
+ end
@@ -262,6 +262,19 @@ module NotionRubyMapping
262
262
  "v1/data_sources/#{data_source_id}/templates#{options}"
263
263
  end
264
264
 
265
+ # @param [String] page_id
266
+ # @return [String] path
267
+ def markdown_page_path(page_id)
268
+ "v1/pages/#{page_id}/markdown"
269
+ end
270
+
271
+ # @param [String] page_id
272
+ # @param [Hash] payload
273
+ # @return [Hash] response hash
274
+ def markdown_page_request(page_id, payload)
275
+ request :patch, markdown_page_path(page_id), payload
276
+ end
277
+
265
278
  # @param [String] page_id
266
279
  # @param [Hash] payload
267
280
  # @return [Hash] response hash
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
- VERSION = "3.0.6"
5
- NOTION_VERSION = "2025-09-03"
4
+ VERSION = "4.0.0"
5
+ NOTION_VERSION = "2026-03-11"
6
6
  end
@@ -11,7 +11,7 @@ require_relative "notion_ruby_mapping/version"
11
11
  image_block toggle_heading1_block toggle_heading2_block toggle_heading3_block url_base_block
12
12
  link_preview_block link_to_page_block numbered_list_item_block paragraph_block pdf_block quote_block
13
13
  synced_block table_block table_row_block table_of_contents_block to_do_block
14
- toggle_block video_block audio_block],
14
+ toggle_block video_block audio_block heading4_block toggle_heading4_block],
15
15
  controllers: %w[notion_cache payload property_cache query rich_text_array discussion_thread search mermaid
16
16
  mermaid_data_source],
17
17
  objects: %w[rich_text_object emoji_object equation_object file_object mention_object text_object user_object
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion_ruby_mapping
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.6
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroyuki KOBAYASHI
@@ -242,6 +242,7 @@ files:
242
242
  - lib/notion_ruby_mapping/blocks/heading1_block.rb
243
243
  - lib/notion_ruby_mapping/blocks/heading2_block.rb
244
244
  - lib/notion_ruby_mapping/blocks/heading3_block.rb
245
+ - lib/notion_ruby_mapping/blocks/heading4_block.rb
245
246
  - lib/notion_ruby_mapping/blocks/image_block.rb
246
247
  - lib/notion_ruby_mapping/blocks/link_preview_block.rb
247
248
  - lib/notion_ruby_mapping/blocks/link_to_page_block.rb
@@ -261,6 +262,7 @@ files:
261
262
  - lib/notion_ruby_mapping/blocks/toggle_heading1_block.rb
262
263
  - lib/notion_ruby_mapping/blocks/toggle_heading2_block.rb
263
264
  - lib/notion_ruby_mapping/blocks/toggle_heading3_block.rb
265
+ - lib/notion_ruby_mapping/blocks/toggle_heading4_block.rb
264
266
  - lib/notion_ruby_mapping/blocks/url_base_block.rb
265
267
  - lib/notion_ruby_mapping/blocks/url_caption_base_block.rb
266
268
  - lib/notion_ruby_mapping/blocks/video_block.rb
@@ -332,7 +334,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
332
334
  - !ruby/object:Gem::Version
333
335
  version: '0'
334
336
  requirements: []
335
- rubygems_version: 4.0.3
337
+ rubygems_version: 4.0.6
336
338
  specification_version: 4
337
339
  summary: Notion Ruby mapping tool
338
340
  test_files: []