notion_ruby_mapping 4.0.2 → 4.2.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/CHANGELOG.md +21 -1
- data/README.md +5 -3
- data/lib/notion_ruby_mapping/blocks/block.rb +51 -48
- data/lib/notion_ruby_mapping/blocks/breadcrumb_block.rb +4 -4
- data/lib/notion_ruby_mapping/blocks/callout_block.rb +6 -1
- data/lib/notion_ruby_mapping/blocks/divider_block.rb +4 -4
- data/lib/notion_ruby_mapping/blocks/equation_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/file_base_block.rb +48 -19
- data/lib/notion_ruby_mapping/blocks/file_block.rb +4 -2
- data/lib/notion_ruby_mapping/blocks/heading1_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/heading2_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/heading3_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/heading4_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/list.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/table_of_contents_block.rb +6 -5
- data/lib/notion_ruby_mapping/controllers/mermaid_data_source.rb +3 -3
- data/lib/notion_ruby_mapping/controllers/rich_text_array.rb +6 -1
- data/lib/notion_ruby_mapping/objects/equation_object.rb +6 -4
- data/lib/notion_ruby_mapping/objects/file_object.rb +50 -25
- data/lib/notion_ruby_mapping/objects/file_upload_object.rb +114 -68
- data/lib/notion_ruby_mapping/properties/button_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/checkbox_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/created_time_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/email_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/files_property.rb +10 -16
- data/lib/notion_ruby_mapping/properties/last_edited_by_property.rb +0 -1
- data/lib/notion_ruby_mapping/properties/last_edited_time_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/multi_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/multi_select_property.rb +11 -11
- data/lib/notion_ruby_mapping/properties/number_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/people_property.rb +24 -5
- data/lib/notion_ruby_mapping/properties/phone_number_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/property.rb +14 -35
- data/lib/notion_ruby_mapping/properties/relation_property.rb +7 -7
- data/lib/notion_ruby_mapping/properties/rich_text_property.rb +0 -22
- data/lib/notion_ruby_mapping/properties/select_property.rb +11 -11
- data/lib/notion_ruby_mapping/properties/status_property.rb +50 -2
- data/lib/notion_ruby_mapping/properties/text_property.rb +59 -1
- data/lib/notion_ruby_mapping/properties/title_property.rb +0 -38
- data/lib/notion_ruby_mapping/properties/unique_id_property.rb +39 -3
- data/lib/notion_ruby_mapping/properties/url_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/verification_property.rb +8 -12
- data/lib/notion_ruby_mapping/version.rb +1 -1
- metadata +2 -2
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "forwardable"
|
|
4
|
-
|
|
5
3
|
module NotionRubyMapping
|
|
6
4
|
# abstract class for property
|
|
7
5
|
class Property
|
|
8
|
-
extend Forwardable
|
|
9
|
-
|
|
10
6
|
### Public announced methods
|
|
11
7
|
|
|
12
8
|
## Common methods
|
|
@@ -14,18 +10,6 @@ module NotionRubyMapping
|
|
|
14
10
|
attr_reader :name, :will_update, :property_id
|
|
15
11
|
attr_accessor :property_cache
|
|
16
12
|
|
|
17
|
-
def_delegators :retrieve_page_property, :<<, :[], :add_person, :add_relation, :checkbox, :checkbox=, :created_by,
|
|
18
|
-
:created_time, :date, :each, :email, :email=, :end_date, :end_date=, :files, :files=, :filter_after,
|
|
19
|
-
:filter_before, :filter_contains, :filter_does_not_contain, :filter_does_not_equal,
|
|
20
|
-
:filter_ends_with, :filter_equals, :filter_greater_than, :filter_greater_than_or_equal_to,
|
|
21
|
-
:filter_is_empty, :filter_is_not_empty, :filter_less_than, :filter_less_than_or_equal_to,
|
|
22
|
-
:filter_next_month, :filter_next_week, :filter_next_year, :filter_on_or_after, :filter_on_or_before,
|
|
23
|
-
:filter_past_month, :filter_past_week, :filter_past_year, :filter_starts_with, :formula, :full_text,
|
|
24
|
-
:last_edited_by, :last_edited_time, :multi_select, :multi_select=, :multi_select_names, :number,
|
|
25
|
-
:number=, :people, :people=, :phone_number, :phone_number=, :property_values_json, :relation=,
|
|
26
|
-
:rollup, :start_date, :start_date=, :time_zone, :time_zone=, :select, :select=, :select_name, :url,
|
|
27
|
-
:url=, :start_date_obj, :end_date_obj
|
|
28
|
-
|
|
29
13
|
## Database property only methods
|
|
30
14
|
|
|
31
15
|
# @param [String] new_name
|
|
@@ -72,12 +56,13 @@ module NotionRubyMapping
|
|
|
72
56
|
|
|
73
57
|
type = input_json["type"]
|
|
74
58
|
if type.nil?
|
|
75
|
-
|
|
59
|
+
raise StandardError, "Property value is not returned: #{name}"
|
|
76
60
|
elsif type == "property_item"
|
|
77
61
|
tmp = new name, property_id: input_json["property_item"]["id"], base_type: base_type,
|
|
78
62
|
property_cache: property_cache, query: query
|
|
79
63
|
objects = List.new(json: input_json, type: "property", value: tmp, query: query).to_a
|
|
80
|
-
|
|
64
|
+
input_type = input_json["property_item"]["type"]
|
|
65
|
+
case input_type
|
|
81
66
|
when "people"
|
|
82
67
|
PeopleProperty.new name, people: objects, base_type: base_type,
|
|
83
68
|
property_cache: property_cache, query: query
|
|
@@ -94,7 +79,7 @@ module NotionRubyMapping
|
|
|
94
79
|
TitleProperty.new name, text_objects: objects, base_type: base_type,
|
|
95
80
|
property_cache: property_cache, query: query
|
|
96
81
|
else
|
|
97
|
-
raise StandardError, "
|
|
82
|
+
raise StandardError, "Unsupported property type: #{input_type} (#{name}). Please update notion_ruby_mapping."
|
|
98
83
|
end
|
|
99
84
|
else
|
|
100
85
|
klass = {
|
|
@@ -123,7 +108,10 @@ module NotionRubyMapping
|
|
|
123
108
|
url: UrlProperty,
|
|
124
109
|
verification: VerificationProperty,
|
|
125
110
|
}[type.to_sym]
|
|
126
|
-
|
|
111
|
+
unless klass
|
|
112
|
+
raise StandardError,
|
|
113
|
+
"Unsupported property type: #{type} (#{name}). Please update notion_ruby_mapping."
|
|
114
|
+
end
|
|
127
115
|
|
|
128
116
|
answer = klass.new name, property_id: input_json["id"], json: input_json[type], base_type: base_type,
|
|
129
117
|
property_cache: property_cache
|
|
@@ -152,11 +140,6 @@ module NotionRubyMapping
|
|
|
152
140
|
%w[database data_source].include? @base_type
|
|
153
141
|
end
|
|
154
142
|
|
|
155
|
-
# @return [TrueClass, FalseClass] true if it has Property contents
|
|
156
|
-
def contents?
|
|
157
|
-
!instance_of? Property
|
|
158
|
-
end
|
|
159
|
-
|
|
160
143
|
# @param [String] key query parameter
|
|
161
144
|
# @param [Object] value query value
|
|
162
145
|
# @return [NotionRubyMapping::Query] generated Query object
|
|
@@ -180,26 +163,21 @@ module NotionRubyMapping
|
|
|
180
163
|
# @param [Hash] json
|
|
181
164
|
def update_from_json(json)
|
|
182
165
|
@will_update = false
|
|
183
|
-
return unless
|
|
166
|
+
return unless json.key?(type)
|
|
184
167
|
|
|
185
|
-
@json = json[type]
|
|
168
|
+
@json = json[type]
|
|
186
169
|
end
|
|
187
170
|
|
|
188
|
-
# @return [
|
|
171
|
+
# @return [String] property type
|
|
189
172
|
def type
|
|
190
173
|
self.class::TYPE
|
|
191
174
|
end
|
|
192
175
|
|
|
193
176
|
## Database property only methods
|
|
194
177
|
|
|
195
|
-
# @param [Symbol, nil] method
|
|
196
|
-
def assert_database_property(method)
|
|
197
|
-
raise StandardError, "#{method} can execute only Database property." unless database?
|
|
198
|
-
end
|
|
199
|
-
|
|
200
178
|
# @param [Symbol, nil] method
|
|
201
179
|
def assert_database_or_data_source_property(method)
|
|
202
|
-
raise StandardError, "#{method} can execute only Database property."
|
|
180
|
+
raise StandardError, "#{method} can execute only Database or DataSource property." unless database_or_data_source?
|
|
203
181
|
end
|
|
204
182
|
|
|
205
183
|
# @return [Hash]
|
|
@@ -209,6 +187,7 @@ module NotionRubyMapping
|
|
|
209
187
|
end
|
|
210
188
|
|
|
211
189
|
## DataSource property only methods
|
|
190
|
+
# @param [Symbol, nil] method
|
|
212
191
|
def assert_data_source_property(method)
|
|
213
192
|
raise StandardError, "#{method} can execute only DataSource property." unless data_source?
|
|
214
193
|
end
|
|
@@ -229,7 +208,7 @@ module NotionRubyMapping
|
|
|
229
208
|
|
|
230
209
|
# @param [Symbol, nil] method
|
|
231
210
|
def assert_page_property(method)
|
|
232
|
-
raise StandardError, "#{method} can execute only Page property."
|
|
211
|
+
raise StandardError, "#{method} can execute only Page property." unless page?
|
|
233
212
|
end
|
|
234
213
|
|
|
235
214
|
# @return [NotionRubyMapping::Property, Array<UserObject>, nil]
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module NotionRubyMapping
|
|
4
|
-
#
|
|
4
|
+
# Relation property
|
|
5
5
|
class RelationProperty < MultiProperty
|
|
6
6
|
TYPE = "relation"
|
|
7
|
+
RELATION_PROPERTY_TYPES = %w[dual_property single_property].freeze
|
|
7
8
|
|
|
8
9
|
### Public announced methods
|
|
9
10
|
|
|
10
11
|
## Common methods
|
|
11
12
|
|
|
12
|
-
# @return [Hash
|
|
13
|
+
# @return [Array<Hash>, Hash, nil] relation value or relation schema
|
|
13
14
|
# @see https://www.notion.so/hkob/RelationProperty-f608ab41a1f0476b98456620346fba03#6c14207b2d1340d2bbc08d17eee2cb22
|
|
14
15
|
def relation
|
|
15
16
|
@json
|
|
@@ -35,6 +36,7 @@ module NotionRubyMapping
|
|
|
35
36
|
def relation=(page_ids_or_jsons)
|
|
36
37
|
assert_page_property __method__
|
|
37
38
|
@will_update = true
|
|
39
|
+
page_ids_or_jsons = [] if page_ids_or_jsons.nil?
|
|
38
40
|
page_ids_or_jsons = [page_ids_or_jsons] unless page_ids_or_jsons.is_a? Array
|
|
39
41
|
|
|
40
42
|
@json = page_ids_or_jsons.map do |page_id_or_json|
|
|
@@ -47,7 +49,7 @@ module NotionRubyMapping
|
|
|
47
49
|
# @return [String] relation data_source_id
|
|
48
50
|
# @see https://www.notion.so/hkob/RelationProperty-f608ab41a1f0476b98456620346fba03#eb40f1a2ad5c4e368d343870a7e529f9
|
|
49
51
|
def relation_data_source_id
|
|
50
|
-
|
|
52
|
+
assert_database_or_data_source_property __method__
|
|
51
53
|
@json["data_source_id"]
|
|
52
54
|
end
|
|
53
55
|
|
|
@@ -56,6 +58,8 @@ module NotionRubyMapping
|
|
|
56
58
|
# @see https://www.notion.so/hkob/RelationProperty-f608ab41a1f0476b98456620346fba03#7f5029fb7f6e4c009f22888b233e6f64
|
|
57
59
|
def replace_relation_data_source(data_source_id: nil, type: "dual_property")
|
|
58
60
|
assert_database_or_data_source_property __method__
|
|
61
|
+
raise ArgumentError, "type must be dual_property or single_property" unless RELATION_PROPERTY_TYPES.include? type
|
|
62
|
+
|
|
59
63
|
@will_update = true
|
|
60
64
|
@json["data_source_id"] = data_source_id if data_source_id
|
|
61
65
|
@json["type"] = type
|
|
@@ -97,10 +101,6 @@ module NotionRubyMapping
|
|
|
97
101
|
ans
|
|
98
102
|
end
|
|
99
103
|
|
|
100
|
-
def data_source_id
|
|
101
|
-
@json["data_source_id"]
|
|
102
|
-
end
|
|
103
|
-
|
|
104
104
|
# @return [TrueClass, FalseClass] true if dual_property
|
|
105
105
|
def dual_property?
|
|
106
106
|
assert_database_or_data_source_property __method__
|
|
@@ -9,28 +9,6 @@ module NotionRubyMapping
|
|
|
9
9
|
|
|
10
10
|
## Common methods
|
|
11
11
|
|
|
12
|
-
# @param [Hash] json
|
|
13
|
-
def update_from_json(json)
|
|
14
|
-
@will_update = false
|
|
15
|
-
if database_or_data_source?
|
|
16
|
-
@json = json["rich_text"] || {}
|
|
17
|
-
else
|
|
18
|
-
@text_objects = RichTextArray.new "rich_text", json: json["rich_text"]
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
12
|
## Page property only methods
|
|
23
|
-
|
|
24
|
-
# @return [Hash] created json
|
|
25
|
-
def property_values_json
|
|
26
|
-
assert_page_property __method__
|
|
27
|
-
text_json = @text_objects.map(&:property_values_json)
|
|
28
|
-
{
|
|
29
|
-
@name => {
|
|
30
|
-
"type" => "rich_text",
|
|
31
|
-
"rich_text" => text_json.empty? ? (@json || []) : text_json,
|
|
32
|
-
},
|
|
33
|
-
}
|
|
34
|
-
end
|
|
35
13
|
end
|
|
36
14
|
end
|
|
@@ -11,7 +11,7 @@ module NotionRubyMapping
|
|
|
11
11
|
|
|
12
12
|
## Common methods
|
|
13
13
|
|
|
14
|
-
# @return [Hash]
|
|
14
|
+
# @return [Hash] raw select object for page property, or select schema object for database/data_source property
|
|
15
15
|
# @see https://www.notion.so/hkob/SelectProperty-6d6a0defa70d4b26af0fdbdcfbf99f28#7ad3734ac42c43068f1e04633bab400b
|
|
16
16
|
def select
|
|
17
17
|
@json
|
|
@@ -19,7 +19,7 @@ module NotionRubyMapping
|
|
|
19
19
|
|
|
20
20
|
## Page property only methods
|
|
21
21
|
|
|
22
|
-
# @return [String]
|
|
22
|
+
# @return [String, nil]
|
|
23
23
|
# @see https://www.notion.so/hkob/SelectProperty-6d6a0defa70d4b26af0fdbdcfbf99f28#27a05e52715a4acd9156b5f146653e51
|
|
24
24
|
def select_name
|
|
25
25
|
assert_page_property __method__
|
|
@@ -30,27 +30,27 @@ module NotionRubyMapping
|
|
|
30
30
|
|
|
31
31
|
# @param [String] name
|
|
32
32
|
# @param [String] color
|
|
33
|
-
# @return [Array]
|
|
33
|
+
# @return [Array<Hash>] updated select options
|
|
34
34
|
# @see https://www.notion.so/hkob/SelectProperty-6d6a0defa70d4b26af0fdbdcfbf99f28#3e1c7dbda7fb455f94ee93d9653b7880
|
|
35
35
|
def add_select_option(name:, color:)
|
|
36
36
|
edit_select_options << {"name" => name, "color" => color}
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
# @return [Array]
|
|
39
|
+
# @return [Array<Hash>] editable select options
|
|
40
40
|
def edit_select_options
|
|
41
41
|
assert_database_or_data_source_property __method__
|
|
42
42
|
@will_update = true
|
|
43
43
|
@json["options"] ||= []
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
# @return [Array]
|
|
46
|
+
# @return [Array<Hash>]
|
|
47
47
|
# @see https://www.notion.so/hkob/SelectProperty-6d6a0defa70d4b26af0fdbdcfbf99f28#790a297f2c1b4ba5a4d86074d4c70a89
|
|
48
48
|
def select_options
|
|
49
49
|
assert_database_or_data_source_property __method__
|
|
50
50
|
@json["options"] || []
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
# @return [String]
|
|
53
|
+
# @return [Array<String>]
|
|
54
54
|
# @see https://www.notion.so/hkob/SelectProperty-6d6a0defa70d4b26af0fdbdcfbf99f28#72da1632793c4a5296f3bc89de2df413
|
|
55
55
|
def select_names
|
|
56
56
|
assert_database_or_data_source_property __method__
|
|
@@ -59,12 +59,12 @@ module NotionRubyMapping
|
|
|
59
59
|
|
|
60
60
|
## Page property only methods
|
|
61
61
|
|
|
62
|
-
# @param [String]
|
|
62
|
+
# @param [String, nil] name
|
|
63
63
|
# @see https://www.notion.so/hkob/SelectProperty-6d6a0defa70d4b26af0fdbdcfbf99f28#3bd195bf5c0a498ebf850409f7deb67a
|
|
64
|
-
def select=(
|
|
64
|
+
def select=(name)
|
|
65
65
|
assert_page_property __method__
|
|
66
66
|
@will_update = true
|
|
67
|
-
@json = {"name" =>
|
|
67
|
+
@json = {"name" => name}
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
### Not public announced methods
|
|
@@ -72,8 +72,8 @@ module NotionRubyMapping
|
|
|
72
72
|
## Common methods
|
|
73
73
|
|
|
74
74
|
# @param [String, Symbol] name Property name
|
|
75
|
-
# @param [Hash] json
|
|
76
|
-
# @param [String] select
|
|
75
|
+
# @param [Hash, nil] json
|
|
76
|
+
# @param [String, nil] select select option name (optional)
|
|
77
77
|
def initialize(name, will_update: false, base_type: "page", json: nil, select: nil, property_id: nil,
|
|
78
78
|
property_cache: nil)
|
|
79
79
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
|
@@ -25,8 +25,6 @@ module NotionRubyMapping
|
|
|
25
25
|
@json["name"]
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
## Page property only methods
|
|
29
|
-
|
|
30
28
|
# @param [String] status
|
|
31
29
|
# @see https://www.notion.so/hkob/StatusProperty-c8b2c83019bc42edbc1527386c7ef453#b3fba1b6322140f28308de3ba70a8b7b
|
|
32
30
|
def status=(status)
|
|
@@ -35,6 +33,35 @@ module NotionRubyMapping
|
|
|
35
33
|
@json = {"name" => status}
|
|
36
34
|
end
|
|
37
35
|
|
|
36
|
+
## Database or DataSource property only methods
|
|
37
|
+
# @param [String] name
|
|
38
|
+
# @param [String] color
|
|
39
|
+
# @return [Array<Hash>] updated status options
|
|
40
|
+
def add_status_option(name:, color:, group: nil)
|
|
41
|
+
hash = {"name" => name, "color" => color}
|
|
42
|
+
hash["group"] = group if group
|
|
43
|
+
edit_status_options << hash
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @return [Array<Hash>] editable status options
|
|
47
|
+
def edit_status_options
|
|
48
|
+
assert_database_or_data_source_property __method__
|
|
49
|
+
@will_update = true
|
|
50
|
+
@json["edit_options"] ||= []
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# @return [Array<Hash>] status options
|
|
54
|
+
def status_options
|
|
55
|
+
assert_database_or_data_source_property __method__
|
|
56
|
+
@json["options"] || []
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# @return [Array<String>] status option names
|
|
60
|
+
def status_names
|
|
61
|
+
assert_database_or_data_source_property __method__
|
|
62
|
+
status_options.map { |s| s["name"] }
|
|
63
|
+
end
|
|
64
|
+
|
|
38
65
|
### Not public announced methods
|
|
39
66
|
|
|
40
67
|
## Common methods
|
|
@@ -54,5 +81,26 @@ module NotionRubyMapping
|
|
|
54
81
|
assert_page_property __method__
|
|
55
82
|
{@name => {"status" => @json, "type" => "status"}}
|
|
56
83
|
end
|
|
84
|
+
|
|
85
|
+
## Database property only methods
|
|
86
|
+
|
|
87
|
+
# @return [Hash]
|
|
88
|
+
def update_property_schema_json
|
|
89
|
+
assert_database_or_data_source_property __method__
|
|
90
|
+
ans = super
|
|
91
|
+
return ans if ans != {} || !@will_update
|
|
92
|
+
|
|
93
|
+
ans[@name] ||= {}
|
|
94
|
+
ans[@name]["status"] ||= {}
|
|
95
|
+
ans[@name]["status"]["options"] = @json["edit_options"]
|
|
96
|
+
ans
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
## Database property only methods
|
|
100
|
+
|
|
101
|
+
# @return [Hash]
|
|
102
|
+
def property_schema_json_sub
|
|
103
|
+
@json["edit_options"] ? {"options" => @json["edit_options"]} : {}
|
|
104
|
+
end
|
|
57
105
|
end
|
|
58
106
|
end
|
|
@@ -5,6 +5,7 @@ require "forwardable"
|
|
|
5
5
|
module NotionRubyMapping
|
|
6
6
|
# Text property
|
|
7
7
|
class TextProperty < Property
|
|
8
|
+
TYPE = "text"
|
|
8
9
|
extend Forwardable
|
|
9
10
|
include Enumerable
|
|
10
11
|
include EqualsDoesNotEqual
|
|
@@ -36,10 +37,67 @@ module NotionRubyMapping
|
|
|
36
37
|
@text_objects = if database_or_data_source?
|
|
37
38
|
json || {}
|
|
38
39
|
else
|
|
39
|
-
RichTextArray.new
|
|
40
|
+
RichTextArray.new self.class::TYPE, json: json, text_objects: text_objects
|
|
40
41
|
end
|
|
41
42
|
end
|
|
42
43
|
|
|
44
|
+
def self.rich_text_array_from_json(json)
|
|
45
|
+
if json["object"] == "list"
|
|
46
|
+
rich_text_objects = List.new(json: json, type: "property", value: self).select { true }
|
|
47
|
+
RichTextArray.rich_text_array self::TYPE, rich_text_objects
|
|
48
|
+
else
|
|
49
|
+
RichTextArray.new self::TYPE, json: json[self::TYPE]
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# @return [Hash] created json
|
|
54
|
+
def property_values_json
|
|
55
|
+
assert_page_property __method__
|
|
56
|
+
text_json = @text_objects.map(&:property_values_json)
|
|
57
|
+
{
|
|
58
|
+
@name => {
|
|
59
|
+
"type" => self.class::TYPE,
|
|
60
|
+
self.class::TYPE => text_json.empty? ? (@json || []) : text_json,
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Replaces all rich text objects with a single plain text object.
|
|
66
|
+
#
|
|
67
|
+
# This method does not preserve annotations, links, mentions, or equations.
|
|
68
|
+
#
|
|
69
|
+
# @param [String] text
|
|
70
|
+
# @raise [ArgumentError] if text is nil
|
|
71
|
+
def plain_text=(text)
|
|
72
|
+
assert_page_property __method__
|
|
73
|
+
raise ArgumentError if text.nil?
|
|
74
|
+
|
|
75
|
+
@text_objects = RichTextArray.new(
|
|
76
|
+
self.class::TYPE,
|
|
77
|
+
text_objects: text,
|
|
78
|
+
)
|
|
79
|
+
@will_update = true
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# @param [Hash] json
|
|
83
|
+
def update_from_json(json)
|
|
84
|
+
@will_update = false
|
|
85
|
+
if database_or_data_source?
|
|
86
|
+
@json = json[self.class::TYPE] || {}
|
|
87
|
+
else
|
|
88
|
+
@text_objects = self.class.rich_text_array_from_json json
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Removes all rich text objects.
|
|
93
|
+
#
|
|
94
|
+
# This method makes the property value an empty rich text array.
|
|
95
|
+
def clear
|
|
96
|
+
assert_page_property __method__
|
|
97
|
+
@text_objects.clear
|
|
98
|
+
@will_update = true
|
|
99
|
+
end
|
|
100
|
+
|
|
43
101
|
# @return [FalseClass]
|
|
44
102
|
def clear_will_update
|
|
45
103
|
super
|
|
@@ -9,44 +9,6 @@ module NotionRubyMapping
|
|
|
9
9
|
|
|
10
10
|
## Common methods
|
|
11
11
|
|
|
12
|
-
def self.rich_text_array_from_json(json)
|
|
13
|
-
if json["object"] == "list"
|
|
14
|
-
rich_text_objects = List.new(json: json, type: "property", value: self).select { true }
|
|
15
|
-
RichTextArray.rich_text_array "title", rich_text_objects
|
|
16
|
-
else
|
|
17
|
-
RichTextArray.new "title", json: json["title"]
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# @param [Hash] json
|
|
22
|
-
def update_from_json(json)
|
|
23
|
-
@will_update = false
|
|
24
|
-
if database_or_data_source?
|
|
25
|
-
@json = json || {}
|
|
26
|
-
else
|
|
27
|
-
@text_objects = TitleProperty.rich_text_array_from_json json
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
12
|
## Page property only methods
|
|
32
|
-
|
|
33
|
-
# @return [FalseClass]
|
|
34
|
-
def clear_will_update
|
|
35
|
-
super
|
|
36
|
-
@text_objects.clear_will_update
|
|
37
|
-
false
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# @return [Hash] created json
|
|
41
|
-
def property_values_json
|
|
42
|
-
assert_page_property __method__
|
|
43
|
-
text_json = map(&:property_values_json)
|
|
44
|
-
{
|
|
45
|
-
@name => {
|
|
46
|
-
"type" => "title",
|
|
47
|
-
"title" => text_json.empty? ? @json : text_json,
|
|
48
|
-
},
|
|
49
|
-
}
|
|
50
|
-
end
|
|
51
13
|
end
|
|
52
14
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module NotionRubyMapping
|
|
4
|
-
#
|
|
4
|
+
# Unique ID property
|
|
5
5
|
class UniqueIdProperty < Property
|
|
6
6
|
include EqualsDoesNotEqual
|
|
7
7
|
include GreaterThanLessThan
|
|
@@ -17,8 +17,26 @@ module NotionRubyMapping
|
|
|
17
17
|
@json
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
# @return [String, nil]
|
|
21
|
+
def prefix
|
|
22
|
+
@json && @json["prefix"]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @return [Integer, nil]
|
|
26
|
+
def number
|
|
27
|
+
@json && @json["number"]
|
|
28
|
+
end
|
|
29
|
+
|
|
20
30
|
## Database property only methods
|
|
21
31
|
|
|
32
|
+
# @param [String, nil] prefix
|
|
33
|
+
# @return [String, nil]
|
|
34
|
+
def prefix=(prefix)
|
|
35
|
+
assert_database_or_data_source_property __method__
|
|
36
|
+
@will_update = true
|
|
37
|
+
@json["prefix"] = prefix
|
|
38
|
+
end
|
|
39
|
+
|
|
22
40
|
## Page property only methods
|
|
23
41
|
|
|
24
42
|
### Not public announced methods
|
|
@@ -26,7 +44,7 @@ module NotionRubyMapping
|
|
|
26
44
|
## Common methods
|
|
27
45
|
|
|
28
46
|
# @param [String] name Property name
|
|
29
|
-
# @param [
|
|
47
|
+
# @param [Hash, nil] json unique_id Hash
|
|
30
48
|
def initialize(name, will_update: false, base_type: "page", json: nil, property_id: nil, property_cache: nil)
|
|
31
49
|
super name, will_update: will_update, base_type: base_type, property_id: property_id, property_cache: property_cache
|
|
32
50
|
@json = json
|
|
@@ -34,7 +52,7 @@ module NotionRubyMapping
|
|
|
34
52
|
end
|
|
35
53
|
|
|
36
54
|
# @param [Hash] json
|
|
37
|
-
# @return [NotionRubyMapping::
|
|
55
|
+
# @return [NotionRubyMapping::UniqueIdProperty]
|
|
38
56
|
def update_from_json(json)
|
|
39
57
|
@will_update = false
|
|
40
58
|
@json = json["unique_id"]
|
|
@@ -43,6 +61,17 @@ module NotionRubyMapping
|
|
|
43
61
|
|
|
44
62
|
## Database property only methods
|
|
45
63
|
|
|
64
|
+
# @return [Hash]
|
|
65
|
+
def update_property_schema_json
|
|
66
|
+
assert_database_or_data_source_property __method__
|
|
67
|
+
ans = super
|
|
68
|
+
return ans if ans != {} || !@will_update
|
|
69
|
+
|
|
70
|
+
ans[@name] ||= {}
|
|
71
|
+
ans[@name]["unique_id"] = @json
|
|
72
|
+
ans
|
|
73
|
+
end
|
|
74
|
+
|
|
46
75
|
## Page property only methods
|
|
47
76
|
|
|
48
77
|
# @return [Hash]
|
|
@@ -51,6 +80,13 @@ module NotionRubyMapping
|
|
|
51
80
|
{@name => {"unique_id" => @json, "type" => "unique_id"}}
|
|
52
81
|
end
|
|
53
82
|
|
|
83
|
+
protected
|
|
84
|
+
|
|
54
85
|
## Database property only methods
|
|
86
|
+
|
|
87
|
+
# @return [Hash]
|
|
88
|
+
def property_schema_json_sub
|
|
89
|
+
{"prefix" => prefix}
|
|
90
|
+
end
|
|
55
91
|
end
|
|
56
92
|
end
|
|
@@ -13,7 +13,7 @@ module NotionRubyMapping
|
|
|
13
13
|
|
|
14
14
|
## Common methods
|
|
15
15
|
|
|
16
|
-
# @return [String, Hash, nil]
|
|
16
|
+
# @return [String, Hash, nil] URL for page properties, empty hash for database/data source properties
|
|
17
17
|
# @see https://www.notion.so/hkob/UrlProperty-8a0094fdf6494151983cb4694f6626cc#8342eef7df3c43eaad10c48d4757b4ae
|
|
18
18
|
def url
|
|
19
19
|
@json
|
|
@@ -21,7 +21,7 @@ module NotionRubyMapping
|
|
|
21
21
|
|
|
22
22
|
## Page property only methods
|
|
23
23
|
|
|
24
|
-
# @param [String] url
|
|
24
|
+
# @param [String, nil] url
|
|
25
25
|
# @see https://www.notion.so/hkob/UrlProperty-8a0094fdf6494151983cb4694f6626cc#cfa5463a121b4002b250b38d7d0a0d34
|
|
26
26
|
def url=(url)
|
|
27
27
|
assert_page_property __method__
|
|
@@ -37,7 +37,7 @@ module NotionRubyMapping
|
|
|
37
37
|
def initialize(name, will_update: false, base_type: "page", json: nil, property_id: nil, property_cache: nil)
|
|
38
38
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
|
39
39
|
property_cache: property_cache
|
|
40
|
-
@json =
|
|
40
|
+
@json = database_or_data_source? ? {} : json
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
## Page property only methods
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module NotionRubyMapping
|
|
4
|
-
#
|
|
4
|
+
# Verification property
|
|
5
5
|
class VerificationProperty < Property
|
|
6
6
|
TYPE = "verification"
|
|
7
7
|
|
|
@@ -9,21 +9,16 @@ module NotionRubyMapping
|
|
|
9
9
|
|
|
10
10
|
## Common methods
|
|
11
11
|
|
|
12
|
-
# @see https://www.notion.so/hkob/StatusProperty-c8b2c83019bc42edbc1527386c7ef453#bdb34c0aeaa74729887da087d0bd8022
|
|
13
12
|
def verification
|
|
14
13
|
@json
|
|
15
14
|
end
|
|
16
15
|
|
|
17
|
-
## Page property only methods
|
|
18
|
-
|
|
19
|
-
## Page property only methods
|
|
20
|
-
|
|
21
16
|
### Not public announced methods
|
|
22
17
|
|
|
23
18
|
## Common methods
|
|
24
19
|
|
|
25
20
|
# @param [String, Symbol] name Property name
|
|
26
|
-
# @param [
|
|
21
|
+
# @param [Hash] json
|
|
27
22
|
def initialize(name, will_update: false, base_type: "page", property_id: nil, property_cache: nil, json: {})
|
|
28
23
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
|
29
24
|
property_cache: property_cache
|
|
@@ -32,11 +27,12 @@ module NotionRubyMapping
|
|
|
32
27
|
|
|
33
28
|
## DataSource only methods
|
|
34
29
|
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
# @param [String]
|
|
38
|
-
# @
|
|
39
|
-
# @
|
|
30
|
+
# Creates a filter query for the verification status.
|
|
31
|
+
#
|
|
32
|
+
# @param [String] value Verification status. Expected values are "verified", "expired", and "none".
|
|
33
|
+
# @param [String, nil] condition Rollup condition name.
|
|
34
|
+
# @param [String, nil] another_type Rollup target type.
|
|
35
|
+
# @return [NotionRubyMapping::Query] Generated Query object.
|
|
40
36
|
def filter_status(value, condition: nil, another_type: nil)
|
|
41
37
|
make_filter_query "status", value, condition: condition, another_type: another_type
|
|
42
38
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: notion_ruby_mapping
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.0
|
|
4
|
+
version: 4.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hiroyuki KOBAYASHI
|
|
@@ -349,7 +349,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
349
349
|
- !ruby/object:Gem::Version
|
|
350
350
|
version: '0'
|
|
351
351
|
requirements: []
|
|
352
|
-
rubygems_version: 4.0.
|
|
352
|
+
rubygems_version: 4.0.16
|
|
353
353
|
specification_version: 4
|
|
354
354
|
summary: Notion Ruby mapping tool
|
|
355
355
|
test_files: []
|