notion_ruby_mapping 0.3.3 → 0.4.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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -1228
  3. data/env.yml.sample +0 -13
  4. data/lib/notion_ruby_mapping/{base.rb → blocks/base.rb} +155 -88
  5. data/lib/notion_ruby_mapping/blocks/block.rb +547 -0
  6. data/lib/notion_ruby_mapping/{database.rb → blocks/database.rb} +34 -7
  7. data/lib/notion_ruby_mapping/{list.rb → blocks/list.rb} +35 -3
  8. data/lib/notion_ruby_mapping/blocks/page.rb +71 -0
  9. data/lib/notion_ruby_mapping/{notion_cache.rb → controllers/notion_cache.rb} +128 -102
  10. data/lib/notion_ruby_mapping/{payload.rb → controllers/payload.rb} +0 -0
  11. data/lib/notion_ruby_mapping/{property_cache.rb → controllers/property_cache.rb} +21 -20
  12. data/lib/notion_ruby_mapping/{query.rb → controllers/query.rb} +26 -18
  13. data/lib/notion_ruby_mapping/{rich_text_array.rb → controllers/rich_text_array.rb} +26 -15
  14. data/lib/notion_ruby_mapping/objects/emoji_object.rb +40 -0
  15. data/lib/notion_ruby_mapping/objects/equation_object.rb +43 -0
  16. data/lib/notion_ruby_mapping/objects/file_object.rb +60 -0
  17. data/lib/notion_ruby_mapping/{mention_object.rb → objects/mention_object.rb} +11 -0
  18. data/lib/notion_ruby_mapping/{rich_text_object.rb → objects/rich_text_object.rb} +11 -0
  19. data/lib/notion_ruby_mapping/{text_object.rb → objects/text_object.rb} +0 -1
  20. data/lib/notion_ruby_mapping/{user_object.rb → objects/user_object.rb} +9 -4
  21. data/lib/notion_ruby_mapping/{checkbox_property.rb → properties/checkbox_property.rb} +3 -0
  22. data/lib/notion_ruby_mapping/{created_by_property.rb → properties/created_by_property.rb} +0 -0
  23. data/lib/notion_ruby_mapping/{created_time_property.rb → properties/created_time_property.rb} +1 -0
  24. data/lib/notion_ruby_mapping/properties/date_base_property.rb +122 -0
  25. data/lib/notion_ruby_mapping/{date_property.rb → properties/date_property.rb} +13 -0
  26. data/lib/notion_ruby_mapping/{email_property.rb → properties/email_property.rb} +1 -0
  27. data/lib/notion_ruby_mapping/{files_property.rb → properties/files_property.rb} +26 -13
  28. data/lib/notion_ruby_mapping/{formula_property.rb → properties/formula_property.rb} +4 -0
  29. data/lib/notion_ruby_mapping/{last_edited_by_property.rb → properties/last_edited_by_property.rb} +1 -0
  30. data/lib/notion_ruby_mapping/{last_edited_time_property.rb → properties/last_edited_time_property.rb} +1 -0
  31. data/lib/notion_ruby_mapping/{multi_property.rb → properties/multi_property.rb} +0 -0
  32. data/lib/notion_ruby_mapping/{multi_select_property.rb → properties/multi_select_property.rb} +2 -3
  33. data/lib/notion_ruby_mapping/{number_property.rb → properties/number_property.rb} +4 -0
  34. data/lib/notion_ruby_mapping/{people_property.rb → properties/people_property.rb} +8 -3
  35. data/lib/notion_ruby_mapping/{phone_number_property.rb → properties/phone_number_property.rb} +4 -0
  36. data/lib/notion_ruby_mapping/{property.rb → properties/property.rb} +33 -0
  37. data/lib/notion_ruby_mapping/{relation_property.rb → properties/relation_property.rb} +30 -10
  38. data/lib/notion_ruby_mapping/{rich_text_property.rb → properties/rich_text_property.rb} +0 -0
  39. data/lib/notion_ruby_mapping/{rollup_property.rb → properties/rollup_property.rb} +7 -0
  40. data/lib/notion_ruby_mapping/{select_property.rb → properties/select_property.rb} +6 -1
  41. data/lib/notion_ruby_mapping/{text_property.rb → properties/text_property.rb} +0 -0
  42. data/lib/notion_ruby_mapping/{title_property.rb → properties/title_property.rb} +0 -0
  43. data/lib/notion_ruby_mapping/{url_property.rb → properties/url_property.rb} +5 -0
  44. data/lib/notion_ruby_mapping/version.rb +1 -1
  45. data/lib/notion_ruby_mapping.rb +14 -7
  46. metadata +43 -40
  47. data/lib/notion_ruby_mapping/block.rb +0 -10
  48. data/lib/notion_ruby_mapping/date_base_property.rb +0 -75
  49. data/lib/notion_ruby_mapping/page.rb +0 -50
