notion_ruby_mapping 0.6.7 → 0.7.0

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: 378e8aecdacdabc3fd951939783195ed13f2e56665a202a8fe3cf9a2d66e0fab
4
+ data.tar.gz: d92c738818763b3d4d49d06e1f7c326ec2fc60e5214162a8185c4f7a8c3f501a
5
5
  SHA512:
6
- metadata.gz: 0f01ba2a798cd79e608b244a6c9c0157f92b1f7e2f9bd4fd4772b38e60f708d1da5a70ffda0816b8aa136282da49d118ff04ede19a363674c3277b3095a34e91
7
- data.tar.gz: 6135423f52bdc33585247ef2c144a49492b54a28d18ae7429d8f4df9791f4d4189d570c2b381b89f939d0b2e2e1914276172b603f612038dbfc7c495ea250c01
6
+ metadata.gz: 0dd2673402bbe54ccd135331c3476f4009af7c68411895f2244288eae761c8975e5bb7e9e39d14ba5d2fc58b96cb38c8dd4f401de2a422d0ebfaeff4c29277ed
7
+ data.tar.gz: 331fadb7063f5d72c049a7f84907174b3470be179340539796772e31a3ff61dd10222d1638d26688c67fe8470501235c3025c2ebda46ba8942e404cc256aad91
data/README.md CHANGED
@@ -1,97 +1,132 @@
1
1
  # notion_ruby_mapping
2
2
 
3
- Notion Ruby mapping is currently under development.
3
+ Notion Ruby Mapping is a library that makes it easy to access data on Notion using Ruby. It is currently under development.
4
4
 
