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
@@ -5,56 +5,79 @@ 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
- @type = :external
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
- @type = json[:type].to_sym
14
- @url = json[@type][:url]
15
- @expiry_time = json[@type][:expiry_time]
16
+ @type = json["type"]
17
+ @url = json[@type]["url"]
18
+ @expiry_time = json[@type]["expiry_time"]
16
19
  else
17
20
  raise StandardError, "FileObject requires url: or json:"
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
 
34
39
  # @return [TrueClass, FalseClass] true if "type" is "external"
35
40
  def external?
36
- @type == :external
41
+ @type == "external"
42
+ end
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
37
51
  end
38
52
 
39
53
  # @param [String] url
40
54
  # @see https://www.notion.so/hkob/FileObject-6218c354e985423a90904f47a985be33#6b841f75d0234a1aac93fb54348abb96
41
55
  def url=(url)
42
56
  @url = url
43
- @type = :external
57
+ @type = "external"
44
58
  @expiry_time = nil
45
59
  @will_update = true
46
60
  end
47
61
 
48
62
  # @return [Hash]
49
63
  def property_values_json
50
- ans = {
51
- type: @type.to_s,
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
@@ -5,16 +5,16 @@ module NotionRubyMapping
5
5
  class MentionObject < RichTextObject
6
6
  # @return [MentionObject]
7
7
  def initialize(options = {})
8
- super :mention, options
9
- return unless (url = options[:link_preview])
8
+ super "mention", options
9
+ return unless (url = options["link_preview"])
10
10
 
11
- @options[:href] = url
12
- @options[:plain_text] = url
11
+ @options["href"] = url
12
+ @options["plain_text"] = url
13
13
  end
14
14
 
15
15
  # @return [String, NilClass]
16
16
  def page_id
17
- @options[:page_id]
17
+ @options["page_id"]
18
18
  end
19
19
 
20
20
  # @return [String (frozen)]
@@ -23,69 +23,69 @@ module NotionRubyMapping
23
23
  end
24
24
 
25
25
  def partial_property_values_json
26
- if @options.key? :user_id
26
+ if @options.key? "user_id"
27
27
  {
28
- type: "user",
29
- user: {
30
- object: "user",
31
- id: @options[:user_id],
28
+ "type" => "user",
29
+ "user" => {
30
+ "object" => "user",
31
+ "id" => @options["user_id"],
32
32
  },
33
33
  }
34
- elsif @options.key? :page_id
34
+ elsif @options.key? "page_id"
35
35
  {
36
- type: "page",
37
- page: {
38
- id: @options[:page_id],
36
+ "type" => "page",
37
+ "page" => {
38
+ "id" => @options["page_id"],
39
39
  },
40
40
  }
41
- elsif @options.key? :database_id
41
+ elsif @options.key? "database_id"
42
42
  {
43
- type: "database",
44
- database: {
45
- id: @options[:database_id],
43
+ "type" => "database",
44
+ "database" => {
45
+ "id" => @options["database_id"],
46
46
  },
47
47
  }
48
- elsif @options.key? :start
48
+ elsif @options.key? "start"
49
49
  {
50
- type: "date",
51
- date: @options.slice(:start, :end, :time_zone),
50
+ "type" => "date",
51
+ "date" => @options.slice("start", "end", "time_zone"),
52
52
  }
53
- elsif @options.key? :template_mention
54
- sub = case @options[:template_mention]&.to_sym
55
- when :today
56
- @options[:plain_text] = "@Today"
53
+ elsif @options.key? "template_mention"
54
+ sub = case @options["template_mention"]
55
+ when "today"
56
+ @options["plain_text"] = "@Today"
57
57
  {
58
- type: :template_mention_date,
59
- template_mention_date: "today",
58
+ "type" => "template_mention_date",
59
+ "template_mention_date" => "today",
60
60
  }
61
- when :now
62
- @options[:plain_text] = "@Now"
61
+ when "now"
62
+ @options["plain_text"] = "@Now"
63
63
  {
64
- type: :template_mention_date,
65
- template_mention_date: "now",
64
+ "type" => "template_mention_date",
65
+ "template_mention_date" => "now",
66
66
  }
67
67
  else
68
- @options[:plain_text] = "@Me"
68
+ @options["plain_text"] = "@Me"
69
69
  {
70
- type: :template_mention_user,
71
- template_mention_user: "me",
70
+ "type" => "template_mention_user",
71
+ "template_mention_user" => "me",
72
72
  }
73
73
  end
74
74
  {
75
- type: :template_mention,
76
- template_mention: sub,
75
+ "type" => "template_mention",
76
+ "template_mention" => sub,
77
77
  }
78
- elsif @options.key? :link_preview
78
+ elsif @options.key? "link_preview"
79
79
  {
80
- type: :link_preview,
81
- link_preview: {
82
- url: @options[:link_preview],
80
+ "type" => "link_preview",
81
+ "link_preview" => {
82
+ "url" => @options["link_preview"],
83
83
  },
84
84
  }
85
- elsif @options.key? :href
85
+ elsif @options.key? "href"
86
86
  {
87
- type: :link_mention,
88
- link_mention: @options.slice(:href, :icon_url, :link_provider, :thumbnail_url, :title),
87
+ "type" => "link_mention",
88
+ "link_mention" => @options.slice("href", "icon_url", "link_provider", "thumbnail_url", "title"),
89
89
  }
90
90
  else
91
91
  raise StandardError, "Irregular mention type: #{@options.keys}"
@@ -3,7 +3,7 @@
3
3
  module NotionRubyMapping
4
4
  # RichTextObject
5
5
  class RichTextObject
6
- # @param [Symbol] type
6
+ # @param [String] type
7
7
  # @return [TextObject]
8
8
  def initialize(type, options = {})
9
9
  if instance_of?(RichTextObject)
@@ -11,45 +11,45 @@ module NotionRubyMapping
11
11
  "RichTextObject is abstract class. Please use TextObject."
12
12
  end
13
13
 
14
- @type = type.to_sym
14
+ @type = type
15
15
  @options = options
16
16
  end
17
17
  attr_reader :will_update, :options
18
18
 
19
19
  def self.create_from_json(json)
20
- type = json[:type]&.to_sym
21
- options = (json[:annotations] || {}).merge(json.slice(:plain_text, :href))
20
+ type = json["type"]
21
+ options = (json["annotations"] || {}).merge(json.slice("plain_text", "href"))
22
22
  case type
23
- when :text
24
- TextObject.new json[:plain_text], options
25
- when :equation
26
- EquationObject.new json[:equation][:expression], options
27
- when :mention
28
- mention = json[:mention]
29
- case mention[:type]&.to_sym
30
- when :user
31
- MentionObject.new options.merge({user_id: mention[:user][:id]})
32
- when :page
33
- MentionObject.new options.merge({page_id: mention[:page][:id]})
34
- when :database
35
- MentionObject.new options.merge({database_id: mention[:database][:id]})
36
- when :date
37
- MentionObject.new options.merge(mention[:date].slice(:start, :end, :time_zone))
38
- when :template_mention
39
- template_mention = mention[:template_mention]
40
- case template_mention[:type].to_sym
41
- when :template_mention_date
42
- MentionObject.new options.merge({template_mention: template_mention[:template_mention_date]})
23
+ when "text"
24
+ TextObject.new json["plain_text"], options
25
+ when "equation"
26
+ EquationObject.new json["equation"]["expression"], options
27
+ when "mention"
28
+ mention = json["mention"]
29
+ case mention["type"]
30
+ when "user"
31
+ MentionObject.new options.merge({"user_id" => mention["user"]["id"]})
32
+ when "page"
33
+ MentionObject.new options.merge({"page_id" => mention["page"]["id"]})
34
+ when "database"
35
+ MentionObject.new options.merge({"database_id" => mention["database"]["id"]})
36
+ when "date"
37
+ MentionObject.new options.merge(mention["date"].slice("start", "end", "time_zone"))
38
+ when "template_mention"
39
+ template_mention = mention["template_mention"]
40
+ case template_mention["type"]
41
+ when "template_mention_date"
42
+ MentionObject.new options.merge({"template_mention" => template_mention["template_mention_date"]})
43
43
  else
44
- MentionObject.new options.merge({template_mention: template_mention[:template_mention_user]})
44
+ MentionObject.new options.merge({"template_mention" => template_mention["template_mention_user"]})
45
45
  end
46
- when :link_preview
47
- MentionObject.new options.merge({link_preview: mention[:link_preview][:url]})
48
- when :link_mention
49
- lm_keys = %i[href icon_url link_provider thumbnail_url title]
50
- MentionObject.new options.merge(mention[:link_mention].slice(*lm_keys))
46
+ when "link_preview"
47
+ MentionObject.new options.merge({"link_preview" => mention["link_preview"]["url"]})
48
+ when "link_mention"
49
+ lm_keys = %w[href icon_url link_provider thumbnail_url title]
50
+ MentionObject.new options.merge(mention["link_mention"].slice(*lm_keys))
51
51
  else
52
- raise StandardError, "Unknown mention type: #{mention[:type]}"
52
+ raise StandardError, "Unknown mention type: #{mention["type"]}"
53
53
  end
54
54
  else
55
55
  raise StandardError, json
@@ -69,10 +69,10 @@ module NotionRubyMapping
69
69
  # @return [Hash{String (frozen)->Object}]
70
70
  def property_values_json
71
71
  {
72
- type: @type.to_s,
72
+ "type" => @type,
73
73
  @type => partial_property_values_json,
74
- plain_text: @options[:plain_text],
75
- href: @options[:href],
74
+ "plain_text" => @options["plain_text"],
75
+ "href" => @options["href"],
76
76
  }.merge annotations_json
77
77
  end
78
78
 
@@ -85,7 +85,7 @@ module NotionRubyMapping
85
85
  # @return [String] input text
86
86
  def href=(url)
87
87
  @will_update = true
88
- @options[:href] = url
88
+ @options["href"] = url
89
89
  end
90
90
 
91
91
  # @param [String, RichTextObject] value
@@ -98,50 +98,50 @@ module NotionRubyMapping
98
98
  # @return [Boolean] input flag
99
99
  def bold=(flag)
100
100
  @will_update = true
101
- @options[:bold] = flag
101
+ @options["bold"] = flag
102
102
  end
103
103
 
104
104
  # @param [Boolean] flag
105
105
  # @return [Boolean] input flag
106
106
  def italic=(flag)
107
107
  @will_update = true
108
- @options[:italic] = flag
108
+ @options["italic"] = flag
109
109
  end
110
110
 
111
111
  # @param [Boolean] flag
112
112
  # @return [Boolean] input flag
113
113
  def strikethrough=(flag)
114
114
  @will_update = true
115
- @options[:strikethrough] = flag
115
+ @options["strikethrough"] = flag
116
116
  end
117
117
 
118
118
  # @param [Boolean] flag
119
119
  # @return [Boolean] input flag
120
120
  def underline=(flag)
121
121
  @will_update = true
122
- @options[:underline] = flag
122
+ @options["underline"] = flag
123
123
  end
124
124
 
125
125
  # @param [Boolean] flag
126
126
  # @return [Boolean] input flag
127
127
  def code=(flag)
128
128
  @will_update = true
129
- @options[:code] = flag
129
+ @options["code"] = flag
130
130
  end
131
131
 
132
132
  # @param [String] color
133
133
  # @return [String] input color
134
134
  def color=(color)
135
135
  @will_update = true
136
- @options[:color] = color
136
+ @options["color"] = color
137
137
  end
138
138
 
139
139
  protected
140
140
 
141
141
  # @return [Hash, Hash{String (frozen)->Hash}]
142
142
  def annotations_json
143
- annotations = @options.slice(*%i[bold italic strikethrough underline code color])
144
- annotations.empty? ? {} : {annotations: annotations}
143
+ annotations = @options.slice(*%w[bold italic strikethrough underline code color])
144
+ annotations.empty? ? {} : {"annotations" => annotations}
145
145
  end
146
146
  end
147
147
  end
@@ -6,7 +6,7 @@ module NotionRubyMapping
6
6
  # @param [String] text
7
7
  # @return [TextObject]
8
8
  def initialize(text, options = {})
9
- super :text, {plain_text: text}.merge(options)
9
+ super "text", {"plain_text" => text}.merge(options)
10
10
  @text = text
11
11
  @will_update = false
12
12
  end
@@ -20,17 +20,17 @@ module NotionRubyMapping
20
20
  @text = value.text
21
21
  else
22
22
  @text = value
23
- @options[:plain_text] = value
23
+ @options["plain_text"] = value
24
24
  end
25
25
  end
26
26
 
27
27
  protected
28
28
 
29
29
  def partial_property_values_json
30
- url = @options[:href]
30
+ url = @options["href"]
31
31
  {
32
- content: @text,
33
- link: url ? {url: url} : nil,
32
+ "content" => @text,
33
+ "link" => url ? {"url" => url} : nil,
34
34
  }
35
35
  end
36
36
  end
@@ -6,7 +6,7 @@ module NotionRubyMapping
6
6
  # @param [String] user_id
7
7
  # @return [TextObject]
8
8
  def initialize(user_id: nil, json: {})
9
- @user_id = NotionCache.instance.hex_id(user_id || json && json[:id])
9
+ @user_id = NotionCache.instance.hex_id(user_id || json && json["id"])
10
10
  @json = json
11
11
  @will_update = false
12
12
  end
@@ -56,14 +56,14 @@ module NotionRubyMapping
56
56
 
57
57
  # @return [String]
58
58
  def name
59
- @json[:name]
59
+ @json["name"]
60
60
  end
61
61
 
62
62
  # @return [Hash]
63
63
  def property_values_json
64
64
  {
65
- object: "user",
66
- id: @user_id,
65
+ "object" => "user",
66
+ "id" => @user_id,
67
67
  }
68
68
  end
69
69
 
@@ -3,7 +3,7 @@
3
3
  module NotionRubyMapping
4
4
  # Button property
5
5
  class ButtonProperty < Property
6
- TYPE = :button
6
+ TYPE = "button"
7
7
 
8
8
  ### Public announced methods
9
9
 
@@ -16,7 +16,7 @@ module NotionRubyMapping
16
16
 
17
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
21
  property_cache: property_cache
22
22
  @json = json
@@ -27,7 +27,7 @@ module NotionRubyMapping
27
27
  # @return [Hash]
28
28
  def property_values_json
29
29
  assert_page_property __method__
30
- {@name => {button: @json, type: "button"}}
30
+ {@name => {"button" => @json, "type" => "button"}}
31
31
  end
32
32
  end
33
33
  end
@@ -4,7 +4,7 @@ module NotionRubyMapping
4
4
  # Checkbox property
5
5
  class CheckboxProperty < Property
6
6
  include EqualsDoesNotEqual
7
- TYPE = :checkbox
7
+ TYPE = "checkbox"
8
8
 
9
9
  ### Public announced methods
10
10
 
@@ -33,7 +33,7 @@ module NotionRubyMapping
33
33
 
34
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?
@@ -48,7 +48,7 @@ module NotionRubyMapping
48
48
  # @return [Hash]
49
49
  def property_values_json
50
50
  assert_page_property __method__
51
- {@name => {checkbox: @json, type: "checkbox"}}
51
+ {@name => {"checkbox" => @json, "type" => "checkbox"}}
52
52
  end
53
53
  end
54
54
  end
@@ -3,7 +3,7 @@
3
3
  module NotionRubyMapping
4
4
  # CreatedByProperty
5
5
  class CreatedByProperty < MultiProperty
6
- TYPE = :created_by
6
+ TYPE = "created_by"
7
7
 
8
8
  ### Public announced methods
9
9
 
@@ -22,7 +22,7 @@ module NotionRubyMapping
22
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
@@ -36,7 +36,7 @@ module NotionRubyMapping
36
36
  # @param [Hash] json
37
37
  def update_from_json(json)
38
38
  @will_update = false
39
- cb = json[:created_by]
39
+ cb = json["created_by"]
40
40
  @json = database? ? cb : UserObject.new(json: cb)
41
41
  end
42
42
 
@@ -3,7 +3,7 @@
3
3
  module NotionRubyMapping
4
4
  # CreatedTimeProperty
5
5
  class CreatedTimeProperty < DateBaseProperty
6
- TYPE = :created_time
6
+ TYPE = "created_time"
7
7
 
8
8
  ### Public announced methods
9
9
 
@@ -21,7 +21,7 @@ module NotionRubyMapping
21
21
 
22
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