@@ -5,23 +5,54 @@ module NotionRubyMapping
5
5
  class List < Base
6
6
  include Enumerable
7
7
 
8
- def initialize(json: nil, id: nil, database: nil, query: nil)
8
+ def initialize(json: nil, id: nil, database: nil, parent: nil, query: nil)
9
9
  super(json: json, id: id)
10
10
  @has_more = @json["has_more"]
11
11
  @load_all_contents = !@has_more
12
12
  @database = database
13
+ @parent = parent
13
14
  @query = query
14
15
  @index = 0
15
16
  @has_content = true
16
17
  end
17
18
  attr_reader :has_more
18
19
 
19
- ### Public announced methods
20
20
 
21
+ # @return [NotionRubyMapping::List, Enumerator]
22
+ # @see https://www.notion.so/hkob/List-9a0b32335e0d48849a785ce5e162c760#12e1c261a0944a4095776b7515bef4a1
21
23
  def each
22
24
  return enum_for(:each) unless block_given?
23
25
 
24
- if @database
26
+ if @parent
27
+ unless @has_content
28
+ unless @load_all_contents
29
+ @query.start_cursor = nil
30
+ @json = @parent.children @query
31
+ @has_more = @json["has_more"]
32
+ end
33
+ @index = 0
34
+ @has_content = true
35
+ end
36
+
37
+ while @has_content
38
+ if @index < results.length
39
+ object = Base.create_from_json(results[@index])
40
+ @index += 1
41
+ yield object
42
+ elsif @has_more
43
+ if @parent
44
+ @query.start_cursor = @json["next_cursor"]
45
+ @json = @parent.children @query
46
+ @index = 0
47
+ @has_more = @json["has_more"]
48
+ else
49
+ @has_content = false
50
+ end
51
+ else
52
+ @has_content = false
53
+ end
54
+ end
55
+ elsif @database
25
56
  unless @has_content # re-exec
26
57
  unless @load_all_contents
27
58
  @query.start_cursor = nil
@@ -51,6 +82,7 @@ module NotionRubyMapping
51
82
  end
52
83
  end
53
84
  end
85
+ self
54
86
  end
55
87
 
