notion_ruby_mapping 0.8.9 → 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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -1
  3. data/lib/notion_ruby_mapping/blocks/base.rb +28 -14
  4. data/lib/notion_ruby_mapping/blocks/block.rb +42 -41
  5. data/lib/notion_ruby_mapping/blocks/callout_block.rb +1 -1
  6. data/lib/notion_ruby_mapping/blocks/child_database_block.rb +1 -1
  7. data/lib/notion_ruby_mapping/blocks/child_page_block.rb +1 -1
  8. data/lib/notion_ruby_mapping/blocks/code_block.rb +1 -1
  9. data/lib/notion_ruby_mapping/blocks/column_block.rb +1 -1
  10. data/lib/notion_ruby_mapping/blocks/database.rb +1 -1
  11. data/lib/notion_ruby_mapping/blocks/embed_block.rb +1 -1
  12. data/lib/notion_ruby_mapping/blocks/equation_block.rb +1 -1
  13. data/lib/notion_ruby_mapping/blocks/file_base_block.rb +13 -1
  14. data/lib/notion_ruby_mapping/blocks/file_block.rb +1 -1
  15. data/lib/notion_ruby_mapping/blocks/heading1_block.rb +2 -2
  16. data/lib/notion_ruby_mapping/blocks/heading3_block.rb +1 -1
  17. data/lib/notion_ruby_mapping/blocks/image_block.rb +1 -1
  18. data/lib/notion_ruby_mapping/blocks/link_preview_block.rb +1 -1
  19. data/lib/notion_ruby_mapping/blocks/link_to_page_block.rb +1 -1
  20. data/lib/notion_ruby_mapping/blocks/list.rb +12 -11
  21. data/lib/notion_ruby_mapping/blocks/numbered_list_item_block.rb +1 -1
  22. data/lib/notion_ruby_mapping/blocks/page.rb +1 -2
  23. data/lib/notion_ruby_mapping/blocks/paragraph_block.rb +1 -1
  24. data/lib/notion_ruby_mapping/blocks/pdf_block.rb +1 -1
  25. data/lib/notion_ruby_mapping/blocks/toggle_block.rb +1 -1
  26. data/lib/notion_ruby_mapping/blocks/toggle_heading3_block.rb +1 -1
  27. data/lib/notion_ruby_mapping/blocks/video_block.rb +1 -1
  28. data/lib/notion_ruby_mapping/controllers/discussion_thread.rb +1 -1
  29. data/lib/notion_ruby_mapping/controllers/mermaid.rb +2 -5
  30. data/lib/notion_ruby_mapping/controllers/mermaid_database.rb +3 -6
  31. data/lib/notion_ruby_mapping/controllers/notion_cache.rb +73 -9
  32. data/lib/notion_ruby_mapping/controllers/payload.rb +20 -2
  33. data/lib/notion_ruby_mapping/controllers/property_cache.rb +1 -1
  34. data/lib/notion_ruby_mapping/controllers/query.rb +4 -4
  35. data/lib/notion_ruby_mapping/controllers/search.rb +4 -5
  36. data/lib/notion_ruby_mapping/objects/file_object.rb +38 -15
  37. data/lib/notion_ruby_mapping/objects/file_upload_object.rb +78 -0
  38. data/lib/notion_ruby_mapping/properties/button_property.rb +3 -3
  39. data/lib/notion_ruby_mapping/properties/checkbox_property.rb +2 -2
  40. data/lib/notion_ruby_mapping/properties/created_by_property.rb +2 -2
  41. data/lib/notion_ruby_mapping/properties/created_time_property.rb +2 -2
  42. data/lib/notion_ruby_mapping/properties/date_base_property.rb +4 -2
  43. data/lib/notion_ruby_mapping/properties/date_property.rb +4 -4
  44. data/lib/notion_ruby_mapping/properties/email_property.rb +2 -2
  45. data/lib/notion_ruby_mapping/properties/files_property.rb +9 -4
  46. data/lib/notion_ruby_mapping/properties/formula_property.rb +2 -2
  47. data/lib/notion_ruby_mapping/properties/last_edited_by_property.rb +2 -1
  48. data/lib/notion_ruby_mapping/properties/last_edited_time_property.rb +2 -2
  49. data/lib/notion_ruby_mapping/properties/multi_select_property.rb +3 -3
  50. data/lib/notion_ruby_mapping/properties/number_property.rb +3 -3
  51. data/lib/notion_ruby_mapping/properties/people_property.rb +3 -3
  52. data/lib/notion_ruby_mapping/properties/phone_number_property.rb +3 -3
  53. data/lib/notion_ruby_mapping/properties/property.rb +39 -37
  54. data/lib/notion_ruby_mapping/properties/relation_property.rb +2 -2
  55. data/lib/notion_ruby_mapping/properties/rollup_property.rb +2 -2
  56. data/lib/notion_ruby_mapping/properties/select_property.rb +2 -2
  57. data/lib/notion_ruby_mapping/properties/status_property.rb +2 -2
  58. data/lib/notion_ruby_mapping/properties/text_property.rb +2 -2
  59. data/lib/notion_ruby_mapping/properties/title_property.rb +1 -1
  60. data/lib/notion_ruby_mapping/properties/unique_id_property.rb +1 -1
  61. data/lib/notion_ruby_mapping/properties/url_property.rb +2 -2
  62. data/lib/notion_ruby_mapping/properties/verification_property.rb +3 -3
  63. data/lib/notion_ruby_mapping/version.rb +1 -1
  64. data/lib/notion_ruby_mapping.rb +1 -1
  65. data/notion_ruby_mapping.gemspec +3 -2
  66. metadata +20 -6
  67. data/sig/notion_ruby_mapping.rbs +0 -4
