notion-ruby-client 0.0.8 → 0.1.0.pre.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -0
- data/.gitignore +7 -0
- data/.rubocop.yml +9 -0
- data/CHANGELOG.md +19 -0
- data/Gemfile.lock +29 -7
- data/README.md +245 -55
- data/bin/console +31 -0
- data/lib/notion/api/endpoints/blocks.rb +35 -7
- data/lib/notion/api/endpoints/databases.rb +65 -37
- data/lib/notion/api/endpoints/pages.rb +6 -6
- data/lib/notion/api/endpoints/search.rb +41 -0
- data/lib/notion/api/endpoints/users.rb +6 -3
- data/lib/notion/api/endpoints.rb +3 -1
- data/lib/notion/api/errors/too_many_requests.rb +15 -0
- data/lib/notion/api/errors.rb +0 -2
- data/lib/notion/config.rb +2 -0
- data/lib/notion/pagination/cursor.rb +5 -2
- data/lib/notion/version.rb +2 -2
- data/lib/notion-ruby-client.rb +2 -0
- data/notion-ruby-client.gemspec +3 -1
- data/spec/fixtures/notion/block.yml +146 -0
- data/spec/fixtures/notion/block_append_children.yml +76 -62
- data/spec/fixtures/notion/block_children.yml +80 -65
- data/spec/fixtures/notion/create_database.yml +67 -58
- data/spec/fixtures/notion/create_page.yml +68 -59
- data/spec/fixtures/notion/database.yml +78 -61
- data/spec/fixtures/notion/database_query.yml +81 -62
- data/spec/fixtures/notion/databases_list.yml +77 -60
- data/spec/fixtures/notion/page.yml +70 -57
- data/spec/fixtures/notion/paginated_block_children.yml +296 -242
- data/spec/fixtures/notion/paginated_database_query.yml +79 -62
- data/spec/fixtures/notion/paginated_databases_list.yml +78 -61
- data/spec/fixtures/notion/paginated_search.yml +301 -0
- data/spec/fixtures/notion/paginated_users_list.yml +143 -130
- data/spec/fixtures/notion/search.yml +160 -0
- data/spec/fixtures/notion/search_with_query.yml +152 -0
- data/spec/fixtures/notion/update_block.yml +148 -0
- data/spec/fixtures/notion/update_database.yml +152 -0
- data/spec/fixtures/notion/update_page.yml +71 -59
- data/spec/fixtures/notion/users.yml +69 -56
- data/spec/fixtures/notion/users_list.yml +143 -130
- data/spec/notion/api/endpoints/blocks_spec.rb +37 -11
- data/spec/notion/api/endpoints/databases_spec.rb +25 -17
- data/spec/notion/api/endpoints/pages_spec.rb +7 -16
- data/spec/notion/api/endpoints/search_spec.rb +26 -0
- data/spec/notion/api/endpoints/users_spec.rb +4 -4
- data/spec/notion/pagination/cursor_spec.rb +126 -0
- metadata +52 -8
- data/.rspec_status +0 -19
- data/notion-ruby-client-0.0.4.gem +0 -0
- data/scratchpad.rb +0 -22
- data/screenshots/create_notion_bot.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9b83ad4b81b6b52c55b8b65bf33f3075733116d91470d237d000a2428f933ea
|
4
|
+
data.tar.gz: f77c9065b91514bfd3acb7ab42c8a8916c022f6725918861ab5ffce47dedd2df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b080379a4840e4b925a6b7bcb5e4c5ea7a25a85856947281cc95eddcc718dd16bb14466d127fca2d2b02a028e4f5df62ea3225ac1a614057578144e43220288c
|
7
|
+
data.tar.gz: aebf1260e3c10c54abebf62259beb35ab0d4ad520c8f26de98a163ed26d5e1989b09ef3d2189622a0a9b34552ac0b0d0085c567d3cd3488fc4a788fd0ba082a9
|
data/.github/workflows/ci.yml
CHANGED
data/.gitignore
ADDED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
### 0.1.0-beta1 (2021-08-29)
|
2
|
+
|
3
|
+
#### New
|
4
|
+
|
5
|
+
- Add support for the following new endpoints:
|
6
|
+
- [Update database](https://developers.notion.com/reference/update-a-database)
|
7
|
+
- [Update page](https://developers.notion.com/reference/patch-page)
|
8
|
+
- [Retrieve a block](https://developers.notion.com/reference/retrieve-a-block)
|
9
|
+
- [Update a block](https://developers.notion.com/reference/update-a-block)
|
10
|
+
- [Search](https://developers.notion.com/reference/search)
|
11
|
+
- Update Notion API Version to `2021-08-16`
|
12
|
+
- Add `bin/console` command for better DX
|
13
|
+
- Overhauled documentation
|
14
|
+
|
15
|
+
#### Upgrade instructions
|
16
|
+
|
17
|
+
- Please refer to the Notion Changelog to see breaking changes for version `2021-08-16`
|
18
|
+
- Regarding this gem, a lot of `id` parameters got renamed to `block_id`, `page_id`, `user_id` and `database_id`. You might need to rename those in your code as well.
|
19
|
+
|
1
20
|
### 0.0.8 (2021-07-27)
|
2
21
|
|
3
22
|
- Bump `Notion-Version` header to `2021-05-13` (@H0R15H0)
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
notion-ruby-client (0.0.
|
4
|
+
notion-ruby-client (0.1.0.pre.beta1)
|
5
|
+
activesupport
|
6
|
+
dotenv
|
5
7
|
faraday (>= 1.0)
|
6
8
|
faraday_middleware
|
7
9
|
hashie
|
@@ -9,37 +11,54 @@ PATH
|
|
9
11
|
GEM
|
10
12
|
remote: http://rubygems.org/
|
11
13
|
specs:
|
14
|
+
activesupport (6.1.4.1)
|
15
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
+
i18n (>= 1.6, < 2)
|
17
|
+
minitest (>= 5.1)
|
18
|
+
tzinfo (~> 2.0)
|
19
|
+
zeitwerk (~> 2.3)
|
12
20
|
addressable (2.8.0)
|
13
21
|
public_suffix (>= 2.0.2, < 5.0)
|
14
22
|
ast (2.4.2)
|
23
|
+
concurrent-ruby (1.1.9)
|
15
24
|
crack (0.4.5)
|
16
25
|
rexml
|
17
26
|
diff-lcs (1.4.4)
|
18
|
-
|
27
|
+
dotenv (2.7.6)
|
28
|
+
faraday (1.7.0)
|
19
29
|
faraday-em_http (~> 1.0)
|
20
30
|
faraday-em_synchrony (~> 1.0)
|
21
31
|
faraday-excon (~> 1.1)
|
32
|
+
faraday-httpclient (~> 1.0.1)
|
22
33
|
faraday-net_http (~> 1.0)
|
23
34
|
faraday-net_http_persistent (~> 1.1)
|
35
|
+
faraday-patron (~> 1.0)
|
36
|
+
faraday-rack (~> 1.0)
|
24
37
|
multipart-post (>= 1.2, < 3)
|
25
38
|
ruby2_keywords (>= 0.0.4)
|
26
39
|
faraday-em_http (1.0.0)
|
27
40
|
faraday-em_synchrony (1.0.0)
|
28
41
|
faraday-excon (1.1.0)
|
42
|
+
faraday-httpclient (1.0.1)
|
29
43
|
faraday-net_http (1.0.1)
|
30
|
-
faraday-net_http_persistent (1.
|
31
|
-
|
44
|
+
faraday-net_http_persistent (1.2.0)
|
45
|
+
faraday-patron (1.0.0)
|
46
|
+
faraday-rack (1.0.0)
|
47
|
+
faraday_middleware (1.1.0)
|
32
48
|
faraday (~> 1.0)
|
33
49
|
hashdiff (1.0.1)
|
34
50
|
hashie (4.1.0)
|
51
|
+
i18n (1.8.10)
|
52
|
+
concurrent-ruby (~> 1.0)
|
35
53
|
jaro_winkler (1.5.4)
|
54
|
+
minitest (5.14.4)
|
36
55
|
multipart-post (2.1.1)
|
37
56
|
parallel (1.20.1)
|
38
57
|
parser (3.0.1.1)
|
39
58
|
ast (~> 2.4.1)
|
40
59
|
public_suffix (4.0.6)
|
41
60
|
rainbow (3.0.0)
|
42
|
-
rake (
|
61
|
+
rake (13.0.6)
|
43
62
|
rexml (3.2.5)
|
44
63
|
rspec (3.10.0)
|
45
64
|
rspec-core (~> 3.10.0)
|
@@ -67,14 +86,17 @@ GEM
|
|
67
86
|
rubocop-rspec (1.39.0)
|
68
87
|
rubocop (>= 0.68.1)
|
69
88
|
ruby-progressbar (1.11.0)
|
70
|
-
ruby2_keywords (0.0.
|
89
|
+
ruby2_keywords (0.0.5)
|
71
90
|
timecop (0.9.4)
|
91
|
+
tzinfo (2.0.4)
|
92
|
+
concurrent-ruby (~> 1.0)
|
72
93
|
unicode-display_width (1.7.0)
|
73
94
|
vcr (6.0.0)
|
74
95
|
webmock (3.13.0)
|
75
96
|
addressable (>= 2.3.6)
|
76
97
|
crack (>= 0.3.2)
|
77
98
|
hashdiff (>= 0.4.0, < 2.0.0)
|
99
|
+
zeitwerk (2.4.2)
|
78
100
|
|
79
101
|
PLATFORMS
|
80
102
|
arm64-darwin-20
|
@@ -82,7 +104,7 @@ PLATFORMS
|
|
82
104
|
|
83
105
|
DEPENDENCIES
|
84
106
|
notion-ruby-client!
|
85
|
-
rake (~>
|
107
|
+
rake (~> 13)
|
86
108
|
rspec
|
87
109
|
rubocop (~> 0.82.0)
|
88
110
|
rubocop-performance (~> 1.5.2)
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Notion Ruby Client
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/notion-ruby-client)
|
4
|
+
[](https://github.com/orbit-love/notion-ruby-client/actions/workflows/ci.yml)
|
5
|
+
|
3
6
|
A Ruby client for the Notion API.
|
4
7
|
|
5
8
|
## Table of Contents
|
@@ -7,8 +10,28 @@ A Ruby client for the Notion API.
|
|
7
10
|
- [Installation](#installation)
|
8
11
|
- [Usage](#usage)
|
9
12
|
- [Create a New Bot Integration](#create-a-new-bot-integration)
|
10
|
-
- [Declare the API
|
13
|
+
- [Declare the API token](#declare-the-api-token)
|
11
14
|
- [API Client](#api-client)
|
15
|
+
- [Instantiating a new Notion API client](#instantiating-a-new-notion-api-client)
|
16
|
+
- [Pagination](#pagination)
|
17
|
+
- [Endpoints](#endpoints)
|
18
|
+
- [Databases](#databases)
|
19
|
+
- [Query a database](#query-a-database)
|
20
|
+
- [Create a Database](#create-a-database)
|
21
|
+
- [Retrieve a database](#retrieve-a-database)
|
22
|
+
- [List databases](#list-databases)
|
23
|
+
- [Pages](#pages)
|
24
|
+
- [Retrieve a page](#retrieve-a-page)
|
25
|
+
- [Create a page](#create-a-page)
|
26
|
+
- [Update page](#update-page)
|
27
|
+
- [Blocks](#blocks)
|
28
|
+
- [Retrieve block children](#retrieve-block-children)
|
29
|
+
- [Append block children](#append-block-children)
|
30
|
+
- [Users](#users)
|
31
|
+
- [Retrieve a user](#retrieve-a-user)
|
32
|
+
- [List all users](#list-all-users)
|
33
|
+
- [Search](#search)
|
34
|
+
- [Acknowledgements](#acknowledgements)
|
12
35
|
|
13
36
|
## Installation
|
14
37
|
|
@@ -22,15 +45,15 @@ Run `bundle install`.
|
|
22
45
|
|
23
46
|
## Usage
|
24
47
|
|
25
|
-
### Create a New
|
48
|
+
### Create a New Integration
|
26
49
|
|
27
|
-
|
50
|
+
> :blue_book: **Before you start**
|
51
|
+
>
|
52
|
+
> Make sure you are an **Admin** user in your Notion workspace. If you're not an Admin in your current workspace, [create a new personal workspace for free](https://www.notion.so/notion/Create-join-switch-workspaces-3b9be78982a940a7a27ce712ca6bdcf5#9332861c775543d0965f918924448a6d).
|
28
53
|
|
29
|
-
1
|
30
|
-
2. Confirm that you are an Admin in the workspace (see Settings & Members > Members).
|
31
|
-
3. Go to Settings & Members, and click API
|
54
|
+
To create a new integration, follow the steps 1 & 2 outlined in the [Notion documentation](https://developers.notion.com/docs#getting-started). The “_Internal Integration Token_” is what is going to be used to authenticate API calls (referred to here as the “API token”).
|
32
55
|
|
33
|
-
|
56
|
+
> :blue_book: Integrations don't have access to any pages (or databases) in the workspace at first. **A user must share specific pages with an integration in order for those pages to be accessed using the API.**
|
34
57
|
|
35
58
|
### Declare the API token
|
36
59
|
|
@@ -56,36 +79,46 @@ You can specify the token or logger on a per-client basis:
|
|
56
79
|
client = Notion::Client.new(token: '<secret Notion API token>')
|
57
80
|
```
|
58
81
|
|
59
|
-
####
|
82
|
+
#### Pagination
|
60
83
|
|
61
|
-
|
84
|
+
The client natively supports [cursor pagination](https://developers.notion.com/reference/pagination) for methods that allow it, such as `users_list`. Supply a block and the client will make repeated requests adjusting the value of `start_cursor` with every response. The default page size is set to 100 (Notion’s current default and maximum) and can be adjusted via `Notion::Client.config.default_page_size` or by passing it directly into the API call.
|
62
85
|
|
63
86
|
```ruby
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
client.users_list do |page|
|
69
|
-
# paginate through all users
|
87
|
+
all_users = []
|
88
|
+
client.users_list(page_size: 25) do |page|
|
89
|
+
all_users.concat(page.results)
|
70
90
|
end
|
91
|
+
all_users # All users, retrieved 25 at a time
|
71
92
|
```
|
72
93
|
|
73
|
-
|
94
|
+
When using cursor pagination the client will automatically pause and then retry the request if it runs into [Notion rate limiting](https://developers.notion.com/reference/errors#request-limits). (It will pause for 10 seconds before retrying the request, a value that can be overriden with `Notion::Client.config.default_retry_after`.) If it receives too many rate-limited responses in a row it will give up and raise an error. The default number of retries is 100 and can be adjusted via `Notion::Client.config.default_max_retries` or by passing it directly into the method as `max_retries`.
|
95
|
+
|
96
|
+
You can also proactively avoid rate limiting by adding a pause between every paginated request with the `sleep_interval` parameter, which is given in seconds.
|
74
97
|
|
75
98
|
```ruby
|
76
|
-
|
99
|
+
all_users = []
|
100
|
+
client.users_list(sleep_interval: 5, max_retries: 20) do |page|
|
101
|
+
# pauses for 5 seconds between each request
|
102
|
+
# gives up after 20 consecutive rate-limited responses
|
103
|
+
all_users.concat(page.results)
|
104
|
+
end
|
105
|
+
all_users
|
77
106
|
```
|
78
107
|
|
79
|
-
|
108
|
+
## Endpoints
|
80
109
|
|
81
|
-
|
110
|
+
### Databases
|
111
|
+
|
112
|
+
#### Query a database
|
113
|
+
|
114
|
+
Gets a paginated array of [Page](https://developers.notion.com/reference/page) objects contained in the database, filtered and ordered according to the filter conditions and sort criteria provided in the request.
|
82
115
|
|
83
116
|
```ruby
|
84
|
-
client.database_query(
|
117
|
+
client.database_query(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0') # retrieves the first page
|
85
118
|
|
86
|
-
client.database_query(
|
119
|
+
client.database_query(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0', start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')
|
87
120
|
|
88
|
-
client.database_query(
|
121
|
+
client.database_query(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0') do |page|
|
89
122
|
# paginate through all pages
|
90
123
|
end
|
91
124
|
|
@@ -112,28 +145,16 @@ filter = {
|
|
112
145
|
}
|
113
146
|
]
|
114
147
|
}
|
115
|
-
client.database_query(
|
148
|
+
client.database_query(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0', sort: sort, filter: filter)
|
116
149
|
```
|
117
150
|
|
118
|
-
|
119
|
-
|
120
|
-
```ruby
|
121
|
-
client.database(id: 'e383bcee-e0d8-4564-9c63-900d307abdb0')
|
122
|
-
```
|
151
|
+
See [Pagination](#pagination) for details about how to iterate through the list.
|
123
152
|
|
124
|
-
|
153
|
+
See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/post-database-query).
|
125
154
|
|
126
|
-
|
127
|
-
client.databases_list # retrieves the first page
|
155
|
+
#### Create a Database
|
128
156
|
|
129
|
-
|
130
|
-
|
131
|
-
client.databases_list do |page|
|
132
|
-
# paginate through all databases
|
133
|
-
end
|
134
|
-
```
|
135
|
-
|
136
|
-
Create a Database:
|
157
|
+
Creates a database as a subpage in the specified parent page, with the specified properties schema.
|
137
158
|
|
138
159
|
```ruby
|
139
160
|
title = [
|
@@ -144,7 +165,7 @@ title = [
|
|
144
165
|
"link": nil
|
145
166
|
}
|
146
167
|
}
|
147
|
-
]
|
168
|
+
]
|
148
169
|
properties = {
|
149
170
|
"Name": {
|
150
171
|
"title": {}
|
@@ -181,9 +202,76 @@ client.create_database(
|
|
181
202
|
)
|
182
203
|
```
|
183
204
|
|
184
|
-
|
205
|
+
See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/create-a-database).
|
206
|
+
|
207
|
+
#### Update a Database
|
185
208
|
|
186
|
-
|
209
|
+
Updates an existing database as specified by the parameters.
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
title = [
|
213
|
+
{
|
214
|
+
"text": {
|
215
|
+
"content": "Orbit 💜 Notion"
|
216
|
+
}
|
217
|
+
}
|
218
|
+
]
|
219
|
+
client.update_database(database_id: 'dd428e9dd3fe4171870da7a1902c748b', title: title)
|
220
|
+
```
|
221
|
+
|
222
|
+
See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/update-a-database).
|
223
|
+
|
224
|
+
#### Retrieve a database
|
225
|
+
|
226
|
+
Retrieves a [Database object](https://developers.notion.com/reference-link/database) using the ID specified.
|
227
|
+
|
228
|
+
```ruby
|
229
|
+
client.database(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0')
|
230
|
+
```
|
231
|
+
|
232
|
+
See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/retrieve-a-database).
|
233
|
+
|
234
|
+
#### List databases
|
235
|
+
|
236
|
+
List all [Databases](https://developers.notion.com/reference-link/database) shared with the authenticated integration.
|
237
|
+
|
238
|
+
```ruby
|
239
|
+
client.databases_list # retrieves the first page
|
240
|
+
|
241
|
+
client.databases_list(start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')
|
242
|
+
|
243
|
+
client.databases_list do |page|
|
244
|
+
# paginate through all databases
|
245
|
+
end
|
246
|
+
```
|
247
|
+
|
248
|
+
See [Pagination](#pagination) for details about how to iterate through the list.
|
249
|
+
|
250
|
+
See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/list-databases).
|
251
|
+
|
252
|
+
### Pages
|
253
|
+
|
254
|
+
#### Retrieve a page
|
255
|
+
|
256
|
+
Retrieves a [Page object](https://developers.notion.com/reference-link/page) using the ID specified.
|
257
|
+
|
258
|
+
> :blue_book: Responses contains page **properties**, not page content. To fetch page content, use the [retrieve block children](#retrieve-block-children) endpoint.
|
259
|
+
|
260
|
+
```ruby
|
261
|
+
client.page(page_id: 'b55c9c91-384d-452b-81db-d1ef79372b75')
|
262
|
+
```
|
263
|
+
|
264
|
+
See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/retrieve-a-page).
|
265
|
+
|
266
|
+
#### Create a page
|
267
|
+
|
268
|
+
Creates a new page in the specified database or as a child of an existing page.
|
269
|
+
|
270
|
+
If the parent is a database, the [property values](https://developers.notion.com/reference-link/page-property-value) of the new page in the properties parameter must conform to the parent [database](https://developers.notion.com/reference-link/database)'s property schema.
|
271
|
+
|
272
|
+
If the parent is a page, the only valid property is `title`.
|
273
|
+
|
274
|
+
The new page may include page content, described as [blocks](https://developers.notion.com/reference-link/block) in the children parameter.
|
187
275
|
|
188
276
|
```ruby
|
189
277
|
properties = {
|
@@ -241,36 +329,78 @@ client.create_page(
|
|
241
329
|
)
|
242
330
|
```
|
243
331
|
|
244
|
-
|
332
|
+
See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/post-page).
|
245
333
|
|
246
|
-
|
247
|
-
|
248
|
-
|
334
|
+
#### Update page
|
335
|
+
|
336
|
+
Updates [page property values](https://developers.notion.com/reference-link/page-property-value) for the specified page. Properties that are not set via the `properties` parameter will remain unchanged.
|
249
337
|
|
250
|
-
|
338
|
+
If the parent is a database, the new [property values](https://developers.notion.com/reference-link/page-property-value) in the `properties` parameter must conform to the parent [database](https://developers.notion.com/reference-link/database)'s property schema.
|
251
339
|
|
252
340
|
```ruby
|
253
341
|
properties = {
|
254
342
|
"In stock": true
|
255
343
|
}
|
256
|
-
client.update_page(
|
344
|
+
client.update_page(page_id: 'b55c9c91-384d-452b-81db-d1ef79372b75', properties: properties)
|
345
|
+
```
|
346
|
+
|
347
|
+
See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/patch-page).
|
348
|
+
|
349
|
+
### Blocks
|
350
|
+
|
351
|
+
#### Retrieve a block
|
352
|
+
|
353
|
+
Retrieves a [Block object](https://developers.notion.com/reference-link/block) using the ID specified.
|
354
|
+
|
355
|
+
> :blue_book: If a block contains the key `has_children: true`, use the [Retrieve block children](#retrieve-block-children) endpoint to get the list of children
|
356
|
+
|
357
|
+
```ruby
|
358
|
+
client.block(block_id: '9bc30ad4-9373-46a5-84ab-0a7845ee52e6')
|
359
|
+
```
|
360
|
+
|
361
|
+
See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/retrieve-a-block).
|
362
|
+
|
363
|
+
#### Update a block
|
364
|
+
|
365
|
+
Updates the content for the specified block_id based on the block type. Supported fields based on the block object type (see [Block object](https://developers.notion.com/reference-link/block#block-type-object) for available fields and the expected input for each field).
|
366
|
+
|
367
|
+
**Note** The update replaces the entire value for a given field. If a field is omitted (ex: omitting checked when updating a to_do block), the value will not be changed.
|
368
|
+
|
369
|
+
```ruby
|
370
|
+
to_do = {
|
371
|
+
'text': [{
|
372
|
+
'text': { 'content': 'Lacinato kale' }
|
373
|
+
}],
|
374
|
+
'checked': false
|
375
|
+
}
|
376
|
+
client.update_block(block_id: '9bc30ad4-9373-46a5-84ab-0a7845ee52e6', 'to_do' => to_do)
|
257
377
|
```
|
258
378
|
|
259
|
-
|
379
|
+
See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/retrieve-a-block).
|
260
380
|
|
261
|
-
Retrieve children
|
381
|
+
#### Retrieve block children
|
382
|
+
|
383
|
+
Returns a paginated array of child [block objects](https://developers.notion.com/reference-link/block) contained in the block using the ID specified. In order to receive a complete representation of a block, you may need to recursively retrieve the block children of child blocks.
|
262
384
|
|
263
385
|
```ruby
|
264
|
-
client.block_children(
|
386
|
+
client.block_children(block_id: 'b55c9c91-384d-452b-81db-d1ef79372b75')
|
265
387
|
|
266
|
-
client.block_children(start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')
|
388
|
+
client.block_children(block_id: 'b55c9c91-384d-452b-81db-d1ef79372b75', start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')
|
267
389
|
|
268
|
-
client.
|
390
|
+
client.block_children(block_id: 'b55c9c91-384d-452b-81db-d1ef79372b75') do |page|
|
269
391
|
# paginate through all children
|
270
392
|
end
|
271
393
|
```
|
272
394
|
|
273
|
-
|
395
|
+
See [Pagination](#pagination) for details about how to iterate through the list.
|
396
|
+
|
397
|
+
See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/get-block-children).
|
398
|
+
|
399
|
+
#### Append block children
|
400
|
+
|
401
|
+
Creates and appends new children blocks to the parent block specified by `block_id`.
|
402
|
+
|
403
|
+
Returns a paginated list of newly created first level children block objects.
|
274
404
|
|
275
405
|
```ruby
|
276
406
|
children = [
|
@@ -282,5 +412,65 @@ children = [
|
|
282
412
|
}
|
283
413
|
}
|
284
414
|
]
|
285
|
-
client.block_append_children(
|
415
|
+
client.block_append_children(block_id: 'b55c9c91-384d-452b-81db-d1ef79372b75', children: children)
|
416
|
+
```
|
417
|
+
|
418
|
+
See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/patch-block-children).
|
419
|
+
|
420
|
+
### Users
|
421
|
+
|
422
|
+
#### Retrieve a user
|
423
|
+
|
424
|
+
Retrieves a [User](https://developers.notion.com/reference/user) using the ID specified.
|
425
|
+
|
426
|
+
```ruby
|
427
|
+
client.user(user_id: 'd40e767c-d7af-4b18-a86d-55c61f1e39a4')
|
428
|
+
```
|
429
|
+
|
430
|
+
See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/get-user).
|
431
|
+
|
432
|
+
#### List all users
|
433
|
+
|
434
|
+
Returns a paginated list of [Users](https://developers.notion.com/reference/user) for the workspace.
|
435
|
+
|
436
|
+
```ruby
|
437
|
+
client.users_list # retrieves the first page
|
438
|
+
|
439
|
+
client.users_list(start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')
|
440
|
+
|
441
|
+
client.users_list do |page|
|
442
|
+
# paginate through all users
|
443
|
+
end
|
444
|
+
```
|
445
|
+
|
446
|
+
See [Pagination](#pagination) for details about how to iterate through the list.
|
447
|
+
|
448
|
+
See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/get-users).
|
449
|
+
|
450
|
+
### Search
|
451
|
+
|
452
|
+
Searches all pages and child pages that are shared with the integration. The results may include databases.
|
453
|
+
|
454
|
+
```ruby
|
455
|
+
client.search # search through every available page and database
|
456
|
+
|
457
|
+
client.search(query: 'Specific query') # limits which pages are returned by comparing the query to the page title
|
458
|
+
|
459
|
+
client.search(filter: { property: 'object', value: 'page' }) # only returns pages
|
460
|
+
|
461
|
+
client.search(sort: { direction: 'ascending', timestamp: 'last_edited_time' }) # sorts the results based on the provided criteria.
|
462
|
+
|
463
|
+
client.search(start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')
|
464
|
+
|
465
|
+
client.search do |page|
|
466
|
+
# paginate through all search pages
|
467
|
+
end
|
286
468
|
```
|
469
|
+
|
470
|
+
See [Pagination](#pagination) for details about how to iterate through the list.
|
471
|
+
|
472
|
+
See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/post-search).
|
473
|
+
|
474
|
+
## Acknowledgements
|
475
|
+
|
476
|
+
The code, specs and documentation of this gem are an adaptation of the fantastic [Slack Ruby Client](https://github.com/slack-ruby/slack-ruby-client) gem. Many thanks to its author and maintainer [@dblock](https://github.com/dblock) and [contributors](https://github.com/slack-ruby/slack-ruby-client/graphs/contributors).
|