5
- Development note is here. [Idea note of "notion_ruby_mapping"](https://www.notion.so/hkob/Idea-note-of-notion_ruby_mapping-3b0a3bb3c171438a830f9579d41df501)
5
+ Notion Ruby Mapping Ruby Notion 上のデータを簡単にアクセスできるようにするライブラリです。現在開発中です。
6
+
7
+ Development note is here.
8
+
9
+ 開発ノートは以下の URL にあります。
10
+
11
+ → [Idea note of "notion_ruby_mapping"](https://www.notion.so/hkob/Idea-note-of-notion_ruby_mapping-3b0a3bb3c171438a830f9579d41df501)
6
12
 
7
13
  ## Table of Contents
8
14
 
9
- - [notion_ruby_mapping](#notion_ruby_mapping)
15
+ - [notion\_ruby\_mapping](#notion_ruby_mapping)
10
16
  - [Table of Contents](#table-of-contents)
11
- - [0. Changes](#0-changes)
12
- - [0.1 Changes in v0.6.0](#01-changes-in-v060)
13
- - [0.2 Changes in v0.5.0](#02-changes-in-v050)
14
- - [1. Installation](#1-installation)
15
- - [2. How to use](#2-how-to-use)
16
- - [2.1 Create a New Integration](#21-create-a-new-integration)
17
- - [2.2 Create client](#22-create-client)
18
- - [2.3 Sample codes](#23-sample-codes)
19
- - [2.4. Another example code (Use case)](#24-another-example-code-use-case)
20
- - [2.5 API reference](#25-api-reference)
17
+ - [0. History of Major Changes / 主な変更履歴](#0-history-of-major-changes--主な変更履歴)
18
+ - [0.1 Changes in v0.7.0](#01-changes-in-v070)
19
+ - [0.2 Changes in v0.6.0](#02-changes-in-v060)
20
+ - [0.3 Changes in v0.5.0](#03-changes-in-v050)
21
+ - [1. Installation / インストール方法](#1-installation--インストール方法)
22
+ - [2. How to use / 利用方法](#2-how-to-use--利用方法)
23
+ - [2.1 Create a New Integration / インテグレーションの作成](#21-create-a-new-integration--インテグレーションの作成)
24
+ - [2.2 Set your integration token / インテグレーショントークンの設定](#22-set-your-integration-token--インテグレーショントークンの設定)
25
+ - [2.3 Sample codes / サンプルコード](#23-sample-codes--サンプルコード)
26
+ - [2.4. Another example code (Use case) / その他の使用例 (ユースケース)](#24-another-example-code-use-case--その他の使用例-ユースケース)
27
+ - [2.5 API reference / API リファレンス](#25-api-reference--api-リファレンス)
21
28
  - [3. ChangeLog](#3-changelog)
22
- - [4. Contributing](#4-contributing)
23
- - [5. License](#5-license)
24
- - [6. Code of Conduct](#6-code-of-conduct)
29
+ - [4. Contributing / 貢献](#4-contributing--貢献)
30
+ - [5. License / ライセンス](#5-license--ライセンス)
31
+ - [6. Code of Conduct / 行動規範](#6-code-of-conduct--行動規範)
32
+
33
+ ## 0. History of Major Changes / 主な変更履歴
34
+
35
+ ### 0.1 Changes in v0.7.0
25
36
 
26
- ## 0. Changes
37
+ Since the number of Japanese users has increased, we decided to include Japanese as well. In addition, we have simplified the method of setting up integration tokens.
27
38
 
28
- ### 0.1 Changes in v0.6.0
39
+ 日本のユーザが増えたので、日本語も併記することにしました。また、インテグレーショントークンの設定方法を簡単にしました。
40
+
41
+ ### 0.2 Changes in v0.6.0
29
42
 
30
43
  NotionRubyMapping v0.6.0 now supports Notion-Version 2022-06-28.
31
- In 2022-06-28, property values are no longer returned when retrieving pages.
32
- NotionRubyMapping temporarily creates a Property Object and calls the retrieve a property item API when a value is needed.
33
- Therefore, users do not need to be aware of any differences, and existing scripts should work as they are.
44
+ ~~In 2022-06-28, property values are no longer returned when retrieving pages. NotionRubyMapping temporarily creates a Property Object and calls the retrieve a property item API when a value is needed. Therefore, users do not need to be aware of any differences, and existing scripts should work as they are.~~
45
+
46
+ NotionRubyMapping v0.6.0 は、Notion-Version 2022-06-28 に対応しました。
47
+ ~~ 2022-06-28 では、ページを取得する際にプロパティ値を返さなくなりました。NotionRubyMapping は、一時的に Property Object を作成し、値が必要なときにプロパティ項目を取得する API を呼び出します。そのため、ユーザーはこの違いを意識する必要はなく、既存のスクリプトはそのまま動作するはずです。~~
34
48
 
35
- ### 0.2 Changes in v0.5.0
49
+ ### 0.3 Changes in v0.5.0
36
50
 
37
51
  NotionRubyMapping v0.5.0 now supports block updates.
38
52
  For efficiency, subclasses are provided under Block class. As a result, they are no longer compatible with the scripts used in v0.4.0.
39
53
 
40
- ## 1. Installation
54
+ NotionRubyMapping v0.5.0 では、ブロック更新をサポートするようになりました。
55
+ 効率化のため、Blockクラスの下にサブクラスが提供されています。そのため、v0.4.0で使用していたスクリプトとは互換性がなくなりました。
56
+
57
+ ## 1. Installation / インストール方法
41
58
 
42
59
  Add this line to your application's Gemfile:
43
60
 
61
+ アプリケーションのGemfileに次の行を追加します。:
62
+
44
63
  ```ruby
45
64
  gem 'notion_ruby_mapping'
46
65
  ```
47
66
 
48
67
  And then execute:
49
68
 
69
+ そして以下を実行してください:
70
+
50
71
  ```shell
51
72
  bundle install
52
73
  ```
53
74
 
54
75
  Or install it yourself as:
55
76
 
77
+ または、自分でインストールすることもできます。:
78
+
56
79
  ```shell
57
80
  gem install notion_ruby_mapping
58
81
  ```
59
82
 
60
- ## 2. How to use
83
+ ## 2. How to use / 利用方法
61
84
 
62
- ### 2.1 Create a New Integration
85
+ ### 2.1 Create a New Integration / インテグレーションの作成
63
86
 
64
87
  Please check [Notion documentation](https://developers.notion.com/docs#getting-started).
65
88
 
66
- ### 2.2 Create client
89
+ [Notion documentation](https://developers.notion.com/docs#getting-started) を読んでください。
90
+
91
+ ### 2.2 Set your integration token / インテグレーショントークンの設定
92
+
93
+ From v0.7.0, it can be set with `NotionRubymapping.configuration`.
67
94
 
68
- Please create a client (notion-ruby-client) before you use the following class.
95
+ v0.7.0 から `NotionRubyMapping.configuration` で設定できるようになりました。
96
+
97
+ ```ruby
98
+ NotionRubyMapping.configuration do |config|
99
+ config.notion_token = "secret_XXXXXXXXXXXXXXXXXXXX" # write directly
100
+ config.wait = 0
101
+ end
102
+ ```
69
103
 
70
- ```Ruby
71
- NotionCache.instance.create_client "secret_XXXXXXXXXXXXXXXXXXXX" # write directly
72
- NotionCache.instance.create_client ENV["NOTION_API_TOKEN"] # from environment
104
+ ```ruby
105
+ NotionRubyMapping.configuration { |c| c.notion_token = ENV["NOTION_API_TOKEN"] } # from environment
73
106
  ```
74
107
 
75
- ### 2.3 Sample codes
108
+ ### 2.3 Sample codes / サンプルコード
76
109
 
77
- 1. [Database and page access sample](https://www.notion.so/hkob/Database-and-page-access-sample-d30033e707194faf995741167eb2b6f8)
78
- 2. [Append block children sample](https://www.notion.so/hkob/Append-block-children-sample-3867910a437340be931cf7f2c06443c6)
79
- 3. [Update block sample](https://www.notion.so/hkob/update-block-sample-5568c1c36fe84f12b83edfe2dda83028)
110
+ 1. [Database and page access sample / データベースとページのアクセスサンプル](https://www.notion.so/hkob/Database-and-page-access-sample-d30033e707194faf995741167eb2b6f8)
111
+ 2. [Append block children sample / 子ブロック要素の追加サンプル](https://www.notion.so/hkob/Append-block-children-sample-3867910a437340be931cf7f2c06443c6)
112
+ 3. [Update block sample / ブロック要素の更新サンプル](https://www.notion.so/hkob/update-block-sample-5568c1c36fe84f12b83edfe2dda83028)
80
113
 
81
- ### 2.4. Another example code (Use case)
114
+ ### 2.4. Another example code (Use case) / その他の使用例 (ユースケース)
82
115
 
83
- 1. [Set icon to all icon unsettled pages](examples/set_icon_to_all_icon_unsettled_pages.md)
84
- 2. [Renumbering pages](examples/renumbering_pages.md)
85
- 3. [Change title](examples/change_title.md)
86
- 4. [Create ER Diagram from Notion database](https://www.notion.so/hkob/notionErDiagram-Sample-1720c2199c534ca08138cde38f31f710)
87
- 5. [Create Sitemap from Notion pages](https://www.notion.so/hkob/NotionSitemap-sample-14e195c83d024c5382aab09210916c87)
116
+ 1. [Set icon to all icon unsettled pages / 全てのページのアイコンを同一に設定](examples/set_icon_to_all_icon_unsettled_pages.md)
117
+ 2. [Renumbering pages / ページのナンバリング](examples/renumbering_pages.md)
118
+ 3. [Change title / タイトルの変更](examples/change_title.md)
119
+ 4. [Create ER Diagram from Notion database / Notion データベースの ER 図を作成](https://www.notion.so/hkob/notionErDiagram-Sample-1720c2199c534ca08138cde38f31f710)
120
+ 5. [Create Sitemap from Notion pages / Notion page からサイトマップを作成](https://www.notion.so/hkob/NotionSitemap-sample-14e195c83d024c5382aab09210916c87)
88
121
 
89
- ### 2.5 API reference
122
+ ### 2.5 API reference / API リファレンス
90
123
 
91
124
  1. [Notion Ruby Mapping Public API reference](https://www.notion.so/hkob/Notion-Ruby-Mapping-Public-API-reference-4091aca15b664299b63e6253b7601fec)
92
125
 
93
126
  ## 3. ChangeLog
94
127
 
128
+ - 2022/11/28 [v0.7.0] add this_week filter and NotionRubyMapping.configure
129
+ - 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
130
  - 2022/9/2 [v0.6.7] add support for Status property, is_toggleable for headings block, and page property values
96
131
  - 2022/8/10 [v0.6.6] Bug fix(notionSitemap.rb): Skip if child page is empty.
97
132
  - 2022/8/10 [v0.6.5] add notionSitemap.rb, rename createErDiagram to notionErDiagram, and move them to exe directory
@@ -126,14 +161,20 @@ NotionCache.instance.create_client ENV["NOTION_API_TOKEN"] # from environment
126
161
  - 2022/2/13 added Page#set_icon
127
162
  - 2022/2/13 First commit
128
163
 
129
- ## 4. Contributing
164
+ ## 4. Contributing / 貢献
165
+
166
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/hkob/notion_ruby_mapping>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hkob/notion_ruby_mapping/blob/main/CODE_OF_CONDUCT.md).
130
167
 
131
- Bug reports and pull requests are welcome on GitHub at <https://github.com/hkob/notion_ruby_mapping>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/notion_ruby_mapping/blob/main/CODE_OF_CONDUCT.md).
168
+ バグレポートとプルリクエストは、<https://github.com/hkob/notion_ruby_mapping>のGithubで大歓迎です。このプロジェクトは、コラボレーションのための安全で居心地の良いスペースであることを目的としており、貢献者は[行動規範](https://github.com/hkob/notion_ruby_mapping/blob/main/code_of_conduct.md)を遵守することが期待されています。
132
169
 
133
- ## 5. License
170
+ ## 5. License / ライセンス
134
171
 
135
172
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
136
173
 
137
- ## 6. Code of Conduct
174
+ GEMは、[MITライセンス](https://opensource.org/licenses/mit)の条件の下でオープンソースとして入手できます。
175
+
176
+ ## 6. Code of Conduct / 行動規範
177
+
178
+ Everyone interacting in the NotionRubyMapping project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hkob/notion_ruby_mapping/blob/main/CODE_OF_CONDUCT.md).
138
179
 
139
- Everyone interacting in the NotionRubyMapping project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/notion_ruby_mapping/blob/main/CODE_OF_CONDUCT.md).
180
+ NotionRubyMappingプロジェクトのコードベース、問題トラッカー、チャットルーム、メーリングリストで対話する全員が[行動規範](https://github.com/hkob/notion_ruby_mapping/blob/main/code_of_conduct.md)に従うことが期待されています。
@@ -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
@@ -20,11 +20,12 @@ module NotionRubyMapping
20
20
  builder.adapter Faraday.default_adapter
21
21
  end
22
22
  @notion_token = nil
23
- @wait = 0
23
+ @wait = 0.3333
24
24
  @debug = false
25
25
  end
26
26
  attr_reader :object_hash
27
27
  attr_writer :client # for test only
28
+ attr_accessor :notion_token, :wait, :debug
28
29
 
29
30
  # @param [String] block_id
30
31
  # @return [String (frozen)] block_path
@@ -239,7 +240,7 @@ module NotionRubyMapping
239
240
  # @param [Hash] options
240
241
  # @return [Hash] response hash
241
242
  def request(method, path, options = {})
242
- raise "Please call `NotionCache.create_client' before using other methods" unless @notion_token
243
+ raise "Please call `NotionRubyMapping.configure' before using other methods" unless @notion_token
243
244
 
244
245
  sleep @wait
245
246
  response = @client.send(method) do |request|
@@ -284,5 +285,40 @@ module NotionRubyMapping
284
285
  def update_page_request(page_id, payload)
285
286
  request :patch, page_path(page_id), payload
286
287
  end
288
+
289
+ # @param [String] id user_id (with or without "-")
290
+ # @return [NotionRubyMapping::UserObject] UserObject object or nil
291
+ def user(id)
292
+ UserObject.new json: user_request(id)
293
+ end
294
+
295
+ # @param [String] user_id
296
+ # @return [String (frozen)] user_path
297
+ def user_path(user_id)
298
+ "v1/users/#{user_id}"
299
+ end
300
+
301
+ # @param [String] user_id
302
+ # @return [Hash] response
303
+ def user_request(user_id)
304
+ request :get, user_path(user_id)
305
+ end
306
+
307
+ # @return [Array<NotionRubyMapping::UserObject>] UserObject array
308
+ def users
309
+ List.new json: users_request, type: :user_object, value: true
310
+ end
311
+
312
+ # @return [String (frozen)] user_path
313
+ def users_path(option = "")
314
+ "v1/users#{option}"
315
+ end
316
+
317
+ # @param [String] user_id
318
+ # @param [NotionRubyMapping::Query] query query object
319
+ # @return [Hash] response
320
+ def users_request(query = Query.new)
321
+ request :get, users_path, query.query_json
322
+ end
287
323
  end
288
324
  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,129 @@ 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
142
+ # @return [NotionRubyMapping::Query] generated Query object
143
+ # @see
144
+ def filter_this_week(condition: nil, another_type: nil)
145
+ make_filter_query "this_week", {}, condition: condition, another_type: another_type
146
+ end
147
+
148
+ # @param [String] condition Rollup name
149
+ # @param [String] another_type Rollup type
140
150
  # @return [NotionRubyMapping::Query] generated Query object
141
151
  # @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
152
+ def filter_next_week(condition: nil, another_type: nil)
153
+ make_filter_query "next_week", {}, condition: condition, another_type: another_type
144
154
  end
145
155
 
146
- # @param [String] rollup Rollup name
147
- # @param [String] rollup_type Rollup type
156
+ # @param [String] condition Rollup name
157
+ # @param [String] another_type Rollup type
148
158
  # @return [NotionRubyMapping::Query] generated Query object
149
159
  # @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
160
+ def filter_next_month(condition: nil, another_type: nil)
161
+ make_filter_query "next_month", {}, condition: condition, another_type: another_type
152
162
  end
153
163
 
154
- # @param [String] rollup Rollup name
155
- # @param [String] rollup_type Rollup type
164
+ # @param [String] condition Rollup name
165
+ # @param [String] another_type Rollup type
156
166
  # @return [NotionRubyMapping::Query] generated Query object
157
167
  # @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
168
+ def filter_next_year(condition: nil, another_type: nil)
169
+ make_filter_query "next_year", {}, condition: condition, another_type: another_type
160
170
  end
161
171
 
162
172
  # @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.7.0"
5
5
  NOTION_VERSION = "2022-06-28"
6
6
  end
@@ -25,3 +25,11 @@ require_relative "notion_ruby_mapping/version"
25
25
  require_relative "notion_ruby_mapping/#{key}/#{klass}"
26
26
  end
27
27
  end
28
+
29
+ module NotionRubyMapping
30
+ def configure
31
+ yield NotionRubyMapping::NotionCache.instance
32
+ end
33
+ module_function :configure
34
+ end
35
+
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.7.0
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-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday