notion_ruby_mapping 1.0.0 → 2.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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/lib/notion_ruby_mapping/blocks/base.rb +51 -37
  3. data/lib/notion_ruby_mapping/blocks/block.rb +13 -13
  4. data/lib/notion_ruby_mapping/blocks/bookmark_block.rb +1 -1
  5. data/lib/notion_ruby_mapping/blocks/breadcrumb_block.rb +1 -1
  6. data/lib/notion_ruby_mapping/blocks/bulleted_list_item_block.rb +1 -1
  7. data/lib/notion_ruby_mapping/blocks/callout_block.rb +10 -10
  8. data/lib/notion_ruby_mapping/blocks/child_base_block.rb +2 -2
  9. data/lib/notion_ruby_mapping/blocks/child_database_block.rb +3 -3
  10. data/lib/notion_ruby_mapping/blocks/child_page_block.rb +3 -3
  11. data/lib/notion_ruby_mapping/blocks/code_block.rb +7 -7
  12. data/lib/notion_ruby_mapping/blocks/column_block.rb +3 -3
  13. data/lib/notion_ruby_mapping/blocks/column_list_block.rb +2 -2
  14. data/lib/notion_ruby_mapping/blocks/database.rb +5 -5
  15. data/lib/notion_ruby_mapping/blocks/divider_block.rb +1 -1
  16. data/lib/notion_ruby_mapping/blocks/embed_block.rb +2 -2
  17. data/lib/notion_ruby_mapping/blocks/equation_block.rb +5 -5
  18. data/lib/notion_ruby_mapping/blocks/file_base_block.rb +15 -3
  19. data/lib/notion_ruby_mapping/blocks/file_block.rb +2 -2
  20. data/lib/notion_ruby_mapping/blocks/heading1_block.rb +3 -3
  21. data/lib/notion_ruby_mapping/blocks/heading2_block.rb +2 -2
  22. data/lib/notion_ruby_mapping/blocks/heading3_block.rb +3 -3
  23. data/lib/notion_ruby_mapping/blocks/image_block.rb +2 -2
  24. data/lib/notion_ruby_mapping/blocks/link_preview_block.rb +2 -2
  25. data/lib/notion_ruby_mapping/blocks/link_to_page_block.rb +5 -5
  26. data/lib/notion_ruby_mapping/blocks/list.rb +21 -21
  27. data/lib/notion_ruby_mapping/blocks/numbered_list_item_block.rb +2 -2
  28. data/lib/notion_ruby_mapping/blocks/page.rb +8 -8
  29. data/lib/notion_ruby_mapping/blocks/paragraph_block.rb +2 -2
  30. data/lib/notion_ruby_mapping/blocks/pdf_block.rb +2 -2
  31. data/lib/notion_ruby_mapping/blocks/quote_block.rb +1 -1
  32. data/lib/notion_ruby_mapping/blocks/synced_block.rb +5 -5
  33. data/lib/notion_ruby_mapping/blocks/table_block.rb +8 -8
  34. data/lib/notion_ruby_mapping/blocks/table_of_contents_block.rb +3 -3
  35. data/lib/notion_ruby_mapping/blocks/table_row_block.rb +3 -3
  36. data/lib/notion_ruby_mapping/blocks/template_block.rb +3 -3
  37. data/lib/notion_ruby_mapping/blocks/text_sub_block_color_base_block.rb +4 -4
  38. data/lib/notion_ruby_mapping/blocks/to_do_block.rb +4 -4
  39. data/lib/notion_ruby_mapping/blocks/toggle_block.rb +2 -2
  40. data/lib/notion_ruby_mapping/blocks/toggle_heading1_block.rb +2 -2
  41. data/lib/notion_ruby_mapping/blocks/toggle_heading2_block.rb +2 -2
  42. data/lib/notion_ruby_mapping/blocks/toggle_heading3_block.rb +3 -3
  43. data/lib/notion_ruby_mapping/blocks/url_base_block.rb +3 -3
  44. data/lib/notion_ruby_mapping/blocks/url_caption_base_block.rb +4 -4
  45. data/lib/notion_ruby_mapping/blocks/video_block.rb +2 -2
  46. data/lib/notion_ruby_mapping/controllers/mermaid.rb +2 -5
  47. data/lib/notion_ruby_mapping/controllers/mermaid_database.rb +29 -32
  48. data/lib/notion_ruby_mapping/controllers/notion_cache.rb +68 -2
  49. data/lib/notion_ruby_mapping/controllers/payload.rb +29 -11
  50. data/lib/notion_ruby_mapping/controllers/property_cache.rb +8 -9
  51. data/lib/notion_ruby_mapping/controllers/query.rb +14 -14
  52. data/lib/notion_ruby_mapping/controllers/search.rb +5 -5
  53. data/lib/notion_ruby_mapping/objects/comment_object.rb +2 -2
  54. data/lib/notion_ruby_mapping/objects/emoji_object.rb +3 -3
  55. data/lib/notion_ruby_mapping/objects/equation_object.rb +3 -3
  56. data/lib/notion_ruby_mapping/objects/file_object.rb +44 -21
  57. data/lib/notion_ruby_mapping/objects/file_upload_object.rb +78 -0
  58. data/lib/notion_ruby_mapping/objects/mention_object.rb +43 -43
  59. data/lib/notion_ruby_mapping/objects/rich_text_object.rb +43 -43
  60. data/lib/notion_ruby_mapping/objects/text_object.rb +5 -5
  61. data/lib/notion_ruby_mapping/objects/user_object.rb +4 -4
  62. data/lib/notion_ruby_mapping/properties/button_property.rb +3 -3
  63. data/lib/notion_ruby_mapping/properties/checkbox_property.rb +3 -3
  64. data/lib/notion_ruby_mapping/properties/created_by_property.rb +3 -3
  65. data/lib/notion_ruby_mapping/properties/created_time_property.rb +2 -2
  66. data/lib/notion_ruby_mapping/properties/date_base_property.rb +15 -14
  67. data/lib/notion_ruby_mapping/properties/date_property.rb +16 -16
  68. data/lib/notion_ruby_mapping/properties/email_property.rb +3 -3
  69. data/lib/notion_ruby_mapping/properties/files_property.rb +14 -12
  70. data/lib/notion_ruby_mapping/properties/formula_property.rb +7 -7
  71. data/lib/notion_ruby_mapping/properties/last_edited_by_property.rb +4 -3
  72. data/lib/notion_ruby_mapping/properties/last_edited_time_property.rb +2 -2
  73. data/lib/notion_ruby_mapping/properties/multi_select_property.rb +15 -15
  74. data/lib/notion_ruby_mapping/properties/number_property.rb +9 -9
  75. data/lib/notion_ruby_mapping/properties/people_property.rb +7 -7
  76. data/lib/notion_ruby_mapping/properties/phone_number_property.rb +3 -3
  77. data/lib/notion_ruby_mapping/properties/property.rb +55 -56
  78. data/lib/notion_ruby_mapping/properties/relation_property.rb +17 -18
  79. data/lib/notion_ruby_mapping/properties/rich_text_property.rb +5 -5
  80. data/lib/notion_ruby_mapping/properties/rollup_property.rb +15 -15
  81. data/lib/notion_ruby_mapping/properties/select_property.rb +14 -14
  82. data/lib/notion_ruby_mapping/properties/status_property.rb +5 -5
  83. data/lib/notion_ruby_mapping/properties/text_property.rb +1 -1
  84. data/lib/notion_ruby_mapping/properties/title_property.rb +7 -7
  85. data/lib/notion_ruby_mapping/properties/unique_id_property.rb +4 -4
  86. data/lib/notion_ruby_mapping/properties/url_property.rb +3 -3
  87. data/lib/notion_ruby_mapping/properties/verification_property.rb +3 -3
  88. data/lib/notion_ruby_mapping/version.rb +1 -1
  89. data/lib/notion_ruby_mapping.rb +1 -1
  90. data/notion_ruby_mapping.gemspec +2 -0
  91. metadata +35 -3
