notion_ruby_mapping 0.4.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -14
  3. data/examples/change_title.md +1 -1
  4. data/examples/renumbering_pages.md +3 -3
  5. data/examples/set_icon_to_all_icon_unsettled_pages.md +4 -4
  6. data/lib/notion_ruby_mapping/blocks/base.rb +25 -21
  7. data/lib/notion_ruby_mapping/blocks/block.rb +82 -484
  8. data/lib/notion_ruby_mapping/blocks/bookmark_block.rb +11 -0
  9. data/lib/notion_ruby_mapping/blocks/breadcrumb_block.rb +19 -0
  10. data/lib/notion_ruby_mapping/blocks/bulleted_list_item_block.rb +11 -0
  11. data/lib/notion_ruby_mapping/blocks/callout_block.rb +82 -0
  12. data/lib/notion_ruby_mapping/blocks/child_base_block.rb +21 -0
  13. data/lib/notion_ruby_mapping/blocks/child_database_block.rb +11 -0
  14. data/lib/notion_ruby_mapping/blocks/child_page_block.rb +11 -0
  15. data/lib/notion_ruby_mapping/blocks/code_block.rb +50 -0
  16. data/lib/notion_ruby_mapping/blocks/column_block.rb +29 -0
  17. data/lib/notion_ruby_mapping/blocks/column_list_block.rb +33 -0
  18. data/lib/notion_ruby_mapping/blocks/database.rb +7 -1
  19. data/lib/notion_ruby_mapping/blocks/divider_block.rb +19 -0
  20. data/lib/notion_ruby_mapping/blocks/embed_block.rb +11 -0
  21. data/lib/notion_ruby_mapping/blocks/equation_block.rb +43 -0
  22. data/lib/notion_ruby_mapping/blocks/file_base_block.rb +50 -0
  23. data/lib/notion_ruby_mapping/blocks/file_block.rb +11 -0
  24. data/lib/notion_ruby_mapping/blocks/heading1_block.rb +18 -0
  25. data/lib/notion_ruby_mapping/blocks/heading2_block.rb +18 -0
  26. data/lib/notion_ruby_mapping/blocks/heading3_block.rb +18 -0
  27. data/lib/notion_ruby_mapping/blocks/image_block.rb +11 -0
  28. data/lib/notion_ruby_mapping/blocks/link_preview_block.rb +16 -0
  29. data/lib/notion_ruby_mapping/blocks/link_to_page_block.rb +40 -0
  30. data/lib/notion_ruby_mapping/blocks/list.rb +2 -3
  31. data/lib/notion_ruby_mapping/blocks/numbered_list_item_block.rb +11 -0
  32. data/lib/notion_ruby_mapping/blocks/page.rb +6 -0
  33. data/lib/notion_ruby_mapping/blocks/paragraph_block.rb +11 -0
  34. data/lib/notion_ruby_mapping/blocks/pdf_block.rb +11 -0
  35. data/lib/notion_ruby_mapping/blocks/quote_block.rb +11 -0
  36. data/lib/notion_ruby_mapping/blocks/synced_block.rb +49 -0
  37. data/lib/notion_ruby_mapping/blocks/table_block.rb +50 -0
  38. data/lib/notion_ruby_mapping/blocks/table_of_contents_block.rb +34 -0
  39. data/lib/notion_ruby_mapping/blocks/table_row_block.rb +34 -0
  40. data/lib/notion_ruby_mapping/blocks/template_block.rb +34 -0
  41. data/lib/notion_ruby_mapping/blocks/text_sub_block_color_base_block.rb +45 -0
  42. data/lib/notion_ruby_mapping/blocks/to_do_block.rb +42 -0
  43. data/lib/notion_ruby_mapping/blocks/toggle_block.rb +11 -0
  44. data/lib/notion_ruby_mapping/blocks/toggle_heading1_block.rb +11 -0
  45. data/lib/notion_ruby_mapping/blocks/toggle_heading2_block.rb +11 -0
  46. data/lib/notion_ruby_mapping/blocks/toggle_heading3_block.rb +11 -0
  47. data/lib/notion_ruby_mapping/blocks/url_base_block.rb +34 -0
  48. data/lib/notion_ruby_mapping/blocks/url_caption_base_block.rb +46 -0
  49. data/lib/notion_ruby_mapping/blocks/video_block.rb +11 -0
  50. data/lib/notion_ruby_mapping/controllers/notion_cache.rb +34 -18
  51. data/lib/notion_ruby_mapping/controllers/payload.rb +32 -18
  52. data/lib/notion_ruby_mapping/controllers/query.rb +1 -1
  53. data/lib/notion_ruby_mapping/controllers/rich_text_array.rb +13 -2
  54. data/lib/notion_ruby_mapping/objects/rich_text_object.rb +2 -5
  55. data/lib/notion_ruby_mapping/properties/created_by_property.rb +1 -0
  56. data/lib/notion_ruby_mapping/properties/date_base_property.rb +24 -11
  57. data/lib/notion_ruby_mapping/properties/email_property.rb +1 -2
  58. data/lib/notion_ruby_mapping/properties/files_property.rb +1 -1
  59. data/lib/notion_ruby_mapping/properties/formula_property.rb +1 -1
  60. data/lib/notion_ruby_mapping/properties/multi_select_property.rb +2 -0
  61. data/lib/notion_ruby_mapping/properties/phone_number_property.rb +0 -1
  62. data/lib/notion_ruby_mapping/properties/select_property.rb +2 -1
  63. data/lib/notion_ruby_mapping/properties/url_property.rb +0 -2
  64. data/lib/notion_ruby_mapping/version.rb +1 -1
  65. data/lib/notion_ruby_mapping.rb +8 -1
  66. metadata +41 -2
@@ -7,6 +7,28 @@ module NotionRubyMapping
7
7
  class DateBaseProperty < Property
8
8
  include IsEmptyIsNotEmpty
9
9
 
10
+ # @param [Date, Time, DateTime, String, nil] obj
11
+ # @return [String, nil] iso8601 format string
12
+ def self.value_str(obj)
13
+ case obj
14
+ when Date
15
+ obj.iso8601
16
+ when Time
17
+ obj.strftime("%Y-%m-%dT%H:%M:%S%:z")
18
+ when DateTime
19
+ obj.iso8601
20
+ else
21
+ obj
22
+ end
23
+ end
24
+
25
+ # @param [Date, Time, DateTime, String, nil] obj
26
+ # @return [Date, nil] iso8601 format string
27
+ def self.date_from_obj(obj)
28
+ str = value_str obj
29
+ Date.parse str if str
30
+ end
31
+
10
32
  # @param [String] rollup Rollup name
11
33
  # @param [String] rollup_type Rollup type
12
34
  # @return [NotionRubyMapping::Query] generated Query object
@@ -105,18 +127,9 @@ module NotionRubyMapping
105
127
  protected
106
128
 
107
129
  # @param [Date, Time, DateTime, String, nil] obj
108
- # @return [String] iso8601 format string
130
+ # @return [String, nil] iso8601 format string
109
131
  def value_str(obj)
110
- case obj
111
- when Date
112
- obj.iso8601
113
- when Time
114
- obj.strftime("%Y-%m-%dT%H:%M:%S%:z")
115
- when DateTime
116
- obj.iso8601
117
- else
118
- obj
119
- end
132
+ self.class.value_str(obj)
120
133
  end
121
134
  end
122
135
  end
@@ -20,7 +20,7 @@ module NotionRubyMapping
20
20
 
21
21
  ## Page property only methods
22
22
 
23
- # @param [String] str
23
+ # @param [String] email
24
24
  def email=(email)
25
25
  assert_page_property __method__
26
26
  @will_update = true
@@ -32,7 +32,6 @@ module NotionRubyMapping
32
32
  ## Common methods
33
33
 
34
34
  # @param [String] name Property name
35
- # @param [String] email email value (optional)
36
35
  def initialize(name, will_update: false, base_type: :page, json: nil)
37
36
  super name, will_update: will_update, base_type: base_type
38
37
  @json = json || {}
@@ -47,7 +47,7 @@ module NotionRubyMapping
47
47
  {}
48
48
  else
49
49
  files = @files.map(&:property_values_json)
