notion_ruby_mapping 0.8.9 → 1.0.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/.rubocop.yml +12 -1
- data/lib/notion_ruby_mapping/blocks/base.rb +33 -33
- data/lib/notion_ruby_mapping/blocks/block.rb +48 -47
- data/lib/notion_ruby_mapping/blocks/bookmark_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/breadcrumb_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/bulleted_list_item_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/callout_block.rb +10 -10
- data/lib/notion_ruby_mapping/blocks/child_base_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/child_database_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/child_page_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/code_block.rb +7 -7
- data/lib/notion_ruby_mapping/blocks/column_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/column_list_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/database.rb +6 -6
- data/lib/notion_ruby_mapping/blocks/divider_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/embed_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/equation_block.rb +5 -5
- data/lib/notion_ruby_mapping/blocks/file_base_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/file_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/heading1_block.rb +4 -4
- data/lib/notion_ruby_mapping/blocks/heading2_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/heading3_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/image_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/link_preview_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/link_to_page_block.rb +5 -5
- data/lib/notion_ruby_mapping/blocks/list.rb +21 -20
- data/lib/notion_ruby_mapping/blocks/numbered_list_item_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/page.rb +9 -10
- data/lib/notion_ruby_mapping/blocks/paragraph_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/pdf_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/quote_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/synced_block.rb +5 -5
- data/lib/notion_ruby_mapping/blocks/table_block.rb +8 -8
- data/lib/notion_ruby_mapping/blocks/table_of_contents_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/table_row_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/template_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/text_sub_block_color_base_block.rb +4 -4
- data/lib/notion_ruby_mapping/blocks/to_do_block.rb +4 -4
- data/lib/notion_ruby_mapping/blocks/toggle_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/toggle_heading1_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/toggle_heading2_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/toggle_heading3_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/url_base_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/url_caption_base_block.rb +4 -4
- data/lib/notion_ruby_mapping/blocks/video_block.rb +2 -2
- data/lib/notion_ruby_mapping/controllers/discussion_thread.rb +1 -1
- data/lib/notion_ruby_mapping/controllers/mermaid_database.rb +34 -34
- data/lib/notion_ruby_mapping/controllers/notion_cache.rb +6 -8
- data/lib/notion_ruby_mapping/controllers/payload.rb +11 -11
- data/lib/notion_ruby_mapping/controllers/property_cache.rb +8 -7
- data/lib/notion_ruby_mapping/controllers/query.rb +10 -10
- data/lib/notion_ruby_mapping/controllers/search.rb +5 -6
- data/lib/notion_ruby_mapping/objects/comment_object.rb +2 -2
- data/lib/notion_ruby_mapping/objects/emoji_object.rb +3 -3
- data/lib/notion_ruby_mapping/objects/equation_object.rb +3 -3
- data/lib/notion_ruby_mapping/objects/file_object.rb +9 -9
- data/lib/notion_ruby_mapping/objects/mention_object.rb +43 -43
- data/lib/notion_ruby_mapping/objects/rich_text_object.rb +43 -43
- data/lib/notion_ruby_mapping/objects/text_object.rb +5 -5
- data/lib/notion_ruby_mapping/objects/user_object.rb +4 -4
- data/lib/notion_ruby_mapping/properties/button_property.rb +4 -4
- data/lib/notion_ruby_mapping/properties/checkbox_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/created_by_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/created_time_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/date_base_property.rb +14 -13
- data/lib/notion_ruby_mapping/properties/date_property.rb +17 -17
- data/lib/notion_ruby_mapping/properties/email_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/files_property.rb +16 -13
- data/lib/notion_ruby_mapping/properties/formula_property.rb +7 -7
- data/lib/notion_ruby_mapping/properties/last_edited_by_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/last_edited_time_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/multi_select_property.rb +15 -15
- data/lib/notion_ruby_mapping/properties/number_property.rb +9 -9
- data/lib/notion_ruby_mapping/properties/people_property.rb +6 -6
- data/lib/notion_ruby_mapping/properties/phone_number_property.rb +4 -4
- data/lib/notion_ruby_mapping/properties/property.rb +78 -75
- data/lib/notion_ruby_mapping/properties/relation_property.rb +18 -17
- data/lib/notion_ruby_mapping/properties/rich_text_property.rb +5 -5
- data/lib/notion_ruby_mapping/properties/rollup_property.rb +15 -15
- data/lib/notion_ruby_mapping/properties/select_property.rb +14 -14
- data/lib/notion_ruby_mapping/properties/status_property.rb +5 -5
- data/lib/notion_ruby_mapping/properties/text_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/title_property.rb +6 -6
- data/lib/notion_ruby_mapping/properties/unique_id_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/url_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/verification_property.rb +3 -3
- data/lib/notion_ruby_mapping/version.rb +1 -1
- data/notion_ruby_mapping.gemspec +1 -2
- metadata +4 -22
- data/sig/notion_ruby_mapping.rbs +0 -4
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
3
|
require "forwardable"
|
4
4
|
|
5
5
|
module NotionRubyMapping
|
@@ -28,11 +28,11 @@ module NotionRubyMapping
|
|
28
28
|
|
29
29
|
## Database property only methods
|
30
30
|
|
31
|
-
# @param [String] new_name
|
31
|
+
# @param [String, Symbol] new_name
|
32
32
|
def new_name=(new_name)
|
33
33
|
assert_database_property __method__
|
34
34
|
@will_update = true
|
35
|
-
@new_name = new_name
|
35
|
+
@new_name = new_name.to_sym
|
36
36
|
end
|
37
37
|
|
38
38
|
# @return [NotionRubyMapping::Property] self
|
@@ -47,10 +47,10 @@ module NotionRubyMapping
|
|
47
47
|
|
48
48
|
## Common methods
|
49
49
|
|
50
|
-
# @param [String] name Property name
|
50
|
+
# @param [String, Symbol] name Property name
|
51
51
|
# @return [Property] generated Property object
|
52
52
|
def initialize(name, will_update: false, base_type: :page, property_id: nil, property_cache: nil, query: nil)
|
53
|
-
@name = name
|
53
|
+
@name = name.to_sym
|
54
54
|
@will_update = will_update
|
55
55
|
@base_type = base_type
|
56
56
|
@create = false
|
@@ -62,69 +62,72 @@ module NotionRubyMapping
|
|
62
62
|
@query = query
|
63
63
|
end
|
64
64
|
|
65
|
-
# @param [String] name
|
65
|
+
# @param [String, Symbol] name
|
66
66
|
# @param [Hash] input_json
|
67
67
|
# @return [NotionRubyMapping::Property, nil] generated Property object
|
68
68
|
# @param [Symbol] base_type :page or :database
|
69
69
|
# @param [String, nil] page_id
|
70
70
|
def self.create_from_json(name, input_json, base_type = :page, property_cache = nil, query = nil)
|
71
|
-
|
71
|
+
name_sym = name.to_sym
|
72
|
+
raise StandardError, "Property not found: #{name_sym}:#{input_json}" if input_json.nil?
|
72
73
|
|
73
|
-
type = input_json[
|
74
|
+
type = input_json[:type]&.to_sym
|
74
75
|
if type.nil?
|
75
|
-
new
|
76
|
-
elsif type ==
|
77
|
-
tmp = new
|
78
|
-
|
76
|
+
new name_sym, property_id: input_json[:id], base_type: base_type, property_cache: property_cache, query: query
|
77
|
+
elsif type == :property_item
|
78
|
+
tmp = new name_sym, property_id: input_json[:property_item][:id], base_type: base_type,
|
79
|
+
property_cache: property_cache, query: query
|
79
80
|
objects = List.new(json: input_json, type: :property, value: tmp, query: query).to_a
|
80
|
-
case input_json[
|
81
|
-
when
|
82
|
-
PeopleProperty.new
|
83
|
-
|
84
|
-
when
|
85
|
-
RelationProperty.new
|
86
|
-
|
87
|
-
when
|
88
|
-
RichTextProperty.new
|
89
|
-
|
90
|
-
when
|
91
|
-
RollupProperty.new
|
92
|
-
|
93
|
-
when
|
94
|
-
TitleProperty.new
|
95
|
-
|
81
|
+
case input_json[:property_item][:type]&.to_sym
|
82
|
+
when :people
|
83
|
+
PeopleProperty.new name_sym, people: objects, base_type: base_type,
|
84
|
+
property_cache: property_cache, query: query
|
85
|
+
when :relation
|
86
|
+
RelationProperty.new name_sym, relation: objects, base_type: base_type,
|
87
|
+
property_cache: property_cache, query: query
|
88
|
+
when :rich_text
|
89
|
+
RichTextProperty.new name_sym, text_objects: objects, base_type: base_type,
|
90
|
+
property_cache: property_cache, query: query
|
91
|
+
when :rollup
|
92
|
+
RollupProperty.new name_sym, json: objects, base_type: base_type,
|
93
|
+
property_cache: property_cache, query: query
|
94
|
+
when :title
|
95
|
+
TitleProperty.new name_sym, text_objects: objects, base_type: base_type,
|
96
|
+
property_cache: property_cache, query: query
|
97
|
+
else
|
98
|
+
raise StandardError, "Irregular property type: #{input_json[:property_item][:type]}"
|
96
99
|
end
|
97
100
|
else
|
98
101
|
klass = {
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
102
|
+
button: ButtonProperty,
|
103
|
+
checkbox: CheckboxProperty,
|
104
|
+
created_time: CreatedTimeProperty,
|
105
|
+
date: DateProperty,
|
106
|
+
formula: FormulaProperty,
|
107
|
+
last_edited_time: LastEditedTimeProperty,
|
108
|
+
rollup: RollupProperty,
|
109
|
+
email: EmailProperty,
|
110
|
+
files: FilesProperty,
|
111
|
+
created_by: CreatedByProperty,
|
112
|
+
last_edited_by: LastEditedByProperty,
|
113
|
+
multi_select: MultiSelectProperty,
|
114
|
+
relation: RelationProperty,
|
115
|
+
number: NumberProperty,
|
116
|
+
people: PeopleProperty,
|
117
|
+
phone_number: PhoneNumberProperty,
|
118
|
+
select: SelectProperty,
|
119
|
+
status: StatusProperty,
|
120
|
+
title: TitleProperty,
|
121
|
+
rich_text: RichTextProperty,
|
122
|
+
unique_id: UniqueIdProperty,
|
123
|
+
url: UrlProperty,
|
124
|
+
verification: VerificationProperty,
|
122
125
|
}[type]
|
123
126
|
raise StandardError, "Irregular property type: #{type}" unless klass
|
124
127
|
|
125
|
-
answer = klass.new
|
126
|
-
|
127
|
-
answer = answer.retrieve_page_property if answer.is_a?(RelationProperty) && input_json[
|
128
|
+
answer = klass.new name_sym, property_id: input_json[:id], json: input_json[type], base_type: base_type,
|
129
|
+
property_cache: property_cache
|
130
|
+
answer = answer.retrieve_page_property if answer.is_a?(RelationProperty) && input_json[:has_more] == true
|
128
131
|
answer
|
129
132
|
end
|
130
133
|
end
|
@@ -138,7 +141,7 @@ module NotionRubyMapping
|
|
138
141
|
|
139
142
|
# @return [TrueClass, FalseClass] true if database property
|
140
143
|
def database?
|
141
|
-
@base_type == :database
|
144
|
+
@base_type.to_sym == :database
|
142
145
|
end
|
143
146
|
|
144
147
|
# @return [TrueClass, FalseClass] true if it has Property contents
|
@@ -146,18 +149,18 @@ module NotionRubyMapping
|
|
146
149
|
!instance_of? Property
|
147
150
|
end
|
148
151
|
|
149
|
-
# @param [
|
152
|
+
# @param [Symbol] key query parameter
|
150
153
|
# @param [Object] value query value
|
151
154
|
# @return [NotionRubyMapping::Query] generated Query object
|
152
155
|
def make_filter_query(key, value, condition: nil, another_type: nil)
|
153
156
|
if condition
|
154
|
-
Query.new filter: {
|
157
|
+
Query.new filter: {property: @name, type => {condition => {another_type => {key => value}}}}
|
155
158
|
elsif another_type
|
156
|
-
Query.new filter: {
|
157
|
-
elsif @name ==
|
158
|
-
Query.new filter: {
|
159
|
+
Query.new filter: {property: @name, type => {another_type => {key => value}}}
|
160
|
+
elsif @name == :__timestamp__
|
161
|
+
Query.new filter: {timestamp: type.to_s, type => {key => value}}
|
159
162
|
else
|
160
|
-
Query.new filter: {
|
163
|
+
Query.new filter: {property: @name, type => {key => value}}
|
161
164
|
end
|
162
165
|
end
|
163
166
|
|
@@ -198,7 +201,7 @@ module NotionRubyMapping
|
|
198
201
|
if @remove
|
199
202
|
{@name => nil}
|
200
203
|
elsif @new_name
|
201
|
-
{@name => {
|
204
|
+
{@name => {name: @new_name}}
|
202
205
|
else
|
203
206
|
{}
|
204
207
|
end
|
@@ -208,7 +211,7 @@ module NotionRubyMapping
|
|
208
211
|
|
209
212
|
# @param [Symbol, nil] method
|
210
213
|
def assert_page_property(method)
|
211
|
-
raise StandardError, "#{method} can execute only Page property."
|
214
|
+
raise StandardError, "#{method} can execute only Page property." if database?
|
212
215
|
end
|
213
216
|
|
214
217
|
# @return [NotionRubyMapping::Property, Array<UserObject>, nil]
|
@@ -243,7 +246,7 @@ module NotionRubyMapping
|
|
243
246
|
# @return [NotionRubyMapping::Query] generated Query object
|
244
247
|
# @see https://www.notion.so/hkob/CheckboxProperty-ac1edbdb8e264af5ad1432b522b429fd#5f07c4ebc4744986bfc99a43827349fc
|
245
248
|
def filter_equals(value, condition: nil, another_type: nil)
|
246
|
-
make_filter_query
|
249
|
+
make_filter_query :equals, value, condition: condition, another_type: another_type
|
247
250
|
end
|
248
251
|
|
249
252
|
# @param [String, Number] value Query value
|
@@ -252,7 +255,7 @@ module NotionRubyMapping
|
|
252
255
|
# @return [NotionRubyMapping::Query] generated Query object
|
253
256
|
# @see https://www.notion.so/hkob/CheckboxProperty-ac1edbdb8e264af5ad1432b522b429fd#a44a1875c3ef49f2b4f817291953a1d4
|
254
257
|
def filter_does_not_equal(value, condition: nil, another_type: nil)
|
255
|
-
make_filter_query
|
258
|
+
make_filter_query :does_not_equal, value, condition: condition, another_type: another_type
|
256
259
|
end
|
257
260
|
end
|
258
261
|
|
@@ -266,7 +269,7 @@ module NotionRubyMapping
|
|
266
269
|
# @return [NotionRubyMapping::Query] generated Query object
|
267
270
|
# @see https://www.notion.so/hkob/CreatedByProperty-945fa6be1c014da2b7e55a2b76e37b57#271a2ebaa1ec48acae732ca98920feab
|
268
271
|
def filter_contains(value, condition: nil, another_type: nil)
|
269
|
-
make_filter_query
|
272
|
+
make_filter_query :contains, value, condition: condition, another_type: another_type
|
270
273
|
end
|
271
274
|
|
272
275
|
# @param [String] value Query value
|
@@ -275,7 +278,7 @@ module NotionRubyMapping
|
|
275
278
|
# @return [NotionRubyMapping::Query] generated Query object
|
276
279
|
# @see https://www.notion.so/hkob/CreatedByProperty-945fa6be1c014da2b7e55a2b76e37b57#b0328e3b146f48a4ad4c9c2ee5363486
|
277
280
|
def filter_does_not_contain(value, condition: nil, another_type: nil)
|
278
|
-
make_filter_query
|
281
|
+
make_filter_query :does_not_contain, value, condition: condition, another_type: another_type
|
279
282
|
end
|
280
283
|
end
|
281
284
|
|
@@ -289,7 +292,7 @@ module NotionRubyMapping
|
|
289
292
|
# @return [NotionRubyMapping::Query] generated Query object
|
290
293
|
# @see https://www.notion.so/hkob/EmailProperty-39aeb5df56ea4cc1b9380574e4fdeec0#d3e098b2f38c4c8c9d3e815516cfd953
|
291
294
|
def filter_starts_with(value, condition: nil, another_type: nil)
|
292
|
-
make_filter_query
|
295
|
+
make_filter_query :starts_with, value, condition: condition, another_type: another_type
|
293
296
|
end
|
294
297
|
|
295
298
|
# @param [String] value Query value
|
@@ -297,7 +300,7 @@ module NotionRubyMapping
|
|
297
300
|
# @param [String] rollup_type Rollup type
|
298
301
|
# @return [NotionRubyMapping::Query] generated Query object
|
299
302
|
def filter_ends_with(value, condition: nil, another_type: nil)
|
300
|
-
make_filter_query
|
303
|
+
make_filter_query :ends_with, value, condition: condition, another_type: another_type
|
301
304
|
end
|
302
305
|
end
|
303
306
|
|
@@ -310,7 +313,7 @@ module NotionRubyMapping
|
|
310
313
|
# @return [NotionRubyMapping::Query] generated Query object
|
311
314
|
# @see https://www.notion.so/hkob/CreatedByProperty-945fa6be1c014da2b7e55a2b76e37b57#38749dfae0854c68b4c55095d3efbff1
|
312
315
|
def filter_is_empty(condition: nil, another_type: nil)
|
313
|
-
make_filter_query
|
316
|
+
make_filter_query :is_empty, true, condition: condition, another_type: another_type
|
314
317
|
end
|
315
318
|
|
316
319
|
# @param [String] rollup Rollup name
|
@@ -318,7 +321,7 @@ module NotionRubyMapping
|
|
318
321
|
# @return [NotionRubyMapping::Query] generated Query object
|
319
322
|
# @see https://www.notion.so/hkob/CreatedByProperty-945fa6be1c014da2b7e55a2b76e37b57#515659ea52b54fb48c81b813f3b705f6
|
320
323
|
def filter_is_not_empty(condition: nil, another_type: nil)
|
321
|
-
make_filter_query
|
324
|
+
make_filter_query :is_not_empty, true, condition: condition, another_type: another_type
|
322
325
|
end
|
323
326
|
end
|
324
327
|
|
@@ -331,7 +334,7 @@ module NotionRubyMapping
|
|
331
334
|
# @param [String] rollup_type Rollup type
|
332
335
|
# @return [NotionRubyMapping::Query] generated Query object
|
333
336
|
def filter_greater_than(value, condition: nil, another_type: nil)
|
334
|
-
make_filter_query
|
337
|
+
make_filter_query :greater_than, value, condition: condition, another_type: another_type
|
335
338
|
end
|
336
339
|
|
337
340
|
# @param [Number] value Query value
|
@@ -339,7 +342,7 @@ module NotionRubyMapping
|
|
339
342
|
# @param [String] rollup_type Rollup type
|
340
343
|
# @return [NotionRubyMapping::Query] generated Query object
|
341
344
|
def filter_less_than(value, condition: nil, another_type: nil)
|
342
|
-
make_filter_query
|
345
|
+
make_filter_query :less_than, value, condition: condition, another_type: another_type
|
343
346
|
end
|
344
347
|
|
345
348
|
# @param [Number] value Query value
|
@@ -347,7 +350,7 @@ module NotionRubyMapping
|
|
347
350
|
# @param [String] rollup_type Rollup type
|
348
351
|
# @return [NotionRubyMapping::Query] generated Query object
|
349
352
|
def filter_greater_than_or_equal_to(value, condition: nil, another_type: nil)
|
350
|
-
make_filter_query
|
353
|
+
make_filter_query :greater_than_or_equal_to, value, condition: condition, another_type: another_type
|
351
354
|
end
|
352
355
|
|
353
356
|
# @param [Number] value Query value
|
@@ -355,7 +358,7 @@ module NotionRubyMapping
|
|
355
358
|
# @param [String] rollup_type Rollup type
|
356
359
|
# @return [NotionRubyMapping::Query] generated Query object
|
357
360
|
def filter_less_than_or_equal_to(value, condition: nil, another_type: nil)
|
358
|
-
make_filter_query
|
361
|
+
make_filter_query :less_than_or_equal_to, value, condition: condition, another_type: another_type
|
359
362
|
end
|
360
363
|
end
|
361
364
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module NotionRubyMapping
|
4
4
|
# MultiSelect property
|
5
5
|
class RelationProperty < MultiProperty
|
6
|
-
TYPE =
|
6
|
+
TYPE = :relation
|
7
7
|
|
8
8
|
### Public announced methods
|
9
9
|
|
@@ -23,7 +23,7 @@ module NotionRubyMapping
|
|
23
23
|
assert_page_property __method__
|
24
24
|
@will_update = true
|
25
25
|
@json << if page_id_or_json.is_a? String
|
26
|
-
{
|
26
|
+
{id: page_id_or_json}
|
27
27
|
else
|
28
28
|
page_id_or_json
|
29
29
|
end
|
@@ -38,7 +38,7 @@ module NotionRubyMapping
|
|
38
38
|
page_ids_or_jsons = [page_ids_or_jsons] unless page_ids_or_jsons.is_a? Array
|
39
39
|
|
40
40
|
@json = page_ids_or_jsons.map do |page_id_or_json|
|
41
|
-
page_id_or_json.is_a?(String) ? {
|
41
|
+
page_id_or_json.is_a?(String) ? {id: page_id_or_json} : page_id_or_json
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -48,19 +48,20 @@ module NotionRubyMapping
|
|
48
48
|
# @see https://www.notion.so/hkob/RelationProperty-f608ab41a1f0476b98456620346fba03#eb40f1a2ad5c4e368d343870a7e529f9
|
49
49
|
def relation_database_id
|
50
50
|
assert_database_property __method__
|
51
|
-
@json[
|
51
|
+
@json[:database_id]
|
52
52
|
end
|
53
53
|
|
54
54
|
# @param [String] database_id
|
55
55
|
# @param [String] synced_property_name
|
56
56
|
# @see https://www.notion.so/hkob/RelationProperty-f608ab41a1f0476b98456620346fba03#7f5029fb7f6e4c009f22888b233e6f64
|
57
|
-
def replace_relation_database(database_id: nil, type:
|
57
|
+
def replace_relation_database(database_id: nil, type: :dual_property)
|
58
58
|
assert_database_property __method__
|
59
|
+
type_sym = type.to_sym
|
59
60
|
@will_update = true
|
60
|
-
@json[
|
61
|
-
@json[
|
62
|
-
@json[
|
63
|
-
@json.delete
|
61
|
+
@json[:database_id] = database_id if database_id
|
62
|
+
@json[:type] = type_sym.to_s
|
63
|
+
@json[type_sym] = {}
|
64
|
+
@json.delete type_sym == :dual_property ? :single_property : :dual_property
|
64
65
|
@json
|
65
66
|
end
|
66
67
|
|
@@ -68,7 +69,7 @@ module NotionRubyMapping
|
|
68
69
|
|
69
70
|
## Common methods
|
70
71
|
|
71
|
-
# @param [String] name
|
72
|
+
# @param [String, Symbol] name
|
72
73
|
# @param [Hash, Array] json
|
73
74
|
# @param [String, Array] relation
|
74
75
|
def initialize(name, will_update: false, json: nil, relation: nil, base_type: :page, property_id: nil,
|
@@ -78,7 +79,7 @@ module NotionRubyMapping
|
|
78
79
|
@json = if database?
|
79
80
|
json || {}
|
80
81
|
elsif relation
|
81
|
-
Array(relation).map { |r| {
|
82
|
+
Array(relation).map { |r| {id: r} }
|
82
83
|
else
|
83
84
|
json || []
|
84
85
|
end
|
@@ -93,20 +94,20 @@ module NotionRubyMapping
|
|
93
94
|
return ans if ans != {} || !@will_update
|
94
95
|
|
95
96
|
ans[@name] ||= {}
|
96
|
-
ans[@name][
|
97
|
+
ans[@name][:relation] = @json
|
97
98
|
ans
|
98
99
|
end
|
99
100
|
|
100
101
|
def database_id
|
101
|
-
@json[
|
102
|
+
@json[:database_id]
|
102
103
|
end
|
103
104
|
|
104
105
|
def synced_property_id
|
105
|
-
@json[
|
106
|
+
@json[:type] == "dual_property" ? @json[:dual_property][:synced_property_id] : nil
|
106
107
|
end
|
107
108
|
|
108
109
|
def synced_property_name
|
109
|
-
@json[
|
110
|
+
@json[:type] == "dual_property" ? @json[:dual_property][:synced_property_name] : nil
|
110
111
|
end
|
111
112
|
|
112
113
|
# @return [Hash] created json
|
@@ -114,8 +115,8 @@ module NotionRubyMapping
|
|
114
115
|
assert_page_property __method__
|
115
116
|
{
|
116
117
|
@name => {
|
117
|
-
|
118
|
-
|
118
|
+
type: "relation",
|
119
|
+
relation: @json,
|
119
120
|
},
|
120
121
|
}
|
121
122
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module NotionRubyMapping
|
4
4
|
# RichTextProperty
|
5
5
|
class RichTextProperty < TextProperty
|
6
|
-
TYPE =
|
6
|
+
TYPE = :rich_text
|
7
7
|
|
8
8
|
### Not public announced methods
|
9
9
|
|
@@ -13,9 +13,9 @@ module NotionRubyMapping
|
|
13
13
|
def update_from_json(json)
|
14
14
|
@will_update = false
|
15
15
|
if database?
|
16
|
-
@json = json[
|
16
|
+
@json = json[:rich_text] || {}
|
17
17
|
else
|
18
|
-
@text_objects = RichTextArray.new
|
18
|
+
@text_objects = RichTextArray.new :rich_text, json: json[:rich_text]
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -27,8 +27,8 @@ module NotionRubyMapping
|
|
27
27
|
text_json = @text_objects.map(&:property_values_json)
|
28
28
|
{
|
29
29
|
@name => {
|
30
|
-
|
31
|
-
|
30
|
+
type: "rich_text",
|
31
|
+
rich_text: text_json.empty? ? (@json || []) : text_json,
|
32
32
|
},
|
33
33
|
}
|
34
34
|
end
|
@@ -6,7 +6,7 @@ module NotionRubyMapping
|
|
6
6
|
include ContainsDoesNotContain
|
7
7
|
include StartsWithEndsWith
|
8
8
|
include GreaterThanLessThan
|
9
|
-
TYPE =
|
9
|
+
TYPE = :rollup
|
10
10
|
|
11
11
|
### Public announced methods
|
12
12
|
|
@@ -24,7 +24,7 @@ module NotionRubyMapping
|
|
24
24
|
# @see https://www.notion.so/hkob/RollupProperty-eb10fbac3a93436289e74e5c651e9134#94021d4e6c0b44519443c1e1cc6b3aba
|
25
25
|
def function
|
26
26
|
assert_database_property __method__
|
27
|
-
@json[
|
27
|
+
@json[:function]
|
28
28
|
end
|
29
29
|
|
30
30
|
# @param [String] func
|
@@ -32,14 +32,14 @@ module NotionRubyMapping
|
|
32
32
|
def function=(func)
|
33
33
|
assert_database_property __method__
|
34
34
|
@will_update = true
|
35
|
-
@json[
|
35
|
+
@json[:function] = func
|
36
36
|
end
|
37
37
|
|
38
38
|
# @return [String] new or settled relation_property_name
|
39
39
|
# @see https://www.notion.so/hkob/RollupProperty-eb10fbac3a93436289e74e5c651e9134#684fc4739c4f4d6a9b93687f72cd8dad
|
40
40
|
def relation_property_name
|
41
41
|
assert_database_property __method__
|
42
|
-
@json[
|
42
|
+
@json[:relation_property_name]
|
43
43
|
end
|
44
44
|
|
45
45
|
# @param [String] rpn
|
@@ -47,14 +47,14 @@ module NotionRubyMapping
|
|
47
47
|
def relation_property_name=(rpn)
|
48
48
|
assert_database_property __method__
|
49
49
|
@will_update = true
|
50
|
-
@json[
|
50
|
+
@json[:relation_property_name] = rpn
|
51
51
|
end
|
52
52
|
|
53
53
|
# @return [String] new or settled rollup_property_name
|
54
54
|
# @see https://www.notion.so/hkob/RollupProperty-eb10fbac3a93436289e74e5c651e9134#8ce9ee31a2e2473ab7ba21781e4b440d
|
55
55
|
def rollup_property_name
|
56
56
|
assert_database_property __method__
|
57
|
-
@json[
|
57
|
+
@json[:rollup_property_name]
|
58
58
|
end
|
59
59
|
|
60
60
|
# @param [String] rpn
|
@@ -62,14 +62,14 @@ module NotionRubyMapping
|
|
62
62
|
def rollup_property_name=(rpn)
|
63
63
|
assert_database_property __method__
|
64
64
|
@will_update = true
|
65
|
-
@json[
|
65
|
+
@json[:rollup_property_name] = rpn
|
66
66
|
end
|
67
67
|
|
68
68
|
### Not public announced methods
|
69
69
|
|
70
70
|
## Common methods
|
71
71
|
|
72
|
-
# @param [String] name
|
72
|
+
# @param [String, Symbol] name
|
73
73
|
# @param [Hash] json
|
74
74
|
def initialize(name, will_update: false, json: nil, base_type: :page, property_id: nil,
|
75
75
|
property_cache: nil, query: nil)
|
@@ -87,10 +87,10 @@ module NotionRubyMapping
|
|
87
87
|
return ans if ans != {} || !@will_update
|
88
88
|
|
89
89
|
ans[@name] ||= {}
|
90
|
-
ans[@name][
|
91
|
-
ans[@name][
|
92
|
-
ans[@name][
|
93
|
-
ans[@name][
|
90
|
+
ans[@name][:rollup] ||= {}
|
91
|
+
ans[@name][:rollup][:function] = function
|
92
|
+
ans[@name][:rollup][:relation_property_name] = relation_property_name
|
93
|
+
ans[@name][:rollup][:rollup_property_name] = rollup_property_name
|
94
94
|
ans
|
95
95
|
end
|
96
96
|
|
@@ -108,9 +108,9 @@ module NotionRubyMapping
|
|
108
108
|
# @return [Hash]
|
109
109
|
def property_schema_json_sub
|
110
110
|
{
|
111
|
-
|
112
|
-
|
113
|
-
|
111
|
+
function: function,
|
112
|
+
relation_property_name: relation_property_name,
|
113
|
+
rollup_property_name: rollup_property_name,
|
114
114
|
}
|
115
115
|
end
|
116
116
|
end
|
@@ -5,7 +5,7 @@ module NotionRubyMapping
|
|
5
5
|
class SelectProperty < Property
|
6
6
|
include EqualsDoesNotEqual
|
7
7
|
include IsEmptyIsNotEmpty
|
8
|
-
TYPE =
|
8
|
+
TYPE = :select
|
9
9
|
|
10
10
|
### Public announced methods
|
11
11
|
|
@@ -23,7 +23,7 @@ module NotionRubyMapping
|
|
23
23
|
# @see https://www.notion.so/hkob/SelectProperty-6d6a0defa70d4b26af0fdbdcfbf99f28#27a05e52715a4acd9156b5f146653e51
|
24
24
|
def select_name
|
25
25
|
assert_page_property __method__
|
26
|
-
@json[
|
26
|
+
@json[:name]
|
27
27
|
end
|
28
28
|
|
29
29
|
## Database property only methods
|
@@ -33,28 +33,28 @@ module NotionRubyMapping
|
|
33
33
|
# @return [Array] added array
|
34
34
|
# @see https://www.notion.so/hkob/SelectProperty-6d6a0defa70d4b26af0fdbdcfbf99f28#3e1c7dbda7fb455f94ee93d9653b7880
|
35
35
|
def add_select_option(name:, color:)
|
36
|
-
edit_select_options << {
|
36
|
+
edit_select_options << {name: name, color: color}
|
37
37
|
end
|
38
38
|
|
39
39
|
# @return [Array] copyed multi select options
|
40
40
|
def edit_select_options
|
41
41
|
assert_database_property __method__
|
42
42
|
@will_update = true
|
43
|
-
@json[
|
43
|
+
@json[:options] ||= []
|
44
44
|
end
|
45
45
|
|
46
46
|
# @return [Array]
|
47
47
|
# @see https://www.notion.so/hkob/SelectProperty-6d6a0defa70d4b26af0fdbdcfbf99f28#790a297f2c1b4ba5a4d86074d4c70a89
|
48
48
|
def select_options
|
49
49
|
assert_database_property __method__
|
50
|
-
@json[
|
50
|
+
@json[:options] || []
|
51
51
|
end
|
52
52
|
|
53
53
|
# @return [String]
|
54
54
|
# @see https://www.notion.so/hkob/SelectProperty-6d6a0defa70d4b26af0fdbdcfbf99f28#72da1632793c4a5296f3bc89de2df413
|
55
55
|
def select_names
|
56
56
|
assert_database_property __method__
|
57
|
-
@json[
|
57
|
+
@json[:options].map { |s| s[:name] }
|
58
58
|
end
|
59
59
|
|
60
60
|
## Page property only methods
|
@@ -64,14 +64,14 @@ module NotionRubyMapping
|
|
64
64
|
def select=(select)
|
65
65
|
assert_page_property __method__
|
66
66
|
@will_update = true
|
67
|
-
@json = {
|
67
|
+
@json = {name: select}
|
68
68
|
end
|
69
69
|
|
70
70
|
### Not public announced methods
|
71
71
|
|
72
72
|
## Common methods
|
73
73
|
|
74
|
-
# @param [String] name Property name
|
74
|
+
# @param [String, Symbol] name Property name
|
75
75
|
# @param [Hash] json
|
76
76
|
# @param [String] select String value (optional)
|
77
77
|
def initialize(name, will_update: false, base_type: :page, json: nil, select: nil, property_id: nil,
|
@@ -79,9 +79,9 @@ module NotionRubyMapping
|
|
79
79
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
80
80
|
property_cache: property_cache
|
81
81
|
@json = if database?
|
82
|
-
json || {
|
82
|
+
json || {options: []}
|
83
83
|
else
|
84
|
-
json || {
|
84
|
+
json || {name: select}
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -94,8 +94,8 @@ module NotionRubyMapping
|
|
94
94
|
return ans if ans != {} || !@will_update
|
95
95
|
|
96
96
|
ans[@name] ||= {}
|
97
|
-
ans[@name][
|
98
|
-
ans[@name][
|
97
|
+
ans[@name][:select] ||= {}
|
98
|
+
ans[@name][:select][:options] = @json[:options]
|
99
99
|
ans
|
100
100
|
end
|
101
101
|
|
@@ -104,7 +104,7 @@ module NotionRubyMapping
|
|
104
104
|
# @return [Hash]
|
105
105
|
def property_values_json
|
106
106
|
assert_page_property __method__
|
107
|
-
{@name => {
|
107
|
+
{@name => {type: "select", select: @json}}
|
108
108
|
end
|
109
109
|
|
110
110
|
protected
|
@@ -113,7 +113,7 @@ module NotionRubyMapping
|
|
113
113
|
|
114
114
|
# @return [Hash]
|
115
115
|
def property_schema_json_sub
|
116
|
-
{
|
116
|
+
{options: edit_select_options}
|
117
117
|
end
|
118
118
|
end
|
119
119
|
end
|