notion_ruby_mapping 0.1.4 → 0.2.2

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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +1 -1
  3. data/README.md +514 -267
  4. data/env.yml.sample +8 -0
  5. data/lib/notion_ruby_mapping/base.rb +47 -36
  6. data/lib/notion_ruby_mapping/checkbox_property.rb +26 -0
  7. data/lib/notion_ruby_mapping/created_by_property.rb +21 -0
  8. data/lib/notion_ruby_mapping/created_time_property.rb +20 -0
  9. data/lib/notion_ruby_mapping/database.rb +14 -8
  10. data/lib/notion_ruby_mapping/date_base_property.rb +40 -38
  11. data/lib/notion_ruby_mapping/date_property.rb +42 -18
  12. data/lib/notion_ruby_mapping/email_property.rb +30 -1
  13. data/lib/notion_ruby_mapping/files_property.rb +40 -0
  14. data/lib/notion_ruby_mapping/formula_property.rb +18 -0
  15. data/lib/notion_ruby_mapping/last_edited_by_property.rb +21 -0
  16. data/lib/notion_ruby_mapping/last_edited_time_property.rb +20 -0
  17. data/lib/notion_ruby_mapping/list.rb +46 -2
  18. data/lib/notion_ruby_mapping/mention_object.rb +49 -0
  19. data/lib/notion_ruby_mapping/multi_select_property.rb +25 -6
  20. data/lib/notion_ruby_mapping/notion_cache.rb +137 -53
  21. data/lib/notion_ruby_mapping/number_property.rb +13 -8
  22. data/lib/notion_ruby_mapping/page.rb +11 -2
  23. data/lib/notion_ruby_mapping/payload.rb +12 -4
  24. data/lib/notion_ruby_mapping/people_property.rb +38 -0
  25. data/lib/notion_ruby_mapping/phone_number_property.rb +30 -1
  26. data/lib/notion_ruby_mapping/property.rb +79 -43
  27. data/lib/notion_ruby_mapping/property_cache.rb +31 -12
  28. data/lib/notion_ruby_mapping/query.rb +5 -2
  29. data/lib/notion_ruby_mapping/relation_property.rb +37 -0
  30. data/lib/notion_ruby_mapping/rich_text_object.rb +74 -0
  31. data/lib/notion_ruby_mapping/rich_text_property.rb +18 -0
  32. data/lib/notion_ruby_mapping/rollup_property.rb +29 -0
  33. data/lib/notion_ruby_mapping/select_property.rb +12 -6
  34. data/lib/notion_ruby_mapping/text_object.rb +89 -0
  35. data/lib/notion_ruby_mapping/text_property.rb +61 -0
  36. data/lib/notion_ruby_mapping/title_property.rb +18 -0
  37. data/lib/notion_ruby_mapping/url_property.rb +30 -1
  38. data/lib/notion_ruby_mapping/user_object.rb +38 -0
  39. data/lib/notion_ruby_mapping/version.rb +2 -1
  40. data/lib/notion_ruby_mapping.rb +3 -3
  41. data/notion_ruby_mapping.gemspec +3 -1
  42. metadata +40 -7
data/env.yml.sample CHANGED
@@ -1,6 +1,14 @@
1
1
  ---
2
2
  notion_token: "secret_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
3
3
  top_page: "c01166c613ae45cbb96818b4ef2f5a77"
4
+ unpermitted_page: "4a6eb31244204fecb488da11f3caf871"
4
5
  database: "c37a2c66e3aa4a0da44773de3b80c253"
6
+ unpermitted_database: "668d797c76fa49349b05ad288df2d136"
5
7
  h1block: "0250fb6d600142eca4c74efb8794fc6b"
8
+ unpermitted_block: "0c940186ab704351bb342d16f0635d49"
6
9
  db_first_page: "dcdc805c85fa4155a55c20fc28771af7"
10
+ db_second_page: "6601e719a39a460c908e8909467fcccf"
11
+ db_update_page: "206ffaa277744a99baf593e28730240c"
12
+ user_hkob: "2200a911-6a96-44bb-bd38-6bfb1e01b9f6"
13
+ parent1_page: "860753bb6d1f48de96211fa6e0e31f82"
14
+ parent_database: "1d6b1040a9fb48d99a3d041429816e9f"
@@ -3,12 +3,19 @@
3
3
  module NotionRubyMapping
4
4
  # Notion Base object (Parent of Page / Database / List)
