notion-sdk-ruby 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +34 -34
- data/.gitignore +13 -13
- data/.rspec +3 -3
- data/.travis.yml +6 -6
- data/.vscode/settings.json +3 -3
- data/Gemfile +4 -4
- data/Gemfile.lock +2 -2
- data/LICENSE.txt +21 -21
- data/README.md +339 -263
- data/Rakefile +7 -7
- data/bin/console +11 -11
- data/bin/setup +8 -8
- data/lib/notion-sdk-ruby/client.rb +26 -26
- data/lib/notion-sdk-ruby/config.rb +5 -5
- data/lib/notion-sdk-ruby/error.rb +52 -52
- data/lib/notion-sdk-ruby/operations/search.rb +9 -9
- data/lib/notion-sdk-ruby/request_client.rb +50 -50
- data/lib/notion-sdk-ruby/resources/blocks.rb +25 -17
- data/lib/notion-sdk-ruby/resources/databases.rb +25 -19
- data/lib/notion-sdk-ruby/resources/pages.rb +15 -15
- data/lib/notion-sdk-ruby/resources/users.rb +11 -11
- data/lib/notion-sdk-ruby/version.rb +3 -3
- data/lib/notion-sdk-ruby.rb +27 -27
- data/notion-sdk-ruby.gemspec +37 -37
- metadata +7 -7
data/README.md
CHANGED
@@ -1,263 +1,339 @@
|
|
1
|
-
# Notion Ruby SDK
|
2
|
-
|
3
|
-
[![ci](https://github.com/mgmarlow/notion-sdk-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/mgmarlow/notion-sdk-ruby/actions/workflows/ci.yml)
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/notion-sdk-ruby.svg)](https://badge.fury.io/rb/notion-sdk-ruby)
|
5
|
-
|
6
|
-
Unofficial Ruby client for the [Notion APIs](https://developers.notion.com/).
|
7
|
-
|
8
|
-
- [Notion Ruby SDK](#notion-ruby-sdk)
|
9
|
-
- [Installation](#installation)
|
10
|
-
- [Usage](#usage)
|
11
|
-
- [API reference](#api-reference)
|
12
|
-
- [Databases](#databases)
|
13
|
-
- [databases#retrieve](#databasesretrieve)
|
14
|
-
- [databases#list](#databaseslist)
|
15
|
-
- [databases#query](#databasesquery)
|
16
|
-
|
17
|
-
- [
|
18
|
-
|
19
|
-
- [pages#
|
20
|
-
|
21
|
-
- [
|
22
|
-
|
23
|
-
|
24
|
-
- [
|
25
|
-
- [
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
```
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
}
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
}
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
[
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
1
|
+
# Notion Ruby SDK
|
2
|
+
|
3
|
+
[![ci](https://github.com/mgmarlow/notion-sdk-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/mgmarlow/notion-sdk-ruby/actions/workflows/ci.yml)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/notion-sdk-ruby.svg)](https://badge.fury.io/rb/notion-sdk-ruby)
|
5
|
+
|
6
|
+
Unofficial Ruby client for the [Notion APIs](https://developers.notion.com/).
|
7
|
+
|
8
|
+
- [Notion Ruby SDK](#notion-ruby-sdk)
|
9
|
+
- [Installation](#installation)
|
10
|
+
- [Usage](#usage)
|
11
|
+
- [API reference](#api-reference)
|
12
|
+
- [Databases](#databases)
|
13
|
+
- [databases#retrieve](#databasesretrieve)
|
14
|
+
- [databases#list](#databaseslist)
|
15
|
+
- [databases#query](#databasesquery)
|
16
|
+
- [databases#create](#databasescreate)
|
17
|
+
- [databases#update](#databasesupdate)
|
18
|
+
- [Pages](#pages)
|
19
|
+
- [pages#retrieve](#pagesretrieve)
|
20
|
+
- [pages#create](#pagescreate)
|
21
|
+
- [pages#update](#pagesupdate)
|
22
|
+
- [Blocks](#blocks)
|
23
|
+
- [blocks#retrieve](#blocksretrieve)
|
24
|
+
- [blocks#update](#blocksupdate)
|
25
|
+
- [blocks#children#list](#blockschildrenlist)
|
26
|
+
- [blocks#children#append](#blockschildrenappend)
|
27
|
+
- [Users](#users)
|
28
|
+
- [users#retrieve](#usersretrieve)
|
29
|
+
- [users#list](#userslist)
|
30
|
+
- [Search](#search)
|
31
|
+
- [#search](#search-1)
|
32
|
+
- [Development](#development)
|
33
|
+
- [Contributing](#contributing)
|
34
|
+
- [License](#license)
|
35
|
+
|
36
|
+
## Installation
|
37
|
+
|
38
|
+
Add this line to your application's Gemfile:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
gem 'notion-sdk-ruby'
|
42
|
+
```
|
43
|
+
|
44
|
+
And then execute:
|
45
|
+
|
46
|
+
$ bundle install
|
47
|
+
|
48
|
+
## Usage
|
49
|
+
|
50
|
+
Initialize `Notion::Client` with your app's [integration secret](https://developers.notion.com/docs/getting-started#create-a-new-integration).
|
51
|
+
|
52
|
+
```rb
|
53
|
+
require "notion-sdk-ruby"
|
54
|
+
client = Notion::Client.new(token: ENV["NOTION_API_SECRET"])
|
55
|
+
```
|
56
|
+
|
57
|
+
## API reference
|
58
|
+
|
59
|
+
### Databases
|
60
|
+
|
61
|
+
#### databases#retrieve
|
62
|
+
|
63
|
+
[API reference](https://developers.notion.com/reference/get-database)
|
64
|
+
|
65
|
+
```rb
|
66
|
+
client.databases.retrieve("668d797c-76fa-4934-9b05-ad288df2d136")
|
67
|
+
```
|
68
|
+
|
69
|
+
#### databases#list
|
70
|
+
|
71
|
+
[API reference](https://developers.notion.com/reference/get-databases)
|
72
|
+
|
73
|
+
```rb
|
74
|
+
client.databases.list
|
75
|
+
```
|
76
|
+
|
77
|
+
#### databases#query
|
78
|
+
|
79
|
+
[API reference](https://developers.notion.com/reference/post-database-query)
|
80
|
+
|
81
|
+
```rb
|
82
|
+
client.databases.query("668d797c-76fa-4934-9b05-ad288df2d136", {
|
83
|
+
filter: {
|
84
|
+
or: [
|
85
|
+
{
|
86
|
+
property: "In stock",
|
87
|
+
checkbox: {
|
88
|
+
equals: true
|
89
|
+
}
|
90
|
+
},
|
91
|
+
{
|
92
|
+
property: "Cost of next trip",
|
93
|
+
number: {
|
94
|
+
greater_than_or_equal_to: 2
|
95
|
+
}
|
96
|
+
}
|
97
|
+
]
|
98
|
+
},
|
99
|
+
sorts: [
|
100
|
+
{
|
101
|
+
property: "Last ordered",
|
102
|
+
direction: "ascending"
|
103
|
+
}
|
104
|
+
]
|
105
|
+
})
|
106
|
+
```
|
107
|
+
|
108
|
+
#### databases#create
|
109
|
+
|
110
|
+
[API reference](https://developers.notion.com/reference/create-a-database)
|
111
|
+
|
112
|
+
```rb
|
113
|
+
client.databases.create({
|
114
|
+
parent: {
|
115
|
+
type: "page_id",
|
116
|
+
page_id: "98ad959b-2b6a-4774-80ee-00246fb0ea9b"
|
117
|
+
},
|
118
|
+
title: [
|
119
|
+
{
|
120
|
+
type: "text",
|
121
|
+
text: {
|
122
|
+
content: "Grocery List",
|
123
|
+
link: null
|
124
|
+
}
|
125
|
+
}
|
126
|
+
],
|
127
|
+
properties: {
|
128
|
+
Name: {
|
129
|
+
title: {}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
})
|
133
|
+
```
|
134
|
+
|
135
|
+
#### databases#update
|
136
|
+
|
137
|
+
[API reference](https://developers.notion.com/reference/update-a-database)
|
138
|
+
|
139
|
+
```rb
|
140
|
+
client.databases.update("668d797c-76fa-4934-9b05-ad288df2d136", {
|
141
|
+
title: [
|
142
|
+
{
|
143
|
+
type: "text",
|
144
|
+
text: {
|
145
|
+
content: "Grocery List",
|
146
|
+
link: null
|
147
|
+
}
|
148
|
+
}
|
149
|
+
],
|
150
|
+
properties: {
|
151
|
+
Name: {
|
152
|
+
title: {}
|
153
|
+
}
|
154
|
+
}
|
155
|
+
})
|
156
|
+
```
|
157
|
+
|
158
|
+
### Pages
|
159
|
+
|
160
|
+
#### pages#retrieve
|
161
|
+
|
162
|
+
[API reference](https://developers.notion.com/reference/get-page)
|
163
|
+
|
164
|
+
```rb
|
165
|
+
client.pages.retrieve("b55c9c91-384d-452b-81db-d1ef79372b75")
|
166
|
+
```
|
167
|
+
|
168
|
+
#### pages#create
|
169
|
+
|
170
|
+
[API reference](https://developers.notion.com/reference/post-page)
|
171
|
+
|
172
|
+
```rb
|
173
|
+
client.pages.create({
|
174
|
+
parent: { database_id: "48f8fee9cd794180bc2fec0398253067" },
|
175
|
+
properties: {
|
176
|
+
Name: {
|
177
|
+
title: [
|
178
|
+
{
|
179
|
+
text: {
|
180
|
+
content: "Tuscan Kale"
|
181
|
+
}
|
182
|
+
}
|
183
|
+
]
|
184
|
+
},
|
185
|
+
Description: {
|
186
|
+
rich_text: [
|
187
|
+
{
|
188
|
+
text: {
|
189
|
+
content: "A dark green leafy vegetable"
|
190
|
+
}
|
191
|
+
}
|
192
|
+
]
|
193
|
+
},
|
194
|
+
Food group: {
|
195
|
+
select: {
|
196
|
+
name: "Vegetable"
|
197
|
+
}
|
198
|
+
},
|
199
|
+
Price: { number: 2.5 }
|
200
|
+
},
|
201
|
+
children: []
|
202
|
+
})
|
203
|
+
```
|
204
|
+
|
205
|
+
#### pages#update
|
206
|
+
|
207
|
+
[API reference](https://developers.notion.com/reference/patch-page)
|
208
|
+
|
209
|
+
```rb
|
210
|
+
client.pages.update("b55c9c91-384d-452b-81db-d1ef79372b75", {
|
211
|
+
properties: {
|
212
|
+
"In stock": { checkbox: true }
|
213
|
+
}
|
214
|
+
})
|
215
|
+
```
|
216
|
+
|
217
|
+
### Blocks
|
218
|
+
|
219
|
+
#### blocks#retrieve
|
220
|
+
|
221
|
+
[API reference](https://developers.notion.com/reference/retrieve-a-block)
|
222
|
+
|
223
|
+
```rb
|
224
|
+
client.blocks.retrieve("b55c9c91-384d-452b-81db-d1ef79372b75")
|
225
|
+
```
|
226
|
+
|
227
|
+
#### blocks#update
|
228
|
+
|
229
|
+
[API reference](https://developers.notion.com/reference/update-a-block)
|
230
|
+
|
231
|
+
```rb
|
232
|
+
client.blocks.update("b55c9c91-384d-452b-81db-d1ef79372b75", {
|
233
|
+
to_do: {
|
234
|
+
text: [{
|
235
|
+
text: { content: "Lacinato kale" }
|
236
|
+
}],
|
237
|
+
checked: false
|
238
|
+
}
|
239
|
+
})
|
240
|
+
```
|
241
|
+
|
242
|
+
#### blocks#children#list
|
243
|
+
|
244
|
+
[API reference](https://developers.notion.com/reference/get-block-children)
|
245
|
+
|
246
|
+
```rb
|
247
|
+
client.blocks.children.list("b55c9c91-384d-452b-81db-d1ef79372b75", {
|
248
|
+
page_size: 100
|
249
|
+
})
|
250
|
+
```
|
251
|
+
|
252
|
+
#### blocks#children#append
|
253
|
+
|
254
|
+
[API reference](https://developers.notion.com/reference/patch-block-children)
|
255
|
+
|
256
|
+
```rb
|
257
|
+
client.blocks.children.append("b54c9c91-384d-452b-81db-d1ef79372b75", {
|
258
|
+
children: [
|
259
|
+
{
|
260
|
+
object: "block",
|
261
|
+
type: "heading_1",
|
262
|
+
heading_1: {
|
263
|
+
text: [{ type: "text", text: { content: "Lacinato kale" } }]
|
264
|
+
}
|
265
|
+
},
|
266
|
+
{
|
267
|
+
object: "block",
|
268
|
+
type: "paragraph",
|
269
|
+
paragraph: {
|
270
|
+
text: [
|
271
|
+
{
|
272
|
+
type: "text",
|
273
|
+
text: {
|
274
|
+
content: "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.",
|
275
|
+
link: { url: "https://en.wikipedia.org/wiki/Lacinato_kale" }
|
276
|
+
}
|
277
|
+
}
|
278
|
+
]
|
279
|
+
}
|
280
|
+
}
|
281
|
+
]
|
282
|
+
})
|
283
|
+
```
|
284
|
+
|
285
|
+
### Users
|
286
|
+
|
287
|
+
#### users#retrieve
|
288
|
+
|
289
|
+
[API reference](https://developers.notion.com/reference/get-user)
|
290
|
+
|
291
|
+
```rb
|
292
|
+
client.users.retrieve("d40e767c-d7af-4b18-a86d-55c61f1e39a4")
|
293
|
+
```
|
294
|
+
|
295
|
+
#### users#list
|
296
|
+
|
297
|
+
[API reference](https://developers.notion.com/reference/get-users)
|
298
|
+
|
299
|
+
```rb
|
300
|
+
client.users.list
|
301
|
+
```
|
302
|
+
|
303
|
+
### Search
|
304
|
+
|
305
|
+
[API reference](https://developers.notion.com/reference/post-search)
|
306
|
+
|
307
|
+
#### #search
|
308
|
+
|
309
|
+
```rb
|
310
|
+
client.search({
|
311
|
+
query: "External tasks",
|
312
|
+
sort: {
|
313
|
+
direction: "ascending",
|
314
|
+
timestamp: "last_edited_time"
|
315
|
+
}
|
316
|
+
})
|
317
|
+
```
|
318
|
+
|
319
|
+
## Development
|
320
|
+
|
321
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
322
|
+
|
323
|
+
Before using `bin/console` you need to create a new file, `.env`, at the root project directory. This will enable you to run commands directly against your [Notion integration](https://developers.notion.com/docs/getting-started).
|
324
|
+
|
325
|
+
```
|
326
|
+
cat > .env <<EOF
|
327
|
+
API_SECRET=<YOUR NOTION API SECRET HERE>
|
328
|
+
EOF
|
329
|
+
```
|
330
|
+
|
331
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
332
|
+
|
333
|
+
## Contributing
|
334
|
+
|
335
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mgmarlow/notion-sdk-ruby.
|
336
|
+
|
337
|
+
## License
|
338
|
+
|
339
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require "rspec/core/rake_task"
|
3
|
-
require "standard/rake"
|
4
|
-
|
5
|
-
RSpec::Core::RakeTask.new(:spec)
|
6
|
-
|
7
|
-
task default: [:spec, :standard]
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require "standard/rake"
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task default: [:spec, :standard]
|
data/bin/console
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "pry"
|
5
|
-
require 'dotenv/load'
|
6
|
-
|
7
|
-
require "notion-sdk-ruby"
|
8
|
-
|
9
|
-
$client = Notion::Client.new(token: ENV["API_SECRET"])
|
10
|
-
|
11
|
-
Pry.start
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pry"
|
5
|
+
require 'dotenv/load'
|
6
|
+
|
7
|
+
require "notion-sdk-ruby"
|
8
|
+
|
9
|
+
$client = Notion::Client.new(token: ENV["API_SECRET"])
|
10
|
+
|
11
|
+
Pry.start
|
data/bin/setup
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
|
-
|
6
|
-
bundle install
|
7
|
-
|
8
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install
|
7
|
+
|
8
|
+
# Do any other automated setup that you need to do here
|