notion_ruby_mapping 4.0.2 → 4.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -1
- data/README.md +5 -3
- data/lib/notion_ruby_mapping/blocks/block.rb +51 -48
- data/lib/notion_ruby_mapping/blocks/breadcrumb_block.rb +4 -4
- data/lib/notion_ruby_mapping/blocks/callout_block.rb +6 -1
- data/lib/notion_ruby_mapping/blocks/divider_block.rb +4 -4
- data/lib/notion_ruby_mapping/blocks/equation_block.rb +2 -2
- data/lib/notion_ruby_mapping/blocks/file_base_block.rb +48 -19
- data/lib/notion_ruby_mapping/blocks/file_block.rb +4 -2
- data/lib/notion_ruby_mapping/blocks/heading1_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/heading2_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/heading3_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/heading4_block.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/list.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/table_of_contents_block.rb +6 -5
- data/lib/notion_ruby_mapping/controllers/mermaid_data_source.rb +3 -3
- data/lib/notion_ruby_mapping/controllers/rich_text_array.rb +6 -1
- data/lib/notion_ruby_mapping/objects/equation_object.rb +6 -4
- data/lib/notion_ruby_mapping/objects/file_object.rb +50 -25
- data/lib/notion_ruby_mapping/objects/file_upload_object.rb +114 -68
- data/lib/notion_ruby_mapping/properties/button_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/checkbox_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/created_time_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/email_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/files_property.rb +10 -16
- data/lib/notion_ruby_mapping/properties/last_edited_by_property.rb +0 -1
- data/lib/notion_ruby_mapping/properties/last_edited_time_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/multi_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/multi_select_property.rb +11 -11
- data/lib/notion_ruby_mapping/properties/number_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/people_property.rb +24 -5
- data/lib/notion_ruby_mapping/properties/phone_number_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/property.rb +14 -35
- data/lib/notion_ruby_mapping/properties/relation_property.rb +7 -7
- data/lib/notion_ruby_mapping/properties/rich_text_property.rb +0 -22
- data/lib/notion_ruby_mapping/properties/select_property.rb +11 -11
- data/lib/notion_ruby_mapping/properties/status_property.rb +50 -2
- data/lib/notion_ruby_mapping/properties/text_property.rb +59 -1
- data/lib/notion_ruby_mapping/properties/title_property.rb +0 -38
- data/lib/notion_ruby_mapping/properties/unique_id_property.rb +39 -3
- data/lib/notion_ruby_mapping/properties/url_property.rb +3 -3
- data/lib/notion_ruby_mapping/properties/verification_property.rb +8 -12
- data/lib/notion_ruby_mapping/version.rb +1 -1
- metadata +2 -2
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module NotionRubyMapping
|
|
4
|
-
#
|
|
4
|
+
# Represents file information shared by file-based blocks and file properties.
|
|
5
|
+
#
|
|
6
|
+
# Use the owning block or property to update a file. This object is primarily
|
|
7
|
+
# intended for inspecting the current file representation.
|
|
5
8
|
class FileObject
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
|
|
9
|
+
# Creates a file representation.
|
|
10
|
+
#
|
|
11
|
+
# @param url [String, nil] external file URL
|
|
12
|
+
# @param file_upload_object [FileUploadObject, nil] uploaded file
|
|
13
|
+
# @param json [Hash, nil] file JSON returned by the Notion API
|
|
14
|
+
# @raise [ArgumentError] if no file source is provided
|
|
15
|
+
# @api private
|
|
16
|
+
def initialize(url: nil, file_upload_object: nil, json: nil)
|
|
9
17
|
if url
|
|
10
18
|
@type = "external"
|
|
11
19
|
@url = url
|
|
@@ -17,49 +25,66 @@ module NotionRubyMapping
|
|
|
17
25
|
@url = json[@type]["url"]
|
|
18
26
|
@expiry_time = json[@type]["expiry_time"]
|
|
19
27
|
else
|
|
20
|
-
raise
|
|
28
|
+
raise ArgumentError, "FileObject requires url:, file_upload_object:, or json:"
|
|
21
29
|
end
|
|
22
|
-
@will_update = false
|
|
23
30
|
end
|
|
24
|
-
|
|
31
|
+
# @return [String, nil] current file URL
|
|
32
|
+
attr_reader :url
|
|
25
33
|
|
|
26
|
-
# @
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
# @return [String] file type: `"external"`, `"file"`, or `"file_upload"`
|
|
35
|
+
attr_reader :type
|
|
36
|
+
|
|
37
|
+
# @return [FileUploadObject, nil] current file upload object
|
|
38
|
+
attr_reader :file_upload_object
|
|
39
|
+
|
|
40
|
+
# Converts a supported file value to a file object.
|
|
41
|
+
#
|
|
42
|
+
# @param value [String, FileUploadObject, FileObject]
|
|
43
|
+
# external URL, uploaded file, or existing file object
|
|
44
|
+
# @return [FileObject] converted file object
|
|
45
|
+
# @api private
|
|
46
|
+
def self.file_object(value)
|
|
47
|
+
if value.is_a? FileUploadObject
|
|
48
|
+
FileObject.new file_upload_object: value
|
|
49
|
+
elsif value.is_a? FileObject
|
|
50
|
+
value
|
|
34
51
|
else
|
|
35
|
-
FileObject.new url:
|
|
52
|
+
FileObject.new url: value
|
|
36
53
|
end
|
|
37
54
|
end
|
|
38
55
|
|
|
39
|
-
#
|
|
56
|
+
# Checks whether the file uses an external URL.
|
|
57
|
+
#
|
|
58
|
+
# @return [Boolean] true if the file type is `"external"`
|
|
40
59
|
def external?
|
|
41
60
|
@type == "external"
|
|
42
61
|
end
|
|
43
62
|
|
|
44
|
-
#
|
|
45
|
-
|
|
46
|
-
|
|
63
|
+
# Replaces the current representation with an uploaded file.
|
|
64
|
+
#
|
|
65
|
+
# @param file_upload_object [FileUploadObject] uploaded file
|
|
66
|
+
# @api private
|
|
67
|
+
def file_upload_object=(file_upload_object)
|
|
68
|
+
@file_upload_object = file_upload_object
|
|
47
69
|
@type = "file_upload"
|
|
48
70
|
@url = nil
|
|
49
71
|
@expiry_time = nil
|
|
50
|
-
@will_update = true
|
|
51
72
|
end
|
|
52
73
|
|
|
53
|
-
#
|
|
54
|
-
#
|
|
74
|
+
# Replaces the current representation with an external URL.
|
|
75
|
+
#
|
|
76
|
+
# @param url [String] external file URL
|
|
77
|
+
# @api private
|
|
55
78
|
def url=(url)
|
|
56
79
|
@url = url
|
|
57
80
|
@type = "external"
|
|
58
81
|
@expiry_time = nil
|
|
59
|
-
@will_update = true
|
|
60
82
|
end
|
|
61
83
|
|
|
62
|
-
#
|
|
84
|
+
# Builds the Notion API file JSON.
|
|
85
|
+
#
|
|
86
|
+
# @return [Hash{String => Object}] file JSON
|
|
87
|
+
# @api private
|
|
63
88
|
def property_values_json
|
|
64
89
|
if @type == "file_upload"
|
|
65
90
|
{
|
|
@@ -1,86 +1,132 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
else
|
|
12
|
-
raise StandardError, "FileUploadObject requires a valid file name: #{fname}" unless File.exist?(fname)
|
|
3
|
+
module NotionRubyMapping
|
|
4
|
+
# Uploads a local or external file to Notion.
|
|
5
|
+
#
|
|
6
|
+
# Creating an instance starts the upload immediately. Large local files are
|
|
7
|
+
# split into multiple parts before being uploaded.
|
|
8
|
+
class FileUploadObject
|
|
9
|
+
# Maximum size of each upload part.
|
|
10
|
+
MAX_SIZE = 10 * 1024 * 1024
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
# Creates and uploads a file.
|
|
13
|
+
#
|
|
14
|
+
# When +external_url+ is provided, +fname+ is used as the filename sent to
|
|
15
|
+
# Notion. Otherwise, +fname+ must point to an existing local file.
|
|
16
|
+
#
|
|
17
|
+
# @param fname [String] local file path or filename
|
|
18
|
+
# @param external_url [String, nil] URL of a file for Notion to import
|
|
19
|
+
# @raise [StandardError] if the local file does not exist
|
|
20
|
+
# @raise [ArgumentError] if the local file is empty
|
|
21
|
+
def initialize(fname:, external_url: nil)
|
|
22
|
+
@fname = fname
|
|
23
|
+
if external_url
|
|
24
|
+
payload = {mode: "external_url", external_url: external_url, filename: fname}
|
|
25
|
+
create payload
|
|
25
26
|
else
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
raise StandardError, "FileUploadObject requires a valid file name: #{fname}" unless File.exist?(fname)
|
|
28
|
+
|
|
29
|
+
@file_size = File.size fname
|
|
30
|
+
raise ArgumentError, "FileUploadObject requires a non-empty file: #{fname}" if @file_size.zero?
|
|
31
|
+
|
|
32
|
+
@number_of_parts = (@file_size - 1) / MAX_SIZE + 1
|
|
33
|
+
payload = if @number_of_parts == 1
|
|
34
|
+
{}
|
|
35
|
+
else
|
|
36
|
+
{number_of_parts: @number_of_parts, mode: "multi_part",
|
|
37
|
+
filename: File.basename(@fname)}
|
|
38
|
+
end
|
|
39
|
+
create payload
|
|
40
|
+
if @number_of_parts == 1
|
|
41
|
+
single_file_upload
|
|
42
|
+
else
|
|
43
|
+
@temp_files = FileUploadObject.split_to_small_files(@fname, MAX_SIZE)
|
|
44
|
+
@temp_files.each_with_index do |temp_file, i|
|
|
45
|
+
single_file_upload temp_file.path, i + 1
|
|
46
|
+
temp_file.close
|
|
47
|
+
temp_file.unlink
|
|
48
|
+
end
|
|
49
|
+
NotionRubyMapping::NotionCache.instance.complete_a_file_upload_request @id
|
|
31
50
|
end
|
|
32
|
-
NotionRubyMapping::NotionCache.instance.complete_a_file_upload_request @id
|
|
33
51
|
end
|
|
34
52
|
end
|
|
35
|
-
|
|
36
|
-
|
|
53
|
+
# @return [String] file upload ID
|
|
54
|
+
attr_reader :id
|
|
37
55
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
nc = NotionRubyMapping::NotionCache.instance
|
|
41
|
-
response = nc.create_file_upload_request(payload)
|
|
42
|
-
@id = nc.hex_id response["id"]
|
|
43
|
-
@status = response["status"]
|
|
44
|
-
end
|
|
56
|
+
# @return [String] local file path or filename
|
|
57
|
+
attr_reader :fname
|
|
45
58
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
response = nc.file_upload_request @id
|
|
49
|
-
@status = response["status"]
|
|
50
|
-
self
|
|
51
|
-
end
|
|
59
|
+
# @return [String] last retrieved upload status
|
|
60
|
+
attr_reader :status
|
|
52
61
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
# Creates a file upload through the Notion API.
|
|
63
|
+
#
|
|
64
|
+
# @param payload [Hash] file upload creation payload
|
|
65
|
+
# @return [String] initial upload status
|
|
66
|
+
# @api private
|
|
67
|
+
def create(payload)
|
|
68
|
+
nc = NotionRubyMapping::NotionCache.instance
|
|
69
|
+
response = nc.create_file_upload_request(payload)
|
|
70
|
+
@id = nc.hex_id response["id"]
|
|
71
|
+
@status = response["status"]
|
|
62
72
|
end
|
|
63
|
-
nc = NotionRubyMapping::NotionCache.instance
|
|
64
|
-
response = nc.send_file_upload_request fname, @id, options
|
|
65
|
-
return if nc.hex_id(response["id"]) == @id && response["status"] == status
|
|
66
73
|
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
# Reloads the current upload status from Notion.
|
|
75
|
+
#
|
|
76
|
+
# @return [FileUploadObject] self
|
|
77
|
+
def reload
|
|
78
|
+
nc = NotionRubyMapping::NotionCache.instance
|
|
79
|
+
response = nc.file_upload_request @id
|
|
80
|
+
@status = response["status"]
|
|
81
|
+
self
|
|
82
|
+
end
|
|
69
83
|
|
|
70
|
-
|
|
71
|
-
|
|
84
|
+
# Uploads a local file or one part of a multipart upload.
|
|
85
|
+
#
|
|
86
|
+
# @param fname [String] path of the file to upload
|
|
87
|
+
# @param part_number [Integer] multipart part number
|
|
88
|
+
# @return [void]
|
|
89
|
+
# @raise [StandardError] if the upload response is invalid
|
|
90
|
+
# @api private
|
|
91
|
+
def single_file_upload(fname = @fname, part_number = 0)
|
|
92
|
+
if @number_of_parts > 1
|
|
93
|
+
options = {"part_number" => part_number}
|
|
94
|
+
status = "pending"
|
|
95
|
+
else
|
|
96
|
+
options = {}
|
|
97
|
+
status = "uploaded"
|
|
98
|
+
end
|
|
99
|
+
nc = NotionRubyMapping::NotionCache.instance
|
|
100
|
+
response = nc.send_file_upload_request fname, @id, options
|
|
101
|
+
return if nc.hex_id(response["id"]) == @id && response["status"] == status
|
|
102
|
+
|
|
103
|
+
raise StandardError, "File upload failed: #{response}"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Splits a file into temporary files.
|
|
107
|
+
#
|
|
108
|
+
# The caller is responsible for closing and deleting the returned files.
|
|
109
|
+
#
|
|
110
|
+
# @param org_file [String] path of the original file
|
|
111
|
+
# @param max_size [Integer] maximum size of each part in bytes
|
|
112
|
+
# @return [Array<Tempfile>] temporary file parts
|
|
113
|
+
# @raise [StandardError] if the original file does not exist
|
|
114
|
+
# @api private
|
|
115
|
+
def self.split_to_small_files(org_file, max_size = MAX_SIZE)
|
|
116
|
+
raise StandardError, "File does not exist: #{org_file}" unless File.exist?(org_file)
|
|
72
117
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
118
|
+
temp_files = []
|
|
119
|
+
File.open(org_file, "rb") do |file|
|
|
120
|
+
until file.eof?
|
|
121
|
+
chunk = file.read(max_size)
|
|
122
|
+
temp_file = Tempfile.new("part_")
|
|
123
|
+
temp_file.binmode
|
|
124
|
+
temp_file.write(chunk)
|
|
125
|
+
temp_file.rewind
|
|
126
|
+
temp_files << temp_file
|
|
127
|
+
end
|
|
82
128
|
end
|
|
129
|
+
temp_files
|
|
83
130
|
end
|
|
84
|
-
temp_files
|
|
85
131
|
end
|
|
86
132
|
end
|
|
@@ -9,13 +9,13 @@ module NotionRubyMapping
|
|
|
9
9
|
|
|
10
10
|
## Common methods
|
|
11
11
|
|
|
12
|
-
# @return [
|
|
12
|
+
# @return [Hash, nil]
|
|
13
13
|
def button
|
|
14
14
|
@json
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
# @param [String, Symbol] name Property name
|
|
18
|
-
# @param [
|
|
18
|
+
# @param [Hash, nil] json Button property object
|
|
19
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
|
|
@@ -10,7 +10,7 @@ module NotionRubyMapping
|
|
|
10
10
|
|
|
11
11
|
## Common methods
|
|
12
12
|
|
|
13
|
-
# @return [Boolean, Hash,
|
|
13
|
+
# @return [Boolean, Hash] true/false for page property, schema hash for database/data_source property
|
|
14
14
|
# @see https://www.notion.so/hkob/CheckboxProperty-ac1edbdb8e264af5ad1432b522b429fd#20da1bf0cbcc4d4eb22d9125386522c2
|
|
15
15
|
def checkbox
|
|
16
16
|
@json
|
|
@@ -18,7 +18,7 @@ module NotionRubyMapping
|
|
|
18
18
|
|
|
19
19
|
## Page property only methods
|
|
20
20
|
|
|
21
|
-
# @param [Boolean] flag
|
|
21
|
+
# @param [Boolean] flag Checkbox value. Use true or false.
|
|
22
22
|
# @return [TrueClass, FalseClass] settled value
|
|
23
23
|
# @see https://www.notion.so/hkob/CheckboxProperty-ac1edbdb8e264af5ad1432b522b429fd#f167c85c1d2d40dfb8b3b6ce582e0f15
|
|
24
24
|
def checkbox=(flag)
|
|
@@ -39,7 +39,7 @@ module NotionRubyMapping
|
|
|
39
39
|
@json = if database_or_data_source?
|
|
40
40
|
json || {}
|
|
41
41
|
else
|
|
42
|
-
json
|
|
42
|
+
json.nil? ? false : json
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
|
|
@@ -13,14 +13,14 @@ module NotionRubyMapping
|
|
|
13
13
|
|
|
14
14
|
## Common methods
|
|
15
15
|
|
|
16
|
-
# @return [String, Hash]
|
|
16
|
+
# @return [String, Hash, nil] email address for page properties, empty hash for database/data source properties
|
|
17
17
|
def email
|
|
18
18
|
@json
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
## Page property only methods
|
|
22
22
|
|
|
23
|
-
# @param [String] email
|
|
23
|
+
# @param [String, nil] email
|
|
24
24
|
def email=(email)
|
|
25
25
|
assert_page_property __method__
|
|
26
26
|
@will_update = true
|
|
@@ -35,7 +35,7 @@ module NotionRubyMapping
|
|
|
35
35
|
def initialize(name, will_update: false, base_type: "page", json: nil, property_id: nil, property_cache: nil)
|
|
36
36
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
|
37
37
|
property_cache: property_cache
|
|
38
|
-
@json =
|
|
38
|
+
@json = database_or_data_source? ? {} : json
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
# @return [Hash]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module NotionRubyMapping
|
|
4
|
-
#
|
|
4
|
+
# Files property
|
|
5
5
|
class FilesProperty < Property
|
|
6
6
|
include IsEmptyIsNotEmpty
|
|
7
7
|
TYPE = "files"
|
|
@@ -12,6 +12,14 @@ module NotionRubyMapping
|
|
|
12
12
|
|
|
13
13
|
## Page property only methods
|
|
14
14
|
|
|
15
|
+
# Removes all files from the property.
|
|
16
|
+
#
|
|
17
|
+
# This method replaces the files array with an empty array.
|
|
18
|
+
def clear
|
|
19
|
+
assert_page_property __method__
|
|
20
|
+
self.files = []
|
|
21
|
+
end
|
|
22
|
+
|
|
15
23
|
def files=(files = [])
|
|
16
24
|
assert_page_property __method__
|
|
17
25
|
@will_update = true
|
|
@@ -22,7 +30,7 @@ module NotionRubyMapping
|
|
|
22
30
|
def file_names=(file_names = [])
|
|
23
31
|
array_file_names = Array(file_names)
|
|
24
32
|
unless @files.length == array_file_names.length
|
|
25
|
-
raise
|
|
33
|
+
raise ArgumentError,
|
|
26
34
|
"files and file_names must be the same sizes."
|
|
27
35
|
end
|
|
28
36
|
|
|
@@ -75,19 +83,5 @@ module NotionRubyMapping
|
|
|
75
83
|
@will_update = false
|
|
76
84
|
self
|
|
77
85
|
end
|
|
78
|
-
|
|
79
|
-
protected
|
|
80
|
-
|
|
81
|
-
# @param [String] url
|
|
82
|
-
# @return [Hash]
|
|
83
|
-
def url_to_hash(url)
|
|
84
|
-
{
|
|
85
|
-
"name" => url,
|
|
86
|
-
"type" => "external",
|
|
87
|
-
"external" => {
|
|
88
|
-
"url" => url,
|
|
89
|
-
},
|
|
90
|
-
}
|
|
91
|
-
end
|
|
92
86
|
end
|
|
93
87
|
end
|
|
@@ -9,7 +9,7 @@ module NotionRubyMapping
|
|
|
9
9
|
|
|
10
10
|
## Common methods
|
|
11
11
|
|
|
12
|
-
# @return [
|
|
12
|
+
# @return [String, Hash]
|
|
13
13
|
# @see https://www.notion.so/hkob/LastEditedTimeProperty-5058fd594f6748a48fd4db52535f4c18#a7b568bf997c44d49cdbe4bfbf29824e
|
|
14
14
|
def last_edited_time
|
|
15
15
|
@json
|
|
@@ -9,12 +9,12 @@ module NotionRubyMapping
|
|
|
9
9
|
|
|
10
10
|
## Common methods
|
|
11
11
|
|
|
12
|
-
# @return [Array
|
|
12
|
+
# @return [Array<Hash>, Hash] raw multi_select array for page property, or multi_select schema object for database/data_source property
|
|
13
13
|
def multi_select
|
|
14
14
|
@json
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
# @return [Array]
|
|
17
|
+
# @return [Array<String>] selected option names for page property, or schema option names for database/data_source property
|
|
18
18
|
def multi_select_names
|
|
19
19
|
mshs = @base_type == "page" ? @json : @json["options"]
|
|
20
20
|
mshs.map { |h| h["name"] }
|
|
@@ -24,30 +24,30 @@ module NotionRubyMapping
|
|
|
24
24
|
|
|
25
25
|
# @param [String] name
|
|
26
26
|
# @param [String] color
|
|
27
|
-
# @return [Array]
|
|
27
|
+
# @return [Array<Hash>] updated multi_select options
|
|
28
28
|
# @see https://www.notion.so/hkob/MultiSelectProperty-b90bba1c55d540ba97131bb013d4ca74#bcac830b00e04cb6bf7dbbb110d95667
|
|
29
29
|
def add_multi_select_option(name:, color:)
|
|
30
30
|
edit_multi_select_options << {"name" => name, "color" => color}
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
# @return [Array]
|
|
33
|
+
# @return [Array<Hash>] editable multi_select options
|
|
34
34
|
def edit_multi_select_options
|
|
35
35
|
assert_database_or_data_source_property __method__
|
|
36
36
|
@will_update = true
|
|
37
37
|
@json["options"] ||= []
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
# @return [Array]
|
|
40
|
+
# @return [Array<Hash>] schema multi_select options
|
|
41
41
|
# @see https://www.notion.so/hkob/MultiSelectProperty-b90bba1c55d540ba97131bb013d4ca74#5ff6ec299cf64049bde2416f61b30fa9
|
|
42
42
|
def multi_select_options
|
|
43
|
-
|
|
43
|
+
assert_database_or_data_source_property __method__
|
|
44
44
|
@json["options"] || []
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
## Page property only methods
|
|
48
48
|
|
|
49
|
-
# @param [
|
|
50
|
-
# @return [Array
|
|
49
|
+
# @param [String, Array<String>, nil] multi_select selected option name or names
|
|
50
|
+
# @return [Array<Hash>] settled array
|
|
51
51
|
def multi_select=(multi_select)
|
|
52
52
|
assert_page_property __method__
|
|
53
53
|
@will_update = true
|
|
@@ -59,8 +59,8 @@ module NotionRubyMapping
|
|
|
59
59
|
## Common methods
|
|
60
60
|
|
|
61
61
|
# @param [String, Symbol] name
|
|
62
|
-
# @param [Hash] json
|
|
63
|
-
# @param [Array<String>,
|
|
62
|
+
# @param [Hash, nil] json
|
|
63
|
+
# @param [String, Array<String>, nil] multi_select selected option name or names (optional)
|
|
64
64
|
def initialize(name, will_update: false, base_type: "page", json: nil, multi_select: nil,
|
|
65
65
|
property_id: nil, property_cache: nil)
|
|
66
66
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
|
@@ -89,7 +89,7 @@ module NotionRubyMapping
|
|
|
89
89
|
|
|
90
90
|
## Page property only methods
|
|
91
91
|
|
|
92
|
-
# @return [Hash]
|
|
92
|
+
# @return [Hash] page property values payload
|
|
93
93
|
def property_values_json
|
|
94
94
|
assert_page_property __method__
|
|
95
95
|
{
|
|
@@ -38,8 +38,8 @@ module NotionRubyMapping
|
|
|
38
38
|
|
|
39
39
|
## Page property only methods
|
|
40
40
|
|
|
41
|
-
# @param [Numeric] num
|
|
42
|
-
# @return [Numeric] settled number
|
|
41
|
+
# @param [Numeric, nil] num Number value. nil clears the value.
|
|
42
|
+
# @return [Numeric, nil] settled number
|
|
43
43
|
# @see https://www.notion.so/hkob/NumberProperty-964ebc1948074d7ca8340187aa352d40#a3f28cc7029046878dfd694b5b33e8d8
|
|
44
44
|
def number=(num)
|
|
45
45
|
assert_page_property __method__
|
|
@@ -9,7 +9,15 @@ module NotionRubyMapping
|
|
|
9
9
|
|
|
10
10
|
## Common methods
|
|
11
11
|
|
|
12
|
-
#
|
|
12
|
+
# Returns the people assigned to this property.
|
|
13
|
+
#
|
|
14
|
+
# For a page property, this returns an array of UserObject instances.
|
|
15
|
+
# For a database or data source property, this returns the schema payload.
|
|
16
|
+
#
|
|
17
|
+
# Do not modify the returned array directly. Use `people=` or `add_person`
|
|
18
|
+
# to update the property.
|
|
19
|
+
#
|
|
20
|
+
# @return [Array<UserObject>, Hash]
|
|
13
21
|
# @see https://www.notion.so/hkob/PeopleProperty-144355d25f0e4feba9ae39fe28ca6ae7#7e3e56c2080d4834902cfa0223e807e5
|
|
14
22
|
def people
|
|
15
23
|
@json
|
|
@@ -17,8 +25,13 @@ module NotionRubyMapping
|
|
|
17
25
|
|
|
18
26
|
## Page property only methods
|
|
19
27
|
|
|
20
|
-
#
|
|
21
|
-
#
|
|
28
|
+
# Adds a person to this people property.
|
|
29
|
+
#
|
|
30
|
+
# This method marks the property as changed.
|
|
31
|
+
# This method does not remove duplicate users.
|
|
32
|
+
#
|
|
33
|
+
# @param [String, UserObject] user_id_or_uo user ID or user object to add
|
|
34
|
+
# @return [Array<UserObject>] updated people
|
|
22
35
|
# @see https://www.notion.so/hkob/PeopleProperty-144355d25f0e4feba9ae39fe28ca6ae7#26344b145a254cc58dd845780e0a26ea
|
|
23
36
|
def add_person(user_id_or_uo)
|
|
24
37
|
assert_page_property __method__
|
|
@@ -26,8 +39,14 @@ module NotionRubyMapping
|
|
|
26
39
|
@json << UserObject.user_object(user_id_or_uo)
|
|
27
40
|
end
|
|
28
41
|
|
|
29
|
-
#
|
|
30
|
-
#
|
|
42
|
+
# Replaces all people in this property.
|
|
43
|
+
#
|
|
44
|
+
# Passing nil or an empty array clears the people property.
|
|
45
|
+
# This method marks the property as changed.
|
|
46
|
+
#
|
|
47
|
+
# @param [String, UserObject, Array<String>, Array<UserObject>, nil] people
|
|
48
|
+
# user ID, user object, array of them, or nil
|
|
49
|
+
# @return [Array<UserObject>] replaced people
|
|
31
50
|
# @see https://www.notion.so/hkob/PeopleProperty-144355d25f0e4feba9ae39fe28ca6ae7#815acfef9a664e3e8915fb31b8fefc42
|
|
32
51
|
def people=(people)
|
|
33
52
|
assert_page_property __method__
|
|
@@ -13,7 +13,7 @@ module NotionRubyMapping
|
|
|
13
13
|
|
|
14
14
|
## Common methods
|
|
15
15
|
|
|
16
|
-
# @return [String, Hash, nil] phone number
|
|
16
|
+
# @return [String, Hash, nil] phone number for page properties, empty hash for database/data source properties
|
|
17
17
|
# @see https://www.notion.so/hkob/PhoneNumberProperty-5df14aaa938c4888aecd53ab6752d2e6#40bceda04fe04c64b932d6a1ed180eaa
|
|
18
18
|
def phone_number
|
|
19
19
|
@json
|
|
@@ -21,7 +21,7 @@ module NotionRubyMapping
|
|
|
21
21
|
|
|
22
22
|
## Page property only methods
|
|
23
23
|
|
|
24
|
-
# @param [String] phone_number
|
|
24
|
+
# @param [String, nil] phone_number
|
|
25
25
|
# @see https://www.notion.so/hkob/PhoneNumberProperty-5df14aaa938c4888aecd53ab6752d2e6#dc7e00e0558d40f79ca5cade1fccef29
|
|
26
26
|
def phone_number=(phone_number)
|
|
27
27
|
assert_page_property __method__
|