notion_ruby_mapping 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9297c2ca59117bacfab46da55e60bda063c3a08a1bfc0acdd5b8e9b7b029c52
4
- data.tar.gz: fdcfc87ab82132cebedf50f99c174793c74e952cc35608b60935e2bd158a2df6
3
+ metadata.gz: 1372e3b57aef4a44d060751e07ba15bd224d23b974ff46426ac4e40a10c0b0b6
4
+ data.tar.gz: b6310155b12dcb73f022bd9415667c67b8a78246377622128fb0bcd2eccb4bd9
5
5
  SHA512:
6
- metadata.gz: 0f01ba2a798cd79e608b244a6c9c0157f92b1f7e2f9bd4fd4772b38e60f708d1da5a70ffda0816b8aa136282da49d118ff04ede19a363674c3277b3095a34e91
7
- data.tar.gz: 6135423f52bdc33585247ef2c144a49492b54a28d18ae7429d8f4df9791f4d4189d570c2b381b89f939d0b2e2e1914276172b603f612038dbfc7c495ea250c01
6
+ metadata.gz: 01a32f40c022b5916891409b823bf76efd02414520e14eb98dc1f7ec49901fcc60fd085c845fe71f0b38a5d3776e32a6c9bce4e5c2efb5edce750f2b24a66ff8
7
+ data.tar.gz: 06babf96d0c07ccc74c2ab24ccf55500ed8c75506c2e5c0c95837968795af8192eea3e773ca153254048a63204ed6fed4996a1a25f74ced78187d52114c4ca4a
data/README.md CHANGED
@@ -92,6 +92,7 @@ NotionCache.instance.create_client ENV["NOTION_API_TOKEN"] # from environment
92
92
 
93
93
  ## 3. ChangeLog
94
94
 
95
+ - 2022/11/13 [v0.6.8] remove error checking for start and end dates, add Users.all, and change Rollup and Formula query specification
95
96
  - 2022/9/2 [v0.6.7] add support for Status property, is_toggleable for headings block, and page property values
96
97
  - 2022/8/10 [v0.6.6] Bug fix(notionSitemap.rb): Skip if child page is empty.
97
98
  - 2022/8/10 [v0.6.5] add notionSitemap.rb, rename createErDiagram to notionErDiagram, and move them to exe directory
@@ -60,7 +60,7 @@ module NotionRubyMapping
60
60
  end
61
61
  end
62
62
 
63
- # @param [Object] method
63
+ # @param [Symbol] method
64
64
  # @param [Object] path
65
65
  # @param [nil] json
66
66
  def self.dry_run_script(method, path, json = nil)
@@ -82,6 +82,7 @@ module NotionRubyMapping
82
82
  end
83
83
  end
84
84
 
85
+ # @param [Boolean] dry_run true if dry_run
85
86
  def comments(query = nil, dry_run: false)
86
87
  return unless page? || block?
87
88
 
@@ -89,7 +90,7 @@ module NotionRubyMapping
89
90
  self.class.dry_run_script :get, @nc.retrieve_comments_path(@id)
90
91
  else
91
92
  ans = {}