@@ -2,7 +2,8 @@
2
2
 
3
3
  require "singleton"
4
4
  require "faraday"
5
- require "faraday_middleware"
5
+ require "faraday/multipart"
6
+ require "mime/types"
6
7
 
7
8
  module NotionRubyMapping
8
9
  # singleton class of caching Notion objects
@@ -14,10 +15,10 @@ module NotionRubyMapping
14
15
  # @see https://www.notion.so/hkob/NotionCache-65e1599864d6425686d495a5a4b3a623#dca210788f114cf59464090782c073bf
15
16
  def initialize
16
17
  @object_hash = {}
17
- @client = Faraday::Connection.new "https://api.notion.com" do |builder|
18
- builder.use FaradayMiddleware::EncodeJson
19
- builder.use FaradayMiddleware::ParseJson
20
- builder.adapter Faraday.default_adapter
18
+ @client = Faraday.new "https://api.notion.com" do |conn|
19
+ conn.request :json
20
+ conn.response :json
21
+ conn.headers["Notion-Version"] = NotionRubyMapping::NOTION_VERSION
21
22
  end
22
23
  @notion_token = nil
23
24
  @wait = 0.3333
@@ -28,6 +29,14 @@ module NotionRubyMapping
28
29
  attr_writer :client # for test only
29
30
  attr_accessor :notion_token, :wait, :debug, :use_cache
30
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
+
31
40
  # @param [String] block_id
32
41
  # @return [String (frozen)] block_path
33
42
  def append_block_children_block_path(block_id)
@@ -92,6 +101,14 @@ module NotionRubyMapping
92
101
  "v1/comments"
93
102
  end
94
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
+
95
112
  # @param [String] notion_token
96
113
  # @return [NotionRubyMapping::NotionCache] self (NotionCache.instance)
97
114
  def create_client(notion_token, wait: 0.3333, debug: false)
@@ -107,6 +124,12 @@ module NotionRubyMapping
107
124
  request :post, databases_path, payload
108
125
  end
109
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
+
110
133
  # @param [Hash] payload
111
134
  # @return [Hash] response
112
135
  def create_page_request(payload)
@@ -161,6 +184,25 @@ module NotionRubyMapping
161
184
  request :delete, block_path(id)
162
185
  end
163
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
+
164
206
  # @param [String] id id string with "-"
165
207
  # @return [String] id without "-"
166
208
  # @see https://www.notion.so/hkob/NotionCache-65e1599864d6425686d495a5a4b3a623#a2d70a2e019c4c17898aaa1a36580f1d
