notion_ruby_mapping 0.3.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -1237
- data/env.yml.sample +0 -13
- 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/{base.rb → blocks/base.rb} +163 -92
- data/lib/notion_ruby_mapping/blocks/block.rb +145 -0
- 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/{database.rb → blocks/database.rb} +41 -8
- 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/{list.rb → blocks/list.rb} +37 -6
- data/lib/notion_ruby_mapping/blocks/numbered_list_item_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/page.rb +77 -0
- data/lib/notion_ruby_mapping/blocks/paragraph_block.rb +11 -0
- data/lib/notion_ruby_mapping/{block.rb → blocks/pdf_block.rb} +4 -3
- data/lib/notion_ruby_mapping/blocks/quote_block.rb +11 -0
- data/lib/notion_ruby_mapping/blocks/synced_block.rb +44 -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/{notion_cache.rb → controllers/notion_cache.rb} +144 -102
- data/lib/notion_ruby_mapping/{payload.rb → controllers/payload.rb} +32 -18
- data/lib/notion_ruby_mapping/{property_cache.rb → controllers/property_cache.rb} +21 -20
- data/lib/notion_ruby_mapping/{query.rb → controllers/query.rb} +27 -19
- data/lib/notion_ruby_mapping/{rich_text_array.rb → controllers/rich_text_array.rb} +39 -17
- data/lib/notion_ruby_mapping/objects/emoji_object.rb +40 -0
- data/lib/notion_ruby_mapping/objects/equation_object.rb +43 -0
- data/lib/notion_ruby_mapping/objects/file_object.rb +60 -0
- data/lib/notion_ruby_mapping/{mention_object.rb → objects/mention_object.rb} +11 -0
- data/lib/notion_ruby_mapping/{rich_text_object.rb → objects/rich_text_object.rb} +12 -4
- data/lib/notion_ruby_mapping/{text_object.rb → objects/text_object.rb} +0 -1
- data/lib/notion_ruby_mapping/{user_object.rb → objects/user_object.rb} +9 -4
- data/lib/notion_ruby_mapping/{checkbox_property.rb → properties/checkbox_property.rb} +3 -0
- data/lib/notion_ruby_mapping/{created_by_property.rb → properties/created_by_property.rb} +1 -0
- data/lib/notion_ruby_mapping/{created_time_property.rb → properties/created_time_property.rb} +1 -0
- data/lib/notion_ruby_mapping/properties/date_base_property.rb +135 -0
- data/lib/notion_ruby_mapping/{date_property.rb → properties/date_property.rb} +13 -0
- data/lib/notion_ruby_mapping/{email_property.rb → properties/email_property.rb} +2 -2
- data/lib/notion_ruby_mapping/{files_property.rb → properties/files_property.rb} +26 -13
- data/lib/notion_ruby_mapping/{formula_property.rb → properties/formula_property.rb} +5 -1
- data/lib/notion_ruby_mapping/{last_edited_by_property.rb → properties/last_edited_by_property.rb} +1 -0
- data/lib/notion_ruby_mapping/{last_edited_time_property.rb → properties/last_edited_time_property.rb} +1 -0
- data/lib/notion_ruby_mapping/{multi_property.rb → properties/multi_property.rb} +0 -0
- data/lib/notion_ruby_mapping/{multi_select_property.rb → properties/multi_select_property.rb} +4 -3
- data/lib/notion_ruby_mapping/{number_property.rb → properties/number_property.rb} +4 -0
- data/lib/notion_ruby_mapping/{people_property.rb → properties/people_property.rb} +8 -3
- data/lib/notion_ruby_mapping/{phone_number_property.rb → properties/phone_number_property.rb} +4 -1
- data/lib/notion_ruby_mapping/{property.rb → properties/property.rb} +33 -0
- data/lib/notion_ruby_mapping/{relation_property.rb → properties/relation_property.rb} +30 -10
- data/lib/notion_ruby_mapping/{rich_text_property.rb → properties/rich_text_property.rb} +0 -0
- data/lib/notion_ruby_mapping/{rollup_property.rb → properties/rollup_property.rb} +7 -0
- data/lib/notion_ruby_mapping/{select_property.rb → properties/select_property.rb} +8 -2
- data/lib/notion_ruby_mapping/{text_property.rb → properties/text_property.rb} +0 -0
- data/lib/notion_ruby_mapping/{title_property.rb → properties/title_property.rb} +0 -0
- data/lib/notion_ruby_mapping/{url_property.rb → properties/url_property.rb} +4 -1
- data/lib/notion_ruby_mapping/version.rb +1 -1
- data/lib/notion_ruby_mapping.rb +21 -7
- metadata +82 -40
- data/lib/notion_ruby_mapping/date_base_property.rb +0 -75
- data/lib/notion_ruby_mapping/page.rb +0 -50
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
# Notion block
|
5
|
+
class CodeBlock < Block
|
6
|
+
# @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
|
7
|
+
# @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] caption
|
8
|
+
# @param [String] language
|
9
|
+
# @see https://www.notion.so/hkob/CodeBlock-3a25869f60394b3f902c1ed0bf5ce1c9#7777d9b785234278876d7bf6842dd8a2
|
10
|
+
def initialize(text_info = nil, caption: [], language: "shell", json: nil, id: nil, parent: nil)
|
11
|
+
super(json: json, id: id, parent: parent)
|
12
|
+
if @json
|
13
|
+
decode_block_rich_text_array
|
14
|
+
decode_block_caption
|
15
|
+
@language = json[type]["language"] || "shell"
|
16
|
+
else
|
17
|
+
rich_text_array_and_color "rich_text", text_info
|
18
|
+
@caption = RichTextArray.rich_text_array "caption", caption
|
19
|
+
@language = language
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# @see https://www.notion.so/hkob/CodeBlock-3a25869f60394b3f902c1ed0bf5ce1c9#282b6ca100a14841b849ab24519647f3
|
24
|
+
# @see https://www.notion.so/hkob/CodeBlock-3a25869f60394b3f902c1ed0bf5ce1c9#6321da9df4f04ccdbddddcd93b1afbe2
|
25
|
+
# @see https://www.notion.so/hkob/CodeBlock-3a25869f60394b3f902c1ed0bf5ce1c9#9de0cd82fb594a3a8d12095d9e21ea8d
|
26
|
+
attr_reader :caption, :language, :rich_text_array
|
27
|
+
|
28
|
+
# @param [Boolean] not_update false when update
|
29
|
+
# @return [Hash{String (frozen)->Hash}]
|
30
|
+
def block_json(not_update: true)
|
31
|
+
ans = super
|
32
|
+
ans[type] = @rich_text_array.update_property_schema_json(not_update).merge(
|
33
|
+
@caption.update_property_schema_json(not_update),
|
34
|
+
)
|
35
|
+
ans[type]["language"] = @language
|
36
|
+
ans
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param [String] new_language
|
40
|
+
def language=(new_language)
|
41
|
+
@language = new_language
|
42
|
+
@payload.add_update_block_key "language"
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [String (frozen)]
|
46
|
+
def type
|
47
|
+
"code"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
# Notion block
|
5
|
+
class ColumnBlock < Block
|
6
|
+
# @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
|
7
|
+
# @see https://www.notion.so/hkob/ColumnBlock-91cb314fc6594ff6b0c77c1eae6c7fab#4b4486cdf26a474eab1c92f9c6ea8a91
|
8
|
+
def initialize(sub_blocks = [], json: nil, id: nil, parent: nil)
|
9
|
+
super(json: json, id: id, parent: parent)
|
10
|
+
add_sub_blocks sub_blocks unless json
|
11
|
+
@can_have_children = true
|
12
|
+
@can_append = false
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [String (frozen)]
|
16
|
+
def type
|
17
|
+
"column"
|
18
|
+
end
|
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] = {}
|
25
|
+
ans[type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
|
26
|
+
ans
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
# Notion block
|
5
|
+
class ColumnListBlock < Block
|
6
|
+
# @param [Array<Array<NotionRubyMapping::Block, Array<NotionRubyMapping::Block>>>] array_of_sub_blocks
|
7
|
+
# @return [NotionRubyMapping::Block]
|
8
|
+
# @see https://www.notion.so/hkob/ColumnListBlock-78d12860099f4e7d89b65c446bd314ba#6e1c97e1b5da45038232f43994e4d7e5
|
9
|
+
def initialize(array_of_sub_blocks = [], json: nil, id: nil, parent: nil)
|
10
|
+
super(json: json, id: id, parent: parent)
|
11
|
+
unless json
|
12
|
+
raise StandardError, "The column_list must have at least 2 columns." if array_of_sub_blocks.count < 2
|
13
|
+
|
14
|
+
@columns = array_of_sub_blocks.map { |sub_blocks| ColumnBlock.new(sub_blocks) }
|
15
|
+
end
|
16
|
+
@can_have_children = true
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [String (frozen)]
|
20
|
+
def type
|
21
|
+
"column_list"
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param [Boolean] not_update false when update
|
25
|
+
# @return [Hash{String (frozen)->Hash}]
|
26
|
+
def block_json(not_update: true)
|
27
|
+
ans = super
|
28
|
+
ans[type] = {}
|
29
|
+
ans[type]["children"] = @columns.map(&:block_json) if @columns
|
30
|
+
ans
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -7,6 +7,7 @@ module NotionRubyMapping
|
|
7
7
|
|
8
8
|
# @param [String] id
|
9
9
|
# @return [NotionRubyMapping::Database, String]
|
10
|
+
# @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#58ba9190fd544432a9e2a5823d6c33b7
|
10
11
|
def self.find(id, dry_run: false)
|
11
12
|
nc = NotionCache.instance
|
12
13
|
if dry_run
|
@@ -16,9 +17,16 @@ module NotionRubyMapping
|
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
# @
|
20
|
+
# @param [String] key
|
21
|
+
# @return [NotionRubyMapping::PropertyCache, Hash] obtained Page value or PropertyCache
|
22
|
+
def [](key)
|
23
|
+
get key
|
24
|
+
end
|
25
|
+
|
20
26
|
# @param [Class] klass
|
21
27
|
# @param [String] title
|
28
|
+
# @return [NotionRubyMapping::Property]
|
29
|
+
# @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#c9d24269123c444295af88b9b27074a9
|
22
30
|
def add_property(klass, title)
|
23
31
|
prop = assign_property klass, title
|
24
32
|
yield prop if block_given?
|
@@ -29,7 +37,8 @@ module NotionRubyMapping
|
|
29
37
|
|
30
38
|
# @param [Array<Property, Class, String>] assign
|
31
39
|
# @return [NotionRubyMapping::Base]
|
32
|
-
|
40
|
+
# @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#c217ce78020a4de79b720790fce3092d
|
41
|
+
def build_child_page(*assign)
|
33
42
|
assign = properties.map { |p| [p.class, p.name] }.flatten if assign.empty?
|
34
43
|
page = Page.new assign: assign, parent: {"database_id" => @id}
|
35
44
|
pp = page.properties
|
@@ -38,38 +47,62 @@ module NotionRubyMapping
|
|
38
47
|
page
|
39
48
|
end
|
40
49
|
|
50
|
+
# @param [Array<Property, Class, String>] assign
|
51
|
+
# @return [NotionRubyMapping::Base]
|
52
|
+
# @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#c217ce78020a4de79b720790fce3092d
|
53
|
+
def create_child_page(*assign, dry_run: false)
|
54
|
+
assign = properties.map { |p| [p.class, p.name] }.flatten if assign.empty?
|
55
|
+
page = Page.new assign: assign, parent: {"database_id" => @id}
|
56
|
+
pp = page.properties
|
57
|
+
pp.clear_will_update
|
58
|
+
yield page, pp if block_given?
|
59
|
+
page.save dry_run: dry_run
|
60
|
+
end
|
61
|
+
|
41
62
|
# @return [NotionRubyMapping::RichTextArray]
|
63
|
+
# @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#217a7d988c404d68b270c4874a9117b4
|
42
64
|
def database_title
|
43
65
|
@database_title ||= RichTextArray.new "title", json: (self["title"]), will_update: new_record?
|
44
66
|
end
|
45
67
|
|
68
|
+
# @return [Hash] created json for property schemas (for create database)
|
46
69
|
def property_schema_json
|
47
70
|
@payload.property_schema_json @property_cache, database_title
|
48
71
|
end
|
49
72
|
|
50
|
-
# @return [Hash] created json for
|
73
|
+
# @return [Hash] created json for property values
|
51
74
|
def property_values_json
|
52
75
|
@payload.property_values_json @property_cache, database_title
|
53
76
|
end
|
54
77
|
|
55
78
|
# @param [NotionRubyMapping::Query] query object
|
56
79
|
# @return [NotionRubyMapping::List, String]
|
80
|
+
# @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#6bd9acf62c454f64bc555c8828057e6b
|
57
81
|
def query_database(query = Query.new, dry_run: false)
|
58
82
|
if dry_run
|
59
83
|
Base.dry_run_script :post, @nc.query_database_path(@id), query.query_json
|
60
84
|
else
|
61
|
-
response = @nc.
|
85
|
+
response = @nc.database_query_request @id, query
|
62
86
|
List.new json: response, database: self, query: query
|
63
87
|
end
|
64
88
|
end
|
65
89
|
|
66
|
-
# @param [Array]
|
90
|
+
# @param [Array] property_names
|
67
91
|
# @return [Array<NotionRubyMapping::Property>]
|
68
|
-
|
69
|
-
|
92
|
+
# @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#5d15354be2604141adfbf78d14d49942
|
93
|
+
def remove_properties(*property_names)
|
94
|
+
property_names.map { |n| properties[n] }.each(&:remove)
|
95
|
+
end
|
96
|
+
|
97
|
+
# @param [String] old_property_name
|
98
|
+
# @param [String] new_property_name
|
99
|
+
# @return [NotionRubyMapping::Database]
|
100
|
+
def rename_property(old_property_name, new_property_name)
|
101
|
+
properties[old_property_name].new_name = new_property_name
|
102
|
+
self
|
70
103
|
end
|
71
104
|
|
72
|
-
# @return [Hash] created json for update database
|
105
|
+
# @return [Hash] created json for property schemas (for update database)
|
73
106
|
def update_property_schema_json
|
74
107
|
@payload.update_property_schema_json @property_cache, database_title
|
75
108
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
# Notion block
|
5
|
+
class DividerBlock < Block
|
6
|
+
# @param [Boolean] not_update false when update
|
7
|
+
# @return [Hash{String (frozen)->Hash}]
|
8
|
+
def block_json(not_update: true)
|
9
|
+
ans = super
|
10
|
+
ans[type] = {}
|
11
|
+
ans
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [String (frozen)]
|
15
|
+
def type
|
16
|
+
"divider"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
# Notion block
|
5
|
+
class EquationBlock < Block
|
6
|
+
# @param [String, NotionRubyMapping::EquationObject] expression
|
7
|
+
# @see https://www.notion.so/hkob/EquationBlock-df0f823dc5ac41b798052f161dd6540c#cfcd2ceb77194c0e915500b429e8b91b
|
8
|
+
def initialize(expression = nil, json: nil, id: nil, parent: nil)
|
9
|
+
super(json: json, id: id, parent: parent)
|
10
|
+
@equation_object = if @json
|
11
|
+
EquationObject.equation_object @json[type]["expression"]
|
12
|
+
else
|
13
|
+
EquationObject.equation_object expression
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param [Boolean] not_update false when update
|
18
|
+
# @return [Hash{String (frozen)->Hash}]
|
19
|
+
def block_json(not_update: true)
|
20
|
+
ans = super
|
21
|
+
ans[type] = {"expression" => @equation_object.expression}
|
22
|
+
ans
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [String]
|
26
|
+
# @see https://www.notion.so/hkob/EquationBlock-df0f823dc5ac41b798052f161dd6540c#da3e9d93ffac4d84854be3342b4bf3fe
|
27
|
+
def expression
|
28
|
+
@equation_object&.expression
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param [String] new_expression
|
32
|
+
# @see https://www.notion.so/hkob/EquationBlock-df0f823dc5ac41b798052f161dd6540c#f05e3b2c82914cea9f05e9e6644647e1
|
33
|
+
def expression=(new_expression)
|
34
|
+
@equation_object = EquationObject.equation_object new_expression
|
35
|
+
@payload.add_update_block_key "expression"
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [String (frozen)]
|
39
|
+
def type
|
40
|
+
"equation"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
# Notion block
|
5
|
+
class FileBaseBlock < Block
|
6
|
+
# @param [String, nil] url
|
7
|
+
# @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>, nil] caption
|
8
|
+
# @see https://www.notion.so/hkob/FileBlock-08f2aa6948364d00b92beacaac9a619c#ace53d2e6ff2404f937179ae1e966e98
|
9
|
+
# @see https://www.notion.so/hkob/ImageBlock-806b3d2a9a2c4bf5a5aca6e3fbc8a7e2#4cb790b8b5c847acab4341d55e4fa66a
|
10
|
+
def initialize(url = nil, caption: [], json: nil, id: nil, parent: nil)
|
11
|
+
super(json: json, id: id, parent: parent)
|
12
|
+
if @json
|
13
|
+
@file_object = FileObject.new json: @json[type]
|
14
|
+
decode_block_caption
|
15
|
+
@can_append = @file_object.external?
|
16
|
+
else
|
17
|
+
@file_object = FileObject.file_object url
|
18
|
+
@caption = RichTextArray.rich_text_array "caption", caption
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# @see https://www.notion.so/hkob/FileBlock-08f2aa6948364d00b92beacaac9a619c#158487a7e1644fae8778dcff59869356
|
23
|
+
# @see https://www.notion.so/hkob/ImageBlock-806b3d2a9a2c4bf5a5aca6e3fbc8a7e2#19a4aa3e06514bbe84be9d3b8a45a20f
|
24
|
+
attr_reader :caption
|
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] = @file_object.property_values_json
|
31
|
+
ans[type].merge! @caption.update_property_schema_json(not_update) if @caption
|
32
|
+
ans
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [String]
|
36
|
+
# @see https://www.notion.so/hkob/FileBlock-08f2aa6948364d00b92beacaac9a619c#d3e7d31b7b274955aa7603163867fa57
|
37
|
+
# @see https://www.notion.so/hkob/ImageBlock-806b3d2a9a2c4bf5a5aca6e3fbc8a7e2#01e1883119f14c5f9f7f6823793e72ec
|
38
|
+
def url
|
39
|
+
@file_object&.url
|
40
|
+
end
|
41
|
+
|
42
|
+
# @param [String] url
|
43
|
+
# @see https://www.notion.so/hkob/FileBlock-08f2aa6948364d00b92beacaac9a619c#23497b8eb2214c45b3d5881796f984cb
|
44
|
+
# @see https://www.notion.so/hkob/ImageBlock-806b3d2a9a2c4bf5a5aca6e3fbc8a7e2#61598d260b6140f2a359f7d22ea2548a
|
45
|
+
def url=(url)
|
46
|
+
@file_object.url = url
|
47
|
+
@payload.add_update_block_key "external"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
# Notion block
|
5
|
+
class Heading1Block < TextSubBlockColorBaseBlock
|
6
|
+
# @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>, nil] text_info
|
7
|
+
# @param [String] color
|
8
|
+
def initialize(text_info = nil, color: nil, json: nil, id: nil, parent: nil)
|
9
|
+
super(text_info, color: color, json: json, id: id, parent: parent)
|
10
|
+
@can_have_children = false
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [String (frozen)]
|
14
|
+
def type
|
15
|
+
"heading_1"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
# Notion block
|
5
|
+
class Heading2Block < TextSubBlockColorBaseBlock
|
6
|
+
# @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
|
7
|
+
# @param [String] color
|
8
|
+
def initialize(text_info = nil, color: nil, json: nil, id: nil, parent: nil)
|
9
|
+
super(text_info, color: color, json: json, id: id, parent: parent)
|
10
|
+
@can_have_children = false
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [String (frozen)]
|
14
|
+
def type
|
15
|
+
"heading_2"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
# Notion block
|
5
|
+
class Heading3Block < TextSubBlockColorBaseBlock
|
6
|
+
# @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
|
7
|
+
# @param [String] color
|
8
|
+
def initialize(text_info = nil, color: nil, json: nil, id: nil, parent: nil)
|
9
|
+
super(text_info, color: color, json: json, id: id, parent: parent)
|
10
|
+
@can_have_children = false
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [String (frozen)]
|
14
|
+
def type
|
15
|
+
"heading_3"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
# Notion block
|
5
|
+
class LinkPreviewBlock < UrlBaseBlock
|
6
|
+
def initialize(url = nil, json: nil, id: nil, parent: nil)
|
7
|
+
super
|
8
|
+
@can_append = false
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [String (frozen)]
|
12
|
+
def type
|
13
|
+
"link_preview"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
# Notion block
|
5
|
+
class LinkToPageBlock < Block
|
6
|
+
# @param [String] page_id
|
7
|
+
# @param [String] database_id
|
8
|
+
# @see https://www.notion.so/hkob/LinkToPageBlock-e6d09d4742a24fb6bf1101b14a288ff5#d46a2f4288b04cbdbd1b4679f70b7642
|
9
|
+
def initialize(page_id: nil, database_id: nil, json: nil, id: nil, parent: nil)
|
10
|
+
super(json: json, id: id, parent: parent)
|
11
|
+
if @json
|
12
|
+
@page_id, @database_id = @json[type].values_at(*%w[page_id database_id])
|
13
|
+
else
|
14
|
+
@page_id = page_id
|
15
|
+
@database_id = database_id
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# @see https://www.notion.so/hkob/LinkToPageBlock-e6d09d4742a24fb6bf1101b14a288ff5#f0ccbad5a94248baa658efc26d9c0ca3
|
20
|
+
# @see https://www.notion.so/hkob/LinkToPageBlock-e6d09d4742a24fb6bf1101b14a288ff5#1444263ecc7d402c8a18f4dd32a14956
|
21
|
+
attr_reader :database_id, :page_id
|
22
|
+
|
23
|
+
# @param [Boolean] not_update false when update
|
24
|
+
# @return [Hash{String (frozen)->Hash}]
|
25
|
+
def block_json(not_update: true)
|
26
|
+
ans = super
|
27
|
+
ans[type] = if @page_id
|
28
|
+
{"type" => "page_id", "page_id" => @page_id}
|
29
|
+
else
|
30
|
+
{"type" => "database_id", "database_id" => @database_id}
|
31
|
+
end
|
32
|
+
ans
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [String (frozen)]
|
36
|
+
def type
|
37
|
+
"link_to_page"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -5,27 +5,57 @@ module NotionRubyMapping
|
|
5
5
|
class List < Base
|
6
6
|
include Enumerable
|
7
7
|
|
8
|
-
def initialize(json: nil, id: nil, database: nil, query: nil)
|
8
|
+
def initialize(json: nil, id: nil, database: nil, 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
|
+
@parent = parent
|
13
14
|
@query = query
|
14
15
|
@index = 0
|
15
16
|
@has_content = true
|
16
17
|
end
|
17
18
|
attr_reader :has_more
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
# @return [NotionRubyMapping::List, Enumerator]
|
21
|
+
# @see https://www.notion.so/hkob/List-9a0b32335e0d48849a785ce5e162c760#12e1c261a0944a4095776b7515bef4a1
|
21
22
|
def each
|
22
23
|
return enum_for(:each) unless block_given?
|
23
24
|
|
24
|
-
if @
|
25
|
+
if @parent
|
26
|
+
unless @has_content
|
27
|
+
unless @load_all_contents
|
28
|
+
@query.start_cursor = nil
|
29
|
+
@json = @parent.children @query
|
30
|
+
@has_more = @json["has_more"]
|
31
|
+
end
|
32
|
+
@index = 0
|
33
|
+
@has_content = true
|
34
|
+
end
|
35
|
+
|
36
|
+
while @has_content
|
37
|
+
if @index < results.length
|
38
|
+
object = Base.create_from_json(results[@index])
|
39
|
+
@index += 1
|
40
|
+
yield object
|
41
|
+
elsif @has_more
|
42
|
+
if @parent
|
43
|
+
@query.start_cursor = @json["next_cursor"]
|
44
|
+
@json = @parent.children @query
|
45
|
+
@index = 0
|
46
|
+
@has_more = @json["has_more"]
|
47
|
+
else
|
48
|
+
@has_content = false
|
49
|
+
end
|
50
|
+
else
|
51
|
+
@has_content = false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
elsif @database
|
25
55
|
unless @has_content # re-exec
|
26
56
|
unless @load_all_contents
|
27
57
|
@query.start_cursor = nil
|
28
|
-
@json = @database.
|
58
|
+
@json = @nc.database_query_request @database.id, @query
|
29
59
|
@has_more = @json["has_more"]
|
30
60
|
end
|
31
61
|
@index = 0
|
@@ -40,7 +70,7 @@ module NotionRubyMapping
|
|
40
70
|
elsif @has_more
|
41
71
|
if @database
|
42
72
|
@query.start_cursor = @json["next_cursor"]
|
43
|
-
@json = @database.
|
73
|
+
@json = @nc.database_query_request @database.id, @query
|
44
74
|
@index = 0
|
45
75
|
@has_more = @json["has_more"]
|
46
76
|
else
|
@@ -51,6 +81,7 @@ module NotionRubyMapping
|
|
51
81
|
end
|
52
82
|
end
|
53
83
|
end
|
84
|
+
self
|
54
85
|
end
|
55
86
|
|
56
87
|
private
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
# Notion page object
|
5
|
+
class Page < Base
|
6
|
+
### Public announced methods
|
7
|
+
|
8
|
+
# @param [String] id
|
9
|
+
# @return [NotionRubyMapping::Page, String]
|
10
|
+
# @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#7d868b8b81c3473082bbdc7370813a4a
|
11
|
+
def self.find(id, dry_run: false)
|
12
|
+
nc = NotionCache.instance
|
13
|
+
if dry_run
|
14
|
+
Base.dry_run_script :get, nc.page_path(id)
|
15
|
+
else
|
16
|
+
nc.page id
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# @param [String] key
|
21
|
+
# @return [NotionRubyMapping::PropertyCache, Hash] obtained Page value or PropertyCache
|
22
|
+
def [](key)
|
23
|
+
get key
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param [String] title
|
27
|
+
# @param [Array<String, Property>] assigns
|
28
|
+
# @return [NotionRubyMapping::Database]
|
29
|
+
# @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#2e8ca5408afb4f83a92b7b84c0dc9903
|
30
|
+
def build_child_database(title, *assigns)
|
31
|
+
db = Database.new json: {"title" => [TextObject.new(title).property_values_json]},
|
32
|
+
assign: assigns, parent: {"type" => "page_id", "page_id" => @id}
|
33
|
+
yield db, db.properties if block_given?
|
34
|
+
db
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_child_database(title, *assigns, dry_run: false)
|
38
|
+
build_child_database title, *assigns
|
39
|
+
db = Database.new json: {"title" => [TextObject.new(title).property_values_json]},
|
40
|
+
assign: assigns, parent: {"type" => "page_id", "page_id" => @id}
|
41
|
+
yield db, db.properties
|
42
|
+
db.save dry_run: dry_run
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [String] title
|
46
|
+
# @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#2ff7209055f346fbbda454cdbb40b1c8
|
47
|
+
def title
|
48
|
+
properties.select { |p| p.is_a? TitleProperty }.map(&:full_text).join ""
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
# @return [NotionRubyMapping::Base, String]
|
54
|
+
def create(dry_run: false)
|
55
|
+
if dry_run
|
56
|
+
dry_run_script :post, @nc.pages_path, :property_values_json
|
57
|
+
else
|
58
|
+
@new_record = false
|
59
|
+
update_json @nc.create_page_request(property_values_json)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [Hash]
|
64
|
+
def reload_json
|
65
|
+
@nc.page_request @id
|
66
|
+
end
|
67
|
+
|
68
|
+
# @return [NotionRubyMapping::Base, String]
|
69
|
+
def update(dry_run: false)
|
70
|
+
if dry_run
|
71
|
+
dry_run_script :patch, @nc.page_path(@id), :property_values_json
|
72
|
+
else
|
73
|
+
update_json @nc.update_page_request(@id, property_values_json)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|