notion_ruby_mapping 0.6.4 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -11
  3. data/{tools/createErDiagram.rb → exe/notionErDiagram.rb} +20 -7
  4. data/exe/notionSitemap.rb +131 -0
  5. data/lib/notion_ruby_mapping/blocks/base.rb +1 -1
  6. data/lib/notion_ruby_mapping/blocks/heading1_block.rb +8 -0
  7. data/lib/notion_ruby_mapping/blocks/heading2_block.rb +8 -0
  8. data/lib/notion_ruby_mapping/blocks/heading3_block.rb +8 -0
  9. data/lib/notion_ruby_mapping/blocks/page.rb +2 -2
  10. data/lib/notion_ruby_mapping/blocks/toggle_heading1_block.rb +8 -0
  11. data/lib/notion_ruby_mapping/blocks/toggle_heading2_block.rb +8 -0
  12. data/lib/notion_ruby_mapping/blocks/toggle_heading3_block.rb +8 -0
  13. data/lib/notion_ruby_mapping/controllers/property_cache.rb +4 -0
  14. data/lib/notion_ruby_mapping/objects/equation_object.rb +5 -0
  15. data/lib/notion_ruby_mapping/objects/mention_object.rb +5 -0
  16. data/lib/notion_ruby_mapping/properties/checkbox_property.rb +3 -2
  17. data/lib/notion_ruby_mapping/properties/created_by_property.rb +4 -2
  18. data/lib/notion_ruby_mapping/properties/created_time_property.rb +3 -2
  19. data/lib/notion_ruby_mapping/properties/date_property.rb +4 -2
  20. data/lib/notion_ruby_mapping/properties/email_property.rb +3 -2
  21. data/lib/notion_ruby_mapping/properties/files_property.rb +4 -2
  22. data/lib/notion_ruby_mapping/properties/formula_property.rb +4 -2
  23. data/lib/notion_ruby_mapping/properties/last_edited_by_property.rb +4 -2
  24. data/lib/notion_ruby_mapping/properties/last_edited_time_property.rb +3 -2
  25. data/lib/notion_ruby_mapping/properties/multi_select_property.rb +4 -2
  26. data/lib/notion_ruby_mapping/properties/number_property.rb +4 -2
  27. data/lib/notion_ruby_mapping/properties/people_property.rb +11 -3
  28. data/lib/notion_ruby_mapping/properties/phone_number_property.rb +3 -2
  29. data/lib/notion_ruby_mapping/properties/property.rb +12 -6
  30. data/lib/notion_ruby_mapping/properties/relation_property.rb +4 -2
  31. data/lib/notion_ruby_mapping/properties/rollup_property.rb +4 -2
  32. data/lib/notion_ruby_mapping/properties/select_property.rb +4 -2
  33. data/lib/notion_ruby_mapping/properties/status_property.rb +26 -4
  34. data/lib/notion_ruby_mapping/properties/text_property.rb +4 -2
  35. data/lib/notion_ruby_mapping/properties/title_property.rb +6 -2
  36. data/lib/notion_ruby_mapping/properties/url_property.rb +3 -2
  37. data/lib/notion_ruby_mapping/version.rb +1 -1
  38. metadata +7 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 728ebd46ad3c0492c2454e60fec7c3ce271cc325ea0bfce9894f509c9cdcd809
4
- data.tar.gz: 9d1670b5f6dc8a7b366eb84e3c7bbb99bf65007ee208d437f472cc64e5f861c8
3
+ metadata.gz: b9297c2ca59117bacfab46da55e60bda063c3a08a1bfc0acdd5b8e9b7b029c52
4
+ data.tar.gz: fdcfc87ab82132cebedf50f99c174793c74e952cc35608b60935e2bd158a2df6
5
5
  SHA512:
6
- metadata.gz: c8474a85e8cf7b59cc7a0c60681f7a193234a6d6435136a9078872ed54057a39171de01c49232b6bd012ea3f804c4efddd54c02a71ff32324cedbacfd339e5de
7
- data.tar.gz: 209a96f0365eb4d0c8f02283610e484d2a1018c2d453fd4ee3e7f08abd6c0e63077aea43ec5ef2c2aeecf7e69d492d6685c7b32848743498d4b3a9f08fb4e981
6
+ metadata.gz: 0f01ba2a798cd79e608b244a6c9c0157f92b1f7e2f9bd4fd4772b38e60f708d1da5a70ffda0816b8aa136282da49d118ff04ede19a363674c3277b3095a34e91
7
+ data.tar.gz: 6135423f52bdc33585247ef2c144a49492b54a28d18ae7429d8f4df9791f4d4189d570c2b381b89f939d0b2e2e1914276172b603f612038dbfc7c495ea250c01
data/README.md CHANGED
@@ -75,21 +75,16 @@ NotionCache.instance.create_client ENV["NOTION_API_TOKEN"] # from environment
75
75
  ### 2.3 Sample codes
