notion-ruby-client 0.0.4 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec_status +17 -13
- data/CHANGELOG.md +19 -2
- data/CODE_OF_CONDUCT.md +128 -0
- data/Gemfile.lock +10 -6
- data/README.md +94 -13
- data/lib/notion/api/endpoints.rb +2 -0
- data/lib/notion/api/endpoints/blocks.rb +53 -0
- data/lib/notion/api/endpoints/databases.rb +22 -0
- data/lib/notion/api/endpoints/pages.rb +2 -2
- data/lib/notion/faraday/request.rb +1 -0
- data/lib/notion/pagination/cursor.rb +1 -1
- data/lib/notion/version.rb +3 -2
- data/notion-ruby-client-0.0.4.gem +0 -0
- data/spec/fixtures/notion/block_append_children.yml +135 -0
- data/spec/fixtures/notion/block_children.yml +137 -0
- data/spec/fixtures/notion/create_database.yml +140 -0
- data/spec/fixtures/notion/create_page.yml +43 -37
- data/spec/fixtures/notion/database.yml +9 -9
- data/spec/fixtures/notion/database_query.yml +11 -13
- data/spec/fixtures/notion/databases_list.yml +9 -9
- data/spec/fixtures/notion/page.yml +40 -36
- data/spec/fixtures/notion/paginated_block_children.yml +521 -0
- data/spec/fixtures/notion/paginated_database_query.yml +11 -15
- data/spec/fixtures/notion/paginated_databases_list.yml +9 -9
- data/spec/fixtures/notion/paginated_users_list.yml +9 -9
- data/spec/fixtures/notion/update_page.yml +41 -37
- data/spec/fixtures/notion/users.yml +9 -9
- data/spec/fixtures/notion/users_list.yml +9 -9
- data/spec/notion/api/endpoints/blocks_spec.rb +40 -0
- data/spec/notion/api/endpoints/databases_spec.rb +26 -0
- data/spec/notion/api/endpoints/pages_spec.rb +19 -8
- metadata +15 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 819fe0911c48a9f09bb4a8e7c92b1c36f77fc61878944df6da74bfab0bd3a9cf
|
4
|
+
data.tar.gz: 2c93279f5b48004a93b92e0a1268712472ac7e5534dcb57ab8003dd8507676ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d4a7d57457cdbb614eb9600b14e5f4460d0672631ff10f2525b87783f587ed251e4b3e3fc33d04420fe06cd086536b17acbfe008595a2f404cb513887365bdc
|
7
|
+
data.tar.gz: ffdab9a3e8962cfd8f21fd75a274020eba721963d12b7cfbb010eff711e7b7ef7945b2763a8db6f75130f53dc2408e7eafb3f95b9d0e3281cbb2b041cfd57e19
|
data/.rspec_status
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
example_id | status | run_time |
|
2
2
|
---------------------------------------------------- | ------ | --------------- |
|
3
|
-
./spec/notion/api/endpoints/
|
4
|
-
./spec/notion/api/endpoints/
|
5
|
-
./spec/notion/api/endpoints/
|
6
|
-
./spec/notion/api/endpoints/databases_spec.rb[1:1:
|
7
|
-
./spec/notion/api/endpoints/databases_spec.rb[1:1:
|
8
|
-
./spec/notion/api/endpoints/
|
9
|
-
./spec/notion/api/endpoints/
|
10
|
-
./spec/notion/api/endpoints/
|
11
|
-
./spec/notion/api/endpoints/
|
12
|
-
./spec/notion/api/endpoints/
|
13
|
-
./spec/notion/api/endpoints/
|
14
|
-
./spec/notion/
|
15
|
-
./spec/notion/
|
3
|
+
./spec/notion/api/endpoints/blocks_spec.rb[1:1:1] | passed | 0.03873 seconds |
|
4
|
+
./spec/notion/api/endpoints/blocks_spec.rb[1:1:2] | passed | 0.0494 seconds |
|
5
|
+
./spec/notion/api/endpoints/blocks_spec.rb[1:1:3] | passed | 0.02657 seconds |
|
6
|
+
./spec/notion/api/endpoints/databases_spec.rb[1:1:1] | passed | 0.02458 seconds |
|
7
|
+
./spec/notion/api/endpoints/databases_spec.rb[1:1:2] | passed | 0.02588 seconds |
|
8
|
+
./spec/notion/api/endpoints/databases_spec.rb[1:1:3] | passed | 0.0268 seconds |
|
9
|
+
./spec/notion/api/endpoints/databases_spec.rb[1:1:4] | passed | 0.01669 seconds |
|
10
|
+
./spec/notion/api/endpoints/databases_spec.rb[1:1:5] | passed | 0.01661 seconds |
|
11
|
+
./spec/notion/api/endpoints/databases_spec.rb[1:1:6] | passed | 0.0173 seconds |
|
12
|
+
./spec/notion/api/endpoints/pages_spec.rb[1:1:1] | passed | 0.01728 seconds |
|
13
|
+
./spec/notion/api/endpoints/pages_spec.rb[1:1:2] | passed | 0.01656 seconds |
|
14
|
+
./spec/notion/api/endpoints/pages_spec.rb[1:1:3] | passed | 0.0206 seconds |
|
15
|
+
./spec/notion/api/endpoints/users_spec.rb[1:1:1] | passed | 0.02992 seconds |
|
16
|
+
./spec/notion/api/endpoints/users_spec.rb[1:1:2] | passed | 0.02664 seconds |
|
17
|
+
./spec/notion/api/endpoints/users_spec.rb[1:1:3] | passed | 0.02533 seconds |
|
18
|
+
./spec/notion/config_spec.rb[1:1:1] | passed | 0.00016 seconds |
|
19
|
+
./spec/notion/version_spec.rb[1:1] | passed | 0.00016 seconds |
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,25 @@
|
|
1
|
+
### 0.0.8 (2021-07-27)
|
2
|
+
|
3
|
+
- Bump `Notion-Version` header to `2021-05-13` (@H0R15H0)
|
4
|
+
- Add support for the new Create database endpoint (@H0R15H0)
|
5
|
+
|
6
|
+
### 0.0.7 (2021-06-17)
|
7
|
+
|
8
|
+
- Fixes the query parameter for fetching a page resource
|
9
|
+
|
10
|
+
### 0.0.6 (2021-06-09)
|
11
|
+
|
12
|
+
- Added `Notion-Version` required header to all requests
|
13
|
+
|
14
|
+
### 0.0.5 (2020-04-25)
|
15
|
+
|
16
|
+
- Added support for Blocks endpoints
|
17
|
+
|
1
18
|
### 0.0.4 (2020-04-25)
|
2
19
|
|
3
20
|
- Added specs and a CI process with GitHub Actions
|
4
|
-
-
|
5
|
-
-
|
21
|
+
- Added support for GET /databases, POST /databases/<:id>/query endpoints
|
22
|
+
- Added support for `content` when creating a page
|
6
23
|
|
7
24
|
### 0.0.3 (2020-01-30)
|
8
25
|
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity
|
10
|
+
and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the
|
26
|
+
overall community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or
|
31
|
+
advances of any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email
|
35
|
+
address, without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official e-mail address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
nicolas@orbit.love.
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series
|
86
|
+
of actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or
|
93
|
+
permanent ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
113
|
+
the community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.0, available at
|
119
|
+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
122
|
+
enforcement ladder](https://github.com/mozilla/diversity).
|
123
|
+
|
124
|
+
[homepage]: https://www.contributor-covenant.org
|
125
|
+
|
126
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
127
|
+
https://www.contributor-covenant.org/faq. Translations are available at
|
128
|
+
https://www.contributor-covenant.org/translations.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
notion-ruby-client (0.0.
|
4
|
+
notion-ruby-client (0.0.8)
|
5
5
|
faraday (>= 1.0)
|
6
6
|
faraday_middleware
|
7
7
|
hashie
|
@@ -9,18 +9,22 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: http://rubygems.org/
|
11
11
|
specs:
|
12
|
-
addressable (2.
|
12
|
+
addressable (2.8.0)
|
13
13
|
public_suffix (>= 2.0.2, < 5.0)
|
14
14
|
ast (2.4.2)
|
15
15
|
crack (0.4.5)
|
16
16
|
rexml
|
17
17
|
diff-lcs (1.4.4)
|
18
|
-
faraday (1.4.
|
18
|
+
faraday (1.4.2)
|
19
|
+
faraday-em_http (~> 1.0)
|
20
|
+
faraday-em_synchrony (~> 1.0)
|
19
21
|
faraday-excon (~> 1.1)
|
20
22
|
faraday-net_http (~> 1.0)
|
21
23
|
faraday-net_http_persistent (~> 1.1)
|
22
24
|
multipart-post (>= 1.2, < 3)
|
23
25
|
ruby2_keywords (>= 0.0.4)
|
26
|
+
faraday-em_http (1.0.0)
|
27
|
+
faraday-em_synchrony (1.0.0)
|
24
28
|
faraday-excon (1.1.0)
|
25
29
|
faraday-net_http (1.0.1)
|
26
30
|
faraday-net_http_persistent (1.1.0)
|
@@ -31,7 +35,7 @@ GEM
|
|
31
35
|
jaro_winkler (1.5.4)
|
32
36
|
multipart-post (2.1.1)
|
33
37
|
parallel (1.20.1)
|
34
|
-
parser (3.0.1.
|
38
|
+
parser (3.0.1.1)
|
35
39
|
ast (~> 2.4.1)
|
36
40
|
public_suffix (4.0.6)
|
37
41
|
rainbow (3.0.0)
|
@@ -67,7 +71,7 @@ GEM
|
|
67
71
|
timecop (0.9.4)
|
68
72
|
unicode-display_width (1.7.0)
|
69
73
|
vcr (6.0.0)
|
70
|
-
webmock (3.
|
74
|
+
webmock (3.13.0)
|
71
75
|
addressable (>= 2.3.6)
|
72
76
|
crack (>= 0.3.2)
|
73
77
|
hashdiff (>= 0.4.0, < 2.0.0)
|
@@ -88,4 +92,4 @@ DEPENDENCIES
|
|
88
92
|
webmock
|
89
93
|
|
90
94
|
BUNDLED WITH
|
91
|
-
2.2.
|
95
|
+
2.2.16
|
data/README.md
CHANGED
@@ -44,7 +44,7 @@ For Rails projects, the snippet above would go to `config/application.rb`.
|
|
44
44
|
|
45
45
|
### API Client
|
46
46
|
|
47
|
-
####
|
47
|
+
#### Instantiating a new Notion API client
|
48
48
|
|
49
49
|
```ruby
|
50
50
|
client = Notion::Client.new
|
@@ -133,26 +133,78 @@ client.databases_list do |page|
|
|
133
133
|
end
|
134
134
|
```
|
135
135
|
|
136
|
+
Create a Database:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
title = [
|
140
|
+
{
|
141
|
+
"type": "text",
|
142
|
+
"text": {
|
143
|
+
"content": "Grocery List",
|
144
|
+
"link": nil
|
145
|
+
}
|
146
|
+
}
|
147
|
+
],
|
148
|
+
properties = {
|
149
|
+
"Name": {
|
150
|
+
"title": {}
|
151
|
+
},
|
152
|
+
"Description": {
|
153
|
+
"rich_text": {}
|
154
|
+
},
|
155
|
+
"In stock": {
|
156
|
+
"checkbox": {}
|
157
|
+
},
|
158
|
+
"Food group": {
|
159
|
+
"select": {
|
160
|
+
"options": [
|
161
|
+
{
|
162
|
+
"name": "🥦Vegetable",
|
163
|
+
"color": "green"
|
164
|
+
},
|
165
|
+
{
|
166
|
+
"name": "🍎Fruit",
|
167
|
+
"color": "red"
|
168
|
+
},
|
169
|
+
{
|
170
|
+
"name": "💪Protein",
|
171
|
+
"color": "yellow"
|
172
|
+
}
|
173
|
+
]
|
174
|
+
}
|
175
|
+
}
|
176
|
+
}
|
177
|
+
client.create_database(
|
178
|
+
parent: { page_id: '98ad959b-2b6a-4774-80ee-00246fb0ea9b' },
|
179
|
+
title: title,
|
180
|
+
properties: properties
|
181
|
+
)
|
182
|
+
```
|
183
|
+
|
136
184
|
#### Pages
|
137
185
|
|
138
186
|
Create a page:
|
139
187
|
|
140
188
|
```ruby
|
141
189
|
properties = {
|
142
|
-
"Name":
|
143
|
-
|
144
|
-
|
145
|
-
"
|
190
|
+
"Name": {
|
191
|
+
"title": [
|
192
|
+
{
|
193
|
+
"text": {
|
194
|
+
"content": "Tuscan Kale"
|
195
|
+
}
|
146
196
|
}
|
147
|
-
|
148
|
-
|
149
|
-
"Description":
|
150
|
-
|
151
|
-
|
152
|
-
"
|
197
|
+
]
|
198
|
+
},
|
199
|
+
"Description": {
|
200
|
+
"rich_text": [
|
201
|
+
{
|
202
|
+
"text": {
|
203
|
+
"content": "A dark green leafy vegetable"
|
204
|
+
}
|
153
205
|
}
|
154
|
-
|
155
|
-
|
206
|
+
]
|
207
|
+
},
|
156
208
|
"Food group": {
|
157
209
|
"name": "🥦 Vegetable"
|
158
210
|
},
|
@@ -203,3 +255,32 @@ properties = {
|
|
203
255
|
}
|
204
256
|
client.update_page(id: 'b55c9c91-384d-452b-81db-d1ef79372b75', properties: properties)
|
205
257
|
```
|
258
|
+
|
259
|
+
#### Blocks
|
260
|
+
|
261
|
+
Retrieve children Block objects at the requested path:
|
262
|
+
|
263
|
+
```ruby
|
264
|
+
client.block_children(id: 'b55c9c91-384d-452b-81db-d1ef79372b75')
|
265
|
+
|
266
|
+
client.block_children(start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')
|
267
|
+
|
268
|
+
client.block_children_list do |page|
|
269
|
+
# paginate through all children
|
270
|
+
end
|
271
|
+
```
|
272
|
+
|
273
|
+
Creates and appends new children blocks to the parent block in the requested path:
|
274
|
+
|
275
|
+
```ruby
|
276
|
+
children = [
|
277
|
+
{
|
278
|
+
"object": 'block',
|
279
|
+
"type": 'heading_2',
|
280
|
+
"heading_2": {
|
281
|
+
"text": [{ "type": 'text', "text": { "content": 'A Second-level Heading' } }]
|
282
|
+
}
|
283
|
+
}
|
284
|
+
]
|
285
|
+
client.block_append_children(id: 'b55c9c91-384d-452b-81db-d1ef79372b75', children: children)
|
286
|
+
```
|
data/lib/notion/api/endpoints.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'endpoints/blocks'
|
3
4
|
require_relative 'endpoints/databases'
|
4
5
|
require_relative 'endpoints/pages'
|
5
6
|
require_relative 'endpoints/users'
|
@@ -7,6 +8,7 @@ require_relative 'endpoints/users'
|
|
7
8
|
module Notion
|
8
9
|
module Api
|
9
10
|
module Endpoints
|
11
|
+
include Blocks
|
10
12
|
include Databases
|
11
13
|
include Pages
|
12
14
|
include Users
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Notion
|
4
|
+
module Api
|
5
|
+
module Endpoints
|
6
|
+
module Blocks
|
7
|
+
#
|
8
|
+
# Returns a paginated array of Block objects contained in the
|
9
|
+
# block of the requested path using the ID specified.
|
10
|
+
#
|
11
|
+
# Returns a 404 HTTP response if any of the following are true:
|
12
|
+
# - the ID does not exist
|
13
|
+
# - the bot doesn't have access to the block with the given ID
|
14
|
+
#
|
15
|
+
# Returns a 400 or 429 HTTP response if the request exceeds Notion's Request limits.
|
16
|
+
#
|
17
|
+
# @option options [id] :id
|
18
|
+
# Block to get children info on.
|
19
|
+
def block_children(options = {})
|
20
|
+
throw ArgumentError.new('Required arguments :id missing') if options[:id].nil?
|
21
|
+
if block_given?
|
22
|
+
Pagination::Cursor.new(self, :block_children, options).each do |page|
|
23
|
+
yield page
|
24
|
+
end
|
25
|
+
else
|
26
|
+
get("blocks/#{options[:id]}/children", options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Creates and appends new children blocks to the parent block
|
32
|
+
# in the requested path using the ID specified. Returns the Block
|
33
|
+
# object being appended to.
|
34
|
+
#
|
35
|
+
# Returns a 404 HTTP response if any of the following are true:
|
36
|
+
# - the ID does not exist
|
37
|
+
# - the bot doesn't have access to the block with the given ID
|
38
|
+
#
|
39
|
+
# Returns a 400 or 429 HTTP response if the request exceeds Notion's Request limits.
|
40
|
+
#
|
41
|
+
# @option options [id] :id
|
42
|
+
# Block to get children info on.
|
43
|
+
#
|
44
|
+
# @option options [[Object]] :children
|
45
|
+
# Children blocks to append
|
46
|
+
def block_append_children(options = {})
|
47
|
+
throw ArgumentError.new('Required arguments :id missing') if options[:id].nil?
|
48
|
+
patch("blocks/#{options[:id]}/children", options)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|