notion_ruby_mapping 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59ade8b97253e1f77c438f1f337c55d8b642fed859e4434de98d6860610d84e7
|
4
|
+
data.tar.gz: 4703b38b13e146d2b7e55bbd1988ee6efc21b5ee65210cfcc8e304920969c538
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 360025f3bec7e9d20a33c9183ade2b1695137d818119771d219eb7b6f5e0a00ad2bebd8da7fc147c41ee1445879ab1e51088bbd02abc6e91dd78658c8c5a8f16
|
7
|
+
data.tar.gz: c9b917ce45d44cec66c09dd278119ef3ee4848f673c07c65260628250a35a6864c9de4dfccac89e2c2dc31a3df80ec52f32ed7eccd31248b018f6116c86c67b4
|
@@ -4,7 +4,6 @@ module NotionRubyMapping
|
|
4
4
|
# Notion Base object (Parent of Page / Database / List)
|
5
5
|
# The Public API method has a link to the API references.
|
6
6
|
class Base
|
7
|
-
|
8
7
|
# @param [Hash, nil] json
|
9
8
|
# @param [String, nil] id
|
10
9
|
# @param [Array<Property, Class, String>] assign
|
@@ -52,7 +51,7 @@ module NotionRubyMapping
|
|
52
51
|
" -H 'Notion-Version: 2022-02-22'",
|
53
52
|
" -H 'Authorization: Bearer '\"$NOTION_API_KEY\"''",
|
54
53
|
]
|
55
|
-
shell << " -H 'Content-Type: application/json'"
|
54
|
+
shell << " -H 'Content-Type: application/json'" if %i[post patch].include?(method)
|
56
55
|
shell << " --data '#{JSON.generate json}'" if json
|
57
56
|
shell.join(" \\\n")
|
58
57
|
end
|
@@ -73,8 +72,8 @@ module NotionRubyMapping
|
|
73
72
|
end
|
74
73
|
end
|
75
74
|
|
76
|
-
# @param [
|
77
|
-
# @param [
|
75
|
+
# @param [Array<Block>] blocks
|
76
|
+
# @param [Boolean] dry_run
|
78
77
|
# @return [NotionRubyMapping::Block, String]
|
79
78
|
# @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#44bbf83d852c419485c5efe9fe1558fb
|
80
79
|
# @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#2c47f7fedae543cf8566389ba1677132
|
@@ -86,7 +85,7 @@ module NotionRubyMapping
|
|
86
85
|
"children" => Array(blocks).map do |block|
|
87
86
|
assert_parent_children_pair block
|
88
87
|
block.block_json
|
89
|
-
end
|
88
|
+
end,
|
90
89
|
}
|
91
90
|
if dry_run
|
92
91
|
path = @nc.append_block_children_page_path(id)
|
@@ -112,7 +111,7 @@ module NotionRubyMapping
|
|
112
111
|
raise StandardError, "Internal file block can not append." if bt == "file"
|
113
112
|
|
114
113
|
raise StandardError, "Column block can only append column_list block" unless bt == "column" &&
|
115
|
-
|
114
|
+
block? && type == "columu_list"
|
116
115
|
end
|
117
116
|
|
118
117
|
# @param [NotionRubyMapping::Property] klass
|
@@ -172,6 +171,11 @@ module NotionRubyMapping
|
|
172
171
|
self["icon"]
|
173
172
|
end
|
174
173
|
|
174
|
+
# @return [String (frozen)]
|
175
|
+
def inspect
|
176
|
+
"#{self.class.name}-#{@id}"
|
177
|
+
end
|
178
|
+
|
175
179
|
# @return [Hash] json properties
|
176
180
|
def json_properties
|
177
181
|
@json && @json["properties"]
|
@@ -231,6 +235,7 @@ module NotionRubyMapping
|
|
231
235
|
self
|
232
236
|
end
|
233
237
|
|
238
|
+
# @param [Boolean] dry_run
|
234
239
|
# @return [NotionRubyMapping::Base, String]
|
235
240
|
# @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#277085c8439841c798a4b94eae9a7326
|
236
241
|
def save(dry_run: false)
|
@@ -254,8 +259,9 @@ module NotionRubyMapping
|
|
254
259
|
self
|
255
260
|
end
|
256
261
|
|
257
|
-
|
258
|
-
|
262
|
+
# @return [FalseClass] return false except block
|
263
|
+
def synced_block_original?
|
264
|
+
false
|
259
265
|
end
|
260
266
|
|
261
267
|
# @param [Hash] json
|
@@ -13,10 +13,15 @@ module NotionRubyMapping
|
|
13
13
|
attr_reader :can_have_children, :can_append, :type
|
14
14
|
|
15
15
|
# @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#298916c7c379424682f39ff09ee38544
|
16
|
-
# @param [String]
|
16
|
+
# @param [String] id
|
17
17
|
# @return [NotionRubyMapping::Block]
|
18
|
-
def self.find(
|
19
|
-
NotionCache.instance
|
18
|
+
def self.find(id, dry_run: false)
|
19
|
+
nc = NotionCache.instance
|
20
|
+
if dry_run
|
21
|
+
Base.dry_run_script :get, nc.block_path(id)
|
22
|
+
else
|
23
|
+
nc.block id
|
24
|
+
end
|
20
25
|
end
|
21
26
|
|
22
27
|
# @return [Hash{String (frozen)->String (frozen) | Array}, nil]
|
@@ -68,9 +73,11 @@ module NotionRubyMapping
|
|
68
73
|
when "link_preview"
|
69
74
|
ans[@type] = {"url" => @url}
|
70
75
|
when "link_to_page"
|
71
|
-
ans[@type] = @page_id
|
72
|
-
{"type" => "page_id", "page_id" => @page_id}
|
76
|
+
ans[@type] = if @page_id
|
77
|
+
{"type" => "page_id", "page_id" => @page_id}
|
78
|
+
else
|
73
79
|
{"type" => "database_id", "database_id" => @database_id}
|
80
|
+
end
|
74
81
|
when "synced_block"
|
75
82
|
ans[@type] = {"synced_from" => @block_id ? {"type" => "block_id", "block_id" => @block_id} : nil}
|
76
83
|
ans[@type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
|
@@ -80,13 +87,11 @@ module NotionRubyMapping
|
|
80
87
|
"has_row_header" => @has_row_header,
|
81
88
|
"table_width" => @table_width,
|
82
89
|
}
|
83
|
-
if @table_rows
|
84
|
-
ans[@type]["children"] = @table_rows.map(&:block_json)
|
85
|
-
end
|
90
|
+
ans[@type]["children"] = @table_rows.map(&:block_json) if @table_rows
|
86
91
|
when "table_of_contents"
|
87
92
|
ans[@type] = {"color" => @color}
|
88
93
|
when "table_row"
|
89
|
-
ans[@type] = {"cells" => @cells.map { |cell| Array(cell).map
|
94
|
+
ans[@type] = {"cells" => @cells.map { |cell| Array(cell).map(&:property_values_json) }}
|
90
95
|
when "template"
|
91
96
|
@rich_text_array.will_update = true
|
92
97
|
ans[@type] = @rich_text_array.update_property_schema_json
|
@@ -269,6 +274,16 @@ module NotionRubyMapping
|
|
269
274
|
@rich_text_array = RichTextArray.new "rich_text", json: @json[@type]["rich_text"]
|
270
275
|
end
|
271
276
|
|
277
|
+
# @param [Boolean] dry_run
|
278
|
+
# @return [NotionRubyMapping::Base, String]
|
279
|
+
def destroy(dry_run: false)
|
280
|
+
if dry_run
|
281
|
+
Base.dry_run_script :delete, @nc.block_path(@id)
|
282
|
+
else
|
283
|
+
@nc.destroy_block id
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
272
287
|
# @return [NotionRubyMapping::Block]
|
273
288
|
# @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#fe58d26468e04b38b8ae730e4f0c74ae
|
274
289
|
def divider
|
@@ -415,6 +430,11 @@ module NotionRubyMapping
|
|
415
430
|
self
|
416
431
|
end
|
417
432
|
|
433
|
+
# @return [Boolean] true if synced_block & block_id is nil
|
434
|
+
def synced_block_original?
|
435
|
+
@type == "synced_block" && @block_id.nil?
|
436
|
+
end
|
437
|
+
|
418
438
|
def table(table_width:, has_column_header: false, has_row_header: false, table_rows: nil)
|
419
439
|
@type = __method__.to_s
|
420
440
|
@table_width = table_width
|
@@ -520,7 +540,6 @@ module NotionRubyMapping
|
|
520
540
|
end
|
521
541
|
|
522
542
|
# @param [String] url
|
523
|
-
# @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] caption
|
524
543
|
# @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#7aad77515ce14e3bbc7e0a7a5427820b
|
525
544
|
def video(url)
|
526
545
|
@type = __method__.to_s
|
@@ -536,7 +555,6 @@ module NotionRubyMapping
|
|
536
555
|
end
|
537
556
|
|
538
557
|
# @param [String] type
|
539
|
-
# @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] caption
|
540
558
|
# @param [String] color
|
541
559
|
def rich_text_array_and_color(type, text_info, color = "default")
|
542
560
|
@rich_text_array = RichTextArray.rich_text_array type, text_info
|
@@ -38,7 +38,7 @@ module NotionRubyMapping
|
|
38
38
|
def append_block_children_page_path(page_id)
|
39
39
|
"v1/blocks/#{page_id}/children"
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
# @param [String] id
|
43
43
|
# @param [Hash] payload
|
44
44
|
# @return [Hash]
|
@@ -138,6 +138,16 @@ module NotionRubyMapping
|
|
138
138
|
"v1/databases"
|
139
139
|
end
|
140
140
|
|
141
|
+
# @return [NotionRubyMapping::Base]
|
142
|
+
def destroy_block(id)
|
143
|
+
Base.create_from_json destroy_block_request(id)
|
144
|
+
end
|
145
|
+
|
146
|
+
# @param [Hash] response
|
147
|
+
def destroy_block_request(id)
|
148
|
+
request :delete, block_path(id)
|
149
|
+
end
|
150
|
+
|
141
151
|
def inspect
|
142
152
|
"NotionCache"
|
143
153
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notion_ruby_mapping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroyuki KOBAYASHI
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|