notion_ruby_mapping 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/notion_ruby_mapping/blocks/base.rb +19 -5
- data/lib/notion_ruby_mapping/blocks/list.rb +71 -89
- data/lib/notion_ruby_mapping/blocks/page.rb +10 -0
- data/lib/notion_ruby_mapping/controllers/discussion_thread.rb +27 -0
- data/lib/notion_ruby_mapping/controllers/notion_cache.rb +20 -0
- data/lib/notion_ruby_mapping/objects/comment_object.rb +30 -0
- data/lib/notion_ruby_mapping/properties/property.rb +1 -0
- data/lib/notion_ruby_mapping/properties/status_property.rb +36 -0
- data/lib/notion_ruby_mapping/version.rb +1 -1
- data/lib/notion_ruby_mapping.rb +5 -4
- data/tools/createErDiagram.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20cd62581513083b2b99d6fad57d3486fc855bf390f96ba01da263fa47e16029
|
4
|
+
data.tar.gz: da20deff5ce1e53cbbe7d2cda86550676eea088fe1fee890385490b07cfa55ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68fd906fb46c5957d5eb48a41f41752c61a8fb40a7283dfa9ec3e4a95173c38401a966f24707893bdc1ded47ed76606990031488e2100eac234e4e53197de005
|
7
|
+
data.tar.gz: d79d601217f69788eee522185868e5ded0e44598a60e9a4e4173c98b4df96c262c7516893e8f3829ac5d202491cad6c1548bb4de53d1646a691dacc6e8d3a6c8
|
@@ -58,6 +58,24 @@ module NotionRubyMapping
|
|
58
58
|
shell.join(" \\\n")
|
59
59
|
end
|
60
60
|
|
61
|
+
def comments(query = nil, dry_run: false)
|
62
|
+
if page? || block?
|
63
|
+
if dry_run
|
64
|
+
self.class.dry_run_script :get, @nc.retrieve_comments_path(@id)
|
65
|
+
else
|
66
|
+
ans = {}
|
67
|
+
List.new(comment_parent: self,
|
68
|
+
json: @nc.retrieve_comments_request(@id, query),
|
69
|
+
query: query).each do |comment|
|
70
|
+
dt_id = comment.discussion_id
|
71
|
+
dt = ans[dt_id] ||= DiscussionThread.new dt_id
|
72
|
+
dt.comments << comment
|
73
|
+
end
|
74
|
+
ans
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
61
79
|
# @param [String] key
|
62
80
|
# @return [NotionRubyMapping::PropertyCache, Hash] obtained Page value or PropertyCache
|
63
81
|
def get(key)
|
@@ -264,11 +282,7 @@ module NotionRubyMapping
|
|
264
282
|
@new_record ? create(dry_run: true) : update(dry_run: true)
|
265
283
|
else
|
266
284
|
@new_record ? create : update
|
267
|
-
if
|
268
|
-
|
269
|
-
else
|
270
|
-
@property_cache.clear_will_update
|
271
|
-
end
|
285
|
+
@property_cache.clear_will_update if page?
|
272
286
|
@payload.clear
|
273
287
|
self
|
274
288
|
end
|
@@ -5,13 +5,14 @@ module NotionRubyMapping
|
|
5
5
|
class List < Base
|
6
6
|
include Enumerable
|
7
7
|
|
8
|
-
def initialize(json: nil, id: nil, database: nil, parent: nil, property: nil, query: nil)
|
8
|
+
def initialize(json: nil, id: nil, database: nil, parent: nil, property: nil, comment_parent: nil, query: nil)
|
9
9
|
super(json: json, id: id)
|
10
10
|
@has_more = @json["has_more"]
|
11
11
|
@load_all_contents = !@has_more
|
12
12
|
@database = database
|
13
13
|
@parent = parent
|
14
14
|
@property = property
|
15
|
+
@comment_parent = comment_parent
|
15
16
|
@query = query
|
16
17
|
@index = 0
|
17
18
|
@has_content = true
|
@@ -20,105 +21,86 @@ module NotionRubyMapping
|
|
20
21
|
|
21
22
|
# @return [NotionRubyMapping::List, Enumerator]
|
22
23
|
# @see https://www.notion.so/hkob/List-9a0b32335e0d48849a785ce5e162c760#12e1c261a0944a4095776b7515bef4a1
|
23
|
-
def each
|
24
|
-
return enum_for(:each)
|
25
|
-
|
24
|
+
def each(&block)
|
25
|
+
return enum_for(:each) if block.nil?
|
26
26
|
if @parent
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@has_more = @json["has_more"]
|
32
|
-
end
|
33
|
-
@index = 0
|
34
|
-
@has_content = true
|
35
|
-
end
|
36
|
-
|
37
|
-
while @has_content
|
38
|
-
if @index < results.length
|
39
|
-
object = Base.create_from_json(results[@index])
|
40
|
-
@index += 1
|
41
|
-
yield object
|
42
|
-
elsif @has_more
|
43
|
-
if @parent
|
44
|
-
@query.start_cursor = @json["next_cursor"]
|
45
|
-
@json = @parent.children @query
|
46
|
-
@index = 0
|
47
|
-
@has_more = @json["has_more"]
|
48
|
-
else
|
49
|
-
@has_content = false
|
50
|
-
end
|
51
|
-
else
|
52
|
-
@has_content = false
|
53
|
-
end
|
54
|
-
end
|
27
|
+
each_sub base: @page,
|
28
|
+
query: -> { @parent.children @query },
|
29
|
+
create_object: ->(json) { Base.create_from_json json },
|
30
|
+
&block
|
55
31
|
elsif @database
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
32
|
+
each_sub base: @database,
|
33
|
+
query: -> { @nc.database_query_request @database.id, @query },
|
34
|
+
create_object: ->(json) { Base.create_from_json json },
|
35
|
+
&block
|
36
|
+
elsif @property
|
37
|
+
each_sub base: @property,
|
38
|
+
query: -> do
|
39
|
+
@nc.page_property_request @property.property_cache.page_id,
|
40
|
+
@property.property_id,
|
41
|
+
@query.query_json
|
42
|
+
end,
|
43
|
+
create_object: ->(json) do
|
44
|
+
case json["type"]
|
45
|
+
when "people"
|
46
|
+
UserObject.new json: json["people"]
|
47
|
+
when "relation"
|
48
|
+
json["relation"]["id"]
|
49
|
+
when "rich_text"
|
50
|
+
RichTextObject.create_from_json json["rich_text"]
|
51
|
+
when "title"
|
52
|
+
RichTextObject.create_from_json json["title"]
|
53
|
+
else
|
54
|
+
json
|
55
|
+
end
|
56
|
+
end,
|
57
|
+
&block
|
58
|
+
elsif @comment_parent
|
59
|
+
each_sub base: @comment_parent,
|
60
|
+
query: -> { @nc.retrieve_comments_request @comment_parent.id, @query },
|
61
|
+
create_object: ->(json) { CommentObject.new json: json },
|
62
|
+
&block
|
63
|
+
end
|
64
|
+
self
|
65
|
+
end
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
@has_content = false
|
79
|
-
end
|
80
|
-
else
|
81
|
-
@has_content = false
|
82
|
-
end
|
67
|
+
private
|
68
|
+
|
69
|
+
# @param [NotionRubyMapping::Page, NotionRubyMapping::Block] base page or block
|
70
|
+
# @param [Proc] query
|
71
|
+
# @param [Proc] create_object
|
72
|
+
# @param [Proc] block
|
73
|
+
def each_sub(base:, query:, create_object:, &block)
|
74
|
+
unless @has_content
|
75
|
+
unless @load_all_contents
|
76
|
+
@query.start_cursor = nil
|
77
|
+
@json = query.call
|
78
|
+
@has_more = @json["has_more"]
|
83
79
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
end
|
100
|
-
@index += 1
|
101
|
-
yield object
|
102
|
-
elsif @has_more
|
103
|
-
if @property
|
104
|
-
@query ||= Query.new
|
105
|
-
@query.start_cursor = @json["next_cursor"]
|
106
|
-
@json = NotionCache.instance.page_property_request @property.property_cache.page_id, @property.property_id, @query.query_json
|
107
|
-
@index = 0
|
108
|
-
@has_more = @json["has_more"]
|
109
|
-
else
|
110
|
-
@has_content = false
|
111
|
-
end
|
80
|
+
@index = 0
|
81
|
+
@has_content = true
|
82
|
+
end
|
83
|
+
|
84
|
+
while @has_content
|
85
|
+
if @index < results.length
|
86
|
+
object = create_object.call results[@index]
|
87
|
+
@index += 1
|
88
|
+
block.call object
|
89
|
+
elsif @has_more
|
90
|
+
if base
|
91
|
+
@query.start_cursor = @json["next_cursor"]
|
92
|
+
@json = query.call
|
93
|
+
@index = 0
|
94
|
+
@has_more = @json["has_more"]
|
112
95
|
else
|
113
96
|
@has_content = false
|
114
97
|
end
|
98
|
+
else
|
99
|
+
@has_content = false
|
115
100
|
end
|
116
101
|
end
|
117
|
-
self
|
118
102
|
end
|
119
103
|
|
120
|
-
private
|
121
|
-
|
122
104
|
# @return [Hash]
|
123
105
|
def results
|
124
106
|
@json["results"]
|
@@ -23,6 +23,16 @@ module NotionRubyMapping
|
|
23
23
|
get key
|
24
24
|
end
|
25
25
|
|
26
|
+
def append_comment(text_objects, dry_run: false)
|
27
|
+
rto = RichTextArray.new "rich_text", text_objects: text_objects, will_update: true
|
28
|
+
json = rto.property_schema_json.merge({"parent" => {"page_id" => @id}})
|
29
|
+
if dry_run
|
30
|
+
self.class.dry_run_script :post, @nc.comments_path, json
|
31
|
+
else
|
32
|
+
CommentObject.new json: (@nc.append_comment_request json)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
26
36
|
# @param [String] title
|
27
37
|
# @param [Array<String, Property>] assigns
|
28
38
|
# @return [NotionRubyMapping::Database]
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
# DiscussionThread
|
5
|
+
class DiscussionThread
|
6
|
+
# @param [String] discussion_id
|
7
|
+
def initialize(discussion_id)
|
8
|
+
@discussion_id = discussion_id
|
9
|
+
@comments = []
|
10
|
+
end
|
11
|
+
attr_reader :discussion_id, :comments
|
12
|
+
|
13
|
+
# @param [String] text_objects
|
14
|
+
# @param [Boolean] dry_run
|
15
|
+
# @return [String, NotionRubyMapping::CommentObject]
|
16
|
+
def append_comment(text_objects, dry_run: false)
|
17
|
+
rto = RichTextArray.new "rich_text", text_objects: text_objects, will_update: true
|
18
|
+
nc = NotionCache.instance
|
19
|
+
json = rto.property_schema_json.merge({"discussion_id" => @discussion_id})
|
20
|
+
if dry_run
|
21
|
+
Base.dry_run_script :post, nc.comments_path, json
|
22
|
+
else
|
23
|
+
CommentObject.new json: (nc.append_comment_request json)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -45,6 +45,10 @@ module NotionRubyMapping
|
|
45
45
|
request :patch, append_block_children_block_path(id), payload
|
46
46
|
end
|
47
47
|
|
48
|
+
def append_comment_request(json)
|
49
|
+
request :post, comments_path, json
|
50
|
+
end
|
51
|
+
|
48
52
|
# @param [String] id block_id (with or without "-")
|
49
53
|
# @return [NotionRubyMapping::Base] Block object or nil
|
50
54
|
def block(id)
|
@@ -81,6 +85,11 @@ module NotionRubyMapping
|
|
81
85
|
@object_hash = {}
|
82
86
|
end
|
83
87
|
|
88
|
+
# @return [String (frozen)]
|
89
|
+
def comments_path
|
90
|
+
"v1/comments"
|
91
|
+
end
|
92
|
+
|
84
93
|
# @param [String] notion_token
|
85
94
|
# @return [NotionRubyMapping::NotionCache] self (NotionCache.instance)
|
86
95
|
def create_client(notion_token, wait: 0.3333, debug: false)
|
@@ -214,6 +223,17 @@ module NotionRubyMapping
|
|
214
223
|
"v1/databases/#{database_id}/query"
|
215
224
|
end
|
216
225
|
|
226
|
+
# @param [String] block_id
|
227
|
+
def retrieve_comments_path(block_id)
|
228
|
+
"v1/comments?block_id=#{block_id}"
|
229
|
+
end
|
230
|
+
|
231
|
+
# @param [String] block_id
|
232
|
+
# @param [NotionRubyMapping::Query, NilClass] query
|
233
|
+
def retrieve_comments_request(block_id, query)
|
234
|
+
request :get, retrieve_comments_path(block_id), (query&.query_json || {})
|
235
|
+
end
|
236
|
+
|
217
237
|
# @param [Symbol] method
|
218
238
|
# @param [String] path
|
219
239
|
# @param [Hash] options
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
# CommentObject
|
5
|
+
class CommentObject
|
6
|
+
# @param [String] text_objects
|
7
|
+
def initialize(text_objects: nil, json: {})
|
8
|
+
if text_objects
|
9
|
+
@text_objects = RichTextArray.new "rich_text", text_objects: text_objects
|
10
|
+
@json = {}
|
11
|
+
elsif json
|
12
|
+
@json = json
|
13
|
+
@text_objects = RichTextArray.new "rich_text", json: json["rich_text"]
|
14
|
+
else
|
15
|
+
raise StandardError, "Either text_objects or json is required CommentObject"
|
16
|
+
end
|
17
|
+
@will_update = false
|
18
|
+
end
|
19
|
+
attr_reader :will_update, :text_objects
|
20
|
+
|
21
|
+
def discussion_id
|
22
|
+
NotionCache.instance.hex_id @json["discussion_id"]
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [String] full_text
|
26
|
+
def full_text
|
27
|
+
@text_objects.full_text
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -107,6 +107,7 @@ module NotionRubyMapping
|
|
107
107
|
"people" => PeopleProperty,
|
108
108
|
"phone_number" => PhoneNumberProperty,
|
109
109
|
"select" => SelectProperty,
|
110
|
+
"status" => StatusProperty,
|
110
111
|
"title" => TitleProperty,
|
111
112
|
"rich_text" => RichTextProperty,
|
112
113
|
"url" => UrlProperty,
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
# Status property
|
5
|
+
class StatusProperty < Property
|
6
|
+
TYPE = "status"
|
7
|
+
|
8
|
+
### Public announced methods
|
9
|
+
|
10
|
+
## Common methods
|
11
|
+
|
12
|
+
def status
|
13
|
+
@json
|
14
|
+
end
|
15
|
+
|
16
|
+
### Not public announced methods
|
17
|
+
|
18
|
+
## Common methods
|
19
|
+
|
20
|
+
# @param [String] name Property name
|
21
|
+
# @param [Boolean, Hash] json
|
22
|
+
def initialize(name, will_update: false, base_type: :page, property_cache: nil, json: {})
|
23
|
+
super name, will_update: will_update, base_type: base_type, property_cache: property_cache
|
24
|
+
@json = json
|
25
|
+
end
|
26
|
+
|
27
|
+
## Page property only methods
|
28
|
+
|
29
|
+
# @return [Hash]
|
30
|
+
def property_values_json
|
31
|
+
assert_page_property __method__
|
32
|
+
{}
|
33
|
+
#{@name => {"status" => @json, "type" => "status"}}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/notion_ruby_mapping.rb
CHANGED
@@ -12,13 +12,14 @@ require_relative "notion_ruby_mapping/version"
|
|
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 template_block to_do_block
|
14
14
|
toggle_block video_block],
|
15
|
-
controllers: %w[notion_cache payload property_cache query rich_text_array],
|
16
|
-
objects: %w[rich_text_object emoji_object equation_object file_object mention_object text_object user_object
|
15
|
+
controllers: %w[notion_cache payload property_cache query rich_text_array discussion_thread],
|
16
|
+
objects: %w[rich_text_object emoji_object equation_object file_object mention_object text_object user_object
|
17
|
+
comment_object],
|
17
18
|
properties: %w[property checkbox_property multi_property created_by_property date_base_property created_time_property
|
18
19
|
date_property email_property files_property formula_property last_edited_by_property
|
19
20
|
last_edited_time_property multi_select_property number_property people_property phone_number_property
|
20
|
-
relation_property text_property rich_text_property rollup_property select_property
|
21
|
-
url_property],
|
21
|
+
relation_property text_property rich_text_property rollup_property select_property status_property
|
22
|
+
title_property url_property],
|
22
23
|
}.each do |key, values|
|
23
24
|
values.each do |klass|
|
24
25
|
require_relative "notion_ruby_mapping/#{key}/#{klass}"
|
data/tools/createErDiagram.rb
CHANGED
@@ -36,7 +36,7 @@ until dbs.empty?
|
|
36
36
|
append_database(text, db)
|
37
37
|
db.properties.select { |p| p.is_a? RelationProperty }.each_with_index do |p, i|
|
38
38
|
new_db = Database.find p.relation_database_id
|
39
|
-
text << "#{db_title db}
|
39
|
+
text << "#{db_title db} |o--o{ #{db_title new_db} : r#{i}"
|
40
40
|
dbs << new_db unless finished[new_db]
|
41
41
|
end
|
42
42
|
text << ""
|
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.6.
|
4
|
+
version: 0.6.2
|
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-07
|
11
|
+
date: 2022-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -192,11 +192,13 @@ files:
|
|
192
192
|
- lib/notion_ruby_mapping/blocks/url_base_block.rb
|
193
193
|
- lib/notion_ruby_mapping/blocks/url_caption_base_block.rb
|
194
194
|
- lib/notion_ruby_mapping/blocks/video_block.rb
|
195
|
+
- lib/notion_ruby_mapping/controllers/discussion_thread.rb
|
195
196
|
- lib/notion_ruby_mapping/controllers/notion_cache.rb
|
196
197
|
- lib/notion_ruby_mapping/controllers/payload.rb
|
197
198
|
- lib/notion_ruby_mapping/controllers/property_cache.rb
|
198
199
|
- lib/notion_ruby_mapping/controllers/query.rb
|
199
200
|
- lib/notion_ruby_mapping/controllers/rich_text_array.rb
|
201
|
+
- lib/notion_ruby_mapping/objects/comment_object.rb
|
200
202
|
- lib/notion_ruby_mapping/objects/emoji_object.rb
|
201
203
|
- lib/notion_ruby_mapping/objects/equation_object.rb
|
202
204
|
- lib/notion_ruby_mapping/objects/file_object.rb
|
@@ -224,6 +226,7 @@ files:
|
|
224
226
|
- lib/notion_ruby_mapping/properties/rich_text_property.rb
|
225
227
|
- lib/notion_ruby_mapping/properties/rollup_property.rb
|
226
228
|
- lib/notion_ruby_mapping/properties/select_property.rb
|
229
|
+
- lib/notion_ruby_mapping/properties/status_property.rb
|
227
230
|
- lib/notion_ruby_mapping/properties/text_property.rb
|
228
231
|
- lib/notion_ruby_mapping/properties/title_property.rb
|
229
232
|
- lib/notion_ruby_mapping/properties/url_property.rb
|