notion_ruby_mapping 0.3.3 → 0.4.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 +33 -1228
- data/env.yml.sample +0 -13
- data/lib/notion_ruby_mapping/{base.rb → blocks/base.rb} +155 -88
- data/lib/notion_ruby_mapping/blocks/block.rb +547 -0
- data/lib/notion_ruby_mapping/{database.rb → blocks/database.rb} +34 -7
- data/lib/notion_ruby_mapping/{list.rb → blocks/list.rb} +35 -3
- data/lib/notion_ruby_mapping/blocks/page.rb +71 -0
- data/lib/notion_ruby_mapping/{notion_cache.rb → controllers/notion_cache.rb} +128 -102
- data/lib/notion_ruby_mapping/{payload.rb → controllers/payload.rb} +0 -0
- data/lib/notion_ruby_mapping/{property_cache.rb → controllers/property_cache.rb} +21 -20
- data/lib/notion_ruby_mapping/{query.rb → controllers/query.rb} +26 -18
- data/lib/notion_ruby_mapping/{rich_text_array.rb → controllers/rich_text_array.rb} +26 -15
- 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} +11 -0
- 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} +0 -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 +122 -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} +1 -0
- 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} +4 -0
- 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} +2 -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 -0
- 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} +6 -1
- 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} +5 -0
- data/lib/notion_ruby_mapping/version.rb +1 -1
- data/lib/notion_ruby_mapping.rb +14 -7
- metadata +43 -40
- data/lib/notion_ruby_mapping/block.rb +0 -10
- 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
|
@@ -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, RichTextObject] value
|
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)
|
@@ -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
|
File without changes
|
@@ -0,0 +1,122 @@
|
|
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 [String] rollup Rollup name
|
11
|
+
# @param [String] rollup_type Rollup type
|
12
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
13
|
+
# @see https://www.notion.so/hkob/CheckboxProperty-ac1edbdb8e264af5ad1432b522b429fd#5f07c4ebc4744986bfc99a43827349fc
|
14
|
+
def filter_equals(date, rollup = nil, rollup_type = nil)
|
15
|
+
make_filter_query "equals", value_str(date), rollup, rollup_type
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param [String] rollup Rollup name
|
19
|
+
# @param [String] rollup_type Rollup type
|
20
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
21
|
+
def filter_does_not_equal(date, rollup = nil, rollup_type = nil)
|
22
|
+
make_filter_query "does_not_equal", value_str(date), rollup, rollup_type
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param [String] rollup Rollup name
|
26
|
+
# @param [String] rollup_type Rollup type
|
27
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
28
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#841815bfaf684964bebf3fa6712ae26c
|
29
|
+
def filter_before(date, rollup = nil, rollup_type = nil)
|
30
|
+
make_filter_query "before", value_str(date), rollup, rollup_type
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param [String] rollup Rollup name
|
34
|
+
# @param [String] rollup_type Rollup type
|
35
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
36
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#c0ea140866ea46f9a746b24773dc821c
|
37
|
+
def filter_after(date, rollup = nil, rollup_type = nil)
|
38
|
+
make_filter_query "after", value_str(date), rollup, rollup_type
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param [String] rollup Rollup name
|
42
|
+
# @param [String] rollup_type Rollup type
|
43
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
44
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#6a20ade0ee964aad81aae4c08ea29d6b
|
45
|
+
def filter_on_or_before(date, rollup = nil, rollup_type = nil)
|
46
|
+
make_filter_query "on_or_before", value_str(date), rollup, rollup_type
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param [String] rollup Rollup name
|
50
|
+
# @param [String] rollup_type Rollup type
|
51
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
52
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#1469e3fb3068426a8ea8492d191d1563
|
53
|
+
def filter_on_or_after(date, rollup = nil, rollup_type = nil)
|
54
|
+
make_filter_query "on_or_after", value_str(date), rollup, rollup_type
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param [String] rollup Rollup name
|
58
|
+
# @param [String] rollup_type Rollup type
|
59
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
60
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#707e7e848dc9417998420b65024542db
|
61
|
+
def filter_past_week(rollup = nil, rollup_type = nil)
|
62
|
+
make_filter_query "past_week", {}, rollup, rollup_type
|
63
|
+
end
|
64
|
+
|
65
|
+
# @param [String] rollup Rollup name
|
66
|
+
# @param [String] rollup_type Rollup type
|
67
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
68
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#7b2d05c549204c2eb68d95020d7b97c5
|
69
|
+
def filter_past_month(rollup = nil, rollup_type = nil)
|
70
|
+
make_filter_query "past_month", {}, rollup, rollup_type
|
71
|
+
end
|
72
|
+
|
73
|
+
# @param [String] rollup Rollup name
|
74
|
+
# @param [String] rollup_type Rollup type
|
75
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
76
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#9c8bf0a2398a41c8a0714a62afca3aa8
|
77
|
+
def filter_past_year(rollup = nil, rollup_type = nil)
|
78
|
+
make_filter_query "past_year", {}, rollup, rollup_type
|
79
|
+
end
|
80
|
+
|
81
|
+
# @param [String] rollup Rollup name
|
82
|
+
# @param [String] rollup_type Rollup type
|
83
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
84
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#d9dc189ee8244ba8a6c863259eaa9984
|
85
|
+
def filter_next_week(rollup = nil, rollup_type = nil)
|
86
|
+
make_filter_query "next_week", {}, rollup, rollup_type
|
87
|
+
end
|
88
|
+
|
89
|
+
# @param [String] rollup Rollup name
|
90
|
+
# @param [String] rollup_type Rollup type
|
91
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
92
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#0edb4dffbe6b403882255e870cc71066
|
93
|
+
def filter_next_month(rollup = nil, rollup_type = nil)
|
94
|
+
make_filter_query "next_month", {}, rollup, rollup_type
|
95
|
+
end
|
96
|
+
|
97
|
+
# @param [String] rollup Rollup name
|
98
|
+
# @param [String] rollup_type Rollup type
|
99
|
+
# @return [NotionRubyMapping::Query] generated Query object
|
100
|
+
# @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#b59c73dd4b1a488f95d3e8cd19853709
|
101
|
+
def filter_next_year(rollup = nil, rollup_type = nil)
|
102
|
+
make_filter_query "next_year", {}, rollup, rollup_type
|
103
|
+
end
|
104
|
+
|
105
|
+
protected
|
106
|
+
|
107
|
+
# @param [Date, Time, DateTime, String, nil] obj
|
108
|
+
# @return [String] iso8601 format string
|
109
|
+
def value_str(obj)
|
110
|
+
case obj
|
111
|
+
when Date
|
112
|
+
obj.iso8601
|
113
|
+
when Time
|
114
|
+
obj.strftime("%Y-%m-%dT%H:%M:%S%:z")
|
115
|
+
when DateTime
|
116
|
+
obj.iso8601
|
117
|
+
else
|
118
|
+
obj
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
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
|
@@ -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 } if @file_names
|
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
30
|
# @param [String] formula
|
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
|
|
@@ -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
|
@@ -10,22 +10,27 @@ module NotionRubyMapping
|
|
10
10
|
## Common methods
|
11
11
|
|
12
12
|
# @return [Array, Hash]
|
13
|
+
# @see https://www.notion.so/hkob/PeopleProperty-144355d25f0e4feba9ae39fe28ca6ae7#7e3e56c2080d4834902cfa0223e807e5
|
13
14
|
def people
|
14
15
|
@json
|
15
16
|
end
|
16
17
|
|
17
18
|
## Page property only methods
|
18
19
|
|
19
|
-
# @param [String, NotionRubyMapping::UserObject]
|
20
|
+
# @param [String, NotionRubyMapping::UserObject] user_id_or_uo
|
20
21
|
# @return [Array<UserObject>]
|
21
|
-
|
22
|
+
# @see https://www.notion.so/hkob/PeopleProperty-144355d25f0e4feba9ae39fe28ca6ae7#26344b145a254cc58dd845780e0a26ea
|
23
|
+
def add_person(user_id_or_uo)
|
24
|
+
assert_page_property __method__
|
22
25
|
@will_update = true
|
23
|
-
@json << UserObject.user_object(
|
26
|
+
@json << UserObject.user_object(user_id_or_uo)
|
24
27
|
end
|
25
28
|
|
26
29
|
# @param [Hash] people
|
27
30
|
# @return [Array, nil] replaced array
|
31
|
+
# @see https://www.notion.so/hkob/PeopleProperty-144355d25f0e4feba9ae39fe28ca6ae7#815acfef9a664e3e8915fb31b8fefc42
|
28
32
|
def people=(people)
|
33
|
+
assert_page_property __method__
|
29
34
|
@will_update = true
|
30
35
|
@json = people ? Array(people).map { |uo| UserObject.user_object(uo) } : []
|
31
36
|
end
|
data/lib/notion_ruby_mapping/{phone_number_property.rb → properties/phone_number_property.rb}
RENAMED
@@ -14,13 +14,17 @@ module NotionRubyMapping
|
|
14
14
|
## Common methods
|
15
15
|
|
16
16
|
# @return [String, Hash, nil] phone number (Page), {} (Database)
|
17
|
+
# @see https://www.notion.so/hkob/PhoneNumberProperty-5df14aaa938c4888aecd53ab6752d2e6#40bceda04fe04c64b932d6a1ed180eaa
|
17
18
|
def phone_number
|
18
19
|
@json
|
19
20
|
end
|
20
21
|
|
21
22
|
## Page property only methods
|
22
23
|
|
24
|
+
# @param [String] phone_number
|
25
|
+
# @see https://www.notion.so/hkob/PhoneNumberProperty-5df14aaa938c4888aecd53ab6752d2e6#dc7e00e0558d40f79ca5cade1fccef29
|
23
26
|
def phone_number=(phone_number)
|
27
|
+
assert_page_property __method__
|
24
28
|
@will_update = true
|
25
29
|
@json = phone_number
|
26
30
|
end
|