5
5
  class Base
6
- def initialize(json: nil, id: nil)
6
+ # @param [Hash, nil] json
7
+ # @param [String, nil] id
8
+ # @param [Array<Property, Class, String>] assign
9
+ def initialize(json: nil, id: nil, assign: [], parent: nil)
7
10
  @nc = NotionCache.instance
8
11
  @json = json
9
- @id = @nc.hex_id(id || @json["id"])
10
- @payload = nil
12
+ @id = @nc.hex_id(id || json && @json["id"])
13
+ @new_record = true unless parent.nil?
14
+ raise StandardError, "Unknown id" if !is_a?(List) && @id.nil? && parent.nil?
15
+
16
+ @payload = Payload.new(parent && {"parent" => parent})
11
17
  @property_cache = nil
18
+ assign.each_slice(2) { |(klass, key)| assign_property(klass, key) }
12
19
  end
13
20
  attr_reader :json, :id
14
21
 
@@ -25,20 +32,19 @@ module NotionRubyMapping
25
32
  when "block"
26
33
  Block.new json: json
27
34
  else
28
- throw Notion::Api::Errors::ObjectNotFound
35
+ raise StandardError, json.inspect
29
36
  end
30
37
  end
31
38
 
32
- # @return [NotionRubyMapping::Payload] get or created Payload object
33
- def payload
34
- @payload ||= Payload.new
39
+ def new_record?
40
+ @new_record
35
41
  end
36
42
 
37
43
  # @return [NotionRubyMapping::PropertyCache] get or created PropertyCache object
38
44
  def properties
39
45
  unless @property_cache
40
46
  unless @json
41
- return nil if @id.nil?
47
+ raise StandardError, "Unknown id" if @id.nil?
42
48
 
43
49
  reload
44
50
  end
@@ -47,11 +53,21 @@ module NotionRubyMapping
47
53
  @property_cache
48
54
  end
49
55
 
56
+ # @return [String] title
57
+ def title
58
+ properties.select { |p| p.is_a? TitleProperty }.map(&:full_text).join ""
59
+ end
60
+
50
61
  # @return [NotionRubyMapping::Base] reloaded self
51
62
  def reload
52
63
  update_json reload_json
53
64
  self
54
65
  end
66
+
67
+ # @return [NotionRubyMapping::Base]
68
+ def save
69
+ @new_record ? create : update
70
+ end
55
71
 
56
72
  # @return [Hash] json properties
57
73
  def json_properties
@@ -66,28 +82,32 @@ module NotionRubyMapping
66
82
  # @param [Hash] json
67
83
  # @return [NotionRubyMapping::Base]
68
84
  def update_json(json)
69
- if @json.nil? || @json["type"] == json["type"]
70
- @json = json
71
- @id = @nc.hex_id(@json["id"])
72
- clear_object
73
- end
85
+ raise StandardError, json.inspect unless json["object"] != "error" && @json.nil? || @json["type"] == json["type"]
86
+
87
+ @json = json
88
+ @id = @nc.hex_id(@json["id"])
89
+ restore_from_json
74
90
  self
75
91
  end
76
92
 
77
- # @return [NotionRubyMapping::Base]
78
- def clear_object
79
- @payload = nil
80
- @property_cache = nil
81
- self
93
+ def restore_from_json
94
+ @payload.clear
95
+ return if (ps = @json["properties"]).nil?
96
+
97
+ properties.json = json_properties
98
+ return unless is_a? Page
99
+
100
+ ps.each do |key, json|
101
+ properties[key].update_from_json json
102
+ end
82
103
  end
83
104
 
84
105
  # @param [String] emoji
85
106
  # @param [String] url
86
107
  # @return [NotionRubyMapping::Base]
87
108
  def set_icon(emoji: nil, url: nil)
88
- if self.is_a?(Page) || self.is_a?(Database)
89
- payload.set_icon(emoji: emoji, url: url)
90
- update
109
+ if is_a?(Page) || is_a?(Database)
110
+ @payload.set_icon(emoji: emoji, url: url)
91
111
  end
92
112
  self
93
113
  end
@@ -96,9 +116,9 @@ module NotionRubyMapping
96
116
  # @return [NotionRubyMapping::PropertyCache, Hash] obtained Page value or PropertyCache
97
117
  def [](key)
98
118
  unless @json
99
- return nil if @id.nil?
119
+ raise StandardError, "Unknown id" if @id.nil?
100
120
 
101
- update_json reload
121
+ reload
102
122
  end
103
123
  case key
104
124
  when "properties"
@@ -113,29 +133,20 @@ module NotionRubyMapping
113
133
  self["icon"]
114
134
  end
115
135
 
116
- # @param [Property] property Property object for udpate or create
117
- # @return [NotionRubyMapping::Base]
118
- def add_property_for_update(property)
119
- @property_cache ||= PropertyCache.new {}
120
- @property_cache.add_property property, will_update: true
121
- self
122
- end
123
-
124
- # @param [Class] klass
136
+ # @param [Property, Class] klass
125
137
  # @param [String] title
126
138
  # @return [Property] generated property
127
139
  def assign_property(klass, title)
128
140
  @property_cache ||= PropertyCache.new {}
129
141
 
130
- property = klass.new(title)
131
- property.will_update = true
142
+ property = klass.new(title, will_update: true)
132
143
  @property_cache.add_property property
133
144
  property
134
145
  end
135
146
 
136
147
  # @return [Hash] created json
137
- def create_json
138
- payload.create_json @property_cache&.create_json
148
+ def property_values_json
149
+ @payload.property_values_json @property_cache&.property_values_json
139
150
  end
140
151
  end
141
152
  end
@@ -5,5 +5,31 @@ module NotionRubyMapping
5
5
  class CheckboxProperty < Property
6
6
  include EqualsDoesNotEqual
7
7
  TYPE = "checkbox"
8
+
9
+ # @param [String] name Property name
10
+ # @param [Boolean] checkbox Number value (optional)
11
+ def initialize(name, will_update: false, checkbox: false)
12
+ super name, will_update: will_update
13
+ @checkbox = checkbox
14
+ end
15
+ attr_reader :checkbox
16
+
17
+ # @param [Boolean] flag
18
+ # @return [TrueClass, FalseClass] settled value
19
+ def checkbox=(flag)
20
+ @will_update = true
21
+ @checkbox = flag
22
+ end
23
+
24
+ # @param [Hash] json
25
+ def update_from_json(json)
26
+ @will_update = false
27
+ @checkbox = json["checkbox"]
28
+ end
29
+
30
+ # @return [Hash]
31
+ def property_values_json
32
+ {@name => {"checkbox" => @checkbox, "type" => "checkbox"}}
33
+ end
8
34
  end
9
35
  end
@@ -1,7 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
+ # CreatedByProperty
4
5
  class CreatedByProperty < MultiProperty
5
6
  TYPE = "created_by"
7
+
8
+ # @param [String] name Property name
9
+ # @param [String] user_id user_id (optional)
10
+ # @param [Hash] json json (optional)
11
+ def initialize(name, json: nil, user_id: nil)
12
+ super name, will_update: false
13
+ @user = UserObject.new user_id: user_id, json: json
14
+ end
15
+ attr_reader :user
16
+
17
+ # @param [Hash] json
18
+ def update_from_json(json)
19
+ @will_update = false
20
+ @user = UserObject.new json: json["created_by"]
21
+ end
22
+
23
+ # @return [Hash] {} created_time cannot be updated
24
+ def property_values_json
25
+ {}
26
+ end
6
27
  end
7
28
  end
@@ -1,7 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
+ # CreatedTimeProperty
4
5
  class CreatedTimeProperty < DateBaseProperty
5
6
  TYPE = "created_time"
7
+
8
+ # @param [String] name Property name
9
+ # @param [String] created_time created_time value (optional)
10
+ def initialize(name, created_time: nil)
11
+ super name, will_update: false
12
+ @created_time = created_time
13
+ end
14
+ attr_reader :created_time
15
+
16
+ # @param [Hash] json
17
+ def update_from_json(json)
18
+ @will_update = false
19
+ @created_time = json["created_time"]
20
+ end
21
+
22
+ # @return [Hash] {} created_time cannot be updated
23
+ def property_values_json
24
+ {}
25
+ end
6
26
  end
7
27
  end
@@ -7,22 +7,28 @@ module NotionRubyMapping
7
7
  NotionCache.instance.database id
8
8
  end
9
9
 
10
- # @param [String] id database_id (with or without "-")
11
10
  # @param [NotionRubyMapping::Query] query object
