Skip to content

Commit

Permalink
Merge pull request #23 from danmurphy1217/push-singleton-method-updates
Browse files Browse the repository at this point in the history
update singleton methods to support changing select and multi-select values
  • Loading branch information
danmurphy1217 authored Dec 8, 2020
2 parents fb29986 + 166e33f commit 673de5f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/notion_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def initialize(token_v2, active_user_header = nil)
super(token_v2, active_user_header)
end
end
end
end
20 changes: 17 additions & 3 deletions lib/notion_api/notion_types/collection_view_blocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ def create_singleton_methods_and_instance_variables(row, row_data)
parsed_method = __method__.to_s[0...-1].split("_").join(" ")
cookies = Core.options["cookies"]
headers = Core.options["headers"]


p new_value, column_hash.key(parsed_method), column_names, schema

request_id = extract_id(SecureRandom.hex(16))
transaction_id = extract_id(SecureRandom.hex(16))
space_id = extract_id(SecureRandom.hex(16))
Expand All @@ -273,12 +275,24 @@ def create_singleton_methods_and_instance_variables(row, row_data)
space_id: space_id,
}

update_property_value = Utils::CollectionViewComponents.update_property_value(@id, column_hash.key(parsed_method), new_value)
update_property_value_hash = Utils::CollectionViewComponents.update_property_value(@id, column_hash.key(parsed_method), new_value)

operations = [
update_property_value,
update_property_value_hash,
]

if %q[select multi_select].include?(schema[column_hash.key(parsed_method)]["type"])
p "ENTERED THE ABYSS"
options = schema[column_hash.key(parsed_method)]["options"].nil? ? [] : schema[column_hash.key(parsed_method)]["options"].map { |option| option["value"] }
multi_select_multi_options = new_value.split(",")
multi_select_multi_options.each do |option|
if !options.include?(option.strip)
create_new_option = Utils::CollectionViewComponents.add_new_option(column_hash.key(parsed_method), option.strip, @collection_id)
operations.push(create_new_option)
end
end
end

request_url = URLS[:UPDATE_BLOCK]
request_body = build_payload(operations, request_ids)
response = HTTParty.post(
Expand Down
5 changes: 4 additions & 1 deletion lib/notion_api/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,14 @@ def self.add_new_option(column, value, collection_id)
table = "collection"
path = ["schema", column, "options"]
command = "keyedObjectListAfter"
colors = ["default", "gray", "brown", "orange", "yellow", "green", "blue", "purple", "pink", "red"]
random_color = colors[rand(0...colors.length)]

args = {
"value": {
"id": SecureRandom.hex(16),
"value": value,
"color": "green"
"color": random_color
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/notion_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module NotionAPI
VERSION = '1.0.7'
VERSION = '1.1.1'
end

0 comments on commit 673de5f

Please sign in to comment.