notion-sdk-ruby 0.4.0 → 0.6.0
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 +10 -1
- data/Gemfile.lock +48 -9
- data/README.md +8 -216
- data/Rakefile +5 -0
- data/lib/notion-sdk-ruby/api/blocks.rb +56 -0
- data/lib/notion-sdk-ruby/api/databases.rb +47 -0
- data/lib/notion-sdk-ruby/api/pages.rb +36 -0
- data/lib/notion-sdk-ruby/api/search.rb +17 -0
- data/lib/notion-sdk-ruby/api/users.rb +24 -0
- data/lib/notion-sdk-ruby/client.rb +14 -10
- data/lib/notion-sdk-ruby/models/block.rb +7 -0
- data/lib/notion-sdk-ruby/models/database.rb +7 -0
- data/lib/notion-sdk-ruby/models/list.rb +49 -0
- data/lib/notion-sdk-ruby/models/page.rb +7 -0
- data/lib/notion-sdk-ruby/models/user.rb +7 -0
- data/lib/notion-sdk-ruby/request_client.rb +29 -34
- data/lib/notion-sdk-ruby/version.rb +1 -1
- data/lib/notion-sdk-ruby.rb +17 -8
- data/notion-sdk-ruby.gemspec +5 -1
- data/todos.md +11 -0
- metadata +73 -11
- data/lib/notion-sdk-ruby/operations/search.rb +0 -9
- data/lib/notion-sdk-ruby/resources/blocks.rb +0 -17
- data/lib/notion-sdk-ruby/resources/databases.rb +0 -19
- data/lib/notion-sdk-ruby/resources/pages.rb +0 -15
- data/lib/notion-sdk-ruby/resources/users.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 481e5f2cb1fb1e06b040669772b571350568fdc1575b7720de83776cfd965b2b
|
4
|
+
data.tar.gz: b20483bc14df3da9a1323189c798b84f230d9998b6f6891ec6ba0eea00d6ee22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32298bebc868742363f23d46ad0ed35a7a357342de1aace3ac04c6fa78e56e9bc81d21dc7b91eb6079759c1d465309df284918877655c92b2282ef22231abe50
|
7
|
+
data.tar.gz: 5ce80f427551c8841e1410183854cac0c10d49de8cdbdfcc73057b745953c360b4c602e2c014d44c4d29279a75969a04f42b784a9304ba5b3508fcf83b216c16
|
data/.github/workflows/ci.yml
CHANGED
@@ -18,7 +18,7 @@ jobs:
|
|
18
18
|
runs-on: ubuntu-latest
|
19
19
|
strategy:
|
20
20
|
matrix:
|
21
|
-
ruby-version: ["2.
|
21
|
+
ruby-version: ["2.7"]
|
22
22
|
|
23
23
|
steps:
|
24
24
|
- uses: actions/checkout@v2
|
@@ -32,3 +32,12 @@ jobs:
|
|
32
32
|
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
33
33
|
- name: Run tests
|
34
34
|
run: bundle exec rake
|
35
|
+
- name: Build docs
|
36
|
+
run: bundle exec rake yard
|
37
|
+
- name: Deploy docs
|
38
|
+
if: ${{ github.ref == 'refs/heads/main' }}
|
39
|
+
uses: peaceiris/actions-gh-pages@v3
|
40
|
+
with:
|
41
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
42
|
+
publish_dir: ./doc
|
43
|
+
publish_branch: gh-pages
|
data/Gemfile.lock
CHANGED
@@ -1,29 +1,59 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
notion-sdk-ruby (0.
|
5
|
-
|
4
|
+
notion-sdk-ruby (0.6.0)
|
5
|
+
faraday (~> 1.8)
|
6
|
+
faraday_middleware (~> 1.1)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
11
|
+
activesupport (6.1.4.1)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
16
|
+
zeitwerk (~> 2.3)
|
10
17
|
addressable (2.7.0)
|
11
18
|
public_suffix (>= 2.0.2, < 5.0)
|
12
19
|
ast (2.4.2)
|
13
20
|
coderay (1.1.3)
|
21
|
+
concurrent-ruby (1.1.9)
|
14
22
|
crack (0.4.5)
|
15
23
|
rexml
|
16
24
|
diff-lcs (1.4.4)
|
17
25
|
dotenv (2.7.6)
|
26
|
+
faraday (1.10.0)
|
27
|
+
faraday-em_http (~> 1.0)
|
28
|
+
faraday-em_synchrony (~> 1.0)
|
29
|
+
faraday-excon (~> 1.1)
|
30
|
+
faraday-httpclient (~> 1.0)
|
31
|
+
faraday-multipart (~> 1.0)
|
32
|
+
faraday-net_http (~> 1.0)
|
33
|
+
faraday-net_http_persistent (~> 1.0)
|
34
|
+
faraday-patron (~> 1.0)
|
35
|
+
faraday-rack (~> 1.0)
|
36
|
+
faraday-retry (~> 1.0)
|
37
|
+
ruby2_keywords (>= 0.0.4)
|
38
|
+
faraday-em_http (1.0.0)
|
39
|
+
faraday-em_synchrony (1.0.0)
|
40
|
+
faraday-excon (1.1.0)
|
41
|
+
faraday-httpclient (1.0.1)
|
42
|
+
faraday-multipart (1.0.4)
|
43
|
+
multipart-post (~> 2)
|
44
|
+
faraday-net_http (1.0.1)
|
45
|
+
faraday-net_http_persistent (1.2.0)
|
46
|
+
faraday-patron (1.0.0)
|
47
|
+
faraday-rack (1.0.0)
|
48
|
+
faraday-retry (1.0.3)
|
49
|
+
faraday_middleware (1.2.0)
|
50
|
+
faraday (~> 1.0)
|
18
51
|
hashdiff (1.0.1)
|
19
|
-
|
20
|
-
|
21
|
-
multi_xml (>= 0.5.2)
|
52
|
+
i18n (1.8.10)
|
53
|
+
concurrent-ruby (~> 1.0)
|
22
54
|
method_source (1.0.0)
|
23
|
-
|
24
|
-
|
25
|
-
mime-types-data (3.2021.0704)
|
26
|
-
multi_xml (0.6.0)
|
55
|
+
minitest (5.14.4)
|
56
|
+
multipart-post (2.2.3)
|
27
57
|
parallel (1.20.1)
|
28
58
|
parser (3.0.1.1)
|
29
59
|
ast (~> 2.4.1)
|
@@ -63,29 +93,38 @@ GEM
|
|
63
93
|
rubocop (>= 1.7.0, < 2.0)
|
64
94
|
rubocop-ast (>= 0.4.0)
|
65
95
|
ruby-progressbar (1.11.0)
|
96
|
+
ruby2_keywords (0.0.5)
|
66
97
|
standard (1.1.1)
|
67
98
|
rubocop (= 1.14.0)
|
68
99
|
rubocop-performance (= 1.11.2)
|
69
100
|
standardrb (1.0.0)
|
70
101
|
standard
|
102
|
+
tzinfo (2.0.4)
|
103
|
+
concurrent-ruby (~> 1.0)
|
71
104
|
unicode-display_width (2.0.0)
|
105
|
+
vcr (6.1.0)
|
72
106
|
webmock (3.12.2)
|
73
107
|
addressable (>= 2.3.6)
|
74
108
|
crack (>= 0.3.2)
|
75
109
|
hashdiff (>= 0.4.0, < 2.0.0)
|
110
|
+
yard (0.9.26)
|
111
|
+
zeitwerk (2.4.2)
|
76
112
|
|
77
113
|
PLATFORMS
|
78
114
|
ruby
|
79
115
|
x64-mingw32
|
80
116
|
|
81
117
|
DEPENDENCIES
|
118
|
+
activesupport (~> 6.1)
|
82
119
|
dotenv (~> 2.7)
|
83
120
|
notion-sdk-ruby!
|
84
121
|
pry (~> 0.14.1)
|
85
122
|
rake (~> 12.0)
|
86
123
|
rspec (~> 3.0)
|
87
124
|
standardrb (~> 1.0)
|
125
|
+
vcr (~> 6.0)
|
88
126
|
webmock (~> 3.12)
|
127
|
+
yard (~> 0.9.26)
|
89
128
|
|
90
129
|
BUNDLED WITH
|
91
130
|
2.2.3
|
data/README.md
CHANGED
@@ -5,30 +5,6 @@
|
|
5
5
|
|
6
6
|
Unofficial Ruby client for the [Notion APIs](https://developers.notion.com/).
|
7
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
|
-
- [Pages](#pages)
|
17
|
-
- [pages#retrieve](#pagesretrieve)
|
18
|
-
- [pages#create](#pagescreate)
|
19
|
-
- [pages#update](#pagesupdate)
|
20
|
-
- [Blocks](#blocks)
|
21
|
-
- [blocks#children#list](#blockschildrenlist)
|
22
|
-
- [blocks#children#append](#blockschildrenappend)
|
23
|
-
- [Users](#users)
|
24
|
-
- [users#retrieve](#usersretrieve)
|
25
|
-
- [users#list](#userslist)
|
26
|
-
- [Search](#search)
|
27
|
-
- [#search](#search-1)
|
28
|
-
- [Development](#development)
|
29
|
-
- [Contributing](#contributing)
|
30
|
-
- [License](#license)
|
31
|
-
|
32
8
|
## Installation
|
33
9
|
|
34
10
|
Add this line to your application's Gemfile:
|
@@ -39,7 +15,13 @@ gem 'notion-sdk-ruby'
|
|
39
15
|
|
40
16
|
And then execute:
|
41
17
|
|
42
|
-
|
18
|
+
```
|
19
|
+
$ bundle install
|
20
|
+
```
|
21
|
+
|
22
|
+
## Documentation
|
23
|
+
|
24
|
+
- [API documentation](https://mgmarlow.github.io/notion-sdk-ruby/Notion/Client.html)
|
43
25
|
|
44
26
|
## Usage
|
45
27
|
|
@@ -50,196 +32,6 @@ require "notion-sdk-ruby"
|
|
50
32
|
client = Notion::Client.new(token: ENV["NOTION_API_SECRET"])
|
51
33
|
```
|
52
34
|
|
53
|
-
## API reference
|
54
|
-
|
55
|
-
### Databases
|
56
|
-
|
57
|
-
#### databases#retrieve
|
58
|
-
|
59
|
-
[API reference](https://developers.notion.com/reference/get-database)
|
60
|
-
|
61
|
-
```rb
|
62
|
-
client.databases.retrieve("668d797c-76fa-4934-9b05-ad288df2d136")
|
63
|
-
```
|
64
|
-
|
65
|
-
#### databases#list
|
66
|
-
|
67
|
-
[API reference](https://developers.notion.com/reference/get-databases)
|
68
|
-
|
69
|
-
```rb
|
70
|
-
client.databases.list
|
71
|
-
```
|
72
|
-
|
73
|
-
#### databases#query
|
74
|
-
|
75
|
-
[API reference](https://developers.notion.com/reference/post-database-query)
|
76
|
-
|
77
|
-
```rb
|
78
|
-
client.databases.query("668d797c-76fa-4934-9b05-ad288df2d136", {
|
79
|
-
"filter": {
|
80
|
-
"or": [
|
81
|
-
{
|
82
|
-
"property": "In stock",
|
83
|
-
"checkbox": {
|
84
|
-
"equals": true
|
85
|
-
}
|
86
|
-
},
|
87
|
-
{
|
88
|
-
"property": "Cost of next trip",
|
89
|
-
"number": {
|
90
|
-
"greater_than_or_equal_to": 2
|
91
|
-
}
|
92
|
-
}
|
93
|
-
]
|
94
|
-
},
|
95
|
-
"sorts": [
|
96
|
-
{
|
97
|
-
"property": "Last ordered",
|
98
|
-
"direction": "ascending"
|
99
|
-
}
|
100
|
-
]
|
101
|
-
})
|
102
|
-
```
|
103
|
-
|
104
|
-
### Pages
|
105
|
-
|
106
|
-
#### pages#retrieve
|
107
|
-
|
108
|
-
[API reference](https://developers.notion.com/reference/get-page)
|
109
|
-
|
110
|
-
```rb
|
111
|
-
client.pages.retrieve("b55c9c91-384d-452b-81db-d1ef79372b75")
|
112
|
-
```
|
113
|
-
|
114
|
-
#### pages#create
|
115
|
-
|
116
|
-
[API reference](https://developers.notion.com/reference/post-page)
|
117
|
-
|
118
|
-
```rb
|
119
|
-
client.pages.create({
|
120
|
-
"parent": { "database_id": "48f8fee9cd794180bc2fec0398253067" },
|
121
|
-
"properties": {
|
122
|
-
"Name": {
|
123
|
-
"title": [
|
124
|
-
{
|
125
|
-
"text": {
|
126
|
-
"content": "Tuscan Kale"
|
127
|
-
}
|
128
|
-
}
|
129
|
-
]
|
130
|
-
},
|
131
|
-
"Description": {
|
132
|
-
"rich_text": [
|
133
|
-
{
|
134
|
-
"text": {
|
135
|
-
"content": "A dark green leafy vegetable"
|
136
|
-
}
|
137
|
-
}
|
138
|
-
]
|
139
|
-
},
|
140
|
-
"Food group": {
|
141
|
-
"select": {
|
142
|
-
"name": "Vegetable"
|
143
|
-
}
|
144
|
-
},
|
145
|
-
"Price": { "number": 2.5 }
|
146
|
-
},
|
147
|
-
"children": []
|
148
|
-
})
|
149
|
-
```
|
150
|
-
|
151
|
-
#### pages#update
|
152
|
-
|
153
|
-
[API reference](https://developers.notion.com/reference/patch-page)
|
154
|
-
|
155
|
-
```rb
|
156
|
-
client.pages.update("b55c9c91-384d-452b-81db-d1ef79372b75", {
|
157
|
-
"properties": {
|
158
|
-
"In stock": { "checkbox": true }
|
159
|
-
}
|
160
|
-
})
|
161
|
-
```
|
162
|
-
|
163
|
-
### Blocks
|
164
|
-
|
165
|
-
#### blocks#children#list
|
166
|
-
|
167
|
-
[API reference](https://developers.notion.com/reference/get-block-children)
|
168
|
-
|
169
|
-
```rb
|
170
|
-
client.blocks.children.list("b55c9c91-384d-452b-81db-d1ef79372b75", {
|
171
|
-
page_size: 100
|
172
|
-
})
|
173
|
-
```
|
174
|
-
|
175
|
-
#### blocks#children#append
|
176
|
-
|
177
|
-
[API reference](https://developers.notion.com/reference/patch-block-children)
|
178
|
-
|
179
|
-
```rb
|
180
|
-
client.blocks.children.append("b54c9c91-384d-452b-81db-d1ef79372b75", {
|
181
|
-
"children": [
|
182
|
-
{
|
183
|
-
"object": "block",
|
184
|
-
"type": "heading_1",
|
185
|
-
"heading_1": {
|
186
|
-
"text": [{ "type": "text", "text": { "content": "Lacinato kale" } }]
|
187
|
-
}
|
188
|
-
},
|
189
|
-
{
|
190
|
-
"object": "block",
|
191
|
-
"type": "paragraph",
|
192
|
-
"paragraph": {
|
193
|
-
"text": [
|
194
|
-
{
|
195
|
-
"type": "text",
|
196
|
-
"text": {
|
197
|
-
"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.",
|
198
|
-
"link": { "url": "https://en.wikipedia.org/wiki/Lacinato_kale" }
|
199
|
-
}
|
200
|
-
}
|
201
|
-
]
|
202
|
-
}
|
203
|
-
}
|
204
|
-
]
|
205
|
-
})
|
206
|
-
```
|
207
|
-
|
208
|
-
### Users
|
209
|
-
|
210
|
-
#### users#retrieve
|
211
|
-
|
212
|
-
[API reference](https://developers.notion.com/reference/get-user)
|
213
|
-
|
214
|
-
```rb
|
215
|
-
client.users.retrieve("d40e767c-d7af-4b18-a86d-55c61f1e39a4")
|
216
|
-
```
|
217
|
-
|
218
|
-
#### users#list
|
219
|
-
|
220
|
-
[API reference](https://developers.notion.com/reference/get-users)
|
221
|
-
|
222
|
-
```rb
|
223
|
-
client.users.list
|
224
|
-
```
|
225
|
-
|
226
|
-
### Search
|
227
|
-
|
228
|
-
[API reference](https://developers.notion.com/reference/post-search)
|
229
|
-
|
230
|
-
#### #search
|
231
|
-
|
232
|
-
```rb
|
233
|
-
client.search({
|
234
|
-
"query":"External tasks",
|
235
|
-
"sort":{
|
236
|
-
"direction":"ascending",
|
237
|
-
"timestamp":"last_edited_time"
|
238
|
-
}
|
239
|
-
}
|
240
|
-
)
|
241
|
-
```
|
242
|
-
|
243
35
|
## Development
|
244
36
|
|
245
37
|
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.
|
@@ -248,7 +40,7 @@ Before using `bin/console` you need to create a new file, `.env`, at the root pr
|
|
248
40
|
|
249
41
|
```
|
250
42
|
cat > .env <<EOF
|
251
|
-
|
43
|
+
NOTION_API_KEY=<YOUR NOTION API SECRET HERE>
|
252
44
|
EOF
|
253
45
|
```
|
254
46
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
module Notion
|
2
|
+
module Api
|
3
|
+
class BlocksMethods
|
4
|
+
include RequestClient
|
5
|
+
|
6
|
+
# @return [Notion::Api::BlocksChildrenMethods]
|
7
|
+
def children
|
8
|
+
BlocksChildrenMethods.new
|
9
|
+
end
|
10
|
+
|
11
|
+
# Retrieves a Block object using the ID specified.
|
12
|
+
# https://developers.notion.com/reference/retrieve-a-block
|
13
|
+
# @param [String] id block_id
|
14
|
+
# @return [Notion::Block]
|
15
|
+
def retrieve(id)
|
16
|
+
response = get("/v1/blocks/#{id}")
|
17
|
+
Block.new(response.body)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Updates the content for the specified block_id based on the block type.
|
21
|
+
# https://developers.notion.com/reference/update-a-block
|
22
|
+
# @param [String] id block_id
|
23
|
+
# @param [Hash] body
|
24
|
+
# @return [Notion::Block]
|
25
|
+
def update(id, body)
|
26
|
+
response = patch("/v1/blocks/#{id}", body.to_json)
|
27
|
+
Block.new(response.body)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class BlocksChildrenMethods
|
32
|
+
include RequestClient
|
33
|
+
|
34
|
+
# Returns a paginated array of child block objects contained in the block
|
35
|
+
# using the ID specified.
|
36
|
+
# https://developers.notion.com/reference/get-block-children
|
37
|
+
# @param [String] id block_id
|
38
|
+
# @param [Hash] query
|
39
|
+
# @return [Array<Notion::Block>]
|
40
|
+
def list(id, query = {})
|
41
|
+
response = get("/v1/blocks/#{id}/children", query)
|
42
|
+
List.new(response.body)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Creates and appends new children blocks to the parent block_id specified.
|
46
|
+
# https://developers.notion.com/reference/patch-block-children
|
47
|
+
# @param [String] id block_id
|
48
|
+
# @param [Hash] body
|
49
|
+
# @return [Array<Notion::Block>]
|
50
|
+
def append(id, body)
|
51
|
+
response = patch("/v1/blocks/#{id}/children", body.to_json)
|
52
|
+
List.new(response.body)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Notion
|
2
|
+
module Api
|
3
|
+
class DatabasesMethods
|
4
|
+
include RequestClient
|
5
|
+
|
6
|
+
# Retrieves a Database object using the ID specified.
|
7
|
+
# https://developers.notion.com/reference/retrieve-a-database
|
8
|
+
# @param [String] id database_id
|
9
|
+
# @return [Notion::Database]
|
10
|
+
def retrieve(id)
|
11
|
+
response = get("/v1/databases/#{id}")
|
12
|
+
Database.new(response.body)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Gets a list of Pages contained in the database, filtered and ordered according
|
16
|
+
# to the filter conditions and sort criteria provided in the request.
|
17
|
+
# https://developers.notion.com/reference/post-database-query
|
18
|
+
# @param [String] id database_id
|
19
|
+
# @param [Hash] body
|
20
|
+
# @return [Array<Notion::Database>]
|
21
|
+
def query(id, body)
|
22
|
+
response = post("/v1/databases/#{id}/query", body.to_json)
|
23
|
+
List.new(response.body)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Creates a database as a subpage in the specified parent page, with the
|
27
|
+
# specified properties schema.
|
28
|
+
# https://developers.notion.com/reference/create-a-database
|
29
|
+
# @param [Hash] body
|
30
|
+
# @return [Notion::Database]
|
31
|
+
def create(body)
|
32
|
+
response = post("/v1/databases", body.to_json)
|
33
|
+
Database.new(response.body)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Updates an existing database as specified by the parameters.
|
37
|
+
# https://developers.notion.com/reference/update-a-database
|
38
|
+
# @param [String] id database_id
|
39
|
+
# @param [Hash] body
|
40
|
+
# @return [Notion::Database]
|
41
|
+
def update(id, body)
|
42
|
+
response = patch("/v1/databases/#{id}", body.to_json)
|
43
|
+
Database.new(response.body)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Notion
|
2
|
+
module Api
|
3
|
+
class PagesMethods
|
4
|
+
include RequestClient
|
5
|
+
|
6
|
+
# Retrieves a Page object using the ID specified.
|
7
|
+
# https://developers.notion.com/reference/retrieve-a-page
|
8
|
+
# @param [String] id page_id
|
9
|
+
# @return [Notion::Page]
|
10
|
+
def retrieve(id)
|
11
|
+
response = get("/v1/pages/#{id}")
|
12
|
+
Page.new(response.body)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Creates a new page in the specified database or as a child of
|
16
|
+
# an existing page.
|
17
|
+
# https://developers.notion.com/reference/post-page
|
18
|
+
# @param [Hash] body
|
19
|
+
# @return [Notion::Page]
|
20
|
+
def create(body)
|
21
|
+
response = post("/v1/pages", body.to_json)
|
22
|
+
Page.new(response.body)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Updates page property values for the specified page.
|
26
|
+
# https://developers.notion.com/reference/patch-page
|
27
|
+
# @param [String] id page_id
|
28
|
+
# @param [Hash] body
|
29
|
+
# @return [Notion::Page]
|
30
|
+
def update(id, body)
|
31
|
+
response = patch("/v1/pages/#{id}", body.to_json)
|
32
|
+
Page.new(response.body)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Notion
|
2
|
+
module Api
|
3
|
+
module SearchMethods
|
4
|
+
include RequestClient
|
5
|
+
|
6
|
+
# Searches all original pages, databases, and child pages/databases
|
7
|
+
# that are shared with the integration.
|
8
|
+
# https://developers.notion.com/reference/post-search
|
9
|
+
# @param [Hash] body
|
10
|
+
# @return [Array]
|
11
|
+
def search(body)
|
12
|
+
response = post("/v1/search", body.to_json)
|
13
|
+
List.new(response.body)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Notion
|
2
|
+
module Api
|
3
|
+
class UsersMethods
|
4
|
+
include RequestClient
|
5
|
+
|
6
|
+
# Returns a paginated list of Users for the workspace.
|
7
|
+
# https://developers.notion.com/reference/get-users
|
8
|
+
# @return [Array<Notion::User>]
|
9
|
+
def list
|
10
|
+
response = get("/v1/users")
|
11
|
+
List.new(response.body)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Retrieves a User using the ID specified.
|
15
|
+
# https://developers.notion.com/reference/get-user
|
16
|
+
# @param [String] id user_id
|
17
|
+
# @return [Notion::User]
|
18
|
+
def retrieve(id)
|
19
|
+
response = get("/v1/users/#{id}")
|
20
|
+
User.new(response.body)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,26 +1,30 @@
|
|
1
1
|
module Notion
|
2
2
|
class Client
|
3
|
-
include
|
3
|
+
include Api::SearchMethods
|
4
4
|
|
5
|
-
def initialize(token:, notion_version: "
|
5
|
+
def initialize(token:, notion_version: "2022-02-22")
|
6
6
|
Notion.api_token = token
|
7
7
|
Notion.notion_version = notion_version
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
# @return [Notion::Api::DatabasesMethods]
|
11
|
+
def databases
|
12
|
+
Api::DatabasesMethods.new
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
# @return [Notion::Api::UsersMethods]
|
16
|
+
def users
|
17
|
+
Api::UsersMethods.new
|
16
18
|
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
+
# @return [Notion::Api::BlocksMethods]
|
21
|
+
def blocks
|
22
|
+
Api::BlocksMethods.new
|
20
23
|
end
|
21
24
|
|
22
|
-
|
23
|
-
|
25
|
+
# @return [Notion::Api::PagesMethods]
|
26
|
+
def pages
|
27
|
+
Api::PagesMethods.new
|
24
28
|
end
|
25
29
|
end
|
26
30
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Notion
|
2
|
+
# The List object is an intermediate object that helps with pagination.
|
3
|
+
#
|
4
|
+
# https://developers.notion.com/reference/pagination
|
5
|
+
class List
|
6
|
+
# An array of endpoint-dependent objects
|
7
|
+
# @return [Array<Notion::User>]
|
8
|
+
# @return [Array<Notion::Database>]
|
9
|
+
# @return [Array<Notion::Page>]
|
10
|
+
# @return [Array<Notion::Block>]
|
11
|
+
attr_reader :data
|
12
|
+
|
13
|
+
# Used to retrieve the next page of results by passing the value as the
|
14
|
+
# start_cursor parameter to the same endpoint.
|
15
|
+
# @return [nil] if has_more is true.
|
16
|
+
# @return [string] if has_more is false.
|
17
|
+
attr_reader :next_cursor
|
18
|
+
|
19
|
+
# When the response includes the end of the list, false. Otherwise, true.
|
20
|
+
# @return [boolean]
|
21
|
+
attr_reader :has_more
|
22
|
+
|
23
|
+
def initialize(response_body)
|
24
|
+
@data = response_body["results"].map do |d|
|
25
|
+
get_model(d["object"]).new(d)
|
26
|
+
end
|
27
|
+
|
28
|
+
@next_cursor = response_body["next_cursor"]
|
29
|
+
@has_more = response_body["has_more"]
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def get_model(object_name)
|
35
|
+
case object_name
|
36
|
+
when "block"
|
37
|
+
Block
|
38
|
+
when "database"
|
39
|
+
Database
|
40
|
+
when "page"
|
41
|
+
Page
|
42
|
+
when "user"
|
43
|
+
User
|
44
|
+
else
|
45
|
+
raise NotionError.new("unimplemented object type")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,49 +1,44 @@
|
|
1
1
|
module Notion
|
2
|
-
|
3
|
-
|
2
|
+
module RequestClient
|
3
|
+
private
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def self.active_client
|
9
|
-
RequestClient.new(Notion.config)
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize(config)
|
13
|
-
self.class.headers Authorization: "Bearer #{config.api_token}"
|
14
|
-
self.class.headers "Notion-Version": config.notion_version
|
15
|
-
end
|
16
|
-
|
17
|
-
def get(*args, &block)
|
18
|
-
response = self.class.get(*args, &block)
|
19
|
-
raise_on_failure(response)
|
5
|
+
def get(*args)
|
6
|
+
handle_request(:get, *args)
|
20
7
|
end
|
21
8
|
|
22
|
-
def post(*args
|
23
|
-
|
24
|
-
raise_on_failure(response)
|
9
|
+
def post(*args)
|
10
|
+
handle_request(:post, *args)
|
25
11
|
end
|
26
12
|
|
27
|
-
def patch(*args
|
28
|
-
|
29
|
-
raise_on_failure(response)
|
13
|
+
def patch(*args)
|
14
|
+
handle_request(:patch, *args)
|
30
15
|
end
|
31
16
|
|
32
|
-
def
|
33
|
-
|
34
|
-
raise_on_failure(response)
|
17
|
+
def delete(*args)
|
18
|
+
handle_request(:delete, *args)
|
35
19
|
end
|
36
20
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
21
|
+
def handle_request(method, *args)
|
22
|
+
faraday_client.public_send(method, *args)
|
23
|
+
rescue Faraday::ClientError => error
|
24
|
+
error_details = JSON.parse(error.response[:body])
|
25
|
+
raise ErrorFactory.create(error_details)
|
26
|
+
rescue JSON::ParserError => error
|
27
|
+
raise NotionError.new(error.message)
|
40
28
|
end
|
41
29
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
30
|
+
def faraday_client
|
31
|
+
@faraday_client ||= Faraday.new(
|
32
|
+
url: "https://api.notion.com",
|
33
|
+
headers: {
|
34
|
+
"Content-Type" => "application/json",
|
35
|
+
"Notion-Version" => Notion.config.notion_version,
|
36
|
+
"Authorization" => "Bearer #{Notion.config.api_token}"
|
37
|
+
}
|
38
|
+
) do |f|
|
39
|
+
f.request :json
|
40
|
+
f.response :json
|
41
|
+
f.use Faraday::Response::RaiseError
|
47
42
|
end
|
48
43
|
end
|
49
44
|
end
|
data/lib/notion-sdk-ruby.rb
CHANGED
@@ -1,16 +1,25 @@
|
|
1
|
-
require "
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
2
3
|
require "forwardable"
|
4
|
+
require "ostruct"
|
3
5
|
|
4
6
|
require "notion-sdk-ruby/version"
|
5
|
-
|
6
7
|
require "notion-sdk-ruby/config"
|
7
|
-
require "notion-sdk-ruby/resources/blocks"
|
8
|
-
require "notion-sdk-ruby/resources/databases"
|
9
|
-
require "notion-sdk-ruby/resources/pages"
|
10
|
-
require "notion-sdk-ruby/resources/users"
|
11
|
-
require "notion-sdk-ruby/operations/search"
|
12
|
-
require "notion-sdk-ruby/error"
|
13
8
|
require "notion-sdk-ruby/request_client"
|
9
|
+
require "notion-sdk-ruby/error"
|
10
|
+
|
11
|
+
require "notion-sdk-ruby/models/user"
|
12
|
+
require "notion-sdk-ruby/models/list"
|
13
|
+
require "notion-sdk-ruby/models/block"
|
14
|
+
require "notion-sdk-ruby/models/database"
|
15
|
+
require "notion-sdk-ruby/models/page"
|
16
|
+
|
17
|
+
require "notion-sdk-ruby/api/blocks"
|
18
|
+
require "notion-sdk-ruby/api/databases"
|
19
|
+
require "notion-sdk-ruby/api/pages"
|
20
|
+
require "notion-sdk-ruby/api/users"
|
21
|
+
require "notion-sdk-ruby/api/search"
|
22
|
+
|
14
23
|
require "notion-sdk-ruby/client"
|
15
24
|
|
16
25
|
module Notion
|
data/notion-sdk-ruby.gemspec
CHANGED
@@ -26,7 +26,8 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
|
-
spec.add_dependency "
|
29
|
+
spec.add_dependency "faraday", "~> 1.8"
|
30
|
+
spec.add_dependency "faraday_middleware", "~> 1.1"
|
30
31
|
|
31
32
|
spec.add_development_dependency "rake", "~> 12.0"
|
32
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
@@ -34,4 +35,7 @@ Gem::Specification.new do |spec|
|
|
34
35
|
spec.add_development_dependency "webmock", "~> 3.12"
|
35
36
|
spec.add_development_dependency "pry", "~> 0.14.1"
|
36
37
|
spec.add_development_dependency "dotenv", "~> 2.7"
|
38
|
+
spec.add_development_dependency "activesupport", "~> 6.1"
|
39
|
+
spec.add_development_dependency "yard", "~> 0.9.26"
|
40
|
+
spec.add_development_dependency "vcr", "~> 6.0"
|
37
41
|
end
|
data/todos.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# todos
|
2
|
+
|
3
|
+
- [x] Add VCR
|
4
|
+
- [x] Swap over specs to use VCR
|
5
|
+
- [x] Update to latest notion SDK version
|
6
|
+
- [x] Improve generated docs by removing extra module namespaces
|
7
|
+
- [x] Remove manual docs from readme, move to auto-generated docs
|
8
|
+
- [ ] New endpoint: Delete block
|
9
|
+
- [ ] New endpoint: Retrieve a page property item
|
10
|
+
- [ ] Pagination APIs
|
11
|
+
- [ ] Examples
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notion-sdk-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Graham Marlow
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '1.8'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.1'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +122,48 @@ dependencies:
|
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '2.7'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: activesupport
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '6.1'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '6.1'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: yard
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.9.26
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.9.26
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: vcr
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '6.0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '6.0'
|
111
167
|
description:
|
112
168
|
email:
|
113
169
|
- mgmarlow@hey.com
|
@@ -128,17 +184,23 @@ files:
|
|
128
184
|
- bin/console
|
129
185
|
- bin/setup
|
130
186
|
- lib/notion-sdk-ruby.rb
|
187
|
+
- lib/notion-sdk-ruby/api/blocks.rb
|
188
|
+
- lib/notion-sdk-ruby/api/databases.rb
|
189
|
+
- lib/notion-sdk-ruby/api/pages.rb
|
190
|
+
- lib/notion-sdk-ruby/api/search.rb
|
191
|
+
- lib/notion-sdk-ruby/api/users.rb
|
131
192
|
- lib/notion-sdk-ruby/client.rb
|
132
193
|
- lib/notion-sdk-ruby/config.rb
|
133
194
|
- lib/notion-sdk-ruby/error.rb
|
134
|
-
- lib/notion-sdk-ruby/
|
195
|
+
- lib/notion-sdk-ruby/models/block.rb
|
196
|
+
- lib/notion-sdk-ruby/models/database.rb
|
197
|
+
- lib/notion-sdk-ruby/models/list.rb
|
198
|
+
- lib/notion-sdk-ruby/models/page.rb
|
199
|
+
- lib/notion-sdk-ruby/models/user.rb
|
135
200
|
- lib/notion-sdk-ruby/request_client.rb
|
136
|
-
- lib/notion-sdk-ruby/resources/blocks.rb
|
137
|
-
- lib/notion-sdk-ruby/resources/databases.rb
|
138
|
-
- lib/notion-sdk-ruby/resources/pages.rb
|
139
|
-
- lib/notion-sdk-ruby/resources/users.rb
|
140
201
|
- lib/notion-sdk-ruby/version.rb
|
141
202
|
- notion-sdk-ruby.gemspec
|
203
|
+
- todos.md
|
142
204
|
homepage: https://github.com/mgmarlow/notion-sdk-ruby
|
143
205
|
licenses:
|
144
206
|
- MIT
|
@@ -161,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
223
|
- !ruby/object:Gem::Version
|
162
224
|
version: '0'
|
163
225
|
requirements: []
|
164
|
-
rubygems_version: 3.
|
226
|
+
rubygems_version: 3.3.7
|
165
227
|
signing_key:
|
166
228
|
specification_version: 4
|
167
229
|
summary: Notion SDK
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Notion
|
2
|
-
class Blocks
|
3
|
-
def children
|
4
|
-
Children.new
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
class Children
|
9
|
-
def list(block_id, query: {})
|
10
|
-
RequestClient.active_client.get("/v1/blocks/#{block_id}/children", query: query)
|
11
|
-
end
|
12
|
-
|
13
|
-
def append(block_id, body)
|
14
|
-
RequestClient.active_client.patch("/v1/blocks/#{block_id}/children", body: body.to_json)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Notion
|
2
|
-
class Databases
|
3
|
-
def retrieve(id)
|
4
|
-
RequestClient.active_client.get("/v1/databases/#{id}")
|
5
|
-
end
|
6
|
-
|
7
|
-
def list
|
8
|
-
RequestClient.active_client.get("/v1/databases")
|
9
|
-
end
|
10
|
-
|
11
|
-
def query(id, body)
|
12
|
-
RequestClient.active_client.post("/v1/databases/#{id}/query", body: body.to_json)
|
13
|
-
end
|
14
|
-
|
15
|
-
def create(body)
|
16
|
-
RequestClient.active_client.post("/v1/databases", body: body.to_json)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Notion
|
2
|
-
class Pages
|
3
|
-
def retrieve(id)
|
4
|
-
RequestClient.active_client.get("/v1/pages/#{id}")
|
5
|
-
end
|
6
|
-
|
7
|
-
def create(body)
|
8
|
-
RequestClient.active_client.post("/v1/pages", body: body.to_json)
|
9
|
-
end
|
10
|
-
|
11
|
-
def update(id, body)
|
12
|
-
RequestClient.active_client.patch("/v1/pages/#{id}", body: body.to_json)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|