@@ -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][:url]
15
+ @url = @json[type]["url"]
16
16
  decode_block_caption
17
17
  else
18
18
  @url = url
19
- @caption = RichTextArray.rich_text_array :caption, caption
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][:url] = @url
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 :url
43
+ @payload.add_update_block_key "url"
44
44
  end
45
45
  end
46
46
  end
@@ -3,9 +3,9 @@
3
3
  module NotionRubyMapping
4
4
  # Notion block
5
5
  class VideoBlock < FileBaseBlock
6
- # @return [Symbol]
6
+ # @return [String]
7
7
  def type
8
- :video
8
+ "video"
9
9
  end
10
10
  end
11
11
  end
@@ -16,11 +16,10 @@ module NotionRubyMapping
16
16
  until @lines.empty?
17
17
  case @lines.shift
18
18
  when / *(\w+) *[|}][|o]--[o|][|{] *(\w+) *: *"(.*)" */
19
- db_or_create(Regexp.last_match(1)).append_relation_queue db_or_create(Regexp.last_match(2)), Regexp.last_match(3)
19
+ db_or_create(Regexp.last_match(1)).append_relation_queue db_or_create(Regexp.last_match(2)),
20
+ Regexp.last_match(3)
20
21
  when / *(\w+) *{ */
21
22
  append_db_with_attributes Regexp.last_match(1)
22
- else
23
- nil
24
23
  end
25
24
  end
26
25
  end
@@ -41,8 +40,6 @@ module NotionRubyMapping
41
40
  db.add_property Regexp.last_match(1), Regexp.last_match(2)
42
41
  when /^ *([^ ]+) +([^ ]+) *$/
43
42
  db.add_property Regexp.last_match(1), Regexp.last_match(2)
44
- else
45
- nil
46
43
  end
47
44
  end
48
45
  end
@@ -16,11 +16,10 @@ module NotionRubyMapping
16
16
  attr_accessor :name
17
17
 
18
18
  def add_property(key, value)
19
- key_sym = key.to_sym
20
- if key_sym == :title
19
+ if key == "title"
21
20
  @title = value
22
21
  else
23
- @properties[value] = key_sym
22
+ @properties[value] = key
24
23
  end
25
24
  end
26
25
 
@@ -44,7 +43,7 @@ module NotionRubyMapping
44
43
  end
45
44
 
46
45
  def blocked?(name)
47
- @finish_flag[name.to_sym].nil?
46
+ @finish_flag[name].nil?
48
47
  end
49
48
 
50
49
  def count
@@ -66,12 +65,10 @@ module NotionRubyMapping
66
65
  ps = @real_db.properties
67
66
  @properties.each do |(value, key)|
68
67
  name, *options = value.split("|")
69
- name_sym = name.to_sym
70
- key_sym = key.to_sym
71
- next if @finish_flag[name_sym]
68
+ next if @finish_flag[name]
72
69
 
73
- property = ps.values_at(name_sym).first
74
- case key_sym
70
+ property = ps.values_at(name).first
71
+ case key
75
72
  when /checkbox|created_by|created_time|date|email|files|last_edited_by|last_edited_time|people|phone_number|text|url|status/
76
73
  klass = {
77
74
  checkbox: CheckboxProperty, created_by: CreatedByProperty, created_time: CreatedTimeProperty,
@@ -79,9 +76,9 @@ module NotionRubyMapping
79
76
  last_edited_time: LastEditedTimeProperty, people: PeopleProperty, phone_number: PhoneNumberProperty,
80
77
  rich_text: RichTextProperty, url: UrlProperty, status: StatusProperty
81
78
  }[key.to_sym]
82
- @real_db.add_property klass, name_sym unless property
83
- @working << name_sym
84
- when :formula
79
+ @real_db.add_property klass, name unless property
80
+ @working << name
81
+ when "formula"
85
82
  f_e = options.first&.gsub "@", '"'
86
83
  dependencies = f_e&.scan(/prop\("([^"]+)"\)/) || []
87
84
  blocked_key = dependencies.select { |k| blocked? k.first }
@@ -89,37 +86,37 @@ module NotionRubyMapping
89
86
  if property
90
87
  property.formula_expression = f_e unless property.formula_expression == f_e
91
88
  else
92
- @real_db.add_property(FormulaProperty, name_sym) { |dp| dp.formula_expression = f_e }
89
+ @real_db.add_property(FormulaProperty, name) { |dp| dp.formula_expression = f_e }
93
90
  end
94
- @working << name_sym
91
+ @working << name
95
92
  else
96
- print("#{name_sym} blocked by #{blocked_key.flatten}\n")
93
+ print("#{name} blocked by #{blocked_key.flatten}\n")
97
94
  next
98
95
  end
99
96
 
100
- when :multi_select
97
+ when "multi_select"
101
98
  if property
102
- (options - (property.multi_select_options.map { |h| h[:name] })).each do |select_name|
99
+ (options - (property.multi_select_options.map { |h| h["name"] })).each do |select_name|
103
100
  property.add_multi_select_option name: select_name, color: "default"
104
101
  end
105
102
  else
106
- @real_db.add_property(MultiSelectProperty, name_sym) do |dp|
103
+ @real_db.add_property(MultiSelectProperty, name) do |dp|
107
104
  options.each do |select_name|
108
105
  dp.add_multi_select_option name: select_name, color: "default"
109
106
  end
110
107
  end
111
108
  end
112
- @working << name_sym
113
- when :number
109
+ @working << name
110
+ when "number"
114
111
  format_value = options.empty? ? "number" : options.first
115
112
  if property
116
113
  property.format = format_value unless property.format == format_value
117
114
  else
118
- @real_db.add_property(NumberProperty, name_sym) { |p| p.format = format_value }
115
+ @real_db.add_property(NumberProperty, name) { |p| p.format = format_value }
119
116
  end
120
- @working << name_sym
121
- when :rollup
122
- name, *options = value.split("|").map(&:to_sym)
117
+ @working << name
118
+ when "rollup"
119
+ name, *options = value.split("|")
123
120
  relation_name, rollup_name, function = options
124
121
  if blocked? relation_name
125
122
  print("#{name} blocked by #{relation_name}\n")
@@ -146,9 +143,9 @@ module NotionRubyMapping
146
143
  @working << name
147
144
  end
148
145
  end
149
- when :select
146
+ when "select"
150
147
  if property
151
- (options - (property.select_options.map { |h| h[:name] })).each do |select_name|
148
+ (options - (property.select_options.map { |h| h["name"] })).each do |select_name|
152
149
  property.add_select_option name: select_name, color: "default"
153
150
  end
154
151
  else
@@ -164,12 +161,12 @@ module NotionRubyMapping
164
161
  while (array = @relation_queue.shift)
165
162
  value, relation_db = array
166
163
  db_id = relation_db.real_db.id
167
- forward, reverse = value.split("|").map(&:to_sym)
164
+ forward, reverse = value.split("|").map(&:to_s)
168
165
  property = ps.values_at(forward).first
169
166
  if property
170
167
  if reverse
171
168
  if property.database_id == db_id && property.synced_property_name == reverse
172
- relation_db.add_property :relation, reverse
169
+ relation_db.add_property "relation", reverse
173
170
  relation_db.finish_flag[reverse] = true
174
171
  else
175
172
  unless @finish_flag[forward]
@@ -177,14 +174,14 @@ module NotionRubyMapping
177
174
  relation_db.append_reverse_name_queue self, forward, reverse
178
175
  end
179
176
  @working << forward
180
- add_property :relation, forward
177
+ add_property "relation", forward
181
178
  end
182
179
  relation_db.relations[reverse] = self
183
180
  else
184
181
  unless property.database_id == db_id
185
182
  property.replace_relation_database database_id: db_id, type: "single_property"
186
183
  @working << forward
187
- add_property :relation, forward
184
+ add_property "relation", forward
188
185
  end
189
186
  end
190
187
  @relations[forward] = relation_db
@@ -200,7 +197,7 @@ module NotionRubyMapping
200
197
  end
201
198
  @relations[forward] = relation_db
202
199
  @working << forward
203
- add_property :relation, forward
200
+ add_property "relation", forward
204
201
  end
205
202
  end
206
203
  @real_db.property_schema_json
@@ -208,7 +205,7 @@ module NotionRubyMapping
208
205
 
209
206
  def append_reverse_name_queue(other_db, forward, reverse)
210
207
  @reverse_name_queue[reverse] = [other_db, forward]
211
- add_property :relation, reverse
208
+ add_property "relation", reverse
212
209
  end
213
210
 
214
211
  def update_database
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "singleton"
4
4
  require "faraday"
5
+ require "faraday/multipart"
6
+ require "mime/types"
5
7
 
6
8
  module NotionRubyMapping
7
9
  # singleton class of caching Notion objects
@@ -15,7 +17,7 @@ module NotionRubyMapping
15
17
  @object_hash = {}
16
18
  @client = Faraday.new "https://api.notion.com" do |conn|
17
19
  conn.request :json
18
- conn.response :json, parser_options: {symbolize_names: true}
20
+ conn.response :json
19
21
  conn.headers["Notion-Version"] = NotionRubyMapping::NOTION_VERSION
20
22
  end
21
23
  @notion_token = nil
@@ -27,6 +29,14 @@ module NotionRubyMapping
27
29
  attr_writer :client # for test only
28
30
  attr_accessor :notion_token, :wait, :debug, :use_cache
29
31
 
32
+ def multipart_client
33
+ @multipart_client ||= Faraday.new "https://api.notion.com" do |conn|
34
+ conn.request :multipart, flat_encode: true
35
+ conn.response :json
36
+ conn.headers["Notion-Version"] = NotionRubyMapping::NOTION_VERSION
37
+ end
38
+ end
39
+
30
40
  # @param [String] block_id
31
41
  # @return [String (frozen)] block_path
32
42
  def append_block_children_block_path(block_id)
@@ -91,6 +101,14 @@ module NotionRubyMapping
91
101
  "v1/comments"
92
102
  end
93
103
 
104
+ def complete_a_file_upload_path(file_id)
105
+ "v1/file_uploads/#{file_id}/complete"
106
+ end
107
+
108
+ def complete_a_file_upload_request(file_id)
109
+ request :post, complete_a_file_upload_path(file_id)
110
+ end
111
+
94
112
  # @param [String] notion_token
95
113
  # @return [NotionRubyMapping::NotionCache] self (NotionCache.instance)
96
114
  def create_client(notion_token, wait: 0.3333, debug: false)
@@ -106,6 +124,12 @@ module NotionRubyMapping
106
124
  request :post, databases_path, payload
107
125
  end
108
126
 
127
+ # @param [Hash] payload
128
+ # @return [Hash] response
129
+ def create_file_upload_request(payload = {})
130
+ request :post, file_uploads_path, payload
131
+ end
132
+
109
133
  # @param [Hash] payload
110
134
  # @return [Hash] response
111
135
  def create_page_request(payload)
@@ -160,6 +184,25 @@ module NotionRubyMapping
160
184
  request :delete, block_path(id)
161
185
  end
162
186
 
187
+ # @param [String] fname
188
+ # @param [String] id
189
+ # @param [Hash] options
190
+ # @return [Hash]
191
+ def file_upload_request(fname, id, options = {})
192
+ multipart_request(file_upload_path(id), fname, options)
193
+ end
194
+
195
+ # @param [String] id
196
+ # @return [String]
197
+ def file_upload_path(id)
198
+ "v1/file_uploads/#{id}/send"
199
+ end
200
+
201
+ # @return [String]
202
+ def file_uploads_path
203
+ "v1/file_uploads"
204
+ end
205
+
163
206
  # @param [String] id id string with "-"
164
207
  # @return [String] id without "-"
165
208
  # @see https://www.notion.so/hkob/NotionCache-65e1599864d6425686d495a5a4b3a623#a2d70a2e019c4c17898aaa1a36580f1d
@@ -171,6 +214,28 @@ module NotionRubyMapping
171
214
  "NotionCache"
172
215
  end
173
216
 
217
+ # @param [String] path
218
+ # @param [String] fname
219
+ # @param [Hash] options
220
+ # @return [Hash] response hash
221
+ def multipart_request(path, fname, options = {})
222
+ raise "Please call `NotionRubyMapping.configure' before using other methods" unless @notion_token
223
+
224
+ content_type = MIME::Types.type_for(fname).first.to_s
225
+
226
+ sleep @wait
227
+ body = options.map { |k, v| [k, Faraday::Multipart::ParamPart.new(v, "text/plain")] }.to_h
228
+ file_part = Faraday::Multipart::FilePart.new(fname, content_type, File.basename(fname))
229
+ response = multipart_client.send(:post) do |request|
230
+ request.headers["Authorization"] = "Bearer #{@notion_token}"
231
+ request.headers["content-Type"] = "multipart/form-data"
232
+ request.path = path
233
+ request.body = {file: file_part}.merge body
234
+ end
235
+ p response.body if @debug
236
+ response.body
237
+ end
238
+
174
239
  # @param [String] id id (with or without "-")
175
240
  # @return [NotionRubyMapping::Base]
176
241
  def object_for_key(id)
@@ -206,6 +271,7 @@ module NotionRubyMapping
206
271
  # @param [String] property_id
207
272
  # @return [Hash] response
208
273
  def page_property_request(page_id, property_id, query = {})
274
+ p "page_id = #{page_id}, property_id = #{property_id}, query = #{query}" if @debug
209
275
  request :get, page_property_path(page_id, property_id), query
210
276
  end
211
277
 
@@ -320,7 +386,7 @@ module NotionRubyMapping
320
386
 
321
387
  # @return [Array<NotionRubyMapping::UserObject>] UserObject array
322
388
  def users
323
- List.new json: users_request, type: :user_object, value: true
389
+ List.new json: users_request, type: "user_object", value: true
324
390
  end
325
391
 
326
392
  # @return [String (frozen)] user_path
@@ -8,7 +8,7 @@ module NotionRubyMapping
8
8
  @update_block_key = []
9
9
  end
10
10
 
11
- # @param [Symbol] key
11
+ # @param [String] 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 :description, text_objects
23
+ rta = RichTextArray.rich_text_array "description", text_objects
24
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[:is_inline] = flag
29
+ @json["is_inline"] = flag
30
30
  end
31
31
 
32
32
  # @param [Hash] json
33
33
  def merge_property(json)
34
- @json[:properties] ||= {}
35
- @json[:properties].merge!(json)
34
+ @json["properties"] ||= {}
35
+ @json["properties"].merge!(json)
36
36
  end
37
37
 
38
38
  # @return [Hash] created json
@@ -47,26 +47,44 @@ module NotionRubyMapping
47
47
  others.compact.reduce({}) { |hash, o| hash.merge o.property_schema_json }.merge @json
48
48
  end
49
49
 
50
+ # @param [String, nil] url
51
+ # @param [String, nil] file_upload_object
52
+ # @return [NotionRubyMapping::Payload]
53
+ def set_cover(url: nil, file_upload_object: nil)
54
+ payload = if url
55
+ {"type" => "external", "external" => {"url" => url}}
56
+ elsif file_upload_object
57
+ {"type" => "file_upload", "file_upload" => {"id" => file_upload_object.id}}
58
+ else
59
+ {}
60
+ end
61
+ @json["cover"] = payload
62
+ self
63
+ end
64
+
50
65
  # @param [String] emoji
51
66
  # @param [String] url
67
+ # @param [FileUploadObject] file_upload_object
52
68
  # @return [NotionRubyMapping::Payload] updated Payload
53
- def set_icon(emoji: nil, url: nil)
69
+ def set_icon(emoji: nil, url: nil, file_upload_object: nil)
54
70
  payload = if emoji
55
- {type: "emoji", emoji: emoji}
71
+ {"type" => "emoji", "emoji" => emoji}
56
72
  elsif url
57
- {type: "external", external: {url: url}}
73
+ {"type" => "external", "external" => {"url" => url}}
74
+ elsif file_upload_object
75
+ {"type" => "file_upload", "file_upload" => {"id" => file_upload_object.id}}
58
76
  else
59
77
  {}
60
78
  end
61
- @json[:icon] = payload
79
+ @json["icon"] = payload
62
80
  self
63
81
  end
64
82
 
65
83
  def update_block_json(type, json)
66
84
  sub_json = json[type]
67
85
  ans = {type => sub_json.slice(*@update_block_key)}
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]
86
+ ans[type]["caption"] = sub_json["caption"] if sub_json["caption"]
87
+ ans[type]["rich_text"] = sub_json["rich_text"] if sub_json["rich_text"]
70
88
  ans
71
89
  end
72
90
 
@@ -4,7 +4,7 @@ module NotionRubyMapping
4
4
  # PropertyCache class
5
5
  class PropertyCache
6
6
  include Enumerable
7
- def initialize(json = {}, base_type: :page, page_id: nil)
7
+ def initialize(json = {}, base_type: "page", page_id: nil)
8
8
  @properties = {}
9
9
  @json = json
10
10
  @base_type = base_type
@@ -17,8 +17,7 @@ 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
- key_sym = key.to_sym
21
- @properties[key_sym] ||= Property.create_from_json key_sym, @json[key_sym], @base_type, self
20
+ @properties[key] ||= Property.create_from_json key, @json[key], @base_type, self
22
21
  end
23
22
 
24
23
  # @param [Property] property added Property
@@ -57,8 +56,8 @@ module NotionRubyMapping
57
56
  def property_values_json
58
57
  @properties.each_with_object({}) do |(_, property), ans|
59
58
  if property.will_update
60
- ans[:properties] ||= {}
61
- ans[:properties].merge! property.property_values_json
59
+ ans["properties"] ||= {}
60
+ ans["properties"].merge! property.property_values_json
62
61
  end
63
62
  end
64
63
  end
@@ -67,8 +66,8 @@ module NotionRubyMapping
67
66
  def property_schema_json
68
67
  @properties.each_with_object({}) do |(_, property), ans|
69
68
  if property.will_update
70
- ans[:properties] ||= {}
71
- ans[:properties].merge! property.property_schema_json
69
+ ans["properties"] ||= {}
70
+ ans["properties"].merge! property.property_schema_json
72
71
  end
73
72
  end
74
73
  end
@@ -77,8 +76,8 @@ module NotionRubyMapping
77
76
  def update_property_schema_json
78
77
  @properties.each_with_object({}) do |(_, property), ans|
79
78
  if property.will_update
80
- ans[:properties] ||= {}
81
- ans[:properties].merge! property.update_property_schema_json
79
+ ans["properties"] ||= {}
80
+ ans["properties"].merge! property.update_property_schema_json
82
81
  end
83
82
  end
84
83
  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? :and
20
- @filter[:and] << another_query.filter
19
+ if @filter.key? "and"
20
+ @filter["and"] << another_query.filter
21
21
  else
22
- @filter = {and: [@filter, another_query.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) ? :timestamp : :property
31
- @sort << {key => property.name, direction: "ascending"}
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) ? :timestamp : :property
39
- @sort << {key => property.name, direction: "descending"}
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? :or
47
- @filter[:or] << other_query.filter
46
+ if @filter.key? "or"
47
+ @filter["or"] << other_query.filter
48
48
  else
49
- @filter = {or: [@filter, other_query.filter]}
49
+ @filter = {"or" => [@filter, other_query.filter]}
50
50
  end
51
51
  self
52
52
  end
@@ -54,10 +54,10 @@ module NotionRubyMapping
54
54
  # @return [Hash]
55
55
  def query_json
56
56
  parameters = {}
57
- parameters[:filter] = @filter unless @filter.empty?
58
- parameters[:sorts] = @sort unless @sort.empty?
59
- parameters[:start_cursor] = @start_cursor if @start_cursor
60
- parameters[:page_size] = @page_size if @page_size
57
+ parameters["filter"] = @filter unless @filter.empty?
58
+ parameters["sorts"] = @sort unless @sort.empty?
59
+ parameters["start_cursor"] = @start_cursor if @start_cursor
60
+ parameters["page_size"] = @page_size if @page_size
61
61
  parameters
62
62
  end
63
63
 
@@ -12,16 +12,16 @@ module NotionRubyMapping
12
12
  Base.dry_run_script :post, NotionCache.instance.search_path, payload
13
13
  else
14
14
  response = NotionCache.instance.search payload
15
- List.new json: response, type: :search, value: self, query: Query.new
15
+ List.new json: response, type: "search", value: self, query: Query.new
16
16
  end
17
17
  end
18
18
 
19
19
  def payload
20
20
  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
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
25
25
  ans
26
26
  end
27
27
  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[:rich_text]
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[:discussion_id]
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[:emoji]
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
- type: "emoji",
36
- emoji: @emoji,
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 :equation, {plain_text: expression}.merge(options)
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[:plain_text] = expression
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
- expression: @expression,
44
+ "expression" => @expression,
45
45
  }
46
46
  end
47
47
  end