76
76
 
77
77
  1. [Database and page access sample](https://www.notion.so/hkob/Database-and-page-access-sample-d30033e707194faf995741167eb2b6f8)
78
- 1. [Append block children sample](https://www.notion.so/hkob/Append-block-children-sample-3867910a437340be931cf7f2c06443c6)
79
- 1. [Update block sample](https://www.notion.so/hkob/update-block-sample-5568c1c36fe84f12b83edfe2dda83028)
78
+ 2. [Append block children sample](https://www.notion.so/hkob/Append-block-children-sample-3867910a437340be931cf7f2c06443c6)
79
+ 3. [Update block sample](https://www.notion.so/hkob/update-block-sample-5568c1c36fe84f12b83edfe2dda83028)
80
80
 
81
81
  ### 2.4. Another example code (Use case)
82
82
 
83
83
  1. [Set icon to all icon unsettled pages](examples/set_icon_to_all_icon_unsettled_pages.md)
84
- 1. [Renumbering pages](examples/renumbering_pages.md)
85
- 1. [Change title](examples/change_title.md)
86
- 1. [Create erDiagram from Notion database](tools/createErDiagram.rb)
87
-
88
- ```shell
89
- Usage:
90
- ruby tools/createErDiagram.rb database_id code_block_id
91
- ruby tools/createErDiagram.rb "database_url" "code_block_url"
92
- ```
84
+ 2. [Renumbering pages](examples/renumbering_pages.md)
85
+ 3. [Change title](examples/change_title.md)
86
+ 4. [Create ER Diagram from Notion database](https://www.notion.so/hkob/notionErDiagram-Sample-1720c2199c534ca08138cde38f31f710)
87
+ 5. [Create Sitemap from Notion pages](https://www.notion.so/hkob/NotionSitemap-sample-14e195c83d024c5382aab09210916c87)
93
88
 
94
89
  ### 2.5 API reference
95
90
 
@@ -97,6 +92,9 @@ Usage:
97
92
 
98
93
  ## 3. ChangeLog
99
94
 
95
+ - 2022/9/2 [v0.6.7] add support for Status property, is_toggleable for headings block, and page property values
96
+ - 2022/8/10 [v0.6.6] Bug fix(notionSitemap.rb): Skip if child page is empty.
97
+ - 2022/8/10 [v0.6.5] add notionSitemap.rb, rename createErDiagram to notionErDiagram, and move them to exe directory
100
98
  - 2022/8/9 [v0.6.4] url can be entered instead of page_id, block_id and database_id
101
99
  - 2022/8/9 [v0.6.3] update createErDiagram.rb (Fixed a bug with non-ASCII database titles)
102
100
  - 2022/8/7 [v0.6.2] add comment_object support
@@ -6,13 +6,13 @@ include NotionRubyMapping
6
6
  def append_database(text, db, db_titles)
7
7
  base_title = db_title db
8
8
  normalize_db_title(db, db_titles) if db_titles[db].nil?
9
- text << "#{db_titles[db]} {"
10
- text << %( Database title "#{base_title}") unless base_title == db_titles[db]
9
+ text << " #{db_titles[db]} {"
10
+ text << %( Database title "#{base_title}") unless base_title == db_titles[db]
11
11
  db.properties.reject { |p| p.is_a? RelationProperty }.each_with_index do |p, i|
12
12
  class_name = p.class.name.split("::").last.sub /Property/, ""
13
- text << %( #{class_name} p#{i} "#{p.name}")
13
+ text << %( #{class_name} p#{i} "#{p.name}")
14
14
  end
15
- text << "}\n"
15
+ text << " }\n"
16
16
  end
17
17
 
18
18
  def normalize_db_title(db, db_titles)
@@ -25,7 +25,7 @@ def db_title(db)
25
25
  end
26
26
 
27
27
  if ARGV.length < 2
28
- print "Usage: createErDiagram.rb top_database_id code_block_id"
28
+ print "Usage: notionErDiagram.rb top_database_id code_block_id"
29
29
  exit
30
30
  end
31
31
  database_id, code_block_id = ARGV
@@ -47,11 +47,24 @@ until dbs.empty?
47
47
  db.properties.select { |pp| pp.is_a? RelationProperty }.each_with_index do |pp, i|
48
48
  new_db = Database.find pp.relation_database_id
49
49
  normalize_db_title(new_db, db_titles) if db_titles[new_db].nil?
50
- text << "#{db_titles[db]} |o--o{ #{db_titles[new_db]} : r#{i}"
50
+ text << " #{db_titles[db]} |o--o{ #{db_titles[new_db]} : r#{i}"
51
51
  dbs << new_db unless finished[new_db]
52
52
  end
53
53
  text << ""
54
54
  end
55
- block.rich_text_array.rich_text_objects = text.join("\n ")
55
+
56
+ text_objects = text.each_with_object([]) do |str, ans|
57
+ strn = "#{str}\n"
58
+ if (last = ans.last)
59
+ if last.length + strn.length > 1999
60
+ ans << strn
61
+ else
62
+ ans[-1] += strn
63
+ end
64
+ else
65
+ ans << strn
66
+ end
67
+ end
68
+ block.rich_text_array.rich_text_objects = text_objects
56
69
  block.language = "mermaid"
57
70
  block.save
@@ -0,0 +1,131 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require "notion_ruby_mapping"
4
+ include NotionRubyMapping
5
+
6
+ # see https://zenn.dev/kinkinbeer135ml/articles/f08ce790091aca
7
+ def escape_title(title)
8
+ title.gsub /[(){}\[\]!”#$%&’()=^〜|¥1234567890@`「」{};:+*<>、。・?_]/, ""
9
+ end
10
+
11
+ class Sitemap
12
+ def initialize(top_page, orient, nolink)
13
+ @top_page = top_page
14
+ @code = {@top_page => "p0"}
15
+ @queue = [@top_page]
16
+ @finished = {}
17
+ @page_links = Hash.new { |h, k| h[k] = [] }
18
+ @text = ["flowchart #{orient}"]
19
+ @nolink = nolink
20
+ end
21
+ attr_reader :text
22
+
23
+ def dig_pages
24
+ until @queue.empty?
25
+ page = @queue.shift
26
+ @finished[page] = true
27
+ search_blocks(page)
28
+ @text << %(click #{@code[page]} "#{page["url"]}")
29
+ end
30
+ end
31
+
32
+ def code_with_title(page)
33
+ "#{@code[page]}(#{escape_title page.title})"
34
+ end
35
+
36
+ def search_blocks(page)
37
+ print "#{page.title}\n"
38
+ @children = []
39
+ @block_queue = page.children.to_a
40
+ search_block page, @block_queue.shift until @block_queue.empty?
41
+ unless @children.empty?
42
+ title = page == @top_page ? code_with_title(page) : @code[page]
43
+ @text << [title, @children.map { |p| code_with_title p }.join(" & ")].join(" --> ")
44
+ end
45
+ print "\n"
46
+ end
47
+
48
+ def search_block(page, block)
49
+ case block
50
+ when ChildPageBlock
51
+ child_block = block.children.first
52
+ add_child child_block.parent if child_block
53
+ when LinkToPageBlock
54
+ add_link page, block.page_id unless @nolink
55
+ else
56
+ @block_queue += block.children.to_a if block.has_children
57
+ search_link_in_rta(page, block.rich_text_array) if !@nolink && block.is_a?(TextSubBlockColorBaseBlock)
58
+ end
59
+ end
60
+
61
+ def add_child(child)
62
+ @queue << child
63
+ @children << child
64
+ set_code child
65
+ print " --> #{child.title}\n"
66
+ end
67
+
68
+ def set_code(page)
69
+ @code[page] ||= "p#{@code.length}"
70
+ end
71
+
72
+ def add_link(page, link_page_id)
73
+ return unless link_page_id
74
+
75
+ begin
76
+ link_page = Page.find link_page_id
77
+ rescue
78
+ print "\n#{link_page_id} can not read by this integration\n"
79
+ return
80
+ end
81
+ set_code link_page
82
+ @page_links[page] << link_page
83
+ print " -.-> #{link_page.title} "
84
+ end
85
+
86
+ def search_link_in_rta(page, rta)
87
+ rta.each { |to| add_link page, to.page_id if to.is_a?(MentionObject) && to.page_id }
88
+ end
89
+
90
+ def link_pages
91
+ @page_links.each do |org, array|
92
+ link_finished = {}
93
+ array.each do |lp|
94
+ link_finished[lp] = @finished[lp] ? @code[lp] : code_with_title(lp)
95
+ end
96
+ @text << [@code[org], link_finished.values.join(" & ")].join(" -.-> ")
97
+ end
98
+ end
99
+ end
100
+
101
+ if ARGV.length < 3
102
+ print "Usage: notionSitemap.rb top_page_id code_block_id orient(LR or TD) [--nolink]"
103
+ exit
104
+ end
105
+ top_page_id, code_block_id, orient, nolink = ARGV
106
+ NotionCache.instance.create_client ENV["NOTION_API_KEY"]
107
+ code_block = Block.find code_block_id
108
+ unless code_block.is_a? CodeBlock
109
+ print "#{code_block_id} is not CodeBlock's id"
110
+ exit
111
+ end
112
+
113
+ top_page = Page.find top_page_id
114
+ sm = Sitemap.new top_page, orient, nolink == "--nolink"
115
+ sm.dig_pages
116
+ sm.link_pages unless nolink
117
+ text_objects = sm.text.each_with_object([]) do |str, ans|
118
+ strn = "#{str}\n"
119
+ if (last = ans.last)
120
+ if last.length + strn.length > 1999
121
+ ans << strn
122
+ else
123
+ ans[-1] += strn
124
+ end
125
+ else
126
+ ans << strn
127
+ end
128
+ end
129
+ code_block.rich_text_array.rich_text_objects = text_objects
130
+ code_block.language = "mermaid"
131
+ code_block.save
@@ -25,7 +25,7 @@ module NotionRubyMapping
25
25
  assign.each_slice(2) { |(klass, key)| assign_property(klass, key) }
26
26
  @json ||= {}
27
27
  end
28
- attr_reader :json, :id, :archived
28
+ attr_reader :json, :id, :archived, :has_children
29
29
 
30
30
  # @param [Hash, Notion::Messages] json
31
31
  # @return [NotionRubyMapping::Base]
@@ -14,5 +14,13 @@ module NotionRubyMapping
14
14
  def type
15
15
  "heading_1"
16
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
17
25
  end
18
26
  end
@@ -14,5 +14,13 @@ module NotionRubyMapping
14
14
  def type
15
15
  "heading_2"
16
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
17
25
  end
18
26
  end
@@ -14,5 +14,13 @@ module NotionRubyMapping
14
14
  def type
15
15
  "heading_3"
16
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
17
25
  end
18
26
  end
@@ -47,7 +47,7 @@ module NotionRubyMapping
47
47
 
48
48
  # @param [String] title
49
49
  # @param [Array<String, Property>] assigns
50
- # @return [NotionRubyMapping::Database]
50
+ # @return [NotionRubyMapping::Database, String]
51
51
  # @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#e3f1d21e0f724f589e48431468772eed
52
52
  def create_child_database(title, *assigns, dry_run: false)
53
53
  build_child_database(title, *assigns).save dry_run: dry_run
@@ -56,7 +56,7 @@ module NotionRubyMapping
56
56
  # @return [String] title
57
57
  # @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#2ff7209055f346fbbda454cdbb40b1c8
58
58
  def title
59
- tp = properties.select { |p| (p.is_a?(TitleProperty)) || (p.is_a?(Property) && p.property_id == "title") }
59
+ tp = properties.select { |p| p.is_a?(TitleProperty) || (p.is_a?(Property) && p.property_id == "title") }
60
60
  tp.map(&:full_text).join ""
61
61
  end
62
62
 
@@ -7,5 +7,13 @@ module NotionRubyMapping
7
7
  def type
8
8
  "heading_1"
9
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
10
18
  end
11
19
  end
@@ -7,5 +7,13 @@ module NotionRubyMapping
7
7
  def type
8
8
  "heading_2"
9
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
10
18
  end
11
19
  end
@@ -7,5 +7,13 @@ module NotionRubyMapping
7
7
  def type
8
8
  "heading_3"
9
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
10
18
  end
11
19
  end
@@ -48,6 +48,10 @@ module NotionRubyMapping
48
48
  end
49
49
  end
50
50
 
51
+ def inspect
52
+ "PropertyCache"
53
+ end
54
+
51
55
  # @return [Hash] created property values json
52
56
  def property_values_json
53
57
  @properties.each_with_object({}) do |(_, property), ans|
@@ -31,6 +31,11 @@ module NotionRubyMapping
31
31
  @will_update = true
32
32
  end
33
33
 
34
+ # @return [String (frozen)]
35
+ def text
36
+ @expression
37
+ end
38
+
34
39
  protected
35
40
 
36
41
  # @return [Hash{String (frozen)->String}]
@@ -12,6 +12,11 @@ module NotionRubyMapping
12
12
  @options["plain_text"] = url
13
13
  end
14
14
 
15
+ # @return [String, NilClass]
16
+ def page_id
17
+ @options["page_id"]
18
+ end
19
+
15
20
  # @return [String (frozen)]
16
21
  def text
17
22
  ""
@@ -33,8 +33,9 @@ module NotionRubyMapping
33
33
 
34
34
  # @param [String] name Property name
35
35
  # @param [Boolean, Hash] json
36
- def initialize(name, will_update: false, base_type: :page, property_cache: nil, json: nil)
37
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache
36
+ def initialize(name, will_update: false, base_type: :page, property_id: nil, property_cache: nil, json: nil)
37
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
38
+ property_cache: property_cache
38
39
  @json = if database?
39
40
  json || {}
40
41
  else
@@ -22,8 +22,10 @@ module NotionRubyMapping
22
22
  # @param [String] name Property name
23
23
  # @param [String] user_id user_id (optional)
24
24
  # @param [Hash] json json (optional)
25
- def initialize(name, will_update: false, base_type: :page, json: nil, user_id: nil, property_cache: nil)
26
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache
25
+ def initialize(name, will_update: false, base_type: :page, json: nil, user_id: nil, property_id: nil,
26
+ property_cache: nil)
27
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
28
+ property_cache: property_cache
27
29
  @json = if database?
28
30
  json || {}
29
31
  else
@@ -21,8 +21,9 @@ module NotionRubyMapping
21
21
 
22
22
  # @param [String] name Property name
23
23
  # @param [String] json created_time value (optional)
24
- def initialize(name, will_update: false, base_type: :page, json: nil, property_cache: nil)
25
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache
24
+ def initialize(name, will_update: false, base_type: :page, json: nil, property_id: nil, property_cache: nil)
25
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
26
+ property_cache: property_cache
26
27
  @json = json
27
28
  @json ||= {} if database?
28
29
  end
@@ -75,8 +75,10 @@ module NotionRubyMapping
75
75
  # @param [Date, Time, DateTime, String, nil] start_date
76
76
  # @param [Date, Time, DateTime, String, nil] end_date
77
77
  # @param [String, nil] time_zone
78
- def initialize(name, will_update: false, base_type: :page, json: nil, start_date: nil, end_date: nil, time_zone: nil, property_cache: nil)
79
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache
78
+ def initialize(name, will_update: false, base_type: :page, json: nil, start_date: nil, end_date: nil,
79
+ time_zone: nil, property_id: nil, property_cache: nil)
80
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
81
+ property_cache: property_cache
80
82
  @json = json || {}
81
83
  return if database?
82
84
 
@@ -32,8 +32,9 @@ module NotionRubyMapping
32
32
  ## Common methods
33
33
 
34
34
  # @param [String] name Property name
35
- def initialize(name, will_update: false, base_type: :page, json: nil, property_cache: nil)
36
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache
35
+ def initialize(name, will_update: false, base_type: :page, json: nil, property_id: nil, property_cache: nil)
36
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
37
+ property_cache: property_cache
37
38
  @json = json || {}
38
39
  end
39
40
 
@@ -33,8 +33,10 @@ module NotionRubyMapping
33
33
 
34
34
  # @param [String] name Property name
35
35
  # @param [String] files files value (optional)
36
- def initialize(name, will_update: false, base_type: :page, json: nil, files: [], property_cache: nil)
37
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache
36
+ def initialize(name, will_update: false, base_type: :page, json: nil, files: [], property_id: nil,
37
+ property_cache: nil)
38
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
39
+ property_cache: property_cache
38
40
  if database?
39
41
  @files = json || {}
40
42
  elsif json
@@ -41,8 +41,10 @@ module NotionRubyMapping
41
41
 
42
42
  # @param [String] name
43
43
  # @param [Hash] json
44
- def initialize(name, will_update: false, base_type: :page, json: nil, formula: nil, property_cache: nil)
45
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache
44
+ def initialize(name, will_update: false, base_type: :page, json: nil, formula: nil, property_id: nil,
45
+ property_cache: nil)
46
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
47
+ property_cache: property_cache
46
48
  @json = json || {}
47
49
  return unless database?
48
50
 
@@ -22,8 +22,10 @@ module NotionRubyMapping
22
22
  # @param [String] name Property name
23
23
  # @param [String] user_id user_id (optional)
24
24
  # @param [Hash] json json (optional)
25
- def initialize(name, will_update: false, base_type: :page, json: nil, user_id: nil, property_cache: nil)
26
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache
25
+ def initialize(name, will_update: false, base_type: :page, json: nil, user_id: nil, property_id: nil,
26
+ property_cache: nil)
27
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
28
+ property_cache: property_cache
27
29
  @json = if database?
28
30
  json || {}
29
31
  else
@@ -21,8 +21,9 @@ module NotionRubyMapping
21
21
 
22
22
  # @param [String] name Property name
23
23
  # @param [String] json last_edited_time value (optional)
24
- def initialize(name, will_update: false, base_type: :page, json: nil, property_cache: nil)
25
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache
24
+ def initialize(name, will_update: false, base_type: :page, json: nil, property_id: nil, property_cache: nil)
25
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
26
+ property_cache: property_cache
26
27
  @json = json
27
28
  @json ||= {} if database?
28
29
  end
@@ -61,8 +61,10 @@ module NotionRubyMapping
61
61
  # @param [String] name
62
62
  # @param [Hash] json
63
63
  # @param [Array<String>, String] multi_select
64
- def initialize(name, will_update: false, base_type: :page, json: nil, multi_select: nil, property_cache: nil)
65
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache
64
+ def initialize(name, will_update: false, base_type: :page, json: nil, multi_select: nil,
65
+ property_id: nil, property_cache: nil)
66
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
67
+ property_cache: property_cache
66
68
  if database?
67
69
  @json = json || {"options" => []}
68
70
  else
@@ -53,8 +53,10 @@ module NotionRubyMapping
53
53
 
54
54
  # @param [String] name Property name
55
55
  # @param [Float, Integer, Hash] json Number value or format Hash
56
- def initialize(name, will_update: false, base_type: :page, json: nil, format: nil, property_cache: nil)
57
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache
56
+ def initialize(name, will_update: false, base_type: :page, json: nil, format: nil, property_id: nil,
57
+ property_cache: nil)
58
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
59
+ property_cache: property_cache
58
60
  @json = json
59
61
  @json ||= {"format" => (format || "number")} if database?
60
62
  end
@@ -40,14 +40,22 @@ module NotionRubyMapping
40
40
  ## Common methods
41
41
 
42
42
  def self.people_from_json(json)
43
- List.new(json: json, property: self).select { true }
43
+ if json.is_a? Array
44
+ json.map { |sub_json| UserObject.new json: sub_json }
45
+ elsif json["object"] == "list"
46
+ List.new(json: json, property: self).select { true }
47
+ else
48
+ json["people"].map { |sub_json| UserObject.new json: sub_json }
49
+ end
44
50
  end
45
51
 
46
52
  # @param [String] name
47
53
  # @param [Hash] json
48
54
  # @param [Array] people ids for people
49
- def initialize(name, will_update: false, base_type: :page, json: nil, people: nil, property_cache: nil, query: nil)
50
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache, query: query
55
+ def initialize(name, will_update: false, base_type: :page, json: nil, people: nil, property_id: nil,
56
+ property_cache: nil, query: nil)
57
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
58
+ property_cache: property_cache, query: query
51
59
  @json = if database?
52
60
  {}
53
61
  elsif people
@@ -34,8 +34,9 @@ module NotionRubyMapping
34
34
  ## Common methods
35
35
 
36
36
  # @param [String] name Property name
37
- def initialize(name, will_update: false, base_type: :page, json: nil, property_cache: nil)
38
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache
37
+ def initialize(name, will_update: false, base_type: :page, json: nil, property_id: nil, property_cache: nil)
38
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
39
+ property_cache: property_cache
39
40
  @json = database? ? {} : json
40
41
  end
41
42
 
@@ -79,15 +79,20 @@ module NotionRubyMapping
79
79
  objects = List.new(json: input_json, property: tmp, query: query).select { true }
80
80
  case input_json["property_item"]["type"]
81
81
  when "people"
82
- PeopleProperty.new name, people: objects, base_type: base_type, property_cache: property_cache, query: query
82
+ PeopleProperty.new name, people: objects, base_type: base_type,
83
+ property_cache: property_cache, query: query
83
84
  when "relation"
84
- RelationProperty.new name, relation: objects, base_type: base_type, property_cache: property_cache, query: query
85
+ RelationProperty.new name, relation: objects, base_type: base_type,
86
+ property_cache: property_cache, query: query
85
87
  when "rich_text"
86
- RichTextProperty.new name, text_objects: objects, base_type: base_type, property_cache: property_cache, query: query
88
+ RichTextProperty.new name, text_objects: objects, base_type: base_type,
89
+ property_cache: property_cache, query: query
87
90
  when "rollup"
88
- RollupProperty.new name, json: objects, base_type: base_type, property_cache: property_cache, query: query
91
+ RollupProperty.new name, json: objects, base_type: base_type,
92
+ property_cache: property_cache, query: query
89
93
  when "title"
90
- TitleProperty.new name, text_objects: objects, base_type: base_type, property_cache: property_cache, query: query
94
+ TitleProperty.new name, text_objects: objects, base_type: base_type,
95
+ property_cache: property_cache, query: query
91
96
  end
92
97
  else
93
98
  klass = {
@@ -114,7 +119,8 @@ module NotionRubyMapping
114
119
  }[type]
115
120
  raise StandardError, "Irregular property type: #{type}" unless klass
116
121
 
117
- klass.new name, json: input_json[type], base_type: base_type, property_cache: property_cache
122
+ klass.new name, property_id: input_json["id"], json: input_json[type], base_type: base_type,
123
+ property_cache: property_cache
118
124
  end
119
125
  end
120
126
 
@@ -70,8 +70,10 @@ module NotionRubyMapping
70
70
  # @param [String] name
71
71
  # @param [Hash, Array] json
72
72
  # @param [String, Array] relation
73
- def initialize(name, will_update: false, json: nil, relation: nil, base_type: :page, property_cache: nil, query: nil)
74
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache, query: query
73
+ def initialize(name, will_update: false, json: nil, relation: nil, base_type: :page, property_id: nil,
74
+ property_cache: nil, query: nil)
75
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
76
+ property_cache: property_cache, query: query
75
77
  @json = if database?
76
78
  json || {}
77
79
  elsif relation
@@ -71,8 +71,10 @@ module NotionRubyMapping
71
71
 
72
72
  # @param [String] name
73
73
  # @param [Hash] json
74
- def initialize(name, will_update: false, json: nil, base_type: :page, property_cache: nil, query: nil)
75
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache, query: query
74
+ def initialize(name, will_update: false, json: nil, base_type: :page, property_id: nil,
75
+ property_cache: nil, query: nil)
76
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
77
+ property_cache: property_cache, query: query
76
78
  @json = json || {}
77
79
  end
78
80
 
@@ -74,8 +74,10 @@ module NotionRubyMapping
74
74
  # @param [String] name Property name
75
75
  # @param [Hash] json
76
76
  # @param [String] select String value (optional)
77
- def initialize(name, will_update: false, base_type: :page, json: nil, select: nil, property_cache: nil)
78
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache
77
+ def initialize(name, will_update: false, base_type: :page, json: nil, select: nil, property_id: nil,
78
+ property_cache: nil)
79
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
80
+ property_cache: property_cache
79
81
  @json = if database?
80
82
  json || {"options" => []}
81
83
  else
@@ -3,24 +3,47 @@
3
3
  module NotionRubyMapping
4
4
  # Status property
5
5
  class StatusProperty < Property
6
+ include EqualsDoesNotEqual
7
+ include IsEmptyIsNotEmpty
6
8
  TYPE = "status"
7
9
 
8
10
  ### Public announced methods
9
11
 
10
12
  ## Common methods
11
13
 
14
+ # @see https://www.notion.so/hkob/StatusProperty-c8b2c83019bc42edbc1527386c7ef453#bdb34c0aeaa74729887da087d0bd8022
12
15
  def status
13
16
  @json
14
17
  end
15
18
 
19
+ ## Page property only methods
20
+
21
+ # @return [String]
22
+ # @see https://www.notion.so/hkob/StatusProperty-c8b2c83019bc42edbc1527386c7ef453#69452ceee6c9452296e96bb2a37460ee
23
+ def status_name
24
+ assert_page_property __method__
25
+ @json["name"]
26
+ end
27
+
28
+ ## Page property only methods
29
+
30
+ # @param [String] status
31
+ # @see https://www.notion.so/hkob/StatusProperty-c8b2c83019bc42edbc1527386c7ef453#b3fba1b6322140f28308de3ba70a8b7b
32
+ def status=(status)
33
+ assert_page_property __method__
34
+ @will_update = true
35
+ @json = {"name" => status}
36
+ end
37
+
16
38
  ### Not public announced methods
17
39
 
18
40
  ## Common methods
19
41
 
20
42
  # @param [String] name Property name
21
43
  # @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
44
+ def initialize(name, will_update: false, base_type: :page, property_id: nil, property_cache: nil, json: {})
45
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
46
+ property_cache: property_cache
24
47
  @json = json
25
48
  end
26
49
 
@@ -29,8 +52,7 @@ module NotionRubyMapping
29
52
  # @return [Hash]
30
53
  def property_values_json
31
54
  assert_page_property __method__
32
- {}
33
- #{@name => {"status" => @json, "type" => "status"}}
55
+ {@name => {"status" => @json, "type" => "status"}}
34
56
  end
35
57
  end
36
58
  end
@@ -27,10 +27,12 @@ module NotionRubyMapping
27
27
  # @param [String] name
28
28
  # @param [Hash, Array] json
29
29
  # @param [Array<RichTextObject>] text_objects
30
- def initialize(name, will_update: false, base_type: :page, json: nil, text_objects: nil, property_cache: nil, query: nil)
30
+ def initialize(name, will_update: false, base_type: :page, json: nil, text_objects: nil, property_id: nil,
31
+ property_cache: nil, query: nil)
31
32
  raise StandardError, "TextObject is abstract class. Please use RichTextProperty." if instance_of? TextProperty
32
33
 
33
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache, query: query
34
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
35
+ property_cache: property_cache, query: query
34
36
  @text_objects = if database?
35
37
  json || {}
36
38
  else
@@ -10,8 +10,12 @@ module NotionRubyMapping
10
10
  ## Common methods
11
11
 
12
12
  def self.rich_text_array_from_json(json)
13
- rich_text_objects = List.new(json: json, property: self).select { true }
14
- RichTextArray.rich_text_array "title", rich_text_objects
13
+ if json["object"] == "list"
14
+ rich_text_objects = List.new(json: json, property: self).select { true }
15
+ RichTextArray.rich_text_array "title", rich_text_objects
16
+ else
17
+ RichTextArray.new "title", json: json["title"]
18
+ end
15
19
  end
16
20
 
17
21
  # @param [Hash] json
@@ -34,8 +34,9 @@ module NotionRubyMapping
34
34
  ## Common methods
35
35
 
36
36
  # @param [String] name Property name
37
- def initialize(name, will_update: false, base_type: :page, json: nil, property_cache: nil)
38
- super name, will_update: will_update, base_type: base_type, property_cache: property_cache
37
+ def initialize(name, will_update: false, base_type: :page, json: nil, property_id: nil, property_cache: nil)
38
+ super name, will_update: will_update, base_type: base_type, property_id: property_id,
39
+ property_cache: property_cache
39
40
  @json = json || (database? ? {} : nil)
40
41
  end
41
42
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
- VERSION = "0.6.4"
4
+ VERSION = "0.6.7"
5
5
  NOTION_VERSION = "2022-06-28"
6
6
  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.6.4
4
+ version: 0.6.7
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-08-09 00:00:00.000000000 Z
11
+ date: 2022-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -125,7 +125,9 @@ dependencies:
125
125
  description: Mapping tool from Notion Database/Page/Block to Ruby Objects.
126
126
  email:
127
127
  - hkob@metro-cit.ac.jp
128
- executables: []
128
+ executables:
129
+ - notionErDiagram.rb
130
+ - notionSitemap.rb
129
131
  extensions: []
130
132
  extra_rdoc_files: []
131
133
  files:
@@ -144,6 +146,8 @@ files:
144
146
  - examples/change_title.md
145
147
  - examples/renumbering_pages.md
146
148
  - examples/set_icon_to_all_icon_unsettled_pages.md
149
+ - exe/notionErDiagram.rb
150
+ - exe/notionSitemap.rb
147
151
  - images/post_set_icon.png
148
152
  - images/pre_set_icon.png
149
153
  - images/serial_number.png
@@ -234,7 +238,6 @@ files:
234
238
  - notion_ruby_mapping.gemspec
235
239
  - sig/notion_ruby_mapping.rbs
236
240
  - tools/an
237
- - tools/createErDiagram.rb
238
241
  homepage: https://github.com/hkob/notion_ruby_mapping.git
239
242
  licenses:
240
243
  - MIT