Skip to content

Commit 673de5f

Browse files
Merge pull request #23 from danmurphy1217/push-singleton-method-updates
update singleton methods to support changing select and multi-select values
2 parents fb29986 + 166e33f commit 673de5f

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

lib/notion_api/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ def initialize(token_v2, active_user_header = nil)
1414
super(token_v2, active_user_header)
1515
end
1616
end
17-
end
17+
end

lib/notion_api/notion_types/collection_view_blocks.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ def create_singleton_methods_and_instance_variables(row, row_data)
262262
parsed_method = __method__.to_s[0...-1].split("_").join(" ")
263263
cookies = Core.options["cookies"]
264264
headers = Core.options["headers"]
265-
265+
266+
p new_value, column_hash.key(parsed_method), column_names, schema
267+
266268
request_id = extract_id(SecureRandom.hex(16))
267269
transaction_id = extract_id(SecureRandom.hex(16))
268270
space_id = extract_id(SecureRandom.hex(16))
@@ -273,12 +275,24 @@ def create_singleton_methods_and_instance_variables(row, row_data)
273275
space_id: space_id,
274276
}
275277

276-
update_property_value = Utils::CollectionViewComponents.update_property_value(@id, column_hash.key(parsed_method), new_value)
278+
update_property_value_hash = Utils::CollectionViewComponents.update_property_value(@id, column_hash.key(parsed_method), new_value)
277279

278280
operations = [
279-
update_property_value,
281+
update_property_value_hash,
280282
]
281283

284+
if %q[select multi_select].include?(schema[column_hash.key(parsed_method)]["type"])
285+
p "ENTERED THE ABYSS"
286+
options = schema[column_hash.key(parsed_method)]["options"].nil? ? [] : schema[column_hash.key(parsed_method)]["options"].map { |option| option["value"] }
287+
multi_select_multi_options = new_value.split(",")
288+
multi_select_multi_options.each do |option|
289+
if !options.include?(option.strip)
290+
create_new_option = Utils::CollectionViewComponents.add_new_option(column_hash.key(parsed_method), option.strip, @collection_id)
291+
operations.push(create_new_option)
292+
end
293+
end
294+
end
295+
282296
request_url = URLS[:UPDATE_BLOCK]
283297
request_body = build_payload(operations, request_ids)
284298
response = HTTParty.post(

lib/notion_api/utils.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,14 @@ def self.add_new_option(column, value, collection_id)
494494
table = "collection"
495495
path = ["schema", column, "options"]
496496
command = "keyedObjectListAfter"
497+
colors = ["default", "gray", "brown", "orange", "yellow", "green", "blue", "purple", "pink", "red"]
498+
random_color = colors[rand(0...colors.length)]
499+
497500
args = {
498501
"value": {
499502
"id": SecureRandom.hex(16),
500503
"value": value,
501-
"color": "green"
504+
"color": random_color
502505
}
503506
}
504507

lib/notion_api/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module NotionAPI
2-
VERSION = '1.0.7'
2+
VERSION = '1.1.1'
33
end

0 commit comments

Comments
 (0)