56
88
  private
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # Notion page object
5
+ class Page < Base
6
+ ### Public announced methods
7
+
8
+ # @param [String] id
9
+ # @return [NotionRubyMapping::Page, String]
10
+ # @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#7d868b8b81c3473082bbdc7370813a4a
11
+ def self.find(id, dry_run: false)
12
+ nc = NotionCache.instance
13
+ if dry_run
14
+ Base.dry_run_script :get, nc.page_path(id)
15
+ else
16
+ nc.page id
17
+ end
18
+ end
19
+
20
+ # @param [String] title
21
+ # @param [Array<String, Property>] assigns
22
+ # @return [NotionRubyMapping::Database]
23
+ # @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#2e8ca5408afb4f83a92b7b84c0dc9903
24
+ def build_child_database(title, *assigns)
25
+ db = Database.new json: {"title" => [TextObject.new(title).property_values_json]},
26
+ assign: assigns, parent: {"type" => "page_id", "page_id" => @id}
27
+ yield db, db.properties if block_given?
28
+ db
29
+ end
30
+
31
+ def create_child_database(title, *assigns, dry_run: false)
32
+ build_child_database title, *assigns
33
+ db = Database.new json: {"title" => [TextObject.new(title).property_values_json]},
34
+ assign: assigns, parent: {"type" => "page_id", "page_id" => @id}
35
+ yield db, db.properties
36
+ db.save dry_run: dry_run
37
+ end
38
+
39
+ # @return [String] title
40
+ # @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#2ff7209055f346fbbda454cdbb40b1c8
41
+ def title
42
+ properties.select { |p| p.is_a? TitleProperty }.map(&:full_text).join ""
43
+ end
44
+
45
+ protected
46
+
47
+ # @return [NotionRubyMapping::Base, String]
48
+ def create(dry_run: false)
49
+ if dry_run
50
+ dry_run_script :post, @nc.pages_path, :property_values_json
51
+ else
52
+ @new_record = false
53
+ update_json @nc.create_page_request(property_values_json)
54
+ end
55
+ end
56
+
57
+ # @return [Hash]
58
+ def reload_json
59
+ @nc.page_request @id
60
+ end
61
+
62
+ # @return [NotionRubyMapping::Base, String]
63
+ def update(dry_run: false)
64
+ if dry_run
65
+ dry_run_script :patch, @nc.page_path(@id), :property_values_json
66
+ else
67
+ update_json @nc.update_page_request(@id, property_values_json)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -11,6 +11,8 @@ module NotionRubyMapping
11
11
 
12
12
  ### initialize
13
13
 
14
+
15
+ # @see https://www.notion.so/hkob/NotionCache-65e1599864d6425686d495a5a4b3a623#dca210788f114cf59464090782c073bf
14
16
  def initialize
15
17
  @object_hash = {}
16
18
  @client = Faraday::Connection.new "https://api.notion.com" do |builder|
@@ -25,38 +27,42 @@ module NotionRubyMapping
25
27
  attr_reader :object_hash
26
28
  attr_writer :client # for test only
27
29
 
28
- # @param [String] notion_token
29
- # @return [NotionRubyMapping::NotionCache] self (NotionCache.instance)
30
- def create_client(notion_token, wait: 0.3333, debug: false)
31
- @notion_token = notion_token
32
- @wait = wait
33
- @debug = debug
34
- self
30
+ # @param [String] page_id
31
+ # @return [String (frozen)] block_path
32
+ def append_block_children_block_path(block_id)
33
+ "v1/blocks/#{block_id}/children"
35
34
  end
36
35
 
37
- ### create path methods
38
-
39
- # @param [String] database_id
36
+ # @param [String] page_id
40
37
  # @return [String (frozen)] page_path
41
- def database_path(database_id)
42
- "v1/databases/#{database_id}"
38
+ def append_block_children_page_path(page_id)
39
+ "v1/blocks/#{page_id}/children"
40
+ end
41
+
42
+ # @param [String] id
43
+ # @param [Hash] payload
44
+ # @return [Hash]
45
+ def append_block_children_request(id, payload)
46
+ request :patch, append_block_children_block_path(id), payload
43
47
  end
44
48
 
45
- # @param [String] database_id
46
- # @return [String (frozen)] page_path
47
- def databases_path
48
- "v1/databases"
49
+ # @param [String] id block_id (with or without "-")
50
+ # @return [NotionRubyMapping::Base] Block object or nil
51
+ def block(id)
52
+ object_for_key(id) { block_request id }
49
53
  end
50
54
 
51
55
  # @param [String] page_id
52
56
  # @return [String (frozen)] page_path
53
- def page_path(page_id)
54
- "v1/pages/#{page_id}"
57
+ def block_children_page_path(page_id, query_string = "")
58
+ "v1/blocks/#{page_id}/children#{query_string}"
55
59
  end
56
60
 
57
- # @return [String (frozen)] page_path
58
- def pages_path
59
- "v1/pages"
61
+ # @param [String] id
62
+ # @param [String] query_string
63
+ # @return [Hash]
64
+ def block_children_request(id, query_string)
65
+ request :get, block_children_page_path(id, query_string)
60
66
  end
61
67
 
62
68
  # @param [String] block_id