@@ -172,6 +214,28 @@ module NotionRubyMapping
172
214
  "NotionCache"
173
215
  end
174
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
+
175
239
  # @param [String] id id (with or without "-")
176
240
  # @return [NotionRubyMapping::Base]
177
241
  def object_for_key(id)
@@ -207,6 +271,7 @@ module NotionRubyMapping
207
271
  # @param [String] property_id
208
272
  # @return [Hash] response
209
273
  def page_property_request(page_id, property_id, query = {})
274
+ p "page_id = #{page_id}, property_id = #{property_id}, query = #{query}" if @debug
210
275
  request :get, page_property_path(page_id, property_id), query
211
276
  end
212
277
 
@@ -248,7 +313,6 @@ module NotionRubyMapping
248
313
  sleep @wait
249
314
  response = @client.send(method) do |request|
250
315
  request.headers["Authorization"] = "Bearer #{@notion_token}"
251
- request.headers["Notion-Version"] = NotionRubyMapping::NOTION_VERSION
252
316
  case method
253
317
  when :get, :delete
254
318
  request.url path, options
@@ -266,13 +330,13 @@ module NotionRubyMapping
266
330
  end
267
331
 
268
332
  def search(query)
269
- request(:post, search_path, options = query)
333
+ request(:post, search_path, query)
270
334
  end
271
335
 
272
336
  def search_path
273
337
  "v1/search"
274
338
  end
275
-
339
+
276
340
  # @param [String] token
277
341
  def token=(token)
278
342
  @notion_token = token
@@ -322,7 +386,7 @@ module NotionRubyMapping
322
386
 
323
387
  # @return [Array<NotionRubyMapping::UserObject>] UserObject array
324
388
  def users
325
- List.new json: users_request, type: :user_object, value: true
389
+ List.new json: users_request, type: "user_object", value: true
326
390
  end
327
391
 
328
392
  # @return [String (frozen)] user_path
@@ -21,7 +21,7 @@ module NotionRubyMapping
21
21
 
22
22
  def description=(text_objects)
23
23
  rta = RichTextArray.rich_text_array "description", text_objects
24
- @json.merge!(rta.update_property_schema_json true)
24
+ @json.merge!(rta.update_property_schema_json(true))
25
25
  end
26
26
 
27
27
  # @param [Boolean] flag
@@ -47,14 +47,32 @@ 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
71
  {"type" => "emoji", "emoji" => emoji}
56
72
  elsif url
57
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
@@ -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
@@ -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
 
@@ -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
@@ -13,17 +12,17 @@ module NotionRubyMapping
13
12
  Base.dry_run_script :post, NotionCache.instance.search_path, payload
14
13
  else
15
14
  response = NotionCache.instance.search payload
16
- List.new json: response, type: :search, value: self, query: Query.new
15
+ List.new json: response, type: "search", value: self, query: Query.new
17
16
  end
18
17
  end
19
18
 
20
19
  def payload
21
20
  ans = {}
22
21
  ans["sort"] = {"direction" => "ascending", "timestamp" => "last_edited_time"} if @ascending
23
- ans["filter"] = {"value" => "database", "property" => "object" } if @database_only
24
- ans["filter"] = {"value" => "page", "property" => "object" } if @page_only
22
+ ans["filter"] = {"value" => "database", "property" => "object"} if @database_only
23
+ ans["filter"] = {"value" => "page", "property" => "object"} if @page_only
25
24
  ans["query"] = @query if @query
26
25
  ans
27
26
  end
28
27
  end
29
- end
28
+ end
@@ -5,10 +5,13 @@ module NotionRubyMapping
5
5
  class FileObject
6
6
  # @param [String] url
7
7
  # @return [TextObject]
8
- def initialize(url: nil, json: {})
8
+ def initialize(url: nil, file_upload_object: nil, json: {})
9
9
  if url
10
10
  @type = "external"
11
11
  @url = url
12
+ elsif file_upload_object
13
+ @type = "file_upload"
14
+ @file_upload_object = file_upload_object
12
15
  elsif json
13
16
  @type = json["type"]
14
17
  @url = json[@type]["url"]