12
- def self.query(id, query = nil)
13
- query ||= Query.new
14
- NotionCache.instance.database_query(id, query)
11
+ def query_database(query = Query.new)
12
+ response = @nc.database_query @id, query
13
+ List.new json: response, database: self, query: query
15
14
  end
16
15
 
17
- # @param [String] id database_id (with or without "-")
18
- # @param [Payload] payload
16
+ # @return [NotionRubyMapping::Base]
19
17
  def update
20
- update_json @nc.update_database(@id, create_json)
18
+ update_json @nc.update_database_request(@id, property_values_json)
21
19
  end
22
20
 
21
+ # @param [Array<Property, Class, String>] assign
22
+ # @return [NotionRubyMapping::Base]
23
+ def create_child_page(*assign)
24
+ Page.new assign: assign, parent: {"database_id" => @id}
25
+ end
26
+
27
+ protected
28
+
23
29
  # @return [Hash]
24
30
  def reload_json
25
- @nc.database_json @id
31
+ @nc.database_request @id
26
32
  end
27
33
  end
28
34
  end
@@ -3,71 +3,73 @@
3
3
  require "date"
4
4
 
5
5
  module NotionRubyMapping
6
- # Date base property (date, created_time, last_edited_time)
6
+ # Date base property (date, created_time, last_edited_time, formula)
7
7
  class DateBaseProperty < Property
8
8
  include IsEmptyIsNotEmpty
9
9
 
10
- # @param [Date, Time, DateTime, String, nil] obj
11
- # @return [String] iso8601 format string
12
- def 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
10
+ def filter_equals(date, rollup = nil, rollup_type = nil)
11
+ make_filter_query "equals", value_str(date), rollup, rollup_type
23
12
  end
24
13
 
25
- def filter_equals(value)
26
- make_filter_query "equals", value_str(value)
14
+ def filter_does_not_equal(date, rollup = nil, rollup_type = nil)
15
+ make_filter_query "does_not_equal", value_str(date), rollup, rollup_type
27
16
  end
28
17
 
29
- def filter_does_not_equal(value)
30
- make_filter_query "does_not_equal", value_str(value)
18
+ def filter_before(date, rollup = nil, rollup_type = nil)
19
+ make_filter_query "before", value_str(date), rollup, rollup_type
31
20
  end
32
21
 
33
- def filter_before(value)
34
- make_filter_query "before", value_str(value)
22
+ def filter_after(date, rollup = nil, rollup_type = nil)
23
+ make_filter_query "after", value_str(date), rollup, rollup_type
35
24
  end
36
25
 
37
- def filter_after(value)
38
- make_filter_query "after", value_str(value)
26
+ def filter_on_or_before(date, rollup = nil, rollup_type = nil)
27
+ make_filter_query "on_or_before", value_str(date), rollup, rollup_type
39
28
  end
40
29
 
41
- def filter_on_or_before(value)
42
- make_filter_query "on_or_before", value_str(value)
30
+ def filter_on_or_after(date, rollup = nil, rollup_type = nil)
31
+ make_filter_query "on_or_after", value_str(date), rollup, rollup_type
43
32
  end
44
33
 
45
- def filter_on_or_after(value)
46
- make_filter_query "on_or_after", value_str(value)
34
+ def filter_past_week(rollup = nil, rollup_type = nil)
35
+ make_filter_query "past_week", {}, rollup, rollup_type
47
36
  end
48
37
 
49
- def filter_past_week
50
- make_filter_query "past_week", {}
38
+ def filter_past_month(rollup = nil, rollup_type = nil)
39
+ make_filter_query "past_month", {}, rollup, rollup_type
51
40
  end
52
41
 
53
- def filter_past_month
54
- make_filter_query "past_month", {}
42
+ def filter_past_year(rollup = nil, rollup_type = nil)
43
+ make_filter_query "past_year", {}, rollup, rollup_type
55
44
  end
56
45
 
57
- def filter_past_year
58
- make_filter_query "past_year", {}
46
+ def filter_next_week(rollup = nil, rollup_type = nil)
47
+ make_filter_query "next_week", {}, rollup, rollup_type
59
48
  end
60
49
 
61
- def filter_next_week
62
- make_filter_query "next_week", {}
50
+ def filter_next_month(rollup = nil, rollup_type = nil)
51
+ make_filter_query "next_month", {}, rollup, rollup_type
63
52
  end
64
53
 