@@ -65,84 +71,75 @@ module NotionRubyMapping
65
71
  "v1/blocks/#{block_id}"
66
72
  end
67
73
 
68
- # @param [String] database_id
69
- # @return [String (frozen)] page_path
70
- def query_database_path(database_id)
71
- "v1/databases/#{database_id}/query"
74
+ # @param [String] block_id
75
+ # @return [Hash] response
76
+ def block_request(block_id)
77
+ request :get, block_path(block_id)
72
78
  end
73
79
 
74
- ### Notion API call
75
-
76
- # @param [Symbol] method
77
- # @param [String] path
78
- # @param [Hash] options
79
- # @return [Hash] response hash
80
- def request(method, path, options = {})
81
- raise "Please call `NotionCache.create_client' before using other methods" unless @notion_token
80
+ # @return [Hash]
81
+ def clear_object_hash
82
+ @object_hash = {}
83
+ end
82
84
 
83
- sleep @wait
84
- response = @client.send(method) do |request|
85
- request.headers["Authorization"] = "Bearer #{@notion_token}"
86
- request.headers["Notion-Version"] = NotionRubyMapping::NOTION_VERSION
87
- case method
88
- when :get, :delete
89
- request.url path, options
90
- when :post, :put, :patch
91
- request.headers["Content-Type"] = "application/json"
92
- request.path = path
93
- request.body = options.to_json unless options.empty?
94
- else
95
- raise StandardError, "Unknown method: #{method}"
96
- end
97
- request.options.merge!(options.delete(:request)) if options.key? :request
98
- end
99
- p response.body if @debug
100
- response.body
85
+ # @param [String] notion_token
86
+ # @return [NotionRubyMapping::NotionCache] self (NotionCache.instance)
87
+ def create_client(notion_token, wait: 0.3333, debug: false)
88
+ @notion_token = notion_token
89
+ @wait = wait
90
+ @debug = debug
91
+ self
101
92
  end
102
93
 
103
- # @param [String] page_id
94
+ # @param [Hash] payload
104
95
  # @return [Hash] response
105
- def page_request(page_id)
106
- request :get, page_path(page_id)
96
+ def create_database_request(payload)
97
+ request :post, databases_path, payload
107
98
  end
108
99
 
109
- # @param [String] database_id
100
+ # @param [Hash] payload
110
101
  # @return [Hash] response
111
- def database_request(database_id)
112
- request :get, database_path(database_id)
102
+ def create_page_request(payload)
103
+ request :post, "v1/pages", payload
113
104
  end
114
105
 
115
- def database_query_request(database_id, payload)
116
- request :post, "v1/databases/#{database_id}/query", payload
106
+ # @param [String] id database_id (with or without "-")
107
+ # @return [NotionRubyMapping::Base] Database object or nil
108
+ def database(id)
109
+ object_for_key(id) { database_request id }
117
110
  end
118
111
 
119
- # @param [String] block_id
120
- # @return [Hash] response
121
- def block_request(block_id)
122
- request :get, block_path(block_id)
112
+ # @param [String] database_id
113
+ # @return [String (frozen)] page_path
114
+ def database_path(database_id)
115
+ "v1/databases/#{database_id}"
123
116
  end
124
117
 
125
- # @param [String] database_id
126
- # @return [Hash] response
127
- def update_database_request(database_id, payload)
128
- request :patch, "v1/databases/#{database_id}", payload
118
+ # @param [String] id page_id / block_id (with or without "-")
119
+ # @param [NotionRubyMapping::Query] query query object
120
+ # @return [NotionRubyMapping::Base] List object
121
+ def database_query(id, query)
122
+ Base.create_from_json database_query_request(id, query.query_json)
129
123
  end
130
124
 
131
- # @param [String] page_id
132
- # @param [Hash] payload
133
- # @return [Hash] response
134
- def update_page_request(page_id, payload)
135
- request :patch, "v1/pages/#{page_id}", payload
125
+ def database_query_request(database_id, payload)
126
+ request :post, "v1/databases/#{database_id}/query", payload
136
127
  end
137
128
 
