notion_ruby_mapping 0.3.3 → 0.5.0
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 +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,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module NotionRubyMapping
|
|
4
|
+
# EquationObject
|
|
5
|
+
class EquationObject < RichTextObject
|
|
6
|
+
# @param [String] expression
|
|
7
|
+
# @return [TextObject]
|
|
8
|
+
def initialize(expression, options = {})
|
|
9
|
+
super "equation", {"plain_text" => expression}.merge(options)
|
|
10
|
+
@expression = expression
|
|
11
|
+
@will_update = false
|
|
12
|
+
end
|
|
13
|
+
attr_reader :will_update, :expression
|
|
14
|
+
|
|
15
|
+
# @param [EquationObject, String] uo
|
|
16
|
+
# @return [EquationObject] self or created EquationObject
|
|
17
|
+
# @see https://www.notion.so/hkob/EquationObject-cd50126fce544ad5bb76463a4269859b#45b0b0810d8647a1968a5e4293920aeb
|
|
18
|
+
def self.equation_object(expression_or_eo)
|
|
19
|
+
if expression_or_eo.is_a? EquationObject
|
|
20
|
+
expression_or_eo
|
|
21
|
+
else
|
|
22
|
+
EquationObject.new expression_or_eo
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @param [String] expression
|
|
27
|
+
# @see https://www.notion.so/hkob/EquationObject-cd50126fce544ad5bb76463a4269859b#155800e2c69d4676a2d74572ed8f0de8
|
|
28
|
+
def expression=(expression)
|
|
29
|
+
@expression = expression
|
|
30
|
+
@options["plain_text"] = expression
|
|
31
|
+
@will_update = true
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
protected
|
|
35
|
+
|
|
36
|
+
# @return [Hash{String (frozen)->String}]
|
|
37
|
+
def partial_property_values_json
|
|
38
|
+
{
|
|
39
|
+
"expression" => @expression,
|
|
40
|
+
}
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module NotionRubyMapping
|
|
4
|
+
# TextObject
|
|
5
|
+
class FileObject
|
|
6
|
+
# @param [String] url
|
|
7
|
+
# @return [TextObject]
|
|
8
|
+
def initialize(url: nil, json: {})
|
|
9
|
+
if url
|
|
10
|
+
@type = "external"
|
|
11
|
+
@url = url
|
|
12
|
+
elsif json
|
|
13
|
+
@type = json["type"]
|
|
14
|
+
@url = json[@type]["url"]
|
|
15
|
+
@expiry_time = json[@type]["expiry_time"]
|
|
16
|
+
else
|
|
17
|
+
raise StandardError, "FileObject requires url: or json:"
|
|
18
|
+
end
|
|
19
|
+
@will_update = false
|
|
20
|
+
end
|
|
21
|
+
attr_reader :will_update, :url, :type
|
|
22
|
+
|
|
23
|
+
# @param [FileObject, String] uo
|
|
24
|
+
# @return [FileObject] self or created FileObject
|
|
25
|
+
# @see https://www.notion.so/hkob/FileObject-6218c354e985423a90904f47a985be33#54b37c567e1d4dfcab06f6d8f8fd412e
|
|
26
|
+
def self.file_object(url_or_fo)
|
|
27
|
+
if url_or_fo.is_a? FileObject
|
|
28
|
+
url_or_fo
|
|
29
|
+
else
|
|
30
|
+
FileObject.new url: url_or_fo
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @return [TrueClass, FalseClass] true if "type" is "external"
|
|
35
|
+
def external?
|
|
36
|
+
@type == "external"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# @param [String] url
|
|
40
|
+
# @see https://www.notion.so/hkob/FileObject-6218c354e985423a90904f47a985be33#6b841f75d0234a1aac93fb54348abb96
|
|
41
|
+
def url=(url)
|
|
42
|
+
raise StandardError "internal file url can't change." if @type == "file"
|
|
43
|
+
|
|
44
|
+
@url = url
|
|
45
|
+
@will_update = true
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# @return [Hash]
|
|
49
|
+
def property_values_json
|
|
50
|
+
ans = {
|
|
51
|
+
"type" => @type,
|
|
52
|
+
@type => {
|
|
53
|
+
"url" => @url,
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
ans[@type]["expiry_time"] = @expiry_time if @expiry_time
|
|
57
|
+
ans
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -6,6 +6,10 @@ module NotionRubyMapping
|
|
|
6
6
|
# @return [MentionObject]
|
|
7
7
|
def initialize(options = {})
|
|
8
8
|
super "mention", options
|
|
9
|
+
return unless (url = options["link_preview"])
|
|
10
|
+
|
|
11
|
+
@options["href"] = url
|
|
12
|
+
@options["plain_text"] = url
|
|
9
13
|
end
|
|
10
14
|
|
|
11
15
|
# @return [String (frozen)]
|
|
@@ -66,6 +70,13 @@ module NotionRubyMapping
|
|
|
66
70
|
"type" => "template_mention",
|
|
67
71
|
"template_mention" => sub,
|
|
68
72
|
}
|
|
73
|
+
elsif @options.key? "link_preview"
|
|
74
|
+
{
|
|
75
|
+
"type" => "link_preview",
|
|
76
|
+
"link_preview" => {
|
|
77
|
+
"url" => @options["link_preview"],
|
|
78
|
+
},
|
|
79
|
+
}
|
|
69
80
|
else
|
|
70
81
|
raise StandardError, "Irregular mention type: #{@options.keys}"
|
|
71
82
|
end
|
|
@@ -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"]
|
|
@@ -22,6 +22,8 @@ module NotionRubyMapping
|
|
|
22
22
|
case type
|
|
23
23
|
when "text"
|
|
24
24
|
TextObject.new json["plain_text"], options
|
|
25
|
+
when "equation"
|
|
26
|
+
EquationObject.new json["equation"]["expression"], options
|
|
25
27
|
when "mention"
|
|
26
28
|
mention = json["mention"]
|
|
27
29
|
case mention["type"]
|
|
@@ -41,6 +43,8 @@ module NotionRubyMapping
|
|
|
41
43
|
else
|
|
42
44
|
MentionObject.new options.merge({"template_mention" => template_mention["template_mention_user"]})
|
|
43
45
|
end
|
|
46
|
+
when "link_preview"
|
|
47
|
+
MentionObject.new options.merge({"link_preview" => mention["link_preview"]["url"]})
|
|
44
48
|
else
|
|
45
49
|
raise StandardError, "Unknown mention type: #{mention["type"]}"
|
|
46
50
|
end
|
|
@@ -69,6 +73,13 @@ module NotionRubyMapping
|
|
|
69
73
|
}.merge annotations_json
|
|
70
74
|
end
|
|
71
75
|
|
|
76
|
+
# @param [String] url
|
|
77
|
+
# @return [String] input text
|
|
78
|
+
def href=(url)
|
|
79
|
+
@will_update = true
|
|
80
|
+
@options["href"] = url
|
|
81
|
+
end
|
|
82
|
+
|
|
72
83
|
# @param [String, RichTextObject] value
|
|
73
84
|
# @return [String] input text
|
|
74
85
|
def plain_text=(value)
|
|
@@ -119,9 +130,6 @@ module NotionRubyMapping
|
|
|
119
130
|
|
|
120
131
|
protected
|
|
121
132
|
|
|
122
|
-
# @return [Hash] options
|
|
123
|
-
attr_reader :options
|
|
124
|
-
|
|
125
133
|
# @return [Hash, Hash{String (frozen)->Hash}]
|
|
126
134
|
def annotations_json
|
|
127
135
|
annotations = @options.slice(*%w[bold italic strikethrough underline code color])
|
|
@@ -14,11 +14,11 @@ module NotionRubyMapping
|
|
|
14
14
|
|
|
15
15
|
# @param [UserObject, String] uo
|
|
16
16
|
# @return [UserObject] self or created UserObject
|
|
17
|
-
def self.user_object(
|
|
18
|
-
if
|
|
19
|
-
|
|
17
|
+
def self.user_object(user_id_or_uo)
|
|
18
|
+
if user_id_or_uo.is_a? UserObject
|
|
19
|
+
user_id_or_uo
|
|
20
20
|
else
|
|
21
|
-
UserObject.new user_id:
|
|
21
|
+
UserObject.new user_id: user_id_or_uo
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -34,5 +34,10 @@ module NotionRubyMapping
|
|
|
34
34
|
"id" => @user_id,
|
|
35
35
|
}
|
|
36
36
|
end
|
|
37
|
+
|
|
38
|
+
def user_id=(new_user_id)
|
|
39
|
+
@user_id = new_user_id
|
|
40
|
+
@will_update = true
|
|
41
|
+
end
|
|
37
42
|
end
|
|
38
43
|
end
|
|
@@ -11,6 +11,7 @@ module NotionRubyMapping
|
|
|
11
11
|
## Common methods
|
|
12
12
|
|
|
13
13
|
# @return [Boolean, Hash]
|
|
14
|
+
# @see https://www.notion.so/hkob/CheckboxProperty-ac1edbdb8e264af5ad1432b522b429fd#20da1bf0cbcc4d4eb22d9125386522c2
|
|
14
15
|
def checkbox
|
|
15
16
|
@json
|
|
16
17
|
end
|
|
@@ -19,7 +20,9 @@ module NotionRubyMapping
|
|
|
19
20
|
|
|
20
21
|
# @param [Boolean] flag
|
|
21
22
|
# @return [TrueClass, FalseClass] settled value
|
|
23
|
+
# @see https://www.notion.so/hkob/CheckboxProperty-ac1edbdb8e264af5ad1432b522b429fd#f167c85c1d2d40dfb8b3b6ce582e0f15
|
|
22
24
|
def checkbox=(flag)
|
|
25
|
+
assert_page_property __method__
|
|
23
26
|
@will_update = true
|
|
24
27
|
@json = flag
|
|
25
28
|
end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "date"
|
|
4
|
+
|
|
5
|
+
module NotionRubyMapping
|
|
6
|
+
# Date base property (date, created_time, last_edited_time, formula)
|
|
7
|
+
class DateBaseProperty < Property
|
|
8
|
+
include IsEmptyIsNotEmpty
|
|
9
|
+
|
|
10
|
+
# @param [Date, Time, DateTime, String, nil] obj
|
|
11
|
+
# @return [String, nil] iso8601 format string
|
|
12
|
+
def self.value_str(obj)
|
|
13
|
+
case obj
|
|
14
|
+
when Date
|
|
15
|
+
obj.iso8601
|
|
16
|
+
when Time
|
|
17
|
+
obj.strftime("%Y-%m-%dT%H:%M:%S%:z")
|
|
18
|
+
when DateTime
|
|
19
|
+
obj.iso8601
|
|
20
|
+
else
|
|
21
|
+
obj
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @param [Date, Time, DateTime, String, nil] obj
|
|
26
|
+
# @return [Date, nil] iso8601 format string
|
|
27
|
+
def self.date_from_obj(obj)
|
|
28
|
+
str = value_str obj
|
|
29
|
+
Date.parse str if str
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# @param [String] rollup Rollup name
|
|
33
|
+
# @param [String] rollup_type Rollup type
|
|
34
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
|
35
|
+
# @see https://www.notion.so/hkob/CheckboxProperty-ac1edbdb8e264af5ad1432b522b429fd#5f07c4ebc4744986bfc99a43827349fc
|
|
36
|
+
def filter_equals(date, rollup = nil, rollup_type = nil)
|
|
37
|
+
make_filter_query "equals", value_str(date), rollup, rollup_type
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @param [String] rollup Rollup name
|
|
41
|
+
# @param [String] rollup_type Rollup type
|
|
42
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
|
43
|
+
def filter_does_not_equal(date, rollup = nil, rollup_type = nil)
|
|
44
|
+
make_filter_query "does_not_equal", value_str(date), rollup, rollup_type
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @param [String] rollup Rollup name
|
|
48
|
+
# @param [String] rollup_type Rollup type
|
|
49
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
|
50
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#841815bfaf684964bebf3fa6712ae26c
|
|
51
|
+
def filter_before(date, rollup = nil, rollup_type = nil)
|
|
52
|
+
make_filter_query "before", value_str(date), rollup, rollup_type
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# @param [String] rollup Rollup name
|
|
56
|
+
# @param [String] rollup_type Rollup type
|
|
57
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
|
58
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#c0ea140866ea46f9a746b24773dc821c
|
|
59
|
+
def filter_after(date, rollup = nil, rollup_type = nil)
|
|
60
|
+
make_filter_query "after", value_str(date), rollup, rollup_type
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# @param [String] rollup Rollup name
|
|
64
|
+
# @param [String] rollup_type Rollup type
|
|
65
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
|
66
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#6a20ade0ee964aad81aae4c08ea29d6b
|
|
67
|
+
def filter_on_or_before(date, rollup = nil, rollup_type = nil)
|
|
68
|
+
make_filter_query "on_or_before", value_str(date), rollup, rollup_type
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# @param [String] rollup Rollup name
|
|
72
|
+
# @param [String] rollup_type Rollup type
|
|
73
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
|
74
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#1469e3fb3068426a8ea8492d191d1563
|
|
75
|
+
def filter_on_or_after(date, rollup = nil, rollup_type = nil)
|
|
76
|
+
make_filter_query "on_or_after", value_str(date), rollup, rollup_type
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# @param [String] rollup Rollup name
|
|
80
|
+
# @param [String] rollup_type Rollup type
|
|
81
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
|
82
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#707e7e848dc9417998420b65024542db
|
|
83
|
+
def filter_past_week(rollup = nil, rollup_type = nil)
|
|
84
|
+
make_filter_query "past_week", {}, rollup, rollup_type
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# @param [String] rollup Rollup name
|
|
88
|
+
# @param [String] rollup_type Rollup type
|
|
89
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
|
90
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#7b2d05c549204c2eb68d95020d7b97c5
|
|
91
|
+
def filter_past_month(rollup = nil, rollup_type = nil)
|
|
92
|
+
make_filter_query "past_month", {}, rollup, rollup_type
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# @param [String] rollup Rollup name
|
|
96
|
+
# @param [String] rollup_type Rollup type
|
|
97
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
|
98
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#9c8bf0a2398a41c8a0714a62afca3aa8
|
|
99
|
+
def filter_past_year(rollup = nil, rollup_type = nil)
|
|
100
|
+
make_filter_query "past_year", {}, rollup, rollup_type
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# @param [String] rollup Rollup name
|
|
104
|
+
# @param [String] rollup_type Rollup type
|
|
105
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
|
106
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#d9dc189ee8244ba8a6c863259eaa9984
|
|
107
|
+
def filter_next_week(rollup = nil, rollup_type = nil)
|
|
108
|
+
make_filter_query "next_week", {}, rollup, rollup_type
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# @param [String] rollup Rollup name
|
|
112
|
+
# @param [String] rollup_type Rollup type
|
|
113
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
|
114
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#0edb4dffbe6b403882255e870cc71066
|
|
115
|
+
def filter_next_month(rollup = nil, rollup_type = nil)
|
|
116
|
+
make_filter_query "next_month", {}, rollup, rollup_type
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# @param [String] rollup Rollup name
|
|
120
|
+
# @param [String] rollup_type Rollup type
|
|
121
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
|
122
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#b59c73dd4b1a488f95d3e8cd19853709
|
|
123
|
+
def filter_next_year(rollup = nil, rollup_type = nil)
|
|
124
|
+
make_filter_query "next_year", {}, rollup, rollup_type
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
protected
|
|
128
|
+
|
|
129
|
+
# @param [Date, Time, DateTime, String, nil] obj
|
|
130
|
+
# @return [String, nil] iso8601 format string
|
|
131
|
+
def value_str(obj)
|
|
132
|
+
self.class.value_str(obj)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
@@ -10,6 +10,7 @@ module NotionRubyMapping
|
|
|
10
10
|
## Common methods
|
|
11
11
|
|
|
12
12
|
# @return [Hash]
|
|
13
|
+
# @see https://www.notion.so/hkob/DateProperty-c6e815c060cb430889dbb33b697f00c6#e64792d3d35c439e8123f108987becc3
|
|
13
14
|
def date
|
|
14
15
|
@json
|
|
15
16
|
end
|
|
@@ -17,12 +18,16 @@ module NotionRubyMapping
|
|
|
17
18
|
## Page property only methods
|
|
18
19
|
|
|
19
20
|
# @return [Date, Time, DateTime, String]
|
|
21
|
+
# @see https://www.notion.so/hkob/DateProperty-c6e815c060cb430889dbb33b697f00c6#15f2088e012549cbae93de14ce14d352
|
|
20
22
|
def end_date
|
|
23
|
+
assert_page_property __method__
|
|
21
24
|
@json["end"]
|
|
22
25
|
end
|
|
23
26
|
|
|
24
27
|
# @param [Date, Time, DateTime, String] edt
|
|
28
|
+
# @see https://www.notion.so/hkob/DateProperty-c6e815c060cb430889dbb33b697f00c6#944c02096101429084527c22155683bf
|
|
25
29
|
def end_date=(edt)
|
|
30
|
+
assert_page_property __method__
|
|
26
31
|
@will_update = true
|
|
27
32
|
sdt = start_date
|
|
28
33
|
edt = nil if sdt.class != edt.class || sdt > edt
|
|
@@ -30,12 +35,16 @@ module NotionRubyMapping
|
|
|
30
35
|
end
|
|
31
36
|
|
|
32
37
|
# @return [Date, Time, DateTime, String]
|
|
38
|
+
# @see https://www.notion.so/hkob/DateProperty-c6e815c060cb430889dbb33b697f00c6#d37097c7a3f7481e9b33a7aaae783888
|
|
33
39
|
def start_date
|
|
40
|
+
assert_page_property __method__
|
|
34
41
|
@json["start"]
|
|
35
42
|
end
|
|
36
43
|
|
|
37
44
|
# @param [Date, Time, DateTime, String] sdt
|
|
45
|
+
# @see https://www.notion.so/hkob/DateProperty-c6e815c060cb430889dbb33b697f00c6#4f5931f1588a43f7857af8ab2d73df74
|
|
38
46
|
def start_date=(sdt)
|
|
47
|
+
assert_page_property __method__
|
|
39
48
|
@will_update = true
|
|
40
49
|
edt = end_date
|
|
41
50
|
@json["end"] = nil if sdt.class != edt.class || sdt > edt
|
|
@@ -43,12 +52,16 @@ module NotionRubyMapping
|
|
|
43
52
|
end
|
|
44
53
|
|
|
45
54
|
# @return [String]
|
|
55
|
+
# @see https://www.notion.so/hkob/DateProperty-c6e815c060cb430889dbb33b697f00c6#f892cde82d9a44a0850d69878e31b216
|
|
46
56
|
def time_zone
|
|
57
|
+
assert_page_property __method__
|
|
47
58
|
@json["time_zone"]
|
|
48
59
|
end
|
|
49
60
|
|
|
50
61
|
# @param [String] tzone
|
|
62
|
+
# @see https://www.notion.so/hkob/DateProperty-c6e815c060cb430889dbb33b697f00c6#2529a5ac7982466f9f19299fc51e02a8
|
|
51
63
|
def time_zone=(tzone)
|
|
64
|
+
assert_page_property __method__
|
|
52
65
|
@will_update = true
|
|
53
66
|
@json["time_zone"] = tzone
|
|
54
67
|
end
|
|
@@ -20,8 +20,9 @@ module NotionRubyMapping
|
|
|
20
20
|
|
|
21
21
|
## Page property only methods
|
|
22
22
|
|
|
23
|
-
# @param [String]
|
|
23
|
+
# @param [String] email
|
|
24
24
|
def email=(email)
|
|
25
|
+
assert_page_property __method__
|
|
25
26
|
@will_update = true
|
|
26
27
|
@json = email
|
|
27
28
|
end
|
|
@@ -31,7 +32,6 @@ module NotionRubyMapping
|
|
|
31
32
|
## Common methods
|
|
32
33
|
|
|
33
34
|
# @param [String] name Property name
|
|
34
|
-
# @param [String] email email value (optional)
|
|
35
35
|
def initialize(name, will_update: false, base_type: :page, json: nil)
|
|
36
36
|
super name, will_update: will_update, base_type: base_type
|
|
37
37
|
@json = json || {}
|
|
@@ -6,20 +6,17 @@ module NotionRubyMapping
|
|
|
6
6
|
include IsEmptyIsNotEmpty
|
|
7
7
|
TYPE = "files"
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## Common methods
|
|
9
|
+
attr_reader :files
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
def files
|
|
15
|
-
@json
|
|
16
|
-
end
|
|
11
|
+
### Public announced methods
|
|
17
12
|
|
|
18
13
|
## Page property only methods
|
|
19
14
|
|
|
20
15
|
def files=(files = [])
|
|
16
|
+
assert_page_property __method__
|
|
21
17
|
@will_update = true
|
|
22
|
-
@
|
|
18
|
+
@files = Array(files).map { |url| FileObject.file_object url }
|
|
19
|
+
@file_names = Array(files)
|
|
23
20
|
end
|
|
24
21
|
|
|
25
22
|
### Not public announced methods
|
|
@@ -31,23 +28,39 @@ module NotionRubyMapping
|
|
|
31
28
|
def initialize(name, will_update: false, base_type: :page, json: nil, files: [])
|
|
32
29
|
super name, will_update: will_update, base_type: base_type
|
|
33
30
|
if database?
|
|
34
|
-
@
|
|
31
|
+
@files = json || {}
|
|
32
|
+
elsif json
|
|
33
|
+
@files = json.map { |sub_json| FileObject.new json: sub_json }
|
|
34
|
+
@file_names = json.map { |sub_json| sub_json["name"] }
|
|
35
|
+
elsif !files.empty?
|
|
36
|
+
@files = Array(files).map { |url| FileObject.file_object url }
|
|
37
|
+
@file_names = Array(files)
|
|
35
38
|
else
|
|
36
|
-
@
|
|
37
|
-
@json = Array(files).map { |url| url_to_hash url } unless files.empty?
|
|
39
|
+
@files = []
|
|
38
40
|
end
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
# @return [Hash]
|
|
42
44
|
def property_values_json
|
|
43
45
|
assert_page_property __method__
|
|
44
|
-
if @
|
|
46
|
+
if @files.map(&:type).include? "file"
|
|
45
47
|
{}
|
|
46
48
|
else
|
|
47
|
-
|
|
49
|
+
files = @files.map(&:property_values_json)
|
|
50
|
+
@file_names&.each_with_index { |name, i| files[i]["name"] = name }
|
|
51
|
+
{@name => {"files" => files, "type" => "files"}}
|
|
48
52
|
end
|
|
49
53
|
end
|
|
50
54
|
|
|
55
|
+
def update_from_json(json)
|
|
56
|
+
return if database?
|
|
57
|
+
|
|
58
|
+
@files = json["files"].map { |sub_json| FileObject.new json: sub_json }
|
|
59
|
+
@file_names = json["files"].map { |sub_json| sub_json["name"] }
|
|
60
|
+
@will_update = false
|
|
61
|
+
p self
|
|
62
|
+
end
|
|
63
|
+
|
|
51
64
|
protected
|
|
52
65
|
|
|
53
66
|
# @param [String] url
|
|
@@ -13,18 +13,22 @@ module NotionRubyMapping
|
|
|
13
13
|
## Common methods
|
|
14
14
|
|
|
15
15
|
# @return [Hash]
|
|
16
|
+
# @see https://www.notion.so/hkob/FormulaProperty-d6b22ca70822407a9fef0bac8925cd0d#4fda982987a141ec962e4cd76cb81f76
|
|
16
17
|
def formula
|
|
17
18
|
@json
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
## Database property only methods
|
|
21
22
|
|
|
23
|
+
# @return [String] formula_expression
|
|
24
|
+
# @see https://www.notion.so/hkob/FormulaProperty-d6b22ca70822407a9fef0bac8925cd0d#a24d2a7b99254d2a9226c00153f1d516
|
|
22
25
|
def formula_expression
|
|
23
26
|
assert_database_property __method__
|
|
24
27
|
@json["expression"]
|
|
25
28
|
end
|
|
26
29
|
|
|
27
|
-
# @param [String]
|
|
30
|
+
# @param [String] f_e
|
|
31
|
+
# @see https://www.notion.so/hkob/FormulaProperty-d6b22ca70822407a9fef0bac8925cd0d#fdb3aaa8d0474440b7ed941673ee13b7
|
|
28
32
|
def formula_expression=(f_e)
|
|
29
33
|
assert_database_property __method__
|
|
30
34
|
@will_update = true
|
|
File without changes
|
data/lib/notion_ruby_mapping/{multi_select_property.rb → properties/multi_select_property.rb}
RENAMED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
module NotionRubyMapping
|
|
4
4
|
# MultiSelect property
|
|
5
5
|
class MultiSelectProperty < MultiProperty
|
|
6
|
-
include ContainsDoesNotContain
|
|
7
|
-
include IsEmptyIsNotEmpty
|
|
8
6
|
TYPE = "multi_select"
|
|
9
7
|
|
|
10
8
|
### Public announced methods
|
|
@@ -27,7 +25,8 @@ module NotionRubyMapping
|
|
|
27
25
|
# @param [String] name
|
|
28
26
|
# @param [String] color
|
|
29
27
|
# @return [Array] added array
|
|
30
|
-
|
|
28
|
+
# @see https://www.notion.so/hkob/MultiSelectProperty-b90bba1c55d540ba97131bb013d4ca74#bcac830b00e04cb6bf7dbbb110d95667
|
|
29
|
+
def add_multi_select_option(name:, color:)
|
|
31
30
|
edit_multi_select_options << {"name" => name, "color" => color}
|
|
32
31
|
end
|
|
33
32
|
|
|
@@ -39,6 +38,7 @@ module NotionRubyMapping
|
|
|
39
38
|
end
|
|
40
39
|
|
|
41
40
|
# @return [Array]
|
|
41
|
+
# @see https://www.notion.so/hkob/MultiSelectProperty-b90bba1c55d540ba97131bb013d4ca74#5ff6ec299cf64049bde2416f61b30fa9
|
|
42
42
|
def multi_select_options
|
|
43
43
|
assert_database_property __method__
|
|
44
44
|
@json["options"] || []
|
|
@@ -49,6 +49,7 @@ module NotionRubyMapping
|
|
|
49
49
|
# @param [Hash] multi_select
|
|
50
50
|
# @return [Array, nil] settled array
|
|
51
51
|
def multi_select=(multi_select)
|
|
52
|
+
assert_page_property __method__
|
|
52
53
|
@will_update = true
|
|
53
54
|
@json = multi_select ? Array(multi_select).map { |ms| {"name" => ms} } : []
|
|
54
55
|
end
|
|
@@ -13,6 +13,7 @@ module NotionRubyMapping
|
|
|
13
13
|
## Common methods
|
|
14
14
|
|
|
15
15
|
# @return [Numeric, Hash]
|
|
16
|
+
# @see https://www.notion.so/hkob/NumberProperty-964ebc1948074d7ca8340187aa352d40#571b41dd33ae42039e6b982a502b7ac7
|
|
16
17
|
def number
|
|
17
18
|
@json
|
|
18
19
|
end
|
|
@@ -20,6 +21,7 @@ module NotionRubyMapping
|
|
|
20
21
|
## Database property only methods
|
|
21
22
|
|
|
22
23
|
# @return [String] new or settled format
|
|
24
|
+
# @see https://www.notion.so/hkob/NumberProperty-964ebc1948074d7ca8340187aa352d40#5e3682ed9e124d518f735b236787d7a7
|
|
23
25
|
def format
|
|
24
26
|
assert_database_property __method__
|
|
25
27
|
@json["format"]
|
|
@@ -27,6 +29,7 @@ module NotionRubyMapping
|
|
|
27
29
|
|
|
28
30
|
# @param [String] format
|
|
29
31
|
# @return [String] settled format
|
|
32
|
+
# @see https://www.notion.so/hkob/NumberProperty-964ebc1948074d7ca8340187aa352d40#89695432078643e48307c348e2983456
|
|
30
33
|
def format=(format)
|
|
31
34
|
assert_database_property __method__
|
|
32
35
|
@will_update = true
|
|
@@ -37,6 +40,7 @@ module NotionRubyMapping
|
|
|
37
40
|
|
|
38
41
|
# @param [Numeric] num
|
|
39
42
|
# @return [Numeric] settled number
|
|
43
|
+
# @see https://www.notion.so/hkob/NumberProperty-964ebc1948074d7ca8340187aa352d40#a3f28cc7029046878dfd694b5b33e8d8
|
|
40
44
|
def number=(num)
|
|
41
45
|
assert_page_property __method__
|
|
42
46
|
@will_update = true
|