notion_ruby_mapping 3.0.6 → 4.0.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.
- checksums.yaml +4 -4
- data/README.md +17 -8
- data/lib/notion_ruby_mapping/blocks/base.rb +21 -7
- data/lib/notion_ruby_mapping/blocks/block.rb +4 -2
- data/lib/notion_ruby_mapping/blocks/data_source.rb +10 -4
- data/lib/notion_ruby_mapping/blocks/heading4_block.rb +26 -0
- data/lib/notion_ruby_mapping/blocks/page.rb +39 -4
- data/lib/notion_ruby_mapping/blocks/toggle_heading4_block.rb +19 -0
- data/lib/notion_ruby_mapping/controllers/notion_cache.rb +35 -0
- data/lib/notion_ruby_mapping/objects/comment_object.rb +48 -2
- data/lib/notion_ruby_mapping/version.rb +2 -2
- data/lib/notion_ruby_mapping.rb +1 -1
- data/mise.toml +2 -0
- data/notion_ruby_mapping.gemspec +1 -0
- metadata +19 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 60caedd2da9ab654284cb0d15f93fdef648e3d93b85e73a2d8e0b074657b6658
|
|
4
|
+
data.tar.gz: 5b2474e262b7ed381d6ab266a898df26b736d5990c2cb441391c730615b40b8d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0785e9cd53092787c84aedeba453559934d4501cc73f75ffed2be447d939dc817ee69ee05696af03025d21184d495fdd2c699336e756bca3d84511cc6595d7b0'
|
|
7
|
+
data.tar.gz: 69e57b27cfa5d4ff92e1c71b1de13ab44f6706fe2c83cde73aa82f65d24e02788898e8deafe8ed240ef9f752a3e919998d367aa099cd0efca87a226cc8ba93a6
|
data/README.md
CHANGED
|
@@ -15,10 +15,11 @@ Development note is here.
|
|
|
15
15
|
- [notion\_ruby\_mapping](#notion_ruby_mapping)
|
|
16
16
|
- [Table of Contents](#table-of-contents)
|
|
17
17
|
- [0. History of Major Changes / 主な変更履歴](#0-history-of-major-changes--主な変更履歴)
|
|
18
|
-
- [0.1 Changes in
|
|
19
|
-
- [0.2 Changes in
|
|
20
|
-
- [0.3 Changes in v0.
|
|
21
|
-
- [0.4 Changes in v0.
|
|
18
|
+
- [0.1 Changes in v4.0.0](#01-changes-in-v400)
|
|
19
|
+
- [0.2 Changes in v3.0.0](#02-changes-in-v300)
|
|
20
|
+
- [0.3 Changes in v0.7.0](#03-changes-in-v070)
|
|
21
|
+
- [0.4 Changes in v0.6.0](#04-changes-in-v060)
|
|
22
|
+
- [0.5 Changes in v0.5.0](#05-changes-in-v050)
|
|
22
23
|
- [1. Installation / インストール方法](#1-installation--インストール方法)
|
|
23
24
|
- [2. How to use / 利用方法](#2-how-to-use--利用方法)
|
|
24
25
|
- [2.1 Create a New Integration / インテグレーションの作成](#21-create-a-new-integration--インテグレーションの作成)
|
|
@@ -33,7 +34,13 @@ Development note is here.
|
|
|
33
34
|
|
|
34
35
|
## 0. History of Major Changes / 主な変更履歴
|
|
35
36
|
|
|
36
|
-
### 0.1 Changes in
|
|
37
|
+
### 0.1 Changes in v4.0.0
|
|
38
|
+
|
|
39
|
+
NotionRubyMapping v4.0.0 now supports Notion-Version 2026-03-11.
|
|
40
|
+
|
|
41
|
+
NotionRubyMapping v4.0.0 は、Notion-Version 2026-03-11 に対応しました。
|
|
42
|
+
|
|
43
|
+
### 0.2 Changes in v3.0.0
|
|
37
44
|
|
|
38
45
|
NotionRubyMapping v3.0.0 now supports Notion-Version 2025-09-03.
|
|
39
46
|
|
|
@@ -41,13 +48,13 @@ NotionRubyMapping v3.0.0 は、Notion-Version 2025-09-03 に対応しました
|
|
|
41
48
|
これまで Database で実行していた API は、ほとんど DataSource の API に変更になりました。
|
|
42
49
|
そのため、NotionRubyMapping でも新規に DataSource クラスを追加しました。
|
|
43
50
|
|
|
44
|
-
### 0.
|
|
51
|
+
### 0.3 Changes in v0.7.0
|
|
45
52
|
|
|
46
53
|
Since the number of Japanese users has increased, we decided to include Japanese as well. In addition, we have simplified the method of setting up integration tokens.
|
|
47
54
|
|
|
48
55
|
日本のユーザが増えたので、日本語も併記することにしました。また、インテグレーショントークンの設定方法を簡単にしました。
|
|
49
56
|
|
|
50
|
-
### 0.
|
|
57
|
+
### 0.4 Changes in v0.6.0
|
|
51
58
|
|
|
52
59
|
NotionRubyMapping v0.6.0 now supports Notion-Version 2022-06-28.
|
|
53
60
|
~~In 2022-06-28, property values are no longer returned when retrieving pages. NotionRubyMapping temporarily creates a Property Object and calls the retrieve a property item API when a value is needed. Therefore, users do not need to be aware of any differences, and existing scripts should work as they are.~~
|
|
@@ -55,7 +62,7 @@ NotionRubyMapping v0.6.0 now supports Notion-Version 2022-06-28.
|
|
|
55
62
|
NotionRubyMapping v0.6.0 は、Notion-Version 2022-06-28 に対応しました。
|
|
56
63
|
~~ 2022-06-28 では、ページを取得する際にプロパティ値を返さなくなりました。NotionRubyMapping は、一時的に Property Object を作成し、値が必要なときにプロパティ項目を取得する API を呼び出します。そのため、ユーザーはこの違いを意識する必要はなく、既存のスクリプトはそのまま動作するはずです。~~
|
|
57
64
|
|
|
58
|
-
### 0.
|
|
65
|
+
### 0.5 Changes in v0.5.0
|
|
59
66
|
|
|
60
67
|
NotionRubyMapping v0.5.0 now supports block updates.
|
|
61
68
|
For efficiency, subclasses are provided under Block class. As a result, they are no longer compatible with the scripts used in v0.4.0.
|
|
@@ -136,6 +143,8 @@ NotionRubyMapping.configuration { |c| c.notion_token = ENV["NOTION_API_TOKEN"] }
|
|
|
136
143
|
|
|
137
144
|
## 3. ChangeLog
|
|
138
145
|
|
|
146
|
+
- 2027/5/4 [v4.0.1] Add retrieve / update / delete a comment
|
|
147
|
+
- 2027/3/23 [v4.0.0] Add markdown support, headnig_4, toggle_heading_4, and position support for appending blocks
|
|
139
148
|
- 2026/1/25 [v3.0.6] add move page, list templates, and create child page to page
|
|
140
149
|
- 2025/12/15 [v3.0.5] add AudioBlock
|
|
141
150
|
- 2025/12/9 [v3.0.4] Fix the issue where page.parent could not be executed for pages with a data source as parent
|
|
@@ -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
|
-
|
|
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
|
-
@
|
|
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, :
|
|
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]
|
|
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,
|
|
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
|
-
|
|
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,
|
|
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["
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
@@ -101,6 +101,14 @@ module NotionRubyMapping
|
|
|
101
101
|
"v1/comments"
|
|
102
102
|
end
|
|
103
103
|
|
|
104
|
+
def comment_path(comment_id)
|
|
105
|
+
"v1/comments/#{comment_id}"
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def comment_request(comment_id)
|
|
109
|
+
request :get, comment_path(comment_id)
|
|
110
|
+
end
|
|
111
|
+
|
|
104
112
|
def complete_a_file_upload_path(file_id)
|
|
105
113
|
"v1/file_uploads/#{file_id}/complete"
|
|
106
114
|
end
|
|
@@ -213,6 +221,12 @@ module NotionRubyMapping
|
|
|
213
221
|
request :delete, block_path(id)
|
|
214
222
|
end
|
|
215
223
|
|
|
224
|
+
# @param [String] id
|
|
225
|
+
# @return [Hash]
|
|
226
|
+
def destroy_comment_request(id)
|
|
227
|
+
request :delete, comment_path(id)
|
|
228
|
+
end
|
|
229
|
+
|
|
216
230
|
# @param [String] fname
|
|
217
231
|
# @param [String] id
|
|
218
232
|
# @param [Hash] options
|
|
@@ -262,6 +276,19 @@ module NotionRubyMapping
|
|
|
262
276
|
"v1/data_sources/#{data_source_id}/templates#{options}"
|
|
263
277
|
end
|
|
264
278
|
|
|
279
|
+
# @param [String] page_id
|
|
280
|
+
# @return [String] path
|
|
281
|
+
def markdown_page_path(page_id)
|
|
282
|
+
"v1/pages/#{page_id}/markdown"
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
# @param [String] page_id
|
|
286
|
+
# @param [Hash] payload
|
|
287
|
+
# @return [Hash] response hash
|
|
288
|
+
def markdown_page_request(page_id, payload)
|
|
289
|
+
request :patch, markdown_page_path(page_id), payload
|
|
290
|
+
end
|
|
291
|
+
|
|
265
292
|
# @param [String] page_id
|
|
266
293
|
# @param [Hash] payload
|
|
267
294
|
# @return [Hash] response hash
|
|
@@ -415,6 +442,14 @@ module NotionRubyMapping
|
|
|
415
442
|
request :patch, block_path(block_id), payload
|
|
416
443
|
end
|
|
417
444
|
|
|
445
|
+
def update_comment_request(comment_id, rich_text: nil, markdown: nil)
|
|
446
|
+
if rich_text
|
|
447
|
+
request :patch, comment_path(comment_id), {"rich_text" => rich_text}
|
|
448
|
+
else
|
|
449
|
+
request :patch, comment_path(comment_id), {"markdown" => markdown}
|
|
450
|
+
end
|
|
451
|
+
end
|
|
452
|
+
|
|
418
453
|
# @param [String] id page_id (with or without "-")
|
|
419
454
|
# @param [Hash] payload
|
|
420
455
|
# def update_database(id, payload)
|
|
@@ -4,19 +4,36 @@ module NotionRubyMapping
|
|
|
4
4
|
# CommentObject
|
|
5
5
|
class CommentObject
|
|
6
6
|
# @param [String] text_objects
|
|
7
|
-
def initialize(text_objects: nil, json: {})
|
|
7
|
+
def initialize(id: nil, text_objects: nil, json: {})
|
|
8
|
+
nc = NotionCache.instance
|
|
8
9
|
if text_objects
|
|
10
|
+
@id = nc.hex_id id
|
|
9
11
|
@text_objects = RichTextArray.new "rich_text", text_objects: text_objects
|
|
10
12
|
@json = {}
|
|
11
13
|
elsif json
|
|
12
14
|
@json = json
|
|
15
|
+
@id = nc.hex_id json["id"]
|
|
13
16
|
@text_objects = RichTextArray.new "rich_text", json: json["rich_text"]
|
|
14
17
|
else
|
|
15
18
|
raise StandardError, "Either text_objects or json is required CommentObject"
|
|
16
19
|
end
|
|
17
20
|
@will_update = false
|
|
18
21
|
end
|
|
19
|
-
attr_reader :will_update, :text_objects, :json
|
|
22
|
+
attr_reader :will_update, :text_objects, :json, :id
|
|
23
|
+
|
|
24
|
+
def self.find(comment_id)
|
|
25
|
+
new json: NotionCache.instance.comment_request(comment_id)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def destroy(dry_run: false)
|
|
29
|
+
if dry_run
|
|
30
|
+
Base.dry_run_script :delete, NotionCache.instance.comment_path(id)
|
|
31
|
+
else
|
|
32
|
+
json = NotionCache.instance.destroy_comment_request id
|
|
33
|
+
@text_objects = RichTextArray.new "rich_text", json: json["rich_text"]
|
|
34
|
+
self
|
|
35
|
+
end
|
|
36
|
+
end
|
|
20
37
|
|
|
21
38
|
def discussion_id
|
|
22
39
|
NotionCache.instance.hex_id @json["discussion_id"]
|
|
@@ -26,5 +43,34 @@ module NotionRubyMapping
|
|
|
26
43
|
def full_text
|
|
27
44
|
@text_objects.full_text
|
|
28
45
|
end
|
|
46
|
+
|
|
47
|
+
def markdown=(markdown)
|
|
48
|
+
@markdown = markdown
|
|
49
|
+
@will_update = true
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def rich_text_objects=(text_objects)
|
|
53
|
+
@text_objects.rich_text_objects = text_objects
|
|
54
|
+
@will_update = true
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def save(dry_run: false)
|
|
58
|
+
return unless @will_update
|
|
59
|
+
|
|
60
|
+
if dry_run
|
|
61
|
+
json = @markdown ? {"markdown" => @markdown} : {"rich_text" => @text_objects.property_values_json}
|
|
62
|
+
@markdown = nil
|
|
63
|
+
Base.dry_run_script :patch, NotionCache.instance.comment_path(id), json
|
|
64
|
+
else
|
|
65
|
+
json = if @markdown
|
|
66
|
+
NotionCache.instance.update_comment_request id, markdown: @markdown
|
|
67
|
+
else
|
|
68
|
+
NotionCache.instance.update_comment_request id, rich_text: @text_objects.property_values_json
|
|
69
|
+
end
|
|
70
|
+
@markdown = nil
|
|
71
|
+
@text_objects = RichTextArray.new "rich_text", json: json["rich_text"]
|
|
72
|
+
@will_update = false
|
|
73
|
+
end
|
|
74
|
+
end
|
|
29
75
|
end
|
|
30
76
|
end
|
data/lib/notion_ruby_mapping.rb
CHANGED
|
@@ -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
|
data/mise.toml
ADDED
data/notion_ruby_mapping.gemspec
CHANGED
|
@@ -38,6 +38,7 @@ Gem::Specification.new do |spec|
|
|
|
38
38
|
spec.add_dependency "faraday-multipart"
|
|
39
39
|
spec.add_dependency "mime-types"
|
|
40
40
|
|
|
41
|
+
spec.add_development_dependency "ostruct"
|
|
41
42
|
spec.add_development_dependency "pry"
|
|
42
43
|
spec.add_development_dependency "pry-byebug"
|
|
43
44
|
spec.add_development_dependency "rb-readline"
|
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:
|
|
4
|
+
version: 4.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hiroyuki KOBAYASHI
|
|
@@ -51,6 +51,20 @@ dependencies:
|
|
|
51
51
|
- - ">="
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
53
|
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: ostruct
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
54
68
|
- !ruby/object:Gem::Dependency
|
|
55
69
|
name: pry
|
|
56
70
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -242,6 +256,7 @@ files:
|
|
|
242
256
|
- lib/notion_ruby_mapping/blocks/heading1_block.rb
|
|
243
257
|
- lib/notion_ruby_mapping/blocks/heading2_block.rb
|
|
244
258
|
- lib/notion_ruby_mapping/blocks/heading3_block.rb
|
|
259
|
+
- lib/notion_ruby_mapping/blocks/heading4_block.rb
|
|
245
260
|
- lib/notion_ruby_mapping/blocks/image_block.rb
|
|
246
261
|
- lib/notion_ruby_mapping/blocks/link_preview_block.rb
|
|
247
262
|
- lib/notion_ruby_mapping/blocks/link_to_page_block.rb
|
|
@@ -261,6 +276,7 @@ files:
|
|
|
261
276
|
- lib/notion_ruby_mapping/blocks/toggle_heading1_block.rb
|
|
262
277
|
- lib/notion_ruby_mapping/blocks/toggle_heading2_block.rb
|
|
263
278
|
- lib/notion_ruby_mapping/blocks/toggle_heading3_block.rb
|
|
279
|
+
- lib/notion_ruby_mapping/blocks/toggle_heading4_block.rb
|
|
264
280
|
- lib/notion_ruby_mapping/blocks/url_base_block.rb
|
|
265
281
|
- lib/notion_ruby_mapping/blocks/url_caption_base_block.rb
|
|
266
282
|
- lib/notion_ruby_mapping/blocks/video_block.rb
|
|
@@ -312,6 +328,7 @@ files:
|
|
|
312
328
|
- lib/notion_ruby_mapping/properties/url_property.rb
|
|
313
329
|
- lib/notion_ruby_mapping/properties/verification_property.rb
|
|
314
330
|
- lib/notion_ruby_mapping/version.rb
|
|
331
|
+
- mise.toml
|
|
315
332
|
- notion_ruby_mapping.gemspec
|
|
316
333
|
- tools/an
|
|
317
334
|
homepage: https://github.com/hkob/notion_ruby_mapping.git
|
|
@@ -332,7 +349,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
332
349
|
- !ruby/object:Gem::Version
|
|
333
350
|
version: '0'
|
|
334
351
|
requirements: []
|
|
335
|
-
rubygems_version: 4.0.
|
|
352
|
+
rubygems_version: 4.0.6
|
|
336
353
|
specification_version: 4
|
|
337
354
|
summary: Notion Ruby mapping tool
|
|
338
355
|
test_files: []
|