50
- @file_names.each_with_index { |name, i| files[i]["name"] = name } if @file_names
50
+ @file_names&.each_with_index { |name, i| files[i]["name"] = name }
51
51
  {@name => {"files" => files, "type" => "files"}}
52
52
  end
53
53
  end
@@ -27,7 +27,7 @@ module NotionRubyMapping
27
27
  @json["expression"]
28
28
  end
29
29
 
30
- # @param [String] formula
30
+ # @param [String] f_e
31
31
  # @see https://www.notion.so/hkob/FormulaProperty-d6b22ca70822407a9fef0bac8925cd0d#fdb3aaa8d0474440b7ed941673ee13b7
32
32
  def formula_expression=(f_e)
33
33
  assert_database_property __method__
@@ -38,6 +38,7 @@ module NotionRubyMapping
38
38
  end
39
39
 
40
40
  # @return [Array]
41
+ # @see https://www.notion.so/hkob/MultiSelectProperty-b90bba1c55d540ba97131bb013d4ca74#5ff6ec299cf64049bde2416f61b30fa9
41
42
  def multi_select_options
42
43
  assert_database_property __method__
43
44
  @json["options"] || []
@@ -48,6 +49,7 @@ module NotionRubyMapping
48
49
  # @param [Hash] multi_select
49
50
  # @return [Array, nil] settled array
50
51
  def multi_select=(multi_select)
52
+ assert_page_property __method__
51
53
  @will_update = true
52
54
  @json = multi_select ? Array(multi_select).map { |ms| {"name" => ms} } : []
53
55
  end
@@ -34,7 +34,6 @@ module NotionRubyMapping
34
34
  ## Common methods
35
35
 
36
36
  # @param [String] name Property name
37
- # @param [String] phone_number phone_number value (optional)
38
37
  def initialize(name, will_update: false, base_type: :page, json: nil)
39
38
  super name, will_update: will_update, base_type: base_type
40
39
  @json = database? ? {} : json
@@ -60,8 +60,9 @@ module NotionRubyMapping
60
60
  ## Page property only methods
61
61
 
62
62
  # @param [String] select
63
- # @return [Hash] settled value
63
+ # @see https://www.notion.so/hkob/SelectProperty-6d6a0defa70d4b26af0fdbdcfbf99f28#3bd195bf5c0a498ebf850409f7deb67a
64
64
  def select=(select)
65
+ assert_page_property __method__
65
66
  @will_update = true
66
67
  @json = {"name" => select}
67
68
  end
@@ -21,7 +21,6 @@ module NotionRubyMapping
21
21
 
22
22
  ## Page property only methods
23
23
 
24
-
25
24
  # @param [String] url
26
25
  # @see https://www.notion.so/hkob/UrlProperty-8a0094fdf6494151983cb4694f6626cc#cfa5463a121b4002b250b38d7d0a0d34
27
26
  def url=(url)
@@ -35,7 +34,6 @@ module NotionRubyMapping
35
34
  ## Common methods
36
35
 
37
36
  # @param [String] name Property name
38
- # @param [String] url url value (optional)
39
37
  def initialize(name, will_update: false, base_type: :page, json: nil)
40
38
  super name, will_update: will_update, base_type: base_type
41
39
  @json = json || (database? ? {} : nil)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.1"
5
5
  NOTION_VERSION = "2022-02-22"
6
6
  end
@@ -4,7 +4,14 @@ require "yaml"
4
4
 
5
5
  require_relative "notion_ruby_mapping/version"