138
- # @param [Hash] payload
129
+ # @param [String] database_id
139
130
  # @return [Hash] response
140
- def create_page_request(payload)
141
- request :post, "v1/pages", payload
131
+ def database_request(database_id)
132
+ request :get, database_path(database_id)
142
133
  end
143
134
 
144
- def create_database_request(payload)
145
- request :post, databases_path, payload
135
+ # @param [String] database_id
136
+ # @return [String (frozen)] page_path
137
+ def databases_path
138
+ "v1/databases"
139
+ end
140
+
141
+ def inspect
142
+ "NotionCache"
146
143
  end
147
144
 
148
145
  # @param [String] id id string with "-"
@@ -167,34 +164,54 @@ module NotionRubyMapping
167
164
  object_for_key(id) { page_request id }
168
165
  end
169
166
 
170
- # @param [String] id database_id (with or without "-")
171
- # @return [NotionRubyMapping::Base] Database object or nil
172
- def database(id)
173
- object_for_key(id) { database_request id }
167
+ # @param [String] page_id
168
+ # @return [String (frozen)] page_path
169
+ def page_path(page_id)
170
+ "v1/pages/#{page_id}"
174
171
  end
175
172
 
176
- # @param [String] id block_id (with or without "-")
177
- # @return [NotionRubyMapping::Base] Block object or nil
178
- def block(id)
179
- object_for_key(id) { block_request id }
173
+ # @param [String] page_id
174
+ # @return [Hash] response
175
+ def page_request(page_id)
176
+ request :get, page_path(page_id)
180
177
  end
181
178
 
182
- # @param [String] id page_id / block_id (with or without "-")
183
- # @return [NotionRubyMapping::Base] List object
184
- def block_children(id)
185
- array = []
186
- sleep @wait
187
- @client.block_children(block_id: id, sleep_interval: @wait, max_retries: 20) do |page|
188
- array.concat page.results
189
- end
190
- Base.create_from_json({"object" => "list", "results" => array})
179
+ # @return [String (frozen)] page_path
180
+ def pages_path
181
+ "v1/pages"
191
182
  end
192
183
 
193
- # @param [String] id page_id / block_id (with or without "-")
194
- # @param [NotionRubyMapping::Query] query query object
195
- # @return [NotionRubyMapping::Base] List object
196
- def database_query(id, query)
197
- Base.create_from_json database_query_request(id, query.query_json)
184
+ # @param [String] database_id
185
+ # @return [String (frozen)] page_path
186
+ def query_database_path(database_id)
187
+ "v1/databases/#{database_id}/query"
188
+ end
189
+
190
+ # @param [Symbol] method
191
+ # @param [String] path
192
+ # @param [Hash] options
193
+ # @return [Hash] response hash
194
+ def request(method, path, options = {})
195
+ raise "Please call `NotionCache.create_client' before using other methods" unless @notion_token
196
+
197
+ sleep @wait
198
+ response = @client.send(method) do |request|
199
+ request.headers["Authorization"] = "Bearer #{@notion_token}"
200
+ request.headers["Notion-Version"] = NotionRubyMapping::NOTION_VERSION
201
+ case method
202
+ when :get, :delete
203
+ request.url path, options
204
+ when :post, :put, :patch
205
+ request.headers["Content-Type"] = "application/json"
206
+ request.path = path
207
+ request.body = options.to_json unless options.empty?
208
+ else
209
+ raise StandardError, "Unknown method: #{method}"
210
+ end
211
+ request.options.merge!(options.delete(:request)) if options.key? :request
212
+ end
213
+ p response.body if @debug
214
+ response.body
198
215
  end
199
216
 
200
217
  # @param [String] id page_id (with or without "-")
@@ -204,9 +221,18 @@ module NotionRubyMapping
204
221
  @client.update_database payload.merge({database_id: id})
205
222
  end
206
223
 
207
- # @return [Hash]
208
- def clear_object_hash
209
- @object_hash = {}
224
+ # @param [String] database_id
225
+ # @return [Hash] response
226
+ def update_database_request(database_id, payload)
227
+ request :patch, "v1/databases/#{database_id}", payload
228
+ end
229
+
230
+ # @param [String] page_id
231
+ # @param [Hash] payload
232
+ # @return [Hash] response
233
+ def update_page_request(page_id, payload)
234
+ request :patch, "v1/pages/#{page_id}", payload
210
235
  end