92
- List.new(comment_parent: self,
93
+ List.new(type: :comment_parent, value: self,
93
94
  json: @nc.retrieve_comments_request(@id, query),
94
95
  query: query).each do |comment|
95
96
  dt_id = comment.discussion_id
@@ -117,7 +118,7 @@ module NotionRubyMapping
117
118
  end
118
119
 
119
120
  # @param [Array<Block>] blocks
120
- # @param [Boolean] dry_run
121
+ # @param [Boolean] dry_run true if dry_run
121
122
  # @return [NotionRubyMapping::Block, String]
122
123
  # @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#44bbf83d852c419485c5efe9fe1558fb
123
124
  # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#2c47f7fedae543cf8566389ba1677132
@@ -180,7 +181,7 @@ module NotionRubyMapping
180
181
  end
181
182
 
182
183
  # @param [NotionRubyMapping::Query] query
183
- # @param [Boolean] dry_run
184
+ # @param [Boolean] dry_run true if dry_run
184
185
  # @return [NotionRubyMapping::List, String]
185
186
  def children(query = Query.new, dry_run: false)
186
187
  if dry_run
@@ -190,7 +191,7 @@ module NotionRubyMapping
190
191
  @children
191
192
  else
192
193
  response = @nc.block_children_request @id, query.query_string
193
- @children = List.new json: response, parent: self, query: query
194
+ @children = List.new json: response, type: :parent, value: self, query: query
194
195
  end
195
196
  end
196
197
 
@@ -236,6 +237,7 @@ module NotionRubyMapping
236
237
  is_a? Page
237
238
  end
238
239
 
240
+ # @param [Boolean] dry_run true if dry_run
239
241
  def parent(dry_run: false)
240
242
  parent_json = @json && @json["parent"]
241
243
  raise StandardError, "Unknown parent" if parent_json.nil?
@@ -298,7 +300,7 @@ module NotionRubyMapping
298
300
  self
299
301
  end
300
302
 
301
- # @param [Boolean] dry_run
303
+ # @param [Boolean] dry_run true if dry_run
302
304
  # @return [NotionRubyMapping::Base, NotionRubyMapping::Database, String]
303
305
  # @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#277085c8439841c798a4b94eae9a7326
304
306
  def save(dry_run: false)
@@ -64,6 +64,7 @@ module NotionRubyMapping
64
64
 
65
65
  # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#298916c7c379424682f39ff09ee38544
66
66
  # @param [String] id
67
+ # @param [Boolean] dry_run true if dry_run
67
68
  # @return [NotionRubyMapping::Block]
68
69
  def self.find(id, dry_run: false)
69
70
  nc = NotionCache.instance
@@ -104,7 +105,7 @@ module NotionRubyMapping
104
105
  @rich_text_array = RichTextArray.new "rich_text", json: @json[type]["rich_text"]
105
106
  end
106
107
 
107
- # @param [Boolean] dry_run
108
+ # @param [Boolean] dry_run true if dry_run
108
109
  # @return [NotionRubyMapping::Base, String]
109
110
  def destroy(dry_run: false)
110
111
  if dry_run
@@ -114,6 +115,7 @@ module NotionRubyMapping
114
115
  end
115
116
  end
116
117
 
118
+ # @param [Boolean] dry_run true if dry_run
117
119
  # @return [NotionRubyMapping::Base, String]
118
120
  def update(dry_run: false)
119
121
  if dry_run
@@ -6,6 +6,7 @@ module NotionRubyMapping
6
6
  ### Public announced methods
7
7
 
8
8
  # @param [String] id
9
+ # @param [Boolean] dry_run true if dry_run
9
10
  # @return [NotionRubyMapping::Database, String]
10
11
  # @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#58ba9190fd544432a9e2a5823d6c33b7
11
12
  def self.find(id, dry_run: false)
@@ -49,6 +50,7 @@ module NotionRubyMapping
49
50
  end
50
51
 
51
52
  # @param [Array<Property, Class, String>] assign
53
+ # @param [Boolean] dry_run true if dry_run
52
54
  # @return [NotionRubyMapping::Base]
53
55
  # @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#c217ce78020a4de79b720790fce3092d
54
56
  def create_child_page(*assign, dry_run: false)
@@ -97,6 +99,7 @@ module NotionRubyMapping
97
99
  end
98
100
 
99
101
  # @param [NotionRubyMapping::Query] query object
102
+ # @param [Boolean] dry_run true if dry_run
100
103
  # @return [NotionRubyMapping::List, String]
101
104
  # @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#6bd9acf62c454f64bc555c8828057e6b
102
105
  def query_database(query = Query.new, dry_run: false)
@@ -104,7 +107,7 @@ module NotionRubyMapping
104
107
  Base.dry_run_script :post, @nc.query_database_path(@id), query.query_json
105
108
  else
106
109
  response = @nc.database_query_request @id, query
107
- List.new json: response, database: self, query: query
110
+ List.new json: response, type: :database, value: self, query: query
108
111
  end
109
112
  end
110
113
 
@@ -130,6 +133,7 @@ module NotionRubyMapping
130
133
 
131
134
  protected
132
135
 
136
+ # @param [Boolean] dry_run true if dry_run
133
137
  def create(dry_run: false)
134
138
  if dry_run
135
139
  dry_run_script :post, @nc.databases_path, :property_schema_json
@@ -145,6 +149,7 @@ module NotionRubyMapping
145
149
  @nc.database_request @id
146
150
  end
147
151
 
152
+ # @param [Boolean] dry_run true if dry_run
148
153
  # @return [NotionRubyMapping::Base, String]
149
154
  def update(dry_run: false)
150
155
  if dry_run
@@ -5,14 +5,23 @@ module NotionRubyMapping
5
5
  class List < Base
6
6
  include Enumerable
7
7
 
8
- def initialize(json: nil, id: nil, database: nil, parent: nil, property: nil, comment_parent: nil, query: nil)
8
+ def initialize(json: nil, id: nil, type: nil, value: 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
- @database = database
13
- @parent = parent
14
- @property = property
15
- @comment_parent = comment_parent
12
+
13
+ case type
14
+ when :comment_parent
15
+ @comment_parent = value
16
+ when :database
17
+ @database = value
18
+ when :parent
19
+ @parent = value
20
+ when :property
21
+ @property = value
22
+ when :user_object
23
+ @user_object = true
24
+ end
16
25
  @query = query
17
26
  @index = 0
18
27
  @has_content = true
@@ -60,6 +69,11 @@ module NotionRubyMapping
60
69
  query: -> { @nc.retrieve_comments_request @comment_parent.id, @query },
61
70
  create_object: ->(json) { CommentObject.new json: json },
62
71
  &block
72
+ elsif @user_object
73
+ each_sub base: @user_object,
74
+ query: -> { @nc.users_request @query.query_json },
75
+ create_object: ->(json) { UserObject.new json: json },
76
+ &block
63
77
  end
64
78
  self
65
79
  end
@@ -6,6 +6,7 @@ module NotionRubyMapping
6
6
  ### Public announced methods
7
7
 
8
8
  # @param [String] id
9
+ # @param [Boolean] dry_run true if dry_run
9
10
  # @return [NotionRubyMapping::Page, String]
10
11
  # @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#7d868b8b81c3473082bbdc7370813a4a
11
12
  def self.find(id, dry_run: false)
@@ -24,6 +25,7 @@ module NotionRubyMapping
24
25
  get key
25
26
  end
26
27
 
28
+ # @param [Boolean] dry_run true if dry_run
27
29
  def append_comment(text_objects, dry_run: false)
28
30
  rto = RichTextArray.new "rich_text", text_objects: text_objects, will_update: true
29
31
  json = rto.property_schema_json.merge({"parent" => {"page_id" => @id}})
@@ -47,6 +49,7 @@ module NotionRubyMapping
47
49
 
48
50
  # @param [String] title
49
51
  # @param [Array<String, Property>] assigns
52
+ # @param [Boolean] dry_run true if dry_run
50
53
  # @return [NotionRubyMapping::Database, String]
51
54
  # @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#e3f1d21e0f724f589e48431468772eed
52
55
  def create_child_database(title, *assigns, dry_run: false)
@@ -62,6 +65,7 @@ module NotionRubyMapping
62
65
 
63
66
  protected
64
67
 
68
+ # @param [Boolean] dry_run true if dry_run
65
69
  # @return [NotionRubyMapping::Base, String]
66
70
  def create(dry_run: false)
67
71
  if dry_run
@@ -77,6 +81,7 @@ module NotionRubyMapping
77
81
  @nc.page_request @id
78
82
  end
79
83
 
84
+ # @param [Boolean] dry_run true if dry_run
80
85
  # @return [NotionRubyMapping::Base, String]
81
86
  def update(dry_run: false)
82
87
  if dry_run
@@ -11,7 +11,7 @@ module NotionRubyMapping
11
11
  attr_reader :discussion_id, :comments
12
12
 
13
13
  # @param [String] text_objects
14
- # @param [Boolean] dry_run
14
+ # @param [Boolean] dry_run true if dry_run
15
15
  # @return [String, NotionRubyMapping::CommentObject]
16
16
  def append_comment(text_objects, dry_run: false)
17
17
  rto = RichTextArray.new "rich_text", text_objects: text_objects, will_update: true
@@ -284,5 +284,40 @@ module NotionRubyMapping
284
284
  def update_page_request(page_id, payload)
285
285
  request :patch, page_path(page_id), payload
286
286
  end
287
+
288
+ # @param [String] id user_id (with or without "-")
289
+ # @return [NotionRubyMapping::UserObject] UserObject object or nil
290
+ def user(id)
291
+ UserObject.new json: user_request(id)
292
+ end
293
+
294
+ # @param [String] user_id
295
+ # @return [String (frozen)] user_path
296
+ def user_path(user_id)
297
+ "v1/users/#{user_id}"
298
+ end
299
+
300
+ # @param [String] user_id
301
+ # @return [Hash] response
302
+ def user_request(user_id)
303
+ request :get, user_path(user_id)
304
+ end
305
+
306
+ # @return [Array<NotionRubyMapping::UserObject>] UserObject array
307
+ def users
308
+ List.new json: users_request, type: :user_object, value: true
309
+ end
310
+
311
+ # @return [String (frozen)] user_path
312
+ def users_path(option = "")
313
+ "v1/users#{option}"
314
+ end
315
+
316
+ # @param [String] user_id
317
+ # @param [NotionRubyMapping::Query] query query object
318
+ # @return [Hash] response
319
+ def users_request(query = Query.new)
320
+ request :get, users_path, query.query_json
321
+ end
287
322
  end
288
323
  end
@@ -16,7 +16,7 @@ module NotionRubyMapping
16
16
  end
17
17
  @will_update = false
18
18
  end
19
- attr_reader :will_update, :text_objects
19
+ attr_reader :will_update, :text_objects, :json
20
20
 
21
21
  def discussion_id
22
22
  NotionCache.instance.hex_id @json["discussion_id"]
@@ -6,11 +6,38 @@ module NotionRubyMapping
6
6
  # @param [String] user_id
7
7
  # @return [TextObject]
8
8
  def initialize(user_id: nil, json: {})
9
- @user_id = user_id || json && json["id"]
9
+ @user_id = NotionCache.instance.hex_id(user_id || json && json["id"])
10
10
  @json = json
11
11
  @will_update = false
12
12
  end
13
- attr_reader :will_update, :user_id
13
+ attr_reader :will_update, :user_id, :json
14
+
15
+ # @param [Boolean] dry_run true if dry_run
16
+ def self.all(dry_run: false)
17
+ nc = NotionCache.instance
18
+ if dry_run
19
+ Base.dry_run_script :get, nc.users_path
20
+ else
21
+ nc.users
22
+ end
23
+ end
24
+
25
+ # @param [String] user_id
26
+ # @param [Boolean] dry_run true if dry_run
27
+ # @return [NotionRubyMapping::UserObject, String]
28
+ def self.find(user_id, dry_run: false)
29
+ nc = NotionCache.instance
30
+ if dry_run
31
+ Base.dry_run_script :get, nc.user_path(user_id)
32
+ else
33
+ nc.user user_id
34
+ end
35
+ end
36
+
37
+ # @param [Boolean] dry_run true if dry_run
38
+ def self.find_me(dry_run: false)
39
+ find "me", dry_run: dry_run
40
+ end
14
41
 
15
42
  # @param [UserObject, String] uo
16
43
  # @return [UserObject] self or created UserObject
@@ -22,6 +49,11 @@ module NotionRubyMapping
22
49
  end
23
50
  end
24
51
 
52
+ # @return [String (frozen)]
53
+ def inspect
54
+ "#{self.class.name}-#{@user_id}"
55
+ end
56
+
25
57
  # @return [String]
26
58
  def name
27
59
  @json["name"]
@@ -36,7 +68,7 @@ module NotionRubyMapping
36
68
  end
37
69
 
38
70
  def user_id=(new_user_id)
39
- @user_id = new_user_id
71
+ @user_id = NotionCache.instance.hex_id new_user_id
40
72
  @will_update = true
41
73
  end
42
74
  end
@@ -10,7 +10,7 @@ module NotionRubyMapping
10
10
 
11
11
  ## Common methods
12
12
 
13
- # @return [Boolean, Hash]
13
+ # @return [Boolean, Hash, nil]
14
14
  # @see https://www.notion.so/hkob/CheckboxProperty-ac1edbdb8e264af5ad1432b522b429fd#20da1bf0cbcc4d4eb22d9125386522c2
15
15
  def checkbox
16
16
  @json
@@ -34,7 +34,7 @@ module NotionRubyMapping
34
34
  def self.start_end_time(date)
35
35
  ds = date.iso8601
36
36
  tz = Time.now.strftime "%:z"
37
- %w[00:00:00 23:59:59].map {|t| [ds, "T", t, tz].join("") }
37
+ %w[00:00:00 23:59:59].map { |t| [ds, "T", t, tz].join("") }
38
38
  end
39
39
 
40
40
  # @param [Date, Time, DateTime, String, nil] obj
@@ -44,119 +44,121 @@ module NotionRubyMapping
44
44
  Date.parse str if str
45
45
  end
46
46
 
47
- # @param [String] rollup Rollup name
48
- # @param [String] rollup_type Rollup type
47
+ # @param [String] condition Rollup name
48
+ # @param [String] another_type Rollup type
49
49
  # @return [NotionRubyMapping::Query] generated Query object
50
50
  # @see https://www.notion.so/hkob/CheckboxProperty-ac1edbdb8e264af5ad1432b522b429fd#5f07c4ebc4744986bfc99a43827349fc
51
- def filter_equals(date, rollup = nil, rollup_type = nil)
51
+ def filter_equals(date, condition: nil, another_type: nil)
52
52
  if date.is_a? Date
53
53
  start_date, end_date = self.class.start_end_time date
54
- if rollup
55
- filter_after(start_date, rollup, rollup_type)
56
- .and(filter_before(end_date, rollup, rollup_type))
54
+ if condition
55
+ filter_after(start_date, condition: condition, another_type: another_type)
56
+ .and(filter_before(end_date, condition: condition, another_type: another_type))
57
57
  else
58
- filter_after(start_date).and(filter_before end_date)
58
+ filter_after(start_date, another_type: another_type)
59
+ .and(filter_before(end_date, another_type: another_type))
59
60
  end
60
61
  else
61
- make_filter_query "equals", value_str(date), rollup, rollup_type
62
+ make_filter_query "equals", value_str(date), condition: condition, another_type: another_type
62
63
  end
63
64
  end
64
65
 
65
- # @param [String] rollup Rollup name
66
- # @param [String] rollup_type Rollup type
66
+ # @param [String] condition Rollup name
67
+ # @param [String] another_type Rollup type
67
68
  # @return [NotionRubyMapping::Query] generated Query object
68
- def filter_does_not_equal(date, rollup = nil, rollup_type = nil)
69
+ def filter_does_not_equal(date, condition: nil, another_type: nil)
69
70
  if date.is_a? Date
70
71
  start_date, end_date = self.class.start_end_time date
71
- if rollup
72
- filter_before(start_date, rollup, rollup_type)
73
- .or(filter_after(end_date, rollup, rollup_type))
72
+ if condition
73
+ filter_before(start_date, condition: condition, another_type: another_type)
74
+ .or(filter_after(end_date, condition: condition, another_type: another_type))
74
75
  else
75
- filter_before(start_date).or(filter_after(end_date))
76
+ filter_before(start_date, another_type: another_type)
77
+ .or(filter_after(end_date, another_type: another_type))
76
78
  end
77
79
  else
78
- make_filter_query "does_not_equal", value_str(date), rollup, rollup_type
80
+ make_filter_query "does_not_equal", value_str(date), condition: condition, another_type: another_type
79
81
  end
80
82
  end
81
83
 
82
- # @param [String] rollup Rollup name
83
- # @param [String] rollup_type Rollup type
84
+ # @param [String] condition Rollup name
85
+ # @param [String] another_type Rollup type
84
86
  # @return [NotionRubyMapping::Query] generated Query object
85
87
  # @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#841815bfaf684964bebf3fa6712ae26c
86
- def filter_before(date, rollup = nil, rollup_type = nil)
87
- make_filter_query "before", value_str(date, start_time: true), rollup, rollup_type
88
+ def filter_before(date, condition: nil, another_type: nil)
89
+ make_filter_query "before", value_str(date, start_time: true), condition: condition, another_type: another_type
88
90
  end
89
91
 
90
- # @param [String] rollup Rollup name
91
- # @param [String] rollup_type Rollup type
92
+ # @param [String] condition Rollup name
93
+ # @param [String] another_type Rollup type
92
94
  # @return [NotionRubyMapping::Query] generated Query object
93
95
  # @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#c0ea140866ea46f9a746b24773dc821c
94
- def filter_after(date, rollup = nil, rollup_type = nil)
95
- make_filter_query "after", value_str(date, end_time: true), rollup, rollup_type
96
+ def filter_after(date, condition: nil, another_type: nil)
97
+ make_filter_query "after", value_str(date, end_time: true), condition: condition, another_type: another_type
96
98
  end
97
99
 
98
- # @param [String] rollup Rollup name
99
- # @param [String] rollup_type Rollup type
100
+ # @param [String] condition Rollup name
101
+ # @param [String] another_type Rollup type
100
102
  # @return [NotionRubyMapping::Query] generated Query object
101
103
  # @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#6a20ade0ee964aad81aae4c08ea29d6b
102
- def filter_on_or_before(date, rollup = nil, rollup_type = nil)
103
- make_filter_query "on_or_before", value_str(date, end_time: true), rollup, rollup_type
104
+ def filter_on_or_before(date, condition: nil, another_type: nil)
105
+ make_filter_query "on_or_before", value_str(date, end_time: true), condition: condition, another_type: another_type
104
106
  end
105
107
 
106
- # @param [String] rollup Rollup name
107
- # @param [String] rollup_type Rollup type
108
+ # @param [String] condition Rollup name
109
+ # @param [String] another_type Rollup type
108
110
  # @return [NotionRubyMapping::Query] generated Query object
109
111
  # @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#1469e3fb3068426a8ea8492d191d1563
110
- def filter_on_or_after(date, rollup = nil, rollup_type = nil)
111
- make_filter_query "on_or_after", value_str(date, start_time: true), rollup, rollup_type
112
+ def filter_on_or_after(date, condition: nil, another_type: nil)
113
+ make_filter_query "on_or_after", value_str(date, start_time: true), condition: condition, another_type: another_type
112
114
  end
113
115
 
114
- # @param [String] rollup Rollup name
115
- # @param [String] rollup_type Rollup type
116
+ # @param [String] condition Rollup name
117
+ # @param [String] another_type Rollup type
116
118
  # @return [NotionRubyMapping::Query] generated Query object
117
119
  # @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#707e7e848dc9417998420b65024542db
118
- def filter_past_week(rollup = nil, rollup_type = nil)
119
- make_filter_query "past_week", {}, rollup, rollup_type
120
+ def filter_past_week(condition: nil, another_type: nil)
121
+ make_filter_query "past_week", {}, condition: condition, another_type: another_type
120
122
  end
121
123
 
122
- # @param [String] rollup Rollup name
123
- # @param [String] rollup_type Rollup type
124
+ # @param [String] condition Rollup name
125
+ # @param [String] another_type Rollup type
124
126
  # @return [NotionRubyMapping::Query] generated Query object
125
127
  # @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#7b2d05c549204c2eb68d95020d7b97c5
126
- def filter_past_month(rollup = nil, rollup_type = nil)
127
- make_filter_query "past_month", {}, rollup, rollup_type
128
+ def filter_past_month(condition: nil, another_type: nil)
129
+ make_filter_query "past_month", {}, condition: condition, another_type: another_type
128
130
  end
129
131
 
130
- # @param [String] rollup Rollup name
131
- # @param [String] rollup_type Rollup type
132
+ # @param [String] condition Rollup name
133
+ # @param [String] another_type Rollup type
132
134
  # @return [NotionRubyMapping::Query] generated Query object
133
135
  # @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#9c8bf0a2398a41c8a0714a62afca3aa8
134
- def filter_past_year(rollup = nil, rollup_type = nil)
135
- make_filter_query "past_year", {}, rollup, rollup_type
136
+ def filter_past_year(condition: nil, another_type: nil)
137
+ make_filter_query "past_year", {}, condition: condition, another_type: another_type
136
138
  end
137
139
 
138
- # @param [String] rollup Rollup name
139
- # @param [String] rollup_type Rollup type
140
+ # @param [String] condition Rollup name
141
+ # @param [String] another_type Rollup type
140
142
  # @return [NotionRubyMapping::Query] generated Query object
141
143
  # @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#d9dc189ee8244ba8a6c863259eaa9984
142
- def filter_next_week(rollup = nil, rollup_type = nil)
143
- make_filter_query "next_week", {}, rollup, rollup_type
144
+ def filter_next_week(condition: nil, another_type: nil)
145
+ make_filter_query "next_week", {}, condition: condition, another_type: another_type
144
146
  end
145
147
 
146
- # @param [String] rollup Rollup name
147
- # @param [String] rollup_type Rollup type
148
+ # @param [String] condition Rollup name
149
+ # @param [String] another_type Rollup type
148
150
  # @return [NotionRubyMapping::Query] generated Query object
149
151
  # @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#0edb4dffbe6b403882255e870cc71066
150
- def filter_next_month(rollup = nil, rollup_type = nil)
151
- make_filter_query "next_month", {}, rollup, rollup_type
152
+ def filter_next_month(condition: nil, another_type: nil)
153
+ make_filter_query "next_month", {}, condition: condition, another_type: another_type
152
154
  end
153
155
 
154
- # @param [String] rollup Rollup name
155
- # @param [String] rollup_type Rollup type
156
+ # @param [String] condition Rollup name
157
+ # @param [String] another_type Rollup type
156
158
  # @return [NotionRubyMapping::Query] generated Query object
157
159
  # @see https://www.notion.so/hkob/CreatedTimeProperty-bb979ff02dc04efa9733da1003efa871#b59c73dd4b1a488f95d3e8cd19853709
158
- def filter_next_year(rollup = nil, rollup_type = nil)
159
- make_filter_query "next_year", {}, rollup, rollup_type
160
+ def filter_next_year(condition: nil, another_type: nil)
161
+ make_filter_query "next_year", {}, condition: condition, another_type: another_type
160
162
  end
161
163
 
162
164
  # @param [Date, Time, DateTime, String, nil] obj
@@ -29,8 +29,8 @@ module NotionRubyMapping
29
29
  def end_date=(edt)
30
30
  assert_page_property __method__
31
31
  @will_update = true
32
- sdt = start_date
33
- edt = nil if sdt.class != edt.class || sdt > edt
32
+ # sdt = start_date
33
+ # edt = nil if sdt.class != edt.class || sdt > edt
34
34
  @json["end"] = edt
35
35
  end
36
36
 
@@ -46,8 +46,8 @@ module NotionRubyMapping
46
46
  def start_date=(sdt)
47
47
  assert_page_property __method__
48
48
  @will_update = true
49
- edt = end_date
50
- @json["end"] = nil if sdt.class != edt.class || sdt > edt
49
+ # edt = end_date
50
+ # @json["end"] = nil if sdt.class != edt.class || sdt > edt
51
51
  @json["start"] = sdt
52
52
  end
53
53
 
@@ -41,7 +41,7 @@ module NotionRubyMapping
41
41
 
42
42
  # @param [String] name
43
43
  # @param [Hash] json
44
- def initialize(name, will_update: false, base_type: :page, json: nil, formula: nil, property_id: nil,
44
+ def initialize(name, will_update: false, base_type: :page, json: nil, formula: nil, property_id: nil,
45
45
  property_cache: nil)
46
46
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
47
47
  property_cache: property_cache
@@ -12,7 +12,7 @@ module NotionRubyMapping
12
12
 
13
13
  ## Common methods
14
14
 
15
- # @return [Numeric, Hash]
15
+ # @return [Numeric, Hash, nil]
16
16
  # @see https://www.notion.so/hkob/NumberProperty-964ebc1948074d7ca8340187aa352d40#571b41dd33ae42039e6b982a502b7ac7
17
17
  def number
18
18
  @json
@@ -43,7 +43,7 @@ module NotionRubyMapping
43
43
  if json.is_a? Array
44
44
  json.map { |sub_json| UserObject.new json: sub_json }
45
45
  elsif json["object"] == "list"
46
- List.new(json: json, property: self).select { true }
46
+ List.new(json: json, type: :property, value: self).select { true }
47
47
  else
48
48
  json["people"].map { |sub_json| UserObject.new json: sub_json }
49
49
  end
@@ -76,7 +76,7 @@ module NotionRubyMapping
76
76
  elsif type == "property_item"
77
77
  tmp = new name, property_id: input_json["property_item"]["id"], base_type: base_type,
78
78
  property_cache: property_cache, query: query
79
- objects = List.new(json: input_json, property: tmp, query: query).select { true }
79
+ objects = List.new(json: input_json, type: :property, value: tmp, query: query).to_a
80
80
  case input_json["property_item"]["type"]
81
81
  when "people"
82
82
  PeopleProperty.new name, people: objects, base_type: base_type,
@@ -142,11 +142,13 @@ module NotionRubyMapping
142
142
  # @param [String] key query parameter
143
143
  # @param [Object] value query value
144
144
  # @return [NotionRubyMapping::Query] generated Query object
145
- def make_filter_query(key, value, rollup = nil, rollup_type = nil)
146
- if rollup
147
- Query.new filter: {"property" => @name, rollup => {rollup_type => {key => value}}}
148
- elsif rollup_type
149
- Query.new filter: {"property" => @name, rollup_type => {key => value}}
145
+ def make_filter_query(key, value, condition: nil, another_type: nil)
146
+ if is_a? FormulaProperty
147
+ Query.new filter: {"property" => @name, "formula" => {another_type => {key => value}}}
148
+ elsif condition
149
+ Query.new filter: {"property" => @name, condition => {another_type => {key => value}}}
150
+ elsif another_type
151
+ Query.new filter: {"property" => @name, another_type => {key => value}}
150
152
  elsif @name == "__timestamp__"
151
153
  Query.new filter: {"timestamp" => type, type => {key => value}}
152
154
  else
@@ -235,8 +237,8 @@ module NotionRubyMapping
235
237
  # @param [String] rollup_type Rollup type
236
238
  # @return [NotionRubyMapping::Query] generated Query object
237
239
  # @see https://www.notion.so/hkob/CheckboxProperty-ac1edbdb8e264af5ad1432b522b429fd#5f07c4ebc4744986bfc99a43827349fc
238
- def filter_equals(value, rollup = nil, rollup_type = nil)
239
- make_filter_query "equals", value, rollup, rollup_type
240
+ def filter_equals(value, condition: nil, another_type: nil)
241
+ make_filter_query "equals", value, condition: condition, another_type: another_type
240
242
  end
241
243
 
242
244
  # @param [String, Number] value Query value
@@ -244,8 +246,8 @@ module NotionRubyMapping
244
246
  # @param [String] rollup_type Rollup type
245
247
  # @return [NotionRubyMapping::Query] generated Query object
246
248
  # @see https://www.notion.so/hkob/CheckboxProperty-ac1edbdb8e264af5ad1432b522b429fd#a44a1875c3ef49f2b4f817291953a1d4
247
- def filter_does_not_equal(value, rollup = nil, rollup_type = nil)
248
- make_filter_query "does_not_equal", value, rollup, rollup_type
249
+ def filter_does_not_equal(value, condition: nil, another_type: nil)
250
+ make_filter_query "does_not_equal", value, condition: condition, another_type: another_type
249
251
  end
250
252
  end
251
253
 
@@ -258,8 +260,8 @@ module NotionRubyMapping
258
260
  # @param [String] rollup_type Rollup type
259
261
  # @return [NotionRubyMapping::Query] generated Query object
260
262
  # @see https://www.notion.so/hkob/CreatedByProperty-945fa6be1c014da2b7e55a2b76e37b57#271a2ebaa1ec48acae732ca98920feab
261
- def filter_contains(value, rollup = nil, rollup_type = nil)
262
- make_filter_query "contains", value, rollup, rollup_type
263
+ def filter_contains(value, condition: nil, another_type: nil)
264
+ make_filter_query "contains", value, condition: condition, another_type: another_type
263
265
  end
264
266
 
265
267
  # @param [String] value Query value
@@ -267,8 +269,8 @@ module NotionRubyMapping
267
269
  # @param [String] rollup_type Rollup type
268
270
  # @return [NotionRubyMapping::Query] generated Query object
269
271
  # @see https://www.notion.so/hkob/CreatedByProperty-945fa6be1c014da2b7e55a2b76e37b57#b0328e3b146f48a4ad4c9c2ee5363486
270
- def filter_does_not_contain(value, rollup = nil, rollup_type = nil)
271
- make_filter_query "does_not_contain", value, rollup, rollup_type
272
+ def filter_does_not_contain(value, condition: nil, another_type: nil)
273
+ make_filter_query "does_not_contain", value, condition: condition, another_type: another_type
272
274
  end
273
275
  end
274
276
 
@@ -281,16 +283,16 @@ module NotionRubyMapping
281
283
  # @param [String] rollup_type Rollup type
282
284
  # @return [NotionRubyMapping::Query] generated Query object
283
285
  # @see https://www.notion.so/hkob/EmailProperty-39aeb5df56ea4cc1b9380574e4fdeec0#d3e098b2f38c4c8c9d3e815516cfd953
284
- def filter_starts_with(value, rollup = nil, rollup_type = nil)
285
- make_filter_query "starts_with", value, rollup, rollup_type
286
+ def filter_starts_with(value, condition: nil, another_type: nil)
287
+ make_filter_query "starts_with", value, condition: condition, another_type: another_type
286
288
  end
287
289
 
288
290
  # @param [String] value Query value
289
291
  # @param [String] rollup Rollup name
290
292
  # @param [String] rollup_type Rollup type
291
293
  # @return [NotionRubyMapping::Query] generated Query object
292
- def filter_ends_with(value, rollup = nil, rollup_type = nil)
293
- make_filter_query "ends_with", value, rollup, rollup_type
294
+ def filter_ends_with(value, condition: nil, another_type: nil)
295
+ make_filter_query "ends_with", value, condition: condition, another_type: another_type
294
296
  end
295
297
  end
296
298
 
@@ -302,16 +304,16 @@ module NotionRubyMapping
302
304
  # @param [String] rollup_type Rollup type
303
305
  # @return [NotionRubyMapping::Query] generated Query object
304
306
  # @see https://www.notion.so/hkob/CreatedByProperty-945fa6be1c014da2b7e55a2b76e37b57#38749dfae0854c68b4c55095d3efbff1
305
- def filter_is_empty(rollup = nil, rollup_type = nil)
306
- make_filter_query "is_empty", true, rollup, rollup_type
307
+ def filter_is_empty(condition: nil, another_type: nil)
308
+ make_filter_query "is_empty", true, condition: condition, another_type: another_type
307
309
  end
308
310
 
309
311
  # @param [String] rollup Rollup name
310
312
  # @param [String] rollup_type Rollup type
311
313
  # @return [NotionRubyMapping::Query] generated Query object
312
314
  # @see https://www.notion.so/hkob/CreatedByProperty-945fa6be1c014da2b7e55a2b76e37b57#515659ea52b54fb48c81b813f3b705f6
313
- def filter_is_not_empty(rollup = nil, rollup_type = nil)
314
- make_filter_query "is_not_empty", true, rollup, rollup_type
315
+ def filter_is_not_empty(condition: nil, another_type: nil)
316
+ make_filter_query "is_not_empty", true, condition: condition, another_type: another_type
315
317
  end
316
318
  end
317
319
 
@@ -323,32 +325,32 @@ module NotionRubyMapping
323
325
  # @param [String] rollup Rollup name
324
326
  # @param [String] rollup_type Rollup type
325
327
  # @return [NotionRubyMapping::Query] generated Query object
326
- def filter_greater_than(value, rollup = nil, rollup_type = nil)
327
- make_filter_query "greater_than", value, rollup, rollup_type
328
+ def filter_greater_than(value, condition: nil, another_type: nil)
329
+ make_filter_query "greater_than", value, condition: condition, another_type: another_type
328
330
  end
329
331
 
330
332
  # @param [Number] value Query value
331
333
  # @param [String] rollup Rollup name
332
334
  # @param [String] rollup_type Rollup type
333
335
  # @return [NotionRubyMapping::Query] generated Query object
334
- def filter_less_than(value, rollup = nil, rollup_type = nil)
335
- make_filter_query "less_than", value, rollup, rollup_type
336
+ def filter_less_than(value, condition: nil, another_type: nil)
337
+ make_filter_query "less_than", value, condition: condition, another_type: another_type
336
338
  end
337
339
 
338
340
  # @param [Number] value Query value
339
341
  # @param [String] rollup Rollup name
340
342
  # @param [String] rollup_type Rollup type
341
343
  # @return [NotionRubyMapping::Query] generated Query object
342
- def filter_greater_than_or_equal_to(value, rollup = nil, rollup_type = nil)
343
- make_filter_query "greater_than_or_equal_to", value, rollup, rollup_type
344
+ def filter_greater_than_or_equal_to(value, condition: nil, another_type: nil)
345
+ make_filter_query "greater_than_or_equal_to", value, condition: condition, another_type: another_type
344
346
  end
345
347
 
346
348
  # @param [Number] value Query value
347
349
  # @param [String] rollup Rollup name
348
350
  # @param [String] rollup_type Rollup type
349
351
  # @return [NotionRubyMapping::Query] generated Query object
350
- def filter_less_than_or_equal_to(value, rollup = nil, rollup_type = nil)
351
- make_filter_query "less_than_or_equal_to", value, rollup, rollup_type
352
+ def filter_less_than_or_equal_to(value, condition: nil, another_type: nil)
353
+ make_filter_query "less_than_or_equal_to", value, condition: condition, another_type: another_type
352
354
  end
353
355
  end
354
356
  end
@@ -9,7 +9,7 @@ module NotionRubyMapping
9
9
 
10
10
  ## Common methods
11
11
 
12
- # @return [Hash, Array]
12
+ # @return [Hash, Array, nil]
13
13
  # @see https://www.notion.so/hkob/RelationProperty-f608ab41a1f0476b98456620346fba03#6c14207b2d1340d2bbc08d17eee2cb22
14
14
  def relation
15
15
  @json
@@ -78,10 +78,8 @@ module NotionRubyMapping
78
78
  json || {}
79
79
  elsif relation
80
80
  Array(relation).map { |r| {"id" => r} }
81
- elsif json
82
- json
83
81
  else
84
- []
82
+ json || []
85
83
  end
86
84
  end
87
85
 
@@ -11,7 +11,7 @@ module NotionRubyMapping
11
11
 
12
12
  def self.rich_text_array_from_json(json)
13
13
  if json["object"] == "list"
14
- rich_text_objects = List.new(json: json, property: self).select { true }
14
+ rich_text_objects = List.new(json: json, type: :property, value: self).select { true }
15
15
  RichTextArray.rich_text_array "title", rich_text_objects
16
16
  else
17
17
  RichTextArray.new "title", json: json["title"]
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
- VERSION = "0.6.7"
4
+ VERSION = "0.6.8"
5
5
  NOTION_VERSION = "2022-06-28"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion_ruby_mapping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroyuki KOBAYASHI
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-02 00:00:00.000000000 Z
11
+ date: 2022-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday