notion_ruby_mapping 0.6.3 → 0.6.4

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: b295b0ba6b110a2f9e2f559e251490005a446abd71d2b7cc67903f9b0e2e504a
4
- data.tar.gz: 8b6d1ed3f4c53973c8391981cef7044628ba22894dd42f8b23364f9a995326d9
3
+ metadata.gz: 728ebd46ad3c0492c2454e60fec7c3ce271cc325ea0bfce9894f509c9cdcd809
4
+ data.tar.gz: 9d1670b5f6dc8a7b366eb84e3c7bbb99bf65007ee208d437f472cc64e5f861c8
5
5
  SHA512:
6
- metadata.gz: 5d3e718b49fceea38ee34be30161496d9023158631b24a633408af4b9eb5f5507ae85484c74a4f0094a7e1d8aaa47c851cc2d47af128e45814d98a5c1f5a21f4
7
- data.tar.gz: 95b5374a44768b1454d550abcad6343c06d24333d787045d5317ba91ef0a1f0a1ddb273879ca28e928e2808180b7acbd144a4e8f19c52cb7208d565083d19906
6
+ metadata.gz: c8474a85e8cf7b59cc7a0c60681f7a193234a6d6435136a9078872ed54057a39171de01c49232b6bd012ea3f804c4efddd54c02a71ff32324cedbacfd339e5de
7
+ data.tar.gz: 209a96f0365eb4d0c8f02283610e484d2a1018c2d453fd4ee3e7f08abd6c0e63077aea43ec5ef2c2aeecf7e69d492d6685c7b32848743498d4b3a9f08fb4e981
data/README.md CHANGED
@@ -84,9 +84,11 @@ NotionCache.instance.create_client ENV["NOTION_API_TOKEN"] # from environment
84
84
  1. [Renumbering pages](examples/renumbering_pages.md)
85
85
  1. [Change title](examples/change_title.md)
86
86
  1. [Create erDiagram from Notion database](tools/createErDiagram.rb)
87
+
87
88
  ```shell
88
89
  Usage:
89
90
  ruby tools/createErDiagram.rb database_id code_block_id
91
+ ruby tools/createErDiagram.rb "database_url" "code_block_url"
90
92
  ```
91
93
 
92
94
  ### 2.5 API reference
@@ -95,6 +97,7 @@ Usage:
95
97
 
96
98
  ## 3. ChangeLog
97
99
 
100
+ - 2022/8/9 [v0.6.4] url can be entered instead of page_id, block_id and database_id
98
101
  - 2022/8/9 [v0.6.3] update createErDiagram.rb (Fixed a bug with non-ASCII database titles)
99
102
  - 2022/8/7 [v0.6.2] add comment_object support
100
103
  - 2022/7/28 [v0.6.1] added createErDiagram.rb
@@ -44,6 +44,22 @@ module NotionRubyMapping
44
44
  end
45
45
  end
46
46
 
47
+ def self.block_id(str)
48
+ if /^http/.match str
49
+ /#([\da-f]{32})/.match(str)[1]
50
+ else
51
+ NotionCache.instance.hex_id str
52
+ end
53
+ end
54
+
55
+ def self.database_id(str)
56
+ if /^http/.match str
57
+ /([\da-f]{32})\?/.match(str)[1]
58
+ else
59
+ NotionCache.instance.hex_id str
60
+ end
61
+ end
62
+
47
63
  # @param [Object] method
48
64
  # @param [Object] path
49
65
  # @param [nil] json
@@ -58,21 +74,29 @@ module NotionRubyMapping
58
74
  shell.join(" \\\n")
59
75
  end
60
76
 
77
+ def self.page_id(str)
78
+ if /^http/.match str
79
+ /([\da-f]{32})$/.match(str)[1]
80
+ else
81
+ NotionCache.instance.hex_id str
82
+ end
83
+ end
84
+
61
85
  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
86
+ return unless page? || block?
87
+
88
+ if dry_run
89
+ self.class.dry_run_script :get, @nc.retrieve_comments_path(@id)
90
+ else
91
+ ans = {}
92
+ List.new(comment_parent: self,
93
+ json: @nc.retrieve_comments_request(@id, query),
94
+ query: query).each do |comment|
95
+ dt_id = comment.discussion_id
96
+ dt = ans[dt_id] ||= DiscussionThread.new dt_id
97
+ dt.comments << comment
75
98
  end
99
+ ans
76
100
  end
77
101
  end
78
102
 
@@ -67,10 +67,11 @@ module NotionRubyMapping
67
67
  # @return [NotionRubyMapping::Block]
68
68
  def self.find(id, dry_run: false)
69
69
  nc = NotionCache.instance
70
+ block_id = Base.block_id id
70
71
  if dry_run
71
- Base.dry_run_script :get, nc.block_path(id)
72
+ Base.dry_run_script :get, nc.block_path(block_id)
72
73
  else
73
- nc.block id
74
+ nc.block block_id
74
75
  end
75
76
  end
76
77
 
@@ -10,10 +10,11 @@ module NotionRubyMapping
10
10
  # @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#58ba9190fd544432a9e2a5823d6c33b7
11
11
  def self.find(id, dry_run: false)
12
12
  nc = NotionCache.instance
13
+ database_id = Base.database_id id
13
14
  if dry_run
14
- dry_run_script :get, nc.database_path(id)
15
+ dry_run_script :get, nc.database_path(database_id)
15
16
  else
16
- nc.database id
17
+ nc.database database_id
17
18
  end
18
19
  end
19
20
 
@@ -25,9 +25,9 @@ module NotionRubyMapping
25
25
  def block_json(not_update: true)
26
26
  ans = super
27
27
  ans[type] = if @page_id
28
- {"type" => "page_id", "page_id" => @page_id}
28
+ {"type" => "page_id", "page_id" => Base.page_id(@page_id)}
29
29
  else
30
- {"type" => "database_id", "database_id" => @database_id}
30
+ {"type" => "database_id", "database_id" => Base.database_id(@database_id)}
31
31
  end
32
32
  ans
33
33
  end
@@ -10,10 +10,11 @@ module NotionRubyMapping
10
10
  # @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#7d868b8b81c3473082bbdc7370813a4a
11
11
  def self.find(id, dry_run: false)
12
12
  nc = NotionCache.instance
13
+ page_id = Base.page_id id
13
14
  if dry_run
14
- Base.dry_run_script :get, nc.page_path(id)
15
+ Base.dry_run_script :get, nc.page_path(page_id)
15
16
  else
16
- nc.page id
17
+ nc.page page_id
17
18
  end
18
19
  end
19
20
 
@@ -11,7 +11,7 @@ module NotionRubyMapping
11
11
  synced_from = @json[type]["synced_from"]
12
12
  @block_id = synced_from && @nc.hex_id(synced_from["block_id"])
13
13
  else
14
- @block_id = block_id
14
+ @block_id = Base.block_id block_id
15
15
  add_sub_blocks sub_blocks
16
16
  end
17
17
  @can_have_children = @block_id.nil?
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
- VERSION = "0.6.3"
4
+ VERSION = "0.6.4"
5
5
  NOTION_VERSION = "2022-06-28"
6
6
  end
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: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroyuki KOBAYASHI