65
- def filter_next_month
66
- make_filter_query "next_month", {}
54
+ def filter_next_year(rollup = nil, rollup_type = nil)
55
+ make_filter_query "next_year", {}, rollup, rollup_type
67
56
  end
68
57
 
69
- def filter_next_year
70
- make_filter_query "next_year", {}
58
+ protected
59
+
60
+ # @param [Date, Time, DateTime, String, nil] obj
61
+ # @return [String] iso8601 format string
62
+ def value_str(obj)
63
+ case obj
64
+ when Date
65
+ obj.iso8601
66
+ when Time
67
+ obj.strftime("%Y-%m-%dT%H:%M:%S%:z")
68
+ when DateTime
69
+ obj.iso8601
70
+ else
71
+ obj
72
+ end
71
73
  end
72
74
  end
73
75
  end
@@ -1,44 +1,68 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
+ # DateProperty
4
5
  class DateProperty < DateBaseProperty
5
6
  TYPE = "date"
6
7
 
7
8
  # @param [String] name
8
9
  # @param [Hash] json
9
- # @param [Array] multi_select
10
- def initialize(name, json: nil, start_date: nil, end_date: nil, time_zone: nil)
11
- super(name, json: json)
12
- @end_date = end_date
13
- @start_date = start_date || end_date
14
- @time_zone = time_zone
10
+ # @param [Date, Time, DateTime, String, nil] start_date
11
+ # @param [Date, Time, DateTime, String, nil] end_date
12
+ # @param [String, nil] time_zone
13
+ def initialize(name, will_update: false, json: nil, start_date: nil, end_date: nil, time_zone: nil)
14
+ super name, will_update: will_update
15
+ @start_date = start_date || json && json["start"]
16
+ @end_date = end_date || json && json["end"]
17
+ @time_zone = time_zone || json && json["time_zone"]
15
18
  end
16
19
 
17
20
  # @return [Hash] created json
18
- def create_json
19
- if @end_date
20
- {"date" => {"start" => value_str(@start_date || @end_date), "end" => value_str(@end_date)}}
21
- elsif @start_date
22
- {"date" => {"start" => value_str(@start_date)}}
23
- else
24
- {"date" => @json || {}}
25
- end
21
+ def property_values_json
22
+ {
23
+ @name => {
24
+ "type" => "date",
25
+ "date" => {
26
+ "start" => value_str(@start_date),
27
+ "end" => value_str(@end_date),
28
+ "time_zone" => @time_zone,
29
+ },
30
+ },
31
+ }
26
32
  end
27
33
 
28
- # @param [Hash] multi_select
29
- # @return [Array, nil] settled array
34
+ # @param [Date, Time, DateTime, String] start_date
35
+ # @return [Date, Time, DateTime, String]
30
36
  def start_date=(start_date)
31
37
  @will_update = true
32
38
  @start_date = start_date
33
39
  @end_date = nil if @start_date.class != @end_date.class || @start_date > @end_date
40
+ @start_date
34
41
  end
35
42
 
36
- # @param [Hash] multi_select
37
- # @return [Array, nil] settled array
43
+ # @param [Date, Time, DateTime, String] end_date
44
+ # @return [Date, Time, DateTime, String]
38
45
  def end_date=(end_date)
39
46
  @will_update = true
40
47
  @end_date = end_date
41
48
  @end_date = nil if @start_date.class != @end_date.class || @start_date > @end_date
49
+ @end_date
50
+ end
51
+
52
+ # @param [String] time_zone
53
+ # @return [Array, nil] settled array
54
+ def time_zone=(time_zone)
55
+ @will_update = true
56
+ @time_zone = time_zone
57
+ end
58
+
59
+ # @param [Hash] json
60
+ def update_from_json(json)
61
+ @will_update = false
62
+ jd = json["date"]
63
+ @start_date = jd["start"]
64
+ @end_date = jd["end"]
65
+ @time_zone = jd["time_zone"]
42
66
  end
43
67
  end
44
68
  end
@@ -1,7 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
- class EmailProperty < TextProperty
4
+ # EmailProperty
5
+ class EmailProperty < Property
6
+ include EqualsDoesNotEqual
7
+ include ContainsDoesNotContain
8
+ include StartsWithEndsWith
9
+ include IsEmptyIsNotEmpty
5
10
  TYPE = "email"