@@ -18,16 +21,18 @@ module NotionRubyMapping
18
21
  end
19
22
  @will_update = false
20
23
  end
21
- attr_reader :will_update, :url, :type
24
+ attr_reader :will_update, :url, :type, :file_upload_object
22
25
 
23
- # @param [FileObject, String] uo
26
+ # @param [FileObject, FileUploadObject, String] url_or_fuo_or_fo
24
27
  # @return [FileObject] self or created FileObject
25
28
  # @see https://www.notion.so/hkob/FileObject-6218c354e985423a90904f47a985be33#54b37c567e1d4dfcab06f6d8f8fd412e
26
- def self.file_object(url_or_fo)
27
- if url_or_fo.is_a? FileObject
28
- url_or_fo
29
+ def self.file_object(url_or_fuo_or_fo)
30
+ if url_or_fuo_or_fo.is_a? FileUploadObject
31
+ FileObject.new file_upload_object: url_or_fuo_or_fo
32
+ elsif url_or_fuo_or_fo.is_a? FileObject
33
+ url_or_fuo_or_fo
29
34
  else
30
- FileObject.new url: url_or_fo
35
+ FileObject.new url: url_or_fuo_or_fo
31
36
  end
32
37
  end
33
38
 
@@ -36,6 +41,15 @@ module NotionRubyMapping
36
41
  @type == "external"
37
42
  end
38
43
 
44
+ # @param [FileUploadObject] fuo
45
+ def file_upload_object=(fuo)
46
+ @file_upload_object = fuo
47
+ @type = "file_upload"
48
+ @url = nil
49
+ @expiry_time = nil
50
+ @will_update = true
51
+ end
52
+
39
53
  # @param [String] url
40
54
  # @see https://www.notion.so/hkob/FileObject-6218c354e985423a90904f47a985be33#6b841f75d0234a1aac93fb54348abb96
41
55
  def url=(url)
@@ -47,14 +61,23 @@ module NotionRubyMapping
47
61
 
48
62
  # @return [Hash]
49
63
  def property_values_json
50
- ans = {
51
- "type" => @type,
52
- @type => {
53
- "url" => @url,
54
- },
55
- }
56
- ans[@type]["expiry_time"] = @expiry_time if @expiry_time
57
- ans
64
+ if @type == "file_upload"
65
+ {
66
+ "type" => @type.to_s,
67
+ @type => {
68
+ "id" => @file_upload_object.id,
69
+ },
70
+ }
71
+ else
72
+ ans = {
73
+ "type" => @type.to_s,
74
+ @type => {
75
+ "url" => @url,
76
+ },
77
+ }
78
+ ans[@type]["expiry_time"] = @expiry_time if @expiry_time
79
+ ans
80
+ end
58
81
  end
59
82
  end
60
83
  end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FileUploadObject
