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
@@ -3,16 +3,16 @@
|
|
3
3
|
module NotionRubyMapping
|
4
4
|
# Notion block
|
5
5
|
class ToggleHeading3Block < TextSubBlockColorBaseBlock
|
6
|
-
# @return [
|
6
|
+
# @return [Symbol]
|
7
7
|
def type
|
8
|
-
|
8
|
+
:heading_3
|
9
9
|
end
|
10
10
|
|
11
11
|
# @param [Boolean] not_update false when update
|
12
12
|
# @return [Hash{String (frozen)->Hash}]
|
13
13
|
def block_json(not_update: true)
|
14
14
|
ans = super
|
15
|
-
ans[type][
|
15
|
+
ans[type][:is_toggleable] = true
|
16
16
|
ans
|
17
17
|
end
|
18
18
|
end
|
@@ -9,7 +9,7 @@ module NotionRubyMapping
|
|
9
9
|
|
10
10
|
super(json: json, id: id, parent: parent)
|
11
11
|
@url = if @json
|
12
|
-
@json[type][
|
12
|
+
@json[type][:url]
|
13
13
|
else
|
14
14
|
url
|
15
15
|
end
|
@@ -21,14 +21,14 @@ module NotionRubyMapping
|
|
21
21
|
# @return [Hash{String (frozen)->Hash}]
|
22
22
|
def block_json(not_update: true)
|
23
23
|
ans = super
|
24
|
-
ans[type] = {
|
24
|
+
ans[type] = {url: @url}
|
25
25
|
ans
|
26
26
|
end
|
27
27
|
|
28
28
|
# @param [String] str
|
29
29
|
def url=(str)
|
30
30
|
@url = str
|
31
|
-
@payload.add_update_block_key
|
31
|
+
@payload.add_update_block_key :url
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -12,11 +12,11 @@ module NotionRubyMapping
|
|
12
12
|
|
13
13
|
super(json: json, id: id, parent: parent)
|
14
14
|
if @json
|
15
|
-
@url = @json[type][
|
15
|
+
@url = @json[type][:url]
|
16
16
|
decode_block_caption
|
17
17
|
else
|
18
18
|
@url = url
|
19
|
-
@caption = RichTextArray.rich_text_array
|
19
|
+
@caption = RichTextArray.rich_text_array :caption, caption
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -31,7 +31,7 @@ module NotionRubyMapping
|
|
31
31
|
def block_json(not_update: true)
|
32
32
|
ans = super
|
33
33
|
ans[type] = @caption.update_property_schema_json not_update
|
34
|
-
ans[type][
|
34
|
+
ans[type][:url] = @url
|
35
35
|
ans
|
36
36
|
end
|
37
37
|
|
@@ -40,7 +40,7 @@ module NotionRubyMapping
|
|
40
40
|
# @see https://www.notion.so/hkob/EmbedBlock-57c31e7d8e1d41669eb30f27e1c41035#25ece6bfce0749f8b4bbecc6ba7feedc
|
41
41
|
def url=(str)
|
42
42
|
@url = str
|
43
|
-
@payload.add_update_block_key
|
43
|
+
@payload.add_update_block_key :url
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -16,7 +16,7 @@ module NotionRubyMapping
|
|
16
16
|
def append_comment(text_objects, dry_run: false)
|
17
17
|
rto = RichTextArray.new "rich_text", text_objects: text_objects, will_update: true
|
18
18
|
nc = NotionCache.instance
|
19
|
-
json = rto.property_schema_json.merge({
|
19
|
+
json = rto.property_schema_json.merge({discussion_id: @discussion_id})
|
20
20
|
if dry_run
|
21
21
|
Base.dry_run_script :post, nc.comments_path, json
|
22
22
|
else
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module NotionRubyMapping
|
2
2
|
class MermaidDatabase
|
3
|
-
|
4
3
|
def initialize(key)
|
5
4
|
@key = key
|
6
5
|
@name = key
|
@@ -17,10 +16,11 @@ module NotionRubyMapping
|
|
17
16
|
attr_accessor :name
|
18
17
|
|
19
18
|
def add_property(key, value)
|
20
|
-
|
19
|
+
key_sym = key.to_sym
|
20
|
+
if key_sym == :title
|
21
21
|
@title = value
|
22
22
|
else
|
23
|
-
@properties[value] =
|
23
|
+
@properties[value] = key_sym
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -44,7 +44,7 @@ module NotionRubyMapping
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def blocked?(name)
|
47
|
-
@finish_flag[name].nil?
|
47
|
+
@finish_flag[name.to_sym].nil?
|
48
48
|
end
|
49
49
|
|
50
50
|
def count
|
@@ -66,10 +66,12 @@ module NotionRubyMapping
|
|
66
66
|
ps = @real_db.properties
|
67
67
|
@properties.each do |(value, key)|
|
68
68
|
name, *options = value.split("|")
|
69
|
-
|
69
|
+
name_sym = name.to_sym
|
70
|
+
key_sym = key.to_sym
|
71
|
+
next if @finish_flag[name_sym]
|
70
72
|
|
71
|
-
property = ps.values_at(
|
72
|
-
case
|
73
|
+
property = ps.values_at(name_sym).first
|
74
|
+
case key_sym
|
73
75
|
when /checkbox|created_by|created_time|date|email|files|last_edited_by|last_edited_time|people|phone_number|text|url|status/
|
74
76
|
klass = {
|
75
77
|
checkbox: CheckboxProperty, created_by: CreatedByProperty, created_time: CreatedTimeProperty,
|
@@ -77,9 +79,9 @@ module NotionRubyMapping
|
|
77
79
|
last_edited_time: LastEditedTimeProperty, people: PeopleProperty, phone_number: PhoneNumberProperty,
|
78
80
|
rich_text: RichTextProperty, url: UrlProperty, status: StatusProperty
|
79
81
|
}[key.to_sym]
|
80
|
-
@real_db.add_property klass,
|
81
|
-
@working <<
|
82
|
-
when
|
82
|
+
@real_db.add_property klass, name_sym unless property
|
83
|
+
@working << name_sym
|
84
|
+
when :formula
|
83
85
|
f_e = options.first&.gsub "@", '"'
|
84
86
|
dependencies = f_e&.scan(/prop\("([^"]+)"\)/) || []
|
85
87
|
blocked_key = dependencies.select { |k| blocked? k.first }
|
@@ -87,37 +89,37 @@ module NotionRubyMapping
|
|
87
89
|
if property
|
88
90
|
property.formula_expression = f_e unless property.formula_expression == f_e
|
89
91
|
else
|
90
|
-
@real_db.add_property(FormulaProperty,
|
92
|
+
@real_db.add_property(FormulaProperty, name_sym) { |dp| dp.formula_expression = f_e }
|
91
93
|
end
|
92
|
-
@working <<
|
94
|
+
@working << name_sym
|
93
95
|
else
|
94
|
-
print("#{
|
96
|
+
print("#{name_sym} blocked by #{blocked_key.flatten}\n")
|
95
97
|
next
|
96
98
|
end
|
97
99
|
|
98
|
-
when
|
100
|
+
when :multi_select
|
99
101
|
if property
|
100
|
-
(options - (property.multi_select_options.map { |h| h[
|
102
|
+
(options - (property.multi_select_options.map { |h| h[:name] })).each do |select_name|
|
101
103
|
property.add_multi_select_option name: select_name, color: "default"
|
102
104
|
end
|
103
105
|
else
|
104
|
-
@real_db.add_property(MultiSelectProperty,
|
106
|
+
@real_db.add_property(MultiSelectProperty, name_sym) do |dp|
|
105
107
|
options.each do |select_name|
|
106
108
|
dp.add_multi_select_option name: select_name, color: "default"
|
107
109
|
end
|
108
110
|
end
|
109
111
|
end
|
110
|
-
@working <<
|
111
|
-
when
|
112
|
+
@working << name_sym
|
113
|
+
when :number
|
112
114
|
format_value = options.empty? ? "number" : options.first
|
113
115
|
if property
|
114
116
|
property.format = format_value unless property.format == format_value
|
115
117
|
else
|
116
|
-
@real_db.add_property(NumberProperty,
|
118
|
+
@real_db.add_property(NumberProperty, name_sym) { |p| p.format = format_value }
|
117
119
|
end
|
118
|
-
@working <<
|
119
|
-
when
|
120
|
-
name, *options = value.split("|")
|
120
|
+
@working << name_sym
|
121
|
+
when :rollup
|
122
|
+
name, *options = value.split("|").map(&:to_sym)
|
121
123
|
relation_name, rollup_name, function = options
|
122
124
|
if blocked? relation_name
|
123
125
|
print("#{name} blocked by #{relation_name}\n")
|
@@ -144,9 +146,9 @@ module NotionRubyMapping
|
|
144
146
|
@working << name
|
145
147
|
end
|
146
148
|
end
|
147
|
-
when
|
149
|
+
when :select
|
148
150
|
if property
|
149
|
-
(options - (property.select_options.map { |h| h[
|
151
|
+
(options - (property.select_options.map { |h| h[:name] })).each do |select_name|
|
150
152
|
property.add_select_option name: select_name, color: "default"
|
151
153
|
end
|
152
154
|
else
|
@@ -157,19 +159,17 @@ module NotionRubyMapping
|
|
157
159
|
end
|
158
160
|
end
|
159
161
|
@working << name
|
160
|
-
else
|
161
|
-
nil
|
162
162
|
end
|
163
163
|
end
|
164
|
-
while (array = @relation_queue.shift)
|
164
|
+
while (array = @relation_queue.shift)
|
165
165
|
value, relation_db = array
|
166
166
|
db_id = relation_db.real_db.id
|
167
|
-
forward, reverse = value.split
|
167
|
+
forward, reverse = value.split("|").map(&:to_sym)
|
168
168
|
property = ps.values_at(forward).first
|
169
169
|
if property
|
170
170
|
if reverse
|
171
171
|
if property.database_id == db_id && property.synced_property_name == reverse
|
172
|
-
relation_db.add_property
|
172
|
+
relation_db.add_property :relation, reverse
|
173
173
|
relation_db.finish_flag[reverse] = true
|
174
174
|
else
|
175
175
|
unless @finish_flag[forward]
|
@@ -177,14 +177,14 @@ module NotionRubyMapping
|
|
177
177
|
relation_db.append_reverse_name_queue self, forward, reverse
|
178
178
|
end
|
179
179
|
@working << forward
|
180
|
-
add_property
|
180
|
+
add_property :relation, forward
|
181
181
|
end
|
182
182
|
relation_db.relations[reverse] = self
|
183
183
|
else
|
184
184
|
unless property.database_id == db_id
|
185
185
|
property.replace_relation_database database_id: db_id, type: "single_property"
|
186
186
|
@working << forward
|
187
|
-
add_property
|
187
|
+
add_property :relation, forward
|
188
188
|
end
|
189
189
|
end
|
190
190
|
@relations[forward] = relation_db
|
@@ -200,7 +200,7 @@ module NotionRubyMapping
|
|
200
200
|
end
|
201
201
|
@relations[forward] = relation_db
|
202
202
|
@working << forward
|
203
|
-
add_property
|
203
|
+
add_property :relation, forward
|
204
204
|
end
|
205
205
|
end
|
206
206
|
@real_db.property_schema_json
|
@@ -208,7 +208,7 @@ module NotionRubyMapping
|
|
208
208
|
|
209
209
|
def append_reverse_name_queue(other_db, forward, reverse)
|
210
210
|
@reverse_name_queue[reverse] = [other_db, forward]
|
211
|
-
add_property
|
211
|
+
add_property :relation, reverse
|
212
212
|
end
|
213
213
|
|
214
214
|
def update_database
|
@@ -243,4 +243,4 @@ module NotionRubyMapping
|
|
243
243
|
@reverse_name_queue = {}
|
244
244
|
end
|
245
245
|
end
|
246
|
-
end
|
246
|
+
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require "singleton"
|
4
4
|
require "faraday"
|
5
|
-
require "faraday_middleware"
|
6
5
|
|
7
6
|
module NotionRubyMapping
|
8
7
|
# singleton class of caching Notion objects
|
@@ -14,10 +13,10 @@ module NotionRubyMapping
|
|
14
13
|
# @see https://www.notion.so/hkob/NotionCache-65e1599864d6425686d495a5a4b3a623#dca210788f114cf59464090782c073bf
|
15
14
|
def initialize
|
16
15
|
@object_hash = {}
|
17
|
-
@client = Faraday
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
@client = Faraday.new "https://api.notion.com" do |conn|
|
17
|
+
conn.request :json
|
18
|
+
conn.response :json, parser_options: {symbolize_names: true}
|
19
|
+
conn.headers["Notion-Version"] = NotionRubyMapping::NOTION_VERSION
|
21
20
|
end
|
22
21
|
@notion_token = nil
|
23
22
|
@wait = 0.3333
|
@@ -248,7 +247,6 @@ module NotionRubyMapping
|
|
248
247
|
sleep @wait
|
249
248
|
response = @client.send(method) do |request|
|
250
249
|
request.headers["Authorization"] = "Bearer #{@notion_token}"
|
251
|
-
request.headers["Notion-Version"] = NotionRubyMapping::NOTION_VERSION
|
252
250
|
case method
|
253
251
|
when :get, :delete
|
254
252
|
request.url path, options
|
@@ -266,13 +264,13 @@ module NotionRubyMapping
|
|
266
264
|
end
|
267
265
|
|
268
266
|
def search(query)
|
269
|
-
request(:post, search_path,
|
267
|
+
request(:post, search_path, query)
|
270
268
|
end
|
271
269
|
|
272
270
|
def search_path
|
273
271
|
"v1/search"
|
274
272
|
end
|
275
|
-
|
273
|
+
|
276
274
|
# @param [String] token
|
277
275
|
def token=(token)
|
278
276
|
@notion_token = token
|
@@ -8,7 +8,7 @@ module NotionRubyMapping
|
|
8
8
|
@update_block_key = []
|
9
9
|
end
|
10
10
|
|
11
|
-
# @param [
|
11
|
+
# @param [Symbol] key
|
12
12
|
def add_update_block_key(key)
|
13
13
|
@update_block_key << key
|
14
14
|
end
|
@@ -20,19 +20,19 @@ module NotionRubyMapping
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def description=(text_objects)
|
23
|
-
rta = RichTextArray.rich_text_array
|
24
|
-
@json.merge!(rta.update_property_schema_json
|
23
|
+
rta = RichTextArray.rich_text_array :description, text_objects
|
24
|
+
@json.merge!(rta.update_property_schema_json(true))
|
25
25
|
end
|
26
26
|
|
27
27
|
# @param [Boolean] flag
|
28
28
|
def is_inline=(flag)
|
29
|
-
@json[
|
29
|
+
@json[:is_inline] = flag
|
30
30
|
end
|
31
31
|
|
32
32
|
# @param [Hash] json
|
33
33
|
def merge_property(json)
|
34
|
-
@json[
|
35
|
-
@json[
|
34
|
+
@json[:properties] ||= {}
|
35
|
+
@json[:properties].merge!(json)
|
36
36
|
end
|
37
37
|
|
38
38
|
# @return [Hash] created json
|
@@ -52,21 +52,21 @@ module NotionRubyMapping
|
|
52
52
|
# @return [NotionRubyMapping::Payload] updated Payload
|
53
53
|
def set_icon(emoji: nil, url: nil)
|
54
54
|
payload = if emoji
|
55
|
-
{
|
55
|
+
{type: "emoji", emoji: emoji}
|
56
56
|
elsif url
|
57
|
-
{
|
57
|
+
{type: "external", external: {url: url}}
|
58
58
|
else
|
59
59
|
{}
|
60
60
|
end
|
61
|
-
@json[
|
61
|
+
@json[:icon] = payload
|
62
62
|
self
|
63
63
|
end
|
64
64
|
|
65
65
|
def update_block_json(type, json)
|
66
66
|
sub_json = json[type]
|
67
67
|
ans = {type => sub_json.slice(*@update_block_key)}
|
68
|
-
ans[type][
|
69
|
-
ans[type][
|
68
|
+
ans[type][:caption] = sub_json[:caption] if sub_json[:caption]
|
69
|
+
ans[type][:rich_text] = sub_json[:rich_text] if sub_json[:rich_text]
|
70
70
|
ans
|
71
71
|
end
|
72
72
|
|
@@ -17,7 +17,8 @@ module NotionRubyMapping
|
|
17
17
|
# @return [Property] Property for key
|
18
18
|
# @see https://www.notion.so/hkob/PropertyCache-2451fa64a814432db4809831cc77ba25#9709e2b2a7a0479f9951291a501f65c8
|
19
19
|
def [](key)
|
20
|
-
|
20
|
+
key_sym = key.to_sym
|
21
|
+
@properties[key_sym] ||= Property.create_from_json key_sym, @json[key_sym], @base_type, self
|
21
22
|
end
|
22
23
|
|
23
24
|
# @param [Property] property added Property
|
@@ -56,8 +57,8 @@ module NotionRubyMapping
|
|
56
57
|
def property_values_json
|
57
58
|
@properties.each_with_object({}) do |(_, property), ans|
|
58
59
|
if property.will_update
|
59
|
-
ans[
|
60
|
-
ans[
|
60
|
+
ans[:properties] ||= {}
|
61
|
+
ans[:properties].merge! property.property_values_json
|
61
62
|
end
|
62
63
|
end
|
63
64
|
end
|
@@ -66,8 +67,8 @@ module NotionRubyMapping
|
|
66
67
|
def property_schema_json
|
67
68
|
@properties.each_with_object({}) do |(_, property), ans|
|
68
69
|
if property.will_update
|
69
|
-
ans[
|
70
|
-
ans[
|
70
|
+
ans[:properties] ||= {}
|
71
|
+
ans[:properties].merge! property.property_schema_json
|
71
72
|
end
|
72
73
|
end
|
73
74
|
end
|
@@ -76,8 +77,8 @@ module NotionRubyMapping
|
|
76
77
|
def update_property_schema_json
|
77
78
|
@properties.each_with_object({}) do |(_, property), ans|
|
78
79
|
if property.will_update
|
79
|
-
ans[
|
80
|
-
ans[
|
80
|
+
ans[:properties] ||= {}
|
81
|
+
ans[:properties].merge! property.update_property_schema_json
|
81
82
|
end
|
82
83
|
end
|
83
84
|
end
|
@@ -16,10 +16,10 @@ module NotionRubyMapping
|
|
16
16
|
# @param [Query] another_query other query
|
17
17
|
# @return [NotionRubyMapping::Query] updated self (Query object)
|
18
18
|
def and(another_query)
|
19
|
-
if @filter.key?
|
20
|
-
@filter[
|
19
|
+
if @filter.key? :and
|
20
|
+
@filter[:and] << another_query.filter
|
21
21
|
else
|
22
|
-
@filter = {
|
22
|
+
@filter = {and: [@filter, another_query.filter]}
|
23
23
|
end
|
24
24
|
self
|
25
25
|
end
|
@@ -27,26 +27,26 @@ module NotionRubyMapping
|
|
27
27
|
# @param [NotionRubyMapping::Property] property
|
28
28
|
# @return [NotionRubyMapping::Query] updated self (Query object)
|
29
29
|
def ascending(property)
|
30
|
-
key = property.is_a?(LastEditedTimeProperty) || property.is_a?(CreatedTimeProperty) ?
|
31
|
-
@sort << {key => property.name,
|
30
|
+
key = property.is_a?(LastEditedTimeProperty) || property.is_a?(CreatedTimeProperty) ? :timestamp : :property
|
31
|
+
@sort << {key => property.name, direction: "ascending"}
|
32
32
|
self
|
33
33
|
end
|
34
34
|
|
35
35
|
# @param [NotionRubyMapping::Property] property
|
36
36
|
# @return [NotionRubyMapping::Query] updated self (Query object)
|
37
37
|
def descending(property)
|
38
|
-
key = property.is_a?(LastEditedTimeProperty) || property.is_a?(CreatedTimeProperty) ?
|
39
|
-
@sort << {key => property.name,
|
38
|
+
key = property.is_a?(LastEditedTimeProperty) || property.is_a?(CreatedTimeProperty) ? :timestamp : :property
|
39
|
+
@sort << {key => property.name, direction: "descending"}
|
40
40
|
self
|
41
41
|
end
|
42
42
|
|
43
43
|
# @param [Query] other_query other query
|
44
44
|
# @return [NotionRubyMapping::Query] updated self (Query object)
|
45
45
|
def or(other_query)
|
46
|
-
if @filter.key?
|
47
|
-
@filter[
|
46
|
+
if @filter.key? :or
|
47
|
+
@filter[:or] << other_query.filter
|
48
48
|
else
|
49
|
-
@filter = {
|
49
|
+
@filter = {or: [@filter, other_query.filter]}
|
50
50
|
end
|
51
51
|
self
|
52
52
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module NotionRubyMapping
|
2
2
|
class Search
|
3
|
-
|
4
3
|
def initialize(ascending: false, database_only: false, page_only: false, query: nil)
|
5
4
|
@ascending = ascending
|
6
5
|
@database_only = database_only
|
@@ -19,11 +18,11 @@ module NotionRubyMapping
|
|
19
18
|
|
20
19
|
def payload
|
21
20
|
ans = {}
|
22
|
-
ans[
|
23
|
-
ans[
|
24
|
-
ans[
|
25
|
-
ans[
|
21
|
+
ans[:sort] = {direction: "ascending", timestamp: "last_edited_time"} if @ascending
|
22
|
+
ans[:filter] = {value: "database", property: "object"} if @database_only
|
23
|
+
ans[:filter] = {value: "page", property: "object"} if @page_only
|
24
|
+
ans[:query] = @query if @query
|
26
25
|
ans
|
27
26
|
end
|
28
27
|
end
|
29
|
-
end
|
28
|
+
end
|
@@ -10,7 +10,7 @@ module NotionRubyMapping
|
|
10
10
|
@json = {}
|
11
11
|
elsif json
|
12
12
|
@json = json
|
13
|
-
@text_objects = RichTextArray.new "rich_text", json: json[
|
13
|
+
@text_objects = RichTextArray.new "rich_text", json: json[:rich_text]
|
14
14
|
else
|
15
15
|
raise StandardError, "Either text_objects or json is required CommentObject"
|
16
16
|
end
|
@@ -19,7 +19,7 @@ module NotionRubyMapping
|
|
19
19
|
attr_reader :will_update, :text_objects, :json
|
20
20
|
|
21
21
|
def discussion_id
|
22
|
-
NotionCache.instance.hex_id @json[
|
22
|
+
NotionCache.instance.hex_id @json[:discussion_id]
|
23
23
|
end
|
24
24
|
|
25
25
|
# @return [String] full_text
|
@@ -6,7 +6,7 @@ module NotionRubyMapping
|
|
6
6
|
# @param [String] emoji
|
7
7
|
# @return [TextObject]
|
8
8
|
def initialize(emoji: nil, json: {})
|
9
|
-
@emoji = emoji || json && json[
|
9
|
+
@emoji = emoji || json && json[:emoji]
|
10
10
|
@will_update = false
|
11
11
|
end
|
12
12
|
attr_reader :will_update, :emoji
|
@@ -32,8 +32,8 @@ module NotionRubyMapping
|
|
32
32
|
# @return [Hash]
|
33
33
|
def property_values_json
|
34
34
|
{
|
35
|
-
|
36
|
-
|
35
|
+
type: "emoji",
|
36
|
+
emoji: @emoji,
|
37
37
|
}
|
38
38
|
end
|
39
39
|
end
|
@@ -6,7 +6,7 @@ module NotionRubyMapping
|
|
6
6
|
# @param [String] expression
|
7
7
|
# @return [TextObject]
|
8
8
|
def initialize(expression, options = {})
|
9
|
-
super
|
9
|
+
super :equation, {plain_text: expression}.merge(options)
|
10
10
|
@expression = expression
|
11
11
|
@will_update = false
|
12
12
|
end
|
@@ -27,7 +27,7 @@ module NotionRubyMapping
|
|
27
27
|
# @see https://www.notion.so/hkob/EquationObject-cd50126fce544ad5bb76463a4269859b#155800e2c69d4676a2d74572ed8f0de8
|
28
28
|
def expression=(expression)
|
29
29
|
@expression = expression
|
30
|
-
@options[
|
30
|
+
@options[:plain_text] = expression
|
31
31
|
@will_update = true
|
32
32
|
end
|
33
33
|
|
@@ -41,7 +41,7 @@ module NotionRubyMapping
|
|
41
41
|
# @return [Hash{String (frozen)->String}]
|
42
42
|
def partial_property_values_json
|
43
43
|
{
|
44
|
-
|
44
|
+
expression: @expression,
|
45
45
|
}
|
46
46
|
end
|
47
47
|
end
|
@@ -7,12 +7,12 @@ module NotionRubyMapping
|
|
7
7
|
# @return [TextObject]
|
8
8
|
def initialize(url: nil, json: {})
|
9
9
|
if url
|
10
|
-
@type =
|
10
|
+
@type = :external
|
11
11
|
@url = url
|
12
12
|
elsif json
|
13
|
-
@type = json[
|
14
|
-
@url = json[@type][
|
15
|
-
@expiry_time = json[@type][
|
13
|
+
@type = json[:type].to_sym
|
14
|
+
@url = json[@type][:url]
|
15
|
+
@expiry_time = json[@type][:expiry_time]
|
16
16
|
else
|
17
17
|
raise StandardError, "FileObject requires url: or json:"
|
18
18
|
end
|
@@ -33,14 +33,14 @@ module NotionRubyMapping
|
|
33
33
|
|
34
34
|
# @return [TrueClass, FalseClass] true if "type" is "external"
|
35
35
|
def external?
|
36
|
-
@type ==
|
36
|
+
@type == :external
|
37
37
|
end
|
38
38
|
|
39
39
|
# @param [String] url
|
40
40
|
# @see https://www.notion.so/hkob/FileObject-6218c354e985423a90904f47a985be33#6b841f75d0234a1aac93fb54348abb96
|
41
41
|
def url=(url)
|
42
42
|
@url = url
|
43
|
-
@type =
|
43
|
+
@type = :external
|
44
44
|
@expiry_time = nil
|
45
45
|
@will_update = true
|
46
46
|
end
|
@@ -48,12 +48,12 @@ module NotionRubyMapping
|
|
48
48
|
# @return [Hash]
|
49
49
|
def property_values_json
|
50
50
|
ans = {
|
51
|
-
|
51
|
+
type: @type.to_s,
|
52
52
|
@type => {
|
53
|
-
|
53
|
+
url: @url,
|
54
54
|
},
|
55
55
|
}
|
56
|
-
ans[@type][
|
56
|
+
ans[@type][:expiry_time] = @expiry_time if @expiry_time
|
57
57
|
ans
|
58
58
|
end
|
59
59
|
end
|