11
+
12
+ # @param [String] name Property name
13
+ # @param [String] email email value (optional)
14
+ def initialize(name, will_update: false, email: nil)
15
+ super name, will_update: will_update
16
+ @email = email
17
+ end
18
+ attr_reader :email
19
+
20
+ # @param [Hash] json
21
+ def update_from_json(json)
22
+ @will_update = false
23
+ @email = json["email"]
24
+ end
25
+
26
+ # @return [Hash]
27
+ def property_values_json
28
+ {@name => {"email" => @email, "type" => "email"}}
29
+ end
30
+
31
+ def email=(email)
32
+ @will_update = true
33
+ @email = email
34
+ end
6
35
  end
7
36
  end
@@ -5,5 +5,45 @@ module NotionRubyMapping
5
5
  class FilesProperty < Property
6
6
  include IsEmptyIsNotEmpty
7
7
  TYPE = "files"
8
+
9
+ # @param [String] name Property name
10
+ # @param [String] files files value (optional)
11
+ def initialize(name, will_update: false, json: nil, files: [])
12
+ super name, will_update: will_update
13
+ @files = json || Array(files).map { |url| url_to_hash url } || []
14
+ end
15
+ attr_reader :files
16
+
17
+ # @param [String] url
18
+ # @return [Hash]
19
+ def url_to_hash(url)
20
+ {
21
+ "name" => url,
22
+ "type" => "external",
23
+ "external" => {
24
+ "url" => url,
25
+ },
26
+ }
27
+ end
28
+
29
+ # @param [Hash] json
30
+ def update_from_json(json)
31
+ @will_update = false
32
+ @files = json["files"]
33
+ end
34
+
35
+ # @return [Hash]
36
+ def property_values_json
37
+ if @files.map { |f| f["type"] }.include? "file"
38
+ {}
39
+ else
40
+ {@name => {"files" => @files, "type" => "files"}}
41
+ end
42
+ end
43
+
44
+ def files=(files = [])
45
+ @will_update = true
46
+ @files = Array(files).map { |url| url_to_hash url } || []
47
+ end
8
48
  end
9
49
  end
@@ -7,5 +7,23 @@ module NotionRubyMapping
7
7
  include StartsWithEndsWith
8
8
  include GreaterThanLessThan
9
9
  TYPE = "formula"
10
+
11
+ # @param [String] name
12
+ # @param [Hash] json
13
+ def initialize(name, json: nil)
14
+ super name, will_update: false
15
+ @json = json
16
+ end
17
+
18
+ # @param [Hash] json
19
+ def update_from_json(json)
20
+ @will_update = false
21
+ @json = json["formula"]
22
+ end
23
+
24
+ # @return [Hash] {} created_time cannot be updated
25
+ def property_values_json
26
+ {}
27
+ end
10
28
  end
11
29
  end
@@ -1,7 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
+ # LastEditedByProperty
4
5
  class LastEditedByProperty < MultiProperty
5
6
  TYPE = "last_edited_by"
7
+
8
+ # @param [String] name Property name
9
+ # @param [String] user_id user_id (optional)
10
+ # @param [Hash] json json (optional)
11
+ def initialize(name, user_id: nil, json: nil)
12
+ super name, will_update: false
13
+ @user = UserObject.new user_id: user_id, json: json
14
+ end
15
+ attr_reader :user
16
+
17
+ # @param [Hash] json
18
+ def update_from_json(json)
19
+ @will_update = false
20
+ @user = UserObject.new json: json["last_edited_by"]
21
+ end
22
+
23
+ # @return [Hash] {} created_time cannot be updated
24
+ def property_values_json
25
+ {}
26
+ end
6
27
  end
7
28
  end
@@ -1,7 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
+ # LastEditedTimeProperty
4
5
  class LastEditedTimeProperty < DateBaseProperty
5
6
  TYPE = "last_edited_time"
7
+
8
+ # @param [String] name Property name
9
+ # @param [String] last_edited_time last_edited_time value (optional)
10
+ def initialize(name, last_edited_time: nil)
11
+ super name, will_update: false
12
+ @last_edited_time = last_edited_time
13
+ end
14
+ attr_reader :last_edited_time
15
+
16
+ # @param [Hash] json
17
+ def update_from_json(json)
18
+ @will_update = false
19
+ @last_edited_time = json["last_edited_time"]
20
+ end
21
+
22
+ # @return [Hash] {} created_time cannot be updated
23
+ def property_values_json
24
+ {}
25
+ end
6
26
  end
7
27
  end