notion_ruby_mapping 0.4.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -14
  3. data/examples/change_title.md +1 -1
  4. data/examples/renumbering_pages.md +3 -3
  5. data/examples/set_icon_to_all_icon_unsettled_pages.md +4 -4
  6. data/lib/notion_ruby_mapping/blocks/base.rb +25 -21
  7. data/lib/notion_ruby_mapping/blocks/block.rb +82 -484
  8. data/lib/notion_ruby_mapping/blocks/bookmark_block.rb +11 -0
  9. data/lib/notion_ruby_mapping/blocks/breadcrumb_block.rb +19 -0
  10. data/lib/notion_ruby_mapping/blocks/bulleted_list_item_block.rb +11 -0
  11. data/lib/notion_ruby_mapping/blocks/callout_block.rb +82 -0
  12. data/lib/notion_ruby_mapping/blocks/child_base_block.rb +21 -0
  13. data/lib/notion_ruby_mapping/blocks/child_database_block.rb +11 -0
  14. data/lib/notion_ruby_mapping/blocks/child_page_block.rb +11 -0
  15. data/lib/notion_ruby_mapping/blocks/code_block.rb +50 -0
  16. data/lib/notion_ruby_mapping/blocks/column_block.rb +29 -0
  17. data/lib/notion_ruby_mapping/blocks/column_list_block.rb +33 -0
  18. data/lib/notion_ruby_mapping/blocks/database.rb +7 -1
  19. data/lib/notion_ruby_mapping/blocks/divider_block.rb +19 -0
  20. data/lib/notion_ruby_mapping/blocks/embed_block.rb +11 -0
  21. data/lib/notion_ruby_mapping/blocks/equation_block.rb +43 -0
  22. data/lib/notion_ruby_mapping/blocks/file_base_block.rb +50 -0
  23. data/lib/notion_ruby_mapping/blocks/file_block.rb +11 -0
  24. data/lib/notion_ruby_mapping/blocks/heading1_block.rb +18 -0
  25. data/lib/notion_ruby_mapping/blocks/heading2_block.rb +18 -0
  26. data/lib/notion_ruby_mapping/blocks/heading3_block.rb +18 -0
  27. data/lib/notion_ruby_mapping/blocks/image_block.rb +11 -0
  28. data/lib/notion_ruby_mapping/blocks/link_preview_block.rb +16 -0
  29. data/lib/notion_ruby_mapping/blocks/link_to_page_block.rb +40 -0
  30. data/lib/notion_ruby_mapping/blocks/list.rb +2 -3
  31. data/lib/notion_ruby_mapping/blocks/numbered_list_item_block.rb +11 -0
  32. data/lib/notion_ruby_mapping/blocks/page.rb +6 -0
  33. data/lib/notion_ruby_mapping/blocks/paragraph_block.rb +11 -0
  34. data/lib/notion_ruby_mapping/blocks/pdf_block.rb +11 -0
  35. data/lib/notion_ruby_mapping/blocks/quote_block.rb +11 -0
  36. data/lib/notion_ruby_mapping/blocks/synced_block.rb +49 -0
  37. data/lib/notion_ruby_mapping/blocks/table_block.rb +50 -0
  38. data/lib/notion_ruby_mapping/blocks/table_of_contents_block.rb +34 -0
  39. data/lib/notion_ruby_mapping/blocks/table_row_block.rb +34 -0
  40. data/lib/notion_ruby_mapping/blocks/template_block.rb +34 -0
  41. data/lib/notion_ruby_mapping/blocks/text_sub_block_color_base_block.rb +45 -0
  42. data/lib/notion_ruby_mapping/blocks/to_do_block.rb +42 -0
  43. data/lib/notion_ruby_mapping/blocks/toggle_block.rb +11 -0
  44. data/lib/notion_ruby_mapping/blocks/toggle_heading1_block.rb +11 -0
  45. data/lib/notion_ruby_mapping/blocks/toggle_heading2_block.rb +11 -0
  46. data/lib/notion_ruby_mapping/blocks/toggle_heading3_block.rb +11 -0
  47. data/lib/notion_ruby_mapping/blocks/url_base_block.rb +34 -0
  48. data/lib/notion_ruby_mapping/blocks/url_caption_base_block.rb +46 -0
  49. data/lib/notion_ruby_mapping/blocks/video_block.rb +11 -0
  50. data/lib/notion_ruby_mapping/controllers/notion_cache.rb +34 -18
  51. data/lib/notion_ruby_mapping/controllers/payload.rb +32 -18
  52. data/lib/notion_ruby_mapping/controllers/query.rb +1 -1
  53. data/lib/notion_ruby_mapping/controllers/rich_text_array.rb +13 -2
  54. data/lib/notion_ruby_mapping/objects/rich_text_object.rb +2 -5
  55. data/lib/notion_ruby_mapping/properties/created_by_property.rb +1 -0
  56. data/lib/notion_ruby_mapping/properties/date_base_property.rb +24 -11
  57. data/lib/notion_ruby_mapping/properties/email_property.rb +1 -2
  58. data/lib/notion_ruby_mapping/properties/files_property.rb +1 -1
  59. data/lib/notion_ruby_mapping/properties/formula_property.rb +1 -1
  60. data/lib/notion_ruby_mapping/properties/multi_select_property.rb +2 -0
  61. data/lib/notion_ruby_mapping/properties/phone_number_property.rb +0 -1
  62. data/lib/notion_ruby_mapping/properties/select_property.rb +2 -1
  63. data/lib/notion_ruby_mapping/properties/url_property.rb +0 -2
  64. data/lib/notion_ruby_mapping/version.rb +1 -1
  65. data/lib/notion_ruby_mapping.rb +8 -1
  66. metadata +41 -2
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class TableBlock < Block
6
+ # @param [Integer] table_width
7
+ # @param [Boolean] has_column_header
8
+ # @param [Boolean] has_row_header
9
+ # @param [Array<Array<Object>>] table_rows
10
+ # @param [Hash] json
11
+ # @param [Integer] id
12
+ # @param [Integer] parent
13
+ def initialize(table_width: nil, has_column_header: false, has_row_header: false, table_rows: nil, json: nil, id: nil,
14
+ parent: nil)
15
+ super json: json, id: id, parent: parent
16
+ if @json
17
+ sub_json = @json[type]
18
+ @has_column_header = sub_json["has_column_header"]
19
+ @has_row_header = sub_json["has_row_header"]
20
+ @table_width = sub_json["table_width"]
21
+ else
22
+ @table_width = table_width
23
+ @has_column_header = has_column_header
24
+ @has_row_header = has_row_header
25
+ if table_rows
26
+ @table_rows = table_rows.map do |table_row|
27
+ TableRowBlock.new table_row, @table_width
28
+ end
29
+ end
30
+ end
31
+ @can_have_children = true
32
+ end
33
+
34
+ def block_json(not_update: true)
35
+ ans = super
36
+ ans[type] = {
37
+ "has_column_header" => @has_column_header,
38
+ "has_row_header" => @has_row_header,
39
+ "table_width" => @table_width,
40
+ }
41
+ ans[type]["children"] = @table_rows.map(&:block_json) if @table_rows
42
+ ans
43
+ end
44
+
45
+ # @return [String (frozen)]
46
+ def type
47
+ "table"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ # @param [String] color
6
+ class TableOfContentsBlock < Block
7
+ def initialize(color = "default", json: nil, id: nil, parent: nil)
8
+ super(json: json, id: id, parent: parent)
9
+ if @json
10
+ decode_color
11
+ else
12
+ @color = color
13
+ end
14
+ end
15
+
16
+ def color=(new_color)
17
+ @color = new_color
18
+ @payload.add_update_block_key "color"
19
+ end
20
+
21
+ # @return [String (frozen)]
22
+ def type
23
+ "table_of_contents"
24
+ end
25
+
26
+ # @param [Boolean] not_update false when update
27
+ # @return [Hash{String (frozen)->Hash}]
28
+ def block_json(not_update: true)
29
+ ans = super
30
+ ans[type] = {"color" => @color}
31
+ ans
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class TableRowBlock < Block
6
+ # @param [Array<Array<String, TextObject>>] array_array_of_text_objects
7
+ # @param [Integer] table_width
8
+ def initialize(array_array_of_text_objects = [], table_width = 3, json: nil, id: nil, parent: nil)
9
+ super json: json, id: id, parent: parent
10
+ if @json
11
+ @cells = @json[type]["cells"].map { |cell| cell.map { |to| RichTextObject.create_from_json to } }
12
+ else
13
+ cc = array_array_of_text_objects.count
14
+ raise StandardError, "table width must be #{table_width} (given array size is #{cc}" unless table_width == cc
15
+
16
+ @cells = array_array_of_text_objects.map do |cell|
17
+ Array(cell).map { |text_info| TextObject.text_object text_info }
18
+ end
19
+ end
20
+ @can_have_children = false
21
+ end
22
+
23
+ def block_json(not_update: true)
24
+ ans = super
25
+ ans[type] = {"cells" => @cells.map { |cell| Array(cell).map(&:property_values_json) }}
26
+ ans
27
+ end
28
+
29
+ # @return [String (frozen)]
30
+ def type
31
+ "table_row"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class TemplateBlock < Block
6
+ # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
7
+ # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
8
+ def initialize(text_info = nil, sub_blocks: nil, json: nil, id: nil, parent: nil)
9
+ super(json: json, id: id, parent: parent)
10
+ if @json
11
+ decode_block_rich_text_array
12
+ else
13
+ rich_text_array_and_color "rich_text", text_info, nil
14
+ add_sub_blocks sub_blocks
15
+ end
16
+ @can_have_children = true
17
+ end
18
+
19
+ attr_reader :rich_text_array
20
+
21
+ # @param [Boolean] not_update false when update
22
+ # @return [Hash{String (frozen)->Hash}]
23
+ def block_json(not_update: true)
24
+ ans = super
25
+ ans[type] = @rich_text_array.update_property_schema_json not_update
26
+ ans[type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
27
+ ans
28
+ end
29
+
30
+ def type
31
+ "template"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class TextSubBlockColorBaseBlock < Block
6
+ # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>, nil] text_info
7
+ # @param [String] color
8
+ # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
9
+ def initialize(text_info = nil, sub_blocks: nil, color: "default", json: nil, id: nil, parent: nil)
10
+ raise StandardError, "TextSubBlockColorBaseBlock is abstract class" if instance_of?(TextSubBlockColorBaseBlock)
11
+
12
+ super(json: json, id: id, parent: parent)
13
+ if @json
14
+ decode_block_rich_text_array
15
+ decode_color
16
+ else
17
+ rich_text_array_and_color "rich_text", text_info, color
18
+ add_sub_blocks sub_blocks
19
+ end
20
+ @can_have_children = true
21
+ end
22
+
23
+ # @see https://www.notion.so/hkob/BulletedListItemBlock-ac4978f4efbb40109f0fb3bd00f43476#36d044b3db734fc5b0e21c07d829cb81
24
+ # @see https://www.notion.so/hkob/BulletedListItemBlock-ac4978f4efbb40109f0fb3bd00f43476#cef80016457e46e7bb178f063e4981de
25
+ attr_reader :color, :rich_text_array
26
+
27
+ # @param [String] new_color
28
+ # @see https://www.notion.so/hkob/BulletedListItemBlock-ac4978f4efbb40109f0fb3bd00f43476#2d59111c9e434dfa99d294cc9a74e468
29
+ def color=(new_color)
30
+ @color = new_color
31
+ @payload.add_update_block_key "color"
32
+ @rich_text_array.will_update = true
33
+ end
34
+
35
+ # @param [Boolean] not_update false when update
36
+ # @return [Hash{String (frozen)->Hash}]
37
+ def block_json(not_update: true)
38
+ ans = super
39
+ ans[type] = @rich_text_array.update_property_schema_json not_update
40
+ ans[type]["color"] = @color
41
+ ans[type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
42
+ ans
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class ToDoBlock < TextSubBlockColorBaseBlock
6
+ # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
7
+ # @param [Boolean] checked
8
+ # @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
9
+ # @param [String] color
10
+ def initialize(text_info = nil, checked = false, sub_blocks: nil, color: "default", json: nil, id: nil, parent: nil)
11
+ super(text_info, sub_blocks: sub_blocks, color: color, json: json, id: id, parent: parent)
12
+ @checked = if @json
13
+ @json[type]["checked"]
14
+ else
15
+ checked
16
+ end
17
+ end
18
+
19
+ # @see https://www.notion.so/hkob/ToDoBlock-9e4d863244b541869d91c84620e190d4#a4550dc684de43d2be171d4abbbea7ce
20
+ attr_reader :checked
21
+
22
+ # @param [Boolean] not_update false when update
23
+ # @return [Hash{String (frozen)->Hash}]
24
+ def block_json(not_update: true)
25
+ ans = super
26
+ ans[type]["checked"] = @checked
27
+ ans
28
+ end
29
+
30
+ # @param [Boolean] new_checked
31
+ # @see https://www.notion.so/hkob/ToDoBlock-9e4d863244b541869d91c84620e190d4#8ef8b12721914cccb17790879bdc2fbf
32
+ def checked=(new_checked)
33
+ @checked = new_checked
34
+ @payload.add_update_block_key "checked"
35
+ end
36
+
37
+ # @return [String (frozen)]
38
+ def type
39
+ "to_do"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class ToggleBlock < TextSubBlockColorBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "toggle"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class ToggleHeading1Block < TextSubBlockColorBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "heading_1"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class ToggleHeading2Block < TextSubBlockColorBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "heading_2"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class ToggleHeading3Block < TextSubBlockColorBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "heading_3"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class UrlBaseBlock < Block
6
+ # @param [Sting] url
7
+ def initialize(url, json: nil, id: nil, parent: nil)
8
+ raise StandardError, "UrlBaseBlock is abstract class" if instance_of?(UrlBaseBlock)
9
+
10
+ super(json: json, id: id, parent: parent)
11
+ @url = if @json
12
+ @json[type]["url"]
13
+ else
14
+ url
15
+ end
16
+ end
17
+
18
+ attr_reader :url
19
+
20
+ # @param [Boolean] not_update false when update
21
+ # @return [Hash{String (frozen)->Hash}]
22
+ def block_json(not_update: true)
23
+ ans = super
24
+ ans[type] = {"url" => @url}
25
+ ans
26
+ end
27
+
28
+ # @param [String] str
29
+ def url=(str)
30
+ @url = str
31
+ @payload.add_update_block_key "url"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class UrlCaptionBaseBlock < Block
6
+ # @param [Sting] url
7
+ # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] caption
8
+ # @see https://www.notion.so/hkob/BookmarkBlock-f2a8c15ad469436c966f74b58dcacbd4#845a1349bf5a4392b427199d6f327557
9
+ # @see https://www.notion.so/hkob/EmbedBlock-57c31e7d8e1d41669eb30f27e1c41035#3421ddd6f27f4ebea4c7e4450f81b866
10
+ def initialize(url = nil, caption: [], json: nil, id: nil, parent: nil)
11
+ raise StandardError, "UrlCaptionBaseBlock is abstract class" if instance_of?(UrlCaptionBaseBlock)
12
+
13
+ super(json: json, id: id, parent: parent)
14
+ if @json
15
+ @url = @json[type]["url"]
16
+ decode_block_caption
17
+ else
18
+ @url = url
19
+ @caption = RichTextArray.rich_text_array "caption", caption
20
+ end
21
+ end
22
+
23
+ # @see https://www.notion.so/hkob/BookmarkBlock-f2a8c15ad469436c966f74b58dcacbd4#bb6ff9f5dbdc4d52bbf8cdea89fc66de
24
+ # @see https://www.notion.so/hkob/BookmarkBlock-f2a8c15ad469436c966f74b58dcacbd4#eabb5436af464f77865e4a223da72329
25
+ # @see https://www.notion.so/hkob/EmbedBlock-57c31e7d8e1d41669eb30f27e1c41035#f28b77ca0b634acc8e606f954c516ae9
26
+ # @see https://www.notion.so/hkob/EmbedBlock-57c31e7d8e1d41669eb30f27e1c41035#3df6808f8eed43c7bc07ced53cbce6ba
27
+ attr_reader :caption, :url
28
+
29
+ # @param [Boolean] not_update false when update
30
+ # @return [Hash{String (frozen)->Hash}]
31
+ def block_json(not_update: true)
32
+ ans = super
33
+ ans[type] = @caption.update_property_schema_json not_update
34
+ ans[type]["url"] = @url
35
+ ans
36
+ end
37
+
38
+ # @param [String] str
39
+ # @see https://www.notion.so/hkob/BookmarkBlock-f2a8c15ad469436c966f74b58dcacbd4#054829bf342f40aea4fa6bd23820fbcb
40
+ # @see https://www.notion.so/hkob/EmbedBlock-57c31e7d8e1d41669eb30f27e1c41035#25ece6bfce0749f8b4bbecc6ba7feedc
41
+ def url=(str)
42
+ @url = str
43
+ @payload.add_update_block_key "url"
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion block
5
+ class VideoBlock < FileBaseBlock
6
+ # @return [String (frozen)]
7
+ def type
8
+ "video"
9
+ end
10
+ end
11
+ end
@@ -11,7 +11,6 @@ module NotionRubyMapping
11
11
 
12
12
  ### initialize
13
13
 
14
-
15
14
  # @see https://www.notion.so/hkob/NotionCache-65e1599864d6425686d495a5a4b3a623#dca210788f114cf59464090782c073bf
16
15
  def initialize
17
16
  @object_hash = {}
@@ -27,7 +26,7 @@ module NotionRubyMapping
27
26
  attr_reader :object_hash
28
27
  attr_writer :client # for test only
29
28
 
30
- # @param [String] page_id
29
+ # @param [String] block_id
31
30
  # @return [String (frozen)] block_path
32
31
  def append_block_children_block_path(block_id)
33
32
  "v1/blocks/#{block_id}/children"
@@ -38,7 +37,7 @@ module NotionRubyMapping
38
37
  def append_block_children_page_path(page_id)
39
38
  "v1/blocks/#{page_id}/children"
40
39
  end
41
-
40
+
42
41
  # @param [String] id
43
42
  # @param [Hash] payload
44
43
  # @return [Hash]
@@ -118,12 +117,14 @@ module NotionRubyMapping
118
117
  # @param [String] id page_id / block_id (with or without "-")
119
118
  # @param [NotionRubyMapping::Query] query query object
120
119
  # @return [NotionRubyMapping::Base] List object
121
- def database_query(id, query)
122
- Base.create_from_json database_query_request(id, query.query_json)
123
- end
120
+ # def database_query(id, query)
121
+ # Base.create_from_json database_query_request(id, query.query_json)
122
+ # end
124
123
 
125
- def database_query_request(database_id, payload)
126
- request :post, "v1/databases/#{database_id}/query", payload
124
+ # @param [String] database_id (with or without "-")
125
+ # @param [NotionRubyMapping::Query] query query object
126
+ def database_query_request(database_id, query)
127
+ request :post, "v1/databases/#{database_id}/query", query.query_json
127
128
  end
128
129
 
129
130
  # @param [String] database_id
@@ -132,22 +133,34 @@ module NotionRubyMapping
132
133
  request :get, database_path(database_id)
133
134
  end
134
135
 
135
- # @param [String] database_id
136
136
  # @return [String (frozen)] page_path
137
137
  def databases_path
138
138
  "v1/databases"
139
139
  end
140
140
 
141
- def inspect
142
- "NotionCache"
141
+ # @param [String] id
142
+ # @return [NotionRubyMapping::Base]
143
+ def destroy_block(id)
144
+ Base.create_from_json destroy_block_request(id)
145
+ end
146
+
147
+ # @param [String] id
148
+ # @return [Hash]
149
+ def destroy_block_request(id)
150
+ request :delete, block_path(id)
143
151
  end
144
152
 
145
153
  # @param [String] id id string with "-"
146
154
  # @return [String] id without "-"
155
+ # @see https://www.notion.so/hkob/NotionCache-65e1599864d6425686d495a5a4b3a623#a2d70a2e019c4c17898aaa1a36580f1d
147
156
  def hex_id(id)
148
157
  id&.gsub "-", ""
149
158
  end
150
159
 
160
+ def inspect
161
+ "NotionCache"
162
+ end
163
+
151
164
  # @param [String] id id (with or without "-")
152
165
  # @return [NotionRubyMapping::Base]
153
166
  def object_for_key(id)
@@ -214,25 +227,28 @@ module NotionRubyMapping
214
227
  response.body
215
228
  end
216
229
 
230
+ def update_block_request(block_id, payload)
231
+ request :patch, block_path(block_id), payload
232
+ end
233
+
217
234
  # @param [String] id page_id (with or without "-")
218
235
  # @param [Hash] payload
219
- def update_database(id, payload)
220
- sleep @wait
221
- @client.update_database payload.merge({database_id: id})
222
- end
236
+ # def update_database(id, payload)
237
+ # sleep @wait
238
+ # @client.update_database payload.merge({database_id: id})
239
+ # end
223
240
 
224
241
  # @param [String] database_id
225
242
  # @return [Hash] response
226
243
  def update_database_request(database_id, payload)
227
- request :patch, "v1/databases/#{database_id}", payload
244
+ request :patch, database_path(database_id), payload
228
245
  end
229
246
 
230
247
  # @param [String] page_id
231
248
  # @param [Hash] payload
232
249
  # @return [Hash] response
233
250
  def update_page_request(page_id, payload)
234
- request :patch, "v1/pages/#{page_id}", payload
251
+ request :patch, page_path(page_id), payload
235
252
  end
236
-
237
253
  end
238
254
  end
@@ -5,21 +5,17 @@ module NotionRubyMapping
5
5
  class Payload
6
6
  def initialize(json)
7
7
  @json = json || {}
8
+ @update_block_key = []
8
9
  end
9
10
 
10
- # @param [String] emoji
11
- # @param [String] url
12
- # @return [NotionRubyMapping::Payload] updated Payload
13
- def set_icon(emoji: nil, url: nil)
14
- payload = if emoji
15
- {"type" => "emoji", "emoji" => emoji}
16
- elsif url
17
- {"type" => "external", "external" => {"url" => url}}
18
- else
19
- {}
20
- end
21
- @json["icon"] = payload
22
- self
11
+ # @param [String] key
12
+ def add_update_block_key(key)
13
+ @update_block_key << key
14
+ end
15
+
16
+ # @return [Hash] {}
17
+ def clear
18
+ @json = {}
23
19
  end
24
20
 
25
21
  # @param [Hash] json
@@ -40,15 +36,33 @@ module NotionRubyMapping
40
36
  others.compact.reduce({}) { |hash, o| hash.merge o.property_schema_json }.merge @json
41
37
  end
42
38
 
39
+ # @param [String] emoji
40
+ # @param [String] url
41
+ # @return [NotionRubyMapping::Payload] updated Payload
42
+ def set_icon(emoji: nil, url: nil)
43
+ payload = if emoji
44
+ {"type" => "emoji", "emoji" => emoji}
45
+ elsif url
46
+ {"type" => "external", "external" => {"url" => url}}
47
+ else
48
+ {}
49
+ end
50
+ @json["icon"] = payload
51
+ self
52
+ end
53
+
54
+ def update_block_json(type, json)
55
+ sub_json = json[type]
56
+ ans = {type => sub_json.slice(*@update_block_key)}
57
+ ans[type]["caption"] = sub_json["caption"] if sub_json["caption"]
58
+ ans[type]["rich_text"] = sub_json["rich_text"] if sub_json["rich_text"]
59
+ ans
60
+ end
61
+
43
62
  # @return [Hash] created json
44
63
  # @param [Object] others
45
64
  def update_property_schema_json(*others)
46
65
  others.compact.reduce({}) { |hash, o| hash.merge o.update_property_schema_json }.merge @json
47
66
  end
48
-
49
- # @return [Hash] {}
50
- def clear
51
- @json = {}
52
- end
53
67
  end
54
68
  end
@@ -12,7 +12,7 @@ module NotionRubyMapping
12
12
  attr_reader :filter, :sort, :page_size
13
13
  attr_accessor :start_cursor
14
14
 
15
- # @param [Query] other_query other query
15
+ # @param [Query] another_query other query
16
16
  # @return [NotionRubyMapping::Query] updated self (Query object)
17
17
  def and(another_query)
18
18
  if @filter.key? "and"
@@ -72,6 +72,17 @@ module NotionRubyMapping
72
72
  map(&:text).join ""
73
73
  end
74
74
 
75
+ def rich_text_objects=(text_info)
76
+ @will_update = true
77
+ @rich_text_objects = if text_info.is_a? RichTextArray
78
+ text_info.filter { true }
79
+ else
80
+ Array(text_info).map do |to|
81
+ RichTextObject.text_object to
82
+ end
83
+ end
84
+ end
85
+
75
86
  def property_values_json
76
87
  will_update ? @rich_text_objects.map(&:property_values_json) : []
77
88
  end
@@ -80,8 +91,8 @@ module NotionRubyMapping
80
91
  will_update ? {@key => @rich_text_objects.map(&:property_values_json)} : {}
81
92
  end
82
93
 
83
- def update_property_schema_json
84
- will_update ? {@key => @rich_text_objects.map(&:property_values_json)} : {}
94
+ def update_property_schema_json(flag = false)
95
+ flag || will_update ? {@key => @rich_text_objects.map(&:property_values_json)} : {}
85
96
  end
86
97
 
87
98
  # @return [TrueClass, FalseClass] true if it will update
@@ -14,7 +14,7 @@ module NotionRubyMapping
14
14
  @type = type
15
15
  @options = options
16
16
  end
17
- attr_reader :will_update
17
+ attr_reader :will_update, :options
18
18
 
19
19
  def self.create_from_json(json)
20
20
  type = json["type"]
@@ -73,7 +73,7 @@ module NotionRubyMapping
73
73
  }.merge annotations_json
74
74
  end
75
75
 
76
- # @param [String, RichTextObject] value
76
+ # @param [String] url
77
77
  # @return [String] input text
78
78
  def href=(url)
79
79
  @will_update = true
@@ -130,9 +130,6 @@ module NotionRubyMapping
130
130
 
131
131
  protected
132
132
 
133
- # @return [Hash] options
134
- attr_reader :options
135
-
136
133
  # @return [Hash, Hash{String (frozen)->Hash}]
137
134
  def annotations_json
138
135
  annotations = @options.slice(*%w[bold italic strikethrough underline code color])
@@ -10,6 +10,7 @@ module NotionRubyMapping
10
10
  ## Common methods
11
11
 
12
12
  # @return [NotionRubyMapping::UserObject, Hash]
13
+ # @see https://www.notion.so/hkob/CreatedByProperty-945fa6be1c014da2b7e55a2b76e37b57#d9c4a8d19b9b4ec5952dc86c9e4a25a8
13
14
  def created_by
14
15
  @json
15
16
  end