236
+
211
237
  end
212
238
  end
@@ -13,22 +13,20 @@ module NotionRubyMapping
13
13
 
14
14
  # @param [String] key
15
15
  # @return [Property] Property for key
16
+ # @see https://www.notion.so/hkob/PropertyCache-2451fa64a814432db4809831cc77ba25#9709e2b2a7a0479f9951291a501f65c8
16
17
  def [](key)
17
18
  @properties[key] ||= Property.create_from_json key, @json[key], @base_type
18
19
  end
19
20
 
20
- # @param [Array] key
21
- # @return [Array]
22
- def values_at(*key)
23
- generate_all_properties
24
- @properties.values_at(*key)
21
+ # @param [Property] property added Property
22
+ def add_property(property)
23
+ @properties[property.name] = property
24
+ self
25
25
  end
26
26
 
27
- def generate_all_properties
28
- if @json.empty?
29
- @properties.values
30
- else
31
- @json.keys.map { |key| self[key] }
27
+ def clear_will_update
28
+ @properties.each do |_, property|
29
+ property.clear_will_update
32
30
  end
33
31
  end
34
32
 
@@ -39,16 +37,11 @@ module NotionRubyMapping
39
37
  generate_all_properties.each(&block)
40
38
  end
41
39
 
42
- # @param [Property] property added Property
43
- def add_property(property)
44
- @properties[property.name] = property
45
- self
46
- end
47
-
48
-
49
- def clear_will_update
50
- @properties.each do |_, property|
51
- property.clear_will_update
40
+ def generate_all_properties
41
+ if @json.empty?
42
+ @properties.values
43
+ else
44
+ @json.keys.map { |key| self[key] }
52
45
  end
53
46
  end
54
47
 
@@ -81,5 +74,13 @@ module NotionRubyMapping
81
74
  end
82
75
  end
83
76
  end
77
+
78
+ # @param [Array] key
79
+ # @return [Array]
80
+ # @see https://www.notion.so/hkob/PropertyCache-2451fa64a814432db4809831cc77ba25#6eb10d1d85784063a30feb225f47ede3
81
+ def values_at(*key)
82
+ generate_all_properties
83
+ @properties.values_at(*key)
84
+ end
84
85
  end
85
86
  end
@@ -14,22 +14,11 @@ module NotionRubyMapping
14
14
 
15
15
  # @param [Query] other_query other query
16
16
  # @return [NotionRubyMapping::Query] updated self (Query object)
17
- def and(other_query)
17
+ def and(another_query)
18
18
  if @filter.key? "and"
19
- @filter["and"] << other_query.filter
19
+ @filter["and"] << another_query.filter
20
20
  else
21
- @filter = {"and" => [@filter, other_query.filter]}
22
- end
23
- self
24
- end
25
-
26
- # @param [Query] other_query other query
27
- # @return [NotionRubyMapping::Query] updated self (Query object)
28
- def or(other_query)
29
- if @filter.key? "or"
30
- @filter["or"] << other_query.filter
31
- else
32
- @filter = {"or" => [@filter, other_query.filter]}
21
+ @filter = {"and" => [@filter, another_query.filter]}
33
22
  end
34
23
  self
35
24
  end
@@ -50,14 +39,33 @@ module NotionRubyMapping
50
39
  self
51
40
  end
52
41
 
42
+ # @param [Query] other_query other query
43
+ # @return [NotionRubyMapping::Query] updated self (Query object)
44
+ def or(other_query)
45
+ if @filter.key? "or"
46
+ @filter["or"] << other_query.filter
47
+ else
48
+ @filter = {"or" => [@filter, other_query.filter]}
49
+ end
50
+ self
51
+ end
52
+
53
53
  # @return [Hash]
54
54
  def query_json
55
55
  parameters = {}
