notion_ruby_mapping 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +17 -14
- data/examples/change_title.md +1 -1
- data/examples/renumbering_pages.md +3 -3
- data/examples/set_icon_to_all_icon_unsettled_pages.md +4 -4
- data/lib/notion_ruby_mapping/blocks/base.rb +25 -21
- data/lib/notion_ruby_mapping/blocks/block.rb +82 -484
- data/lib/notion_ruby_mapping/blocks/bookmark_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/breadcrumb_block.rb +19 -0
- data/lib/notion_ruby_mapping/blocks/bulleted_list_item_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/callout_block.rb +82 -0
- data/lib/notion_ruby_mapping/blocks/child_base_block.rb +21 -0
- data/lib/notion_ruby_mapping/blocks/child_database_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/child_page_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/code_block.rb +50 -0
- data/lib/notion_ruby_mapping/blocks/column_block.rb +29 -0
- data/lib/notion_ruby_mapping/blocks/column_list_block.rb +33 -0
- data/lib/notion_ruby_mapping/blocks/database.rb +7 -1
- data/lib/notion_ruby_mapping/blocks/divider_block.rb +19 -0
- data/lib/notion_ruby_mapping/blocks/embed_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/equation_block.rb +43 -0
- data/lib/notion_ruby_mapping/blocks/file_base_block.rb +50 -0
- data/lib/notion_ruby_mapping/blocks/file_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/heading1_block.rb +18 -0
- data/lib/notion_ruby_mapping/blocks/heading2_block.rb +18 -0
- data/lib/notion_ruby_mapping/blocks/heading3_block.rb +18 -0
- data/lib/notion_ruby_mapping/blocks/image_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/link_preview_block.rb +16 -0
- data/lib/notion_ruby_mapping/blocks/link_to_page_block.rb +40 -0
- data/lib/notion_ruby_mapping/blocks/list.rb +2 -3
- data/lib/notion_ruby_mapping/blocks/numbered_list_item_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/page.rb +6 -0
- data/lib/notion_ruby_mapping/blocks/paragraph_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/pdf_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/quote_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/synced_block.rb +49 -0
- data/lib/notion_ruby_mapping/blocks/table_block.rb +50 -0
- data/lib/notion_ruby_mapping/blocks/table_of_contents_block.rb +34 -0
- data/lib/notion_ruby_mapping/blocks/table_row_block.rb +34 -0
- data/lib/notion_ruby_mapping/blocks/template_block.rb +34 -0
- data/lib/notion_ruby_mapping/blocks/text_sub_block_color_base_block.rb +45 -0
- data/lib/notion_ruby_mapping/blocks/to_do_block.rb +42 -0
- data/lib/notion_ruby_mapping/blocks/toggle_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/toggle_heading1_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/toggle_heading2_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/toggle_heading3_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/url_base_block.rb +34 -0
- data/lib/notion_ruby_mapping/blocks/url_caption_base_block.rb +46 -0
- data/lib/notion_ruby_mapping/blocks/video_block.rb +11 -0
- data/lib/notion_ruby_mapping/controllers/notion_cache.rb +34 -18
- data/lib/notion_ruby_mapping/controllers/payload.rb +32 -18
- data/lib/notion_ruby_mapping/controllers/query.rb +1 -1
- data/lib/notion_ruby_mapping/controllers/rich_text_array.rb +13 -2
- data/lib/notion_ruby_mapping/objects/rich_text_object.rb +2 -5
- data/lib/notion_ruby_mapping/properties/created_by_property.rb +1 -0
- data/lib/notion_ruby_mapping/properties/date_base_property.rb +24 -11
- data/lib/notion_ruby_mapping/properties/email_property.rb +1 -2
- data/lib/notion_ruby_mapping/properties/files_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/formula_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/multi_select_property.rb +2 -0
- data/lib/notion_ruby_mapping/properties/phone_number_property.rb +0 -1
- data/lib/notion_ruby_mapping/properties/select_property.rb +2 -1
- data/lib/notion_ruby_mapping/properties/url_property.rb +0 -2
- data/lib/notion_ruby_mapping/version.rb +1 -1
- data/lib/notion_ruby_mapping.rb +8 -1
- metadata +41 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68d4b404cfe0798695934594f05049482f5436f15e0f2eb7c82125031ce3f340
|
4
|
+
data.tar.gz: b179b7d3530ec7f323023f5ec3ada9057f7e402f87a87c65579482c015184c62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35b3b4ec135b729ba8f93e5d583f0e717e75cb6f0bd75779433948ef671b4bfa9cf22346e1a222d473f506b90a1a24efaa4fca856cd533448d773a710160f421
|
7
|
+
data.tar.gz: 92ef1a7218a0551195dae18a9bbbb3f82f440ba6fd2b8af49bcb578c5f21bf9417644750bc5297133d0ddd789987123f5e6dbd024bb7cb8b5b19a3a4c0764758
|
data/README.md
CHANGED
@@ -8,6 +8,7 @@ Development note is here. → [Idea note of "notion_ruby_mapping"](https://www.n
|
|
8
8
|
|
9
9
|
- [notion_ruby_mapping](#notion_ruby_mapping)
|
10
10
|
- [Table of Contents](#table-of-contents)
|
11
|
+
- [0. Changes in v0.5.0](#0-changes-in-v050)
|
11
12
|
- [1. Installation](#1-installation)
|
12
13
|
- [2. How to use](#2-how-to-use)
|
13
14
|
- [2.1 Create a New Integration](#21-create-a-new-integration)
|
@@ -19,7 +20,11 @@ Development note is here. → [Idea note of "notion_ruby_mapping"](https://www.n
|
|
19
20
|
- [4. Contributing](#4-contributing)
|
20
21
|
- [5. License](#5-license)
|
21
22
|
- [6. Code of Conduct](#6-code-of-conduct)
|
22
|
-
|
23
|
+
|
24
|
+
## 0. Changes in v0.5.0
|
25
|
+
|
26
|
+
NotionRubyMapping v.0.5.0 now supports block updates.
|
27
|
+
For efficiency, subclasses are provided under Block class. As a result, they are no longer compatible with the scripts used in v0.4.0.
|
23
28
|
|
24
29
|
## 1. Installation
|
25
30
|
|
@@ -60,6 +65,7 @@ NotionCache.instance.create_client ENV["NOTION_API_TOKEN"] # from environment
|
|
60
65
|
|
61
66
|
1. [Database and page access sample](https://www.notion.so/hkob/Database-and-page-access-sample-d30033e707194faf995741167eb2b6f8)
|
62
67
|
1. [Append block children sample](https://www.notion.so/hkob/Append-block-children-sample-3867910a437340be931cf7f2c06443c6)
|
68
|
+
1. [Update block sample](https://www.notion.so/hkob/update-block-sample-5568c1c36fe84f12b83edfe2dda83028)
|
63
69
|
|
64
70
|
### 2.4. Another example code (Use case)
|
65
71
|
|
@@ -73,17 +79,18 @@ NotionCache.instance.create_client ENV["NOTION_API_TOKEN"] # from environment
|
|
73
79
|
|
74
80
|
## 3. ChangeLog
|
75
81
|
|
76
|
-
- added
|
77
|
-
- added
|
78
|
-
- 2022/
|
82
|
+
- 2022/6/5 [v0.5.1] bug fix for append_block_children. added synced_block_original to SyncedBlock
|
83
|
+
- 2022/6/4 [v0.5.0] added subclasses of the block class and update_block API support
|
84
|
+
- 2022/5/19 [v0.4.1] added delete_block
|
85
|
+
- 2022/4/29 [v0.4.0] Change directory structure, TEST_IDs are moved from env.yml to TestConnection's constants, added retrieve_block spec, added append_block_children
|
79
86
|
- 2022/4/27 added Base#children
|
80
|
-
- 2022/3/27 create_child_page can receive a block for initialization.
|
81
|
-
- 2022/3/27 properties of a created child page are automatically assigned using the parent database.
|
82
|
-
- 2022/3/25 added create_child_database, update_database, add_property, rename_property and remove_property
|
83
|
-
- 2022/3/17 added template_mention objects, tools/an command
|
84
|
-
- 2022/3/16 added database.create_child_page and base.save instead of base.update/create
|
87
|
+
- 2022/3/27 [v0.3.3] create_child_page can receive a block for initialization.
|
88
|
+
- 2022/3/27 [v0.3.2] properties of a created child page are automatically assigned using the parent database.
|
89
|
+
- 2022/3/25 [v0.3.0] added create_child_database, update_database, add_property, rename_property and remove_property
|
90
|
+
- 2022/3/17 [v0.2.3] added template_mention objects, tools/an command
|
91
|
+
- 2022/3/16 [v0.2.2] added database.create_child_page and base.save instead of base.update/create
|
85
92
|
- 2022/3/15 Fixed not to reload from API when all contents are loaded
|
86
|
-
- 2022/3/14 Exclude notion-ruby-client, update Property values, update for Notion-Version 2022-02-22
|
93
|
+
- 2022/3/14 [v0.2.0] Exclude notion-ruby-client, update Property values, update for Notion-Version 2022-02-22
|
87
94
|
- 2022/2/25 add_property_for_update -> assign_property, update README.md
|
88
95
|
- 2022/2/20 add support for MultiSelectProperty
|
89
96
|
- 2022/2/19 add support for SelectProperty
|
@@ -105,7 +112,3 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
105
112
|
## 6. Code of Conduct
|
106
113
|
|
107
114
|
Everyone interacting in the NotionRubyMapping project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/notion_ruby_mapping/blob/main/CODE_OF_CONDUCT.md).
|
108
|
-
|
109
|
-
## 7. Acknowledgements
|
110
|
-
|
111
|
-
The code depends on [notion-ruby-client](https://github.com/orbit-love/notion-ruby-client).
|
data/examples/change_title.md
CHANGED
@@ -12,9 +12,9 @@ db.query_database(tp.filter_is_not_empty.ascending(tp)).each.with_index(1) do |p
|
|
12
12
|
end
|
13
13
|
```
|
14
14
|
|
15
|
-
| After execution
|
16
|
-
|
15
|
+
| After execution |
|
16
|
+
|--------------------------------------------------|
|
17
17
|
|  |
|
18
18
|
|
19
19
|
---
|
20
|
-
[Return to README.md](../README.md
|
20
|
+
[Return to README.md](../README.md)
|
@@ -22,9 +22,9 @@ db.query_database.each do |page|
|
|
22
22
|
end
|
23
23
|
```
|
24
24
|
|
25
|
-
|Before execution|After execution|
|
26
|
-
|
27
|
-
|
25
|
+
| Before execution | After execution |
|
26
|
+
|-------------------------------------------------|-------------------------------------------------|
|
27
|
+
|  |  |
|
28
28
|
|
29
29
|
---
|
30
|
-
[Return to README.md](../README.md
|
30
|
+
[Return to README.md](../README.md)
|
@@ -4,14 +4,15 @@ 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
|
11
10
|
def initialize(json: nil, id: nil, assign: [], parent: nil)
|
12
11
|
@nc = NotionCache.instance
|
13
12
|
@json = json
|
14
|
-
@id = @nc.hex_id(id || json && @json["id"])
|
13
|
+
@id = @nc.hex_id(id || @json && @json["id"])
|
14
|
+
@archived = @json && @json["archived"]
|
15
|
+
@has_children = @json && @json["has_children"]
|
15
16
|
@new_record = true unless parent.nil?
|
16
17
|
raise StandardError, "Unknown id" if !is_a?(List) && !is_a?(Block) && @id.nil? && parent.nil?
|
17
18
|
|
@@ -37,7 +38,7 @@ module NotionRubyMapping
|
|
37
38
|
when "list"
|
38
39
|
List.new json: json
|
39
40
|
when "block"
|
40
|
-
Block.
|
41
|
+
Block.decode_block json
|
41
42
|
else
|
42
43
|
raise StandardError, json.inspect
|
43
44
|
end
|
@@ -52,14 +53,14 @@ module NotionRubyMapping
|
|
52
53
|
" -H 'Notion-Version: 2022-02-22'",
|
53
54
|
" -H 'Authorization: Bearer '\"$NOTION_API_KEY\"''",
|
54
55
|
]
|
55
|
-
shell << " -H 'Content-Type: application/json'"
|
56
|
+
shell << " -H 'Content-Type: application/json'" if %i[post patch].include?(method)
|
56
57
|
shell << " --data '#{JSON.generate json}'" if json
|
57
58
|
shell.join(" \\\n")
|
58
59
|
end
|
59
60
|
|
60
61
|
# @param [String] key
|
61
62
|
# @return [NotionRubyMapping::PropertyCache, Hash] obtained Page value or PropertyCache
|
62
|
-
def
|
63
|
+
def get(key)
|
63
64
|
unless @json
|
64
65
|
raise StandardError, "Unknown id" if @id.nil?
|
65
66
|
|
@@ -73,8 +74,8 @@ module NotionRubyMapping
|
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
76
|
-
# @param [
|
77
|
-
# @param [
|
77
|
+
# @param [Array<Block>] blocks
|
78
|
+
# @param [Boolean] dry_run
|
78
79
|
# @return [NotionRubyMapping::Block, String]
|
79
80
|
# @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#44bbf83d852c419485c5efe9fe1558fb
|
80
81
|
# @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#2c47f7fedae543cf8566389ba1677132
|
@@ -86,7 +87,7 @@ module NotionRubyMapping
|
|
86
87
|
"children" => Array(blocks).map do |block|
|
87
88
|
assert_parent_children_pair block
|
88
89
|
block.block_json
|
89
|
-
end
|
90
|
+
end,
|
90
91
|
}
|
91
92
|
if dry_run
|
92
93
|
path = @nc.append_block_children_page_path(id)
|
@@ -95,7 +96,7 @@ module NotionRubyMapping
|
|
95
96
|
response = @nc.append_block_children_request @id, json
|
96
97
|
raise StandardError, response unless response["results"]
|
97
98
|
|
98
|
-
answers = response["results"].map { |sub_json| Block.
|
99
|
+
answers = response["results"].map { |sub_json| Block.create_from_json sub_json }
|
99
100
|
only_one ? answers.first : answers
|
100
101
|
end
|
101
102
|
end
|
@@ -112,7 +113,7 @@ module NotionRubyMapping
|
|
112
113
|
raise StandardError, "Internal file block can not append." if bt == "file"
|
113
114
|
|
114
115
|
raise StandardError, "Column block can only append column_list block" unless bt == "column" &&
|
115
|
-
|
116
|
+
block? && type == "column_list"
|
116
117
|
end
|
117
118
|
|
118
119
|
# @param [NotionRubyMapping::Property] klass
|
@@ -149,13 +150,6 @@ module NotionRubyMapping
|
|
149
150
|
end
|
150
151
|
end
|
151
152
|
|
152
|
-
# @return [NotionRubyMapping::Block]
|
153
|
-
def create_child_breadcrumb
|
154
|
-
raise StandardError unless page? || (block? && can_have_children)
|
155
|
-
|
156
|
-
Block.new(parent: self).breadcrumb
|
157
|
-
end
|
158
|
-
|
159
153
|
# @return [NotionRubyMapping::CreatedTimeProperty]
|
160
154
|
def created_time
|
161
155
|
@created_time ||= CreatedTimeProperty.new("__timestamp__", json: self["created_time"])
|
@@ -172,6 +166,11 @@ module NotionRubyMapping
|
|
172
166
|
self["icon"]
|
173
167
|
end
|
174
168
|
|
169
|
+
# @return [String (frozen)]
|
170
|
+
def inspect
|
171
|
+
"#{self.class.name}-#{@id}"
|
172
|
+
end
|
173
|
+
|
175
174
|
# @return [Hash] json properties
|
176
175
|
def json_properties
|
177
176
|
@json && @json["properties"]
|
@@ -231,6 +230,7 @@ module NotionRubyMapping
|
|
231
230
|
self
|
232
231
|
end
|
233
232
|
|
233
|
+
# @param [Boolean] dry_run
|
234
234
|
# @return [NotionRubyMapping::Base, String]
|
235
235
|
# @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#277085c8439841c798a4b94eae9a7326
|
236
236
|
def save(dry_run: false)
|
@@ -238,7 +238,7 @@ module NotionRubyMapping
|
|
238
238
|
@new_record ? create(dry_run: true) : update(dry_run: true)
|
239
239
|
else
|
240
240
|
@new_record ? create : update
|
241
|
-
@property_cache.clear_will_update
|
241
|
+
@property_cache.clear_will_update unless block?
|
242
242
|
@payload.clear
|
243
243
|
self
|
244
244
|
end
|
@@ -254,14 +254,18 @@ module NotionRubyMapping
|
|
254
254
|
self
|
255
255
|
end
|
256
256
|
|
257
|
-
|
258
|
-
|
257
|
+
# @return [FalseClass] return false except block
|
258
|
+
def synced_block_original?
|
259
|
+
false
|
259
260
|
end
|
260
261
|
|
261
262
|
# @param [Hash] json
|
262
263
|
# @return [NotionRubyMapping::Base]
|
263
264
|
def update_json(json)
|
264
|
-
|
265
|
+
unless json["object"] != "error" && (@json.nil? || @json["type"] == json["type"])
|
266
|
+
raise StandardError,
|
267
|
+
json.inspect
|
268
|
+
end
|
265
269
|
|
266
270
|
@json = json
|
267
271
|
@id = @nc.hex_id(@json["id"])
|