6
6
  {
7
- blocks: %w[base block database list page],
7
+ blocks: %w[base block database list page url_caption_base_block bookmark_block breadcrumb_block
8
+ text_sub_block_color_base_block bulleted_list_item_block callout_block child_base_block
9
+ child_database_block child_page_block code_block column_list_block column_block divider_block
10
+ embed_block equation_block file_base_block file_block heading1_block heading2_block heading3_block
11
+ image_block toggle_heading1_block toggle_heading2_block toggle_heading3_block url_base_block
12
+ link_preview_block link_to_page_block numbered_list_item_block paragraph_block pdf_block quote_block
13
+ synced_block table_block table_row_block table_of_contents_block template_block to_do_block
14
+ toggle_block video_block],
8
15
  controllers: %w[notion_cache payload property_cache query rich_text_array],
9
16
  objects: %w[rich_text_object emoji_object equation_object file_object mention_object text_object user_object],
10
17
  properties: %w[property checkbox_property multi_property created_by_property date_base_property created_time_property
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion_ruby_mapping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroyuki KOBAYASHI
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-14 00:00:00.000000000 Z
11
+ date: 2022-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -150,9 +150,48 @@ files:
150
150
  - lib/notion_ruby_mapping.rb
151
151
  - lib/notion_ruby_mapping/blocks/base.rb
152
152
  - lib/notion_ruby_mapping/blocks/block.rb
153
+ - lib/notion_ruby_mapping/blocks/bookmark_block.rb
154
+ - lib/notion_ruby_mapping/blocks/breadcrumb_block.rb
155
+ - lib/notion_ruby_mapping/blocks/bulleted_list_item_block.rb
156
+ - lib/notion_ruby_mapping/blocks/callout_block.rb
157
+ - lib/notion_ruby_mapping/blocks/child_base_block.rb
158
+ - lib/notion_ruby_mapping/blocks/child_database_block.rb
159
+ - lib/notion_ruby_mapping/blocks/child_page_block.rb
160
+ - lib/notion_ruby_mapping/blocks/code_block.rb
161
+ - lib/notion_ruby_mapping/blocks/column_block.rb
162
+ - lib/notion_ruby_mapping/blocks/column_list_block.rb
153
163
  - lib/notion_ruby_mapping/blocks/database.rb
164
+ - lib/notion_ruby_mapping/blocks/divider_block.rb
165
+ - lib/notion_ruby_mapping/blocks/embed_block.rb
166
+ - lib/notion_ruby_mapping/blocks/equation_block.rb
167
+ - lib/notion_ruby_mapping/blocks/file_base_block.rb
168
+ - lib/notion_ruby_mapping/blocks/file_block.rb
169
+ - lib/notion_ruby_mapping/blocks/heading1_block.rb
170
+ - lib/notion_ruby_mapping/blocks/heading2_block.rb
171
+ - lib/notion_ruby_mapping/blocks/heading3_block.rb
172
+ - lib/notion_ruby_mapping/blocks/image_block.rb
173
+ - lib/notion_ruby_mapping/blocks/link_preview_block.rb
174
+ - lib/notion_ruby_mapping/blocks/link_to_page_block.rb
154
175
  - lib/notion_ruby_mapping/blocks/list.rb
176
+ - lib/notion_ruby_mapping/blocks/numbered_list_item_block.rb
155
177
  - lib/notion_ruby_mapping/blocks/page.rb
178
+ - lib/notion_ruby_mapping/blocks/paragraph_block.rb
179
+ - lib/notion_ruby_mapping/blocks/pdf_block.rb
180
+ - lib/notion_ruby_mapping/blocks/quote_block.rb
181
+ - lib/notion_ruby_mapping/blocks/synced_block.rb
182
+ - lib/notion_ruby_mapping/blocks/table_block.rb
183
+ - lib/notion_ruby_mapping/blocks/table_of_contents_block.rb
184
+ - lib/notion_ruby_mapping/blocks/table_row_block.rb
185
+ - lib/notion_ruby_mapping/blocks/template_block.rb
186
+ - lib/notion_ruby_mapping/blocks/text_sub_block_color_base_block.rb
187
+ - lib/notion_ruby_mapping/blocks/to_do_block.rb
188
+ - lib/notion_ruby_mapping/blocks/toggle_block.rb
189
+ - lib/notion_ruby_mapping/blocks/toggle_heading1_block.rb
190
+ - lib/notion_ruby_mapping/blocks/toggle_heading2_block.rb
191
+ - lib/notion_ruby_mapping/blocks/toggle_heading3_block.rb
192
+ - lib/notion_ruby_mapping/blocks/url_base_block.rb
193
+ - lib/notion_ruby_mapping/blocks/url_caption_base_block.rb
194
+ - lib/notion_ruby_mapping/blocks/video_block.rb
156
195
  - lib/notion_ruby_mapping/controllers/notion_cache.rb
157
196
  - lib/notion_ruby_mapping/controllers/payload.rb
158
197
  - lib/notion_ruby_mapping/controllers/property_cache.rb