56
- parameters[:filter] = filter unless filter.empty?
57
- parameters[:sorts] = sort unless sort.empty?
58
- parameters[:start_cursor] = start_cursor if start_cursor
59
- parameters[:page_size] = page_size if page_size
56
+ parameters[:filter] = @filter unless @filter.empty?
57
+ parameters[:sorts] = @sort unless @sort.empty?
58
+ parameters[:start_cursor] = @start_cursor if @start_cursor
59
+ parameters[:page_size] = @page_size if @page_size
60
60
  parameters
61
61
  end
62
+
63
+ # @return [String (frozen)]
64
+ def query_string
65
+ ans = []
66
+ ans << "page_size=#{@page_size}" if @page_size
67
+ ans << "start_cursor=#{@start_cursor}" if @start_cursor
68
+ ans.empty? ? "" : "?#{ans.join("&")}"
69
+ end
62
70
  end
63
71
  end
@@ -19,6 +19,32 @@ module NotionRubyMapping
19
19
  end
20
20
  @will_update = will_update
21
21
  end
22
+ attr_writer :will_update
23
+
24
+ def self.rich_text_array(key, text_objects = nil)
25
+ if text_objects.nil?
26
+ RichTextArray.new key
27
+ elsif text_objects.is_a? RichTextArray
28
+ text_objects
29
+ else
30
+ RichTextArray.new key, text_objects: text_objects
31
+ end
32
+ end
33
+
34
+ # @param [String, RichTextObject] to
35
+ # @return [NotionRubyMapping::RichTextObject] added RichTextObject
36
+ def <<(to)
37
+ @will_update = true
38
+ rto = RichTextObject.text_object(to)
39
+ @rich_text_objects << rto
40
+ rto
41
+ end
42
+
43
+ # @param [Numeric] index index number
44
+ # @return [RichTextObject] selected RichTextObject
45
+ def [](index)
46
+ @rich_text_objects[index]
47
+ end
22
48
 
23
49
  # @param [Array] json
24
50
  # @return [Array] RichTextArray
@@ -62,20 +88,5 @@ module NotionRubyMapping
62
88
  def will_update
63
89
  @will_update || @rich_text_objects.map(&:will_update).any?
64
90
  end
65
-
66
- # @param [String, RichTextObject] to
67
- # @return [NotionRubyMapping::RichTextObject] added RichTextObject
68
- def <<(to)
69
- @will_update = true
70
- rto = RichTextObject.text_object(to)
71
- @rich_text_objects << rto
72
- rto
73
- end
74
-
75
- # @param [Numeric] index index number
76
- # @return [RichTextObject] selected RichTextObject
77
- def [](index)
78
- @rich_text_objects[index]
79
- end
80
91
  end
81
92
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRubyMapping
4
+ # TextObject
5
+ class EmojiObject
6
+ # @param [String] emoji
7
+ # @return [TextObject]
8
+ def initialize(emoji: nil, json: {})
9
+ @emoji = emoji || json && json["emoji"]
10
+ @will_update = false
11
+ end
12
+ attr_reader :will_update, :emoji
13
+
14
+ # @param [EmojiObject, String] uo
15
+ # @return [EmojiObject] self or created EmojiObject
16
+ # @see https://www.notion.so/hkob/EmojiObject-4a0d41a10a81490f82471059c5b39b1b#959b7d74c1a54e488b39a96ac8f634e5
17
+ def self.emoji_object(emoji_or_eo)
18
+ if emoji_or_eo.is_a? EmojiObject
19
+ emoji_or_eo
20
+ else
21
+ EmojiObject.new emoji: emoji_or_eo
22
+ end
23
+ end
24
+
25
+ # @param [String] emoji
26
+ # @see https://www.notion.so/hkob/EmojiObject-4a0d41a10a81490f82471059c5b39b1b#b0520d80de084c1c99e8595db9d36542
27
+ def emoji=(emoji)
28
+ @emoji = emoji
29
+ @will_update = true
30
+ end
31
+
32
+ # @return [Hash]
33
+ def property_values_json
34
+ {
35
+ "type" => "emoji",
36
+ "emoji" => @emoji,
37
+ }
38
+ end
39
+ end
40
+ end