4
+ MAX_SIZE = 10 * 1024 * 1024 # 10 MB
5
+ # @param [String] id
6
+ def initialize(fname:, external_url: nil)
7
+ @fname = fname
8
+ if external_url
9
+ payload = {mode: "external_url", external_url: external_url, filename: fname}
10
+ create payload
11
+ else
12
+ raise StandardError, "FileUploadObject requires a valid file name: #{fname}" unless File.exist?(fname)
13
+
14
+ @file_size = File.size fname
15
+ @number_of_parts = (@file_size - 1) / MAX_SIZE + 1
16
+ payload = if @number_of_parts == 1
17
+ {}
18
+ else
19
+ {number_of_parts: @number_of_parts, mode: "multi_part",
20
+ filename: File.basename(@fname)}
21
+ end
22
+ create payload
23
+ if @number_of_parts == 1
24
+ single_file_upload
25
+ else
26
+ @temp_files = FileUploadObject.split_to_small_files(@fname, MAX_SIZE)
27
+ @temp_files.each_with_index do |temp_file, i|
28
+ single_file_upload temp_file.path, i + 1
29
+ temp_file.close
30
+ temp_file.unlink
31
+ end
32
+ NotionRubyMapping::NotionCache.instance.complete_a_file_upload_request @id
33
+ end
34
+ end
35
+ end
36
+ attr_reader :id, :fname
37
+
38
+ # @return [FileUploadObject]
39
+ def create(payload)
40
+ nc = NotionRubyMapping::NotionCache.instance
41
+ response = nc.create_file_upload_request(payload)
42
+ @id = nc.hex_id response["id"]
43
+ end
44
+
45
+ # @param [String] fname
46
+ # @param [Integer, NilClass] part_number
47
+ def single_file_upload(fname = @fname, part_number = 0)
48
+ if @number_of_parts > 1
49
+ options = {"part_number" => part_number}
50
+ status = "pending"
51
+ else
52
+ options = {}
53
+ status = "uploaded"
54
+ end
55
+ nc = NotionRubyMapping::NotionCache.instance
56
+ response = nc.file_upload_request fname, @id, options
57
+ return if nc.hex_id(response["id"]) == @id && response["status"] == status
58
+
59
+ raise StandardError, "File upload failed: #{response}"
60
+ end
61
+
62
+ def self.split_to_small_files(org_file, max_size = MAX_SIZE)
63
+ raise StandardError, "File does not exist: #{org_file}" unless File.exist?(org_file)
64
+
65
+ temp_files = []
66
+ File.open(org_file, "rb") do |file|
67
+ until file.eof?
68
+ chunk = file.read(max_size)
69
+ temp_file = Tempfile.new("part_")
70
+ temp_file.binmode
71
+ temp_file.write(chunk)
72
+ temp_file.rewind
73
+ temp_files << temp_file
74
+ end
75
+ end
76
+ temp_files
77
+ end
78
+ end
@@ -14,11 +14,11 @@ module NotionRubyMapping
14
14
  @json
15
15
  end
16
16
 
17
- # @param [String] name Property name
17
+ # @param [String, Symbol] name Property name
18
18
  # @param [Boolean, Hash] json
19
- def initialize(name, will_update: false, base_type: :page, property_id: nil, property_cache: nil, json: nil)
19
+ def initialize(name, will_update: false, base_type: "page", property_id: nil, property_cache: nil, json: nil)
20
20
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
21
- property_cache: property_cache
21
+ property_cache: property_cache
22
22
  @json = json
23
23
  end
24
24
 
@@ -31,9 +31,9 @@ module NotionRubyMapping
31
31
 
32
32
  ## Common methods
33
33
 
34
- # @param [String] name Property name
34
+ # @param [String, Symbol] name Property name
35
35
  # @param [Boolean, Hash] json
36
- def initialize(name, will_update: false, base_type: :page, property_id: nil, property_cache: nil, json: nil)
36
+ def initialize(name, will_update: false, base_type: "page", property_id: nil, property_cache: nil, json: nil)
37
37
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
38
38
  property_cache: property_cache
39
39
  @json = if database?
@@ -19,10 +19,10 @@ module NotionRubyMapping
19
19
 
20
20
  ## Common methods
21
21
 
22
- # @param [String] name Property name
22
+ # @param [String, Symbol] name Property name
23
23
  # @param [String] user_id user_id (optional)
24
24
  # @param [Hash] json json (optional)
25
- def initialize(name, will_update: false, base_type: :page, json: nil, user_id: nil, property_id: nil,
25
+ def initialize(name, will_update: false, base_type: "page", json: nil, user_id: nil, property_id: nil,
26
26
  property_cache: nil)
27
27
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
28
28
  property_cache: property_cache
@@ -19,9 +19,9 @@ module NotionRubyMapping
19
19
 
20
20
  ## Common methods
21
21
 
22
- # @param [String] name Property name
22
+ # @param [String, Symbol] name Property name
23
23
  # @param [String] json created_time value (optional)
24
- def initialize(name, will_update: false, base_type: :page, json: nil, property_id: nil, property_cache: nil)
24
+ def initialize(name, will_update: false, base_type: "page", json: nil, property_id: nil, property_cache: nil)
25
25
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
26
26
  property_cache: property_cache
27
27
  @json = json
@@ -102,7 +102,8 @@ module NotionRubyMapping
102
102
  # @return [NotionRubyMapping::Query] generated Query object
103
103
  # @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#6a20ade0ee964aad81aae4c08ea29d6b
104
104
  def filter_on_or_before(date, condition: nil, another_type: nil)
105
- make_filter_query "on_or_before", value_str(date, end_time: true), condition: condition, another_type: another_type
105
+ make_filter_query "on_or_before", value_str(date, end_time: true), condition: condition,
106
+ another_type: another_type
106
107
  end
107
108
 
108
109
  # @param [String] condition Rollup name
@@ -110,7 +111,8 @@ module NotionRubyMapping
110
111
  # @return [NotionRubyMapping::Query] generated Query object
111
112
  # @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#1469e3fb3068426a8ea8492d191d1563
112
113
  def filter_on_or_after(date, condition: nil, another_type: nil)
113
- make_filter_query "on_or_after", value_str(date, start_time: true), condition: condition, another_type: another_type
114
+ make_filter_query "on_or_after", value_str(date, start_time: true), condition: condition,
115
+ another_type: another_type
114
116
  end
115
117
 
116
118
  # @param [String] condition Rollup name
@@ -77,7 +77,7 @@ module NotionRubyMapping
77
77
  # @see https://www.notion.so/hkob/DateProperty-c6e815c060cb430889dbb33b697f00c6#f892cde82d9a44a0850d69878e31b216
78
78
  def time_zone
79
79
  assert_page_property __method__
80
- @json["time_zone"]
80
+ @json[:time_zone]
81
81
  end
82
82
 
83
83
  # @param [String] tzone
@@ -85,7 +85,7 @@ module NotionRubyMapping
85
85
  def time_zone=(tzone)
86
86
  assert_page_property __method__
87
87
  @will_update = true
88
- @json["time_zone"] = tzone
88
+ @json[:time_zone] = tzone
89
89
  end
90
90
 
91
91
  ### Not public announced methods
@@ -97,7 +97,7 @@ module NotionRubyMapping
97
97
  # @param [Date, Time, DateTime, String, nil] start_date
98
98
  # @param [Date, Time, DateTime, String, nil] end_date
99
99
  # @param [String, nil] time_zone
100
- def initialize(name, will_update: false, base_type: :page, json: nil, start_date: nil, end_date: nil,
100
+ def initialize(name, will_update: false, base_type: "page", json: nil, start_date: nil, end_date: nil,
101
101
  time_zone: nil, property_id: nil, property_cache: nil)
102
102
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
103
103
  property_cache: property_cache
@@ -117,7 +117,7 @@ module NotionRubyMapping
117
117
  assert_page_property __method__
118
118
  {
119
119
  @name => {
120
- "type" => "date",
120
+ "type" => TYPE,
121
121
  "date" => {
122
122
  "start" => value_str(@json["start"]),
123
123
  "end" => value_str(@json["end"]),
@@ -31,8 +31,8 @@ module NotionRubyMapping
31
31
 
32
32
  ## Common methods
33
33
 
34
- # @param [String] name Property name
35
- def initialize(name, will_update: false, base_type: :page, json: nil, property_id: nil, property_cache: nil)
34
+ # @param [String, Symbol] name Property name
35
+ def initialize(name, will_update: false, base_type: "page", json: nil, property_id: nil, property_cache: nil)
36
36
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
37
37
  property_cache: property_cache
38
38
  @json = json || {}
@@ -21,7 +21,10 @@ module NotionRubyMapping
21
21
 
22
22
  def file_names=(file_names = [])
23
23
  array_file_names = Array(file_names)
24
- raise StandardError, "files and file_names must be the same sizes." unless @files.length == array_file_names.length
24
+ unless @files.length == array_file_names.length
25
+ raise StandardError,
26
+ "files and file_names must be the same sizes."
27
+ end
25
28
 
26
29
  @will_update = true
27
30
  @file_names = array_file_names
@@ -31,9 +34,9 @@ module NotionRubyMapping
31
34
 
32
35
  ## Common methods
33
36
 
34
- # @param [String] name Property name
37
+ # @param [String, Symbol] name Property name
35
38
  # @param [String] files files value (optional)
36
- def initialize(name, will_update: false, base_type: :page, json: nil, files: [], property_id: nil,
39
+ def initialize(name, will_update: false, base_type: "page", json: nil, files: [], property_id: nil,
37
40
  property_cache: nil)
38
41
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
39
42
  property_cache: property_cache
@@ -57,7 +60,9 @@ module NotionRubyMapping
57
60
  {}
58
61
  else
59
62
  files = @files.map(&:property_values_json)
60
- @file_names&.each_with_index { |name, i| files[i]["name"] = name }
63
+ @file_names&.each_with_index do |name, i|
64
+ files[i]["name"] = name.is_a?(FileUploadObject) ? name.fname : name
65
+ end
61
66
  {@name => {"files" => files, "type" => "files"}}
62
67
  end
63
68
  end
@@ -39,9 +39,9 @@ module NotionRubyMapping
39
39
 
40
40
  ## Common methods
41
41
 
42
- # @param [String] name
42
+ # @param [String, Symbol] name
43
43
  # @param [Hash] json
44
- def initialize(name, will_update: false, base_type: :page, json: nil, formula: nil, property_id: nil,
44
+ def initialize(name, will_update: false, base_type: "page", json: nil, formula: nil, property_id: nil,
45
45
  property_cache: nil)
46
46
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
47
47
  property_cache: property_cache
@@ -22,7 +22,8 @@ module NotionRubyMapping
22
22
  # @param [String] name Property name
23
23
  # @param [String] user_id user_id (optional)
24
24
  # @param [Hash] json json (optional)
25
- def initialize(name, will_update: false, base_type: :page, json: nil, user_id: nil, property_id: nil,
25
+ def initialize(name, will_update: false, base_type:
26
+ "page", json: nil, user_id: nil, property_id: nil,
26
27
  property_cache: nil)
27
28
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
28
29
  property_cache: property_cache
@@ -19,9 +19,9 @@ module NotionRubyMapping
19
19
 
20
20
  ## Common methods
21
21
 
22
- # @param [String] name Property name
22
+ # @param [String, Symbol] name Property name
23
23
  # @param [String] json last_edited_time value (optional)
24
- def initialize(name, will_update: false, base_type: :page, json: nil, property_id: nil, property_cache: nil)
24
+ def initialize(name, will_update: false, base_type: "page", json: nil, property_id: nil, property_cache: nil)
25
25
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
26
26
  property_cache: property_cache
27
27
  @json = json
@@ -16,7 +16,7 @@ module NotionRubyMapping
16
16
 
17
17
  # @return [Array]
18
18
  def multi_select_names
19
- mshs = @base_type == :page ? @json : @json["options"]
19
+ mshs = @base_type == "page" ? @json : @json["options"]
20
20
  mshs.map { |h| h["name"] }
21
21
  end
22
22
 
@@ -58,10 +58,10 @@ module NotionRubyMapping
58
58
 
59
59
  ## Common methods
60
60
 
61
- # @param [String] name
61
+ # @param [String, Symbol] name
62
62
  # @param [Hash] json
63
63
  # @param [Array<String>, String] multi_select
64
- def initialize(name, will_update: false, base_type: :page, json: nil, multi_select: nil,
64
+ def initialize(name, will_update: false, base_type: "page", json: nil, multi_select: nil,
65
65
  property_id: nil, property_cache: nil)
66
66
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
67
67
  property_cache: property_cache
@@ -51,14 +51,14 @@ module NotionRubyMapping
51
51
 
52
52
  ## Common methods
53
53
 
54
- # @param [String] name Property name
54
+ # @param [String, Symbol] name Property name
55
55
  # @param [Float, Integer, Hash] json Number value or format Hash
56
- def initialize(name, will_update: false, base_type: :page, json: nil, format: nil, property_id: nil,
56
+ def initialize(name, will_update: false, base_type: "page", json: nil, format: nil, property_id: nil,
57
57
  property_cache: nil)
58
58
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
59
59
  property_cache: property_cache
60
60
  @json = json
61
- @json ||= {"format" => (format || "number")} if database?
61
+ @json ||= {"format" => format || "number"} if database?
62
62
  end
63
63
 
64
64
  # @param [Hash] json