notion-sdk-ruby 0.1.0 → 0.3.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 -0
- data/.gitignore +13 -11
- data/.rspec +3 -3
- data/.travis.yml +6 -6
- data/.vscode/settings.json +4 -0
- data/Gemfile +4 -7
- data/Gemfile.lock +91 -0
- data/LICENSE.txt +21 -21
- data/README.md +263 -40
- data/Rakefile +7 -6
- data/bin/console +11 -14
- data/bin/setup +8 -8
- data/lib/notion-sdk-ruby.rb +27 -0
- data/lib/notion-sdk-ruby/client.rb +26 -0
- data/lib/notion-sdk-ruby/config.rb +5 -0
- data/lib/notion-sdk-ruby/error.rb +52 -0
- data/lib/notion-sdk-ruby/operations/search.rb +9 -0
- data/lib/notion-sdk-ruby/request_client.rb +50 -0
- data/lib/notion-sdk-ruby/resources/blocks.rb +17 -0
- data/lib/notion-sdk-ruby/resources/databases.rb +15 -0
- data/lib/notion-sdk-ruby/resources/pages.rb +15 -0
- data/lib/notion-sdk-ruby/resources/users.rb +11 -0
- data/lib/notion-sdk-ruby/version.rb +3 -0
- data/notion-sdk-ruby.gemspec +37 -26
- metadata +116 -6
- data/lib/notion/sdk/ruby.rb +0 -10
- data/lib/notion/sdk/ruby/version.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 006e8ac9f857ad0644041bd3ba45608730e72095c021e19034254ed0d75372ad
|
4
|
+
data.tar.gz: 8ba2f237a80ca3aebb2532d52f3d5ffa58337181278062dd0f31c01d66d8a5a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2bf9572dd3947686b40b734a642b782fd0ef0efb94f6714b66d7d4815e9625453febb5ae1f5c44588289266c1ca43fa7c24c15aba9bd0bc12f6bceebff1334d
|
7
|
+
data.tar.gz: 2d850b377b632e59c533fcdac1a52b1989f72c7fd64c340332b9c0a7cb752b5e7fb4459b30b43a1b4047dd948b1a86d58cbb7ff5774a734dfdf872df081eb2d8
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: ci
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [main]
|
13
|
+
pull_request:
|
14
|
+
branches: [main]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
strategy:
|
20
|
+
matrix:
|
21
|
+
ruby-version: ["2.6", "2.7", "3.0"]
|
22
|
+
|
23
|
+
steps:
|
24
|
+
- uses: actions/checkout@v2
|
25
|
+
- name: Set up Ruby
|
26
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
27
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
28
|
+
# uses: ruby/setup-ruby@v1
|
29
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby-version }}
|
32
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
33
|
+
- name: Run tests
|
34
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/_yardoc/
|
4
|
-
/coverage/
|
5
|
-
/doc/
|
6
|
-
/pkg/
|
7
|
-
/spec/reports/
|
8
|
-
/tmp/
|
9
|
-
|
10
|
-
# rspec failure tracking
|
11
|
-
.rspec_status
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
|
10
|
+
# rspec failure tracking
|
11
|
+
.rspec_status
|
12
|
+
|
13
|
+
.env
|
data/.rspec
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
--format documentation
|
2
|
-
--color
|
3
|
-
--require spec_helper
|
1
|
+
--format documentation
|
2
|
+
--color
|
3
|
+
--require spec_helper
|
data/.travis.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
---
|
2
|
-
language: ruby
|
3
|
-
cache: bundler
|
4
|
-
rvm:
|
5
|
-
- 2.6.5
|
6
|
-
before_install: gem install bundler -v 2.1.4
|
1
|
+
---
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
rvm:
|
5
|
+
- 2.6.5
|
6
|
+
before_install: gem install bundler -v 2.1.4
|
data/Gemfile
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in notion-sdk-ruby.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
gem "rake", "~> 12.0"
|
7
|
-
gem "rspec", "~> 3.0"
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in notion-sdk-ruby.gemspec
|
4
|
+
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
notion-sdk-ruby (0.3.1)
|
5
|
+
httparty (~> 0.18.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.7.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
ast (2.4.2)
|
13
|
+
coderay (1.1.3)
|
14
|
+
crack (0.4.5)
|
15
|
+
rexml
|
16
|
+
diff-lcs (1.4.4)
|
17
|
+
dotenv (2.7.6)
|
18
|
+
hashdiff (1.0.1)
|
19
|
+
httparty (0.18.1)
|
20
|
+
mime-types (~> 3.0)
|
21
|
+
multi_xml (>= 0.5.2)
|
22
|
+
method_source (1.0.0)
|
23
|
+
mime-types (3.3.1)
|
24
|
+
mime-types-data (~> 3.2015)
|
25
|
+
mime-types-data (3.2021.0225)
|
26
|
+
multi_xml (0.6.0)
|
27
|
+
parallel (1.20.1)
|
28
|
+
parser (3.0.1.1)
|
29
|
+
ast (~> 2.4.1)
|
30
|
+
pry (0.14.1)
|
31
|
+
coderay (~> 1.1)
|
32
|
+
method_source (~> 1.0)
|
33
|
+
public_suffix (4.0.6)
|
34
|
+
rainbow (3.0.0)
|
35
|
+
rake (12.3.3)
|
36
|
+
regexp_parser (2.1.1)
|
37
|
+
rexml (3.2.5)
|
38
|
+
rspec (3.10.0)
|
39
|
+
rspec-core (~> 3.10.0)
|
40
|
+
rspec-expectations (~> 3.10.0)
|
41
|
+
rspec-mocks (~> 3.10.0)
|
42
|
+
rspec-core (3.10.0)
|
43
|
+
rspec-support (~> 3.10.0)
|
44
|
+
rspec-expectations (3.10.0)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.10.0)
|
47
|
+
rspec-mocks (3.10.0)
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
+
rspec-support (~> 3.10.0)
|
50
|
+
rspec-support (3.10.0)
|
51
|
+
rubocop (1.14.0)
|
52
|
+
parallel (~> 1.10)
|
53
|
+
parser (>= 3.0.0.0)
|
54
|
+
rainbow (>= 2.2.2, < 4.0)
|
55
|
+
regexp_parser (>= 1.8, < 3.0)
|
56
|
+
rexml
|
57
|
+
rubocop-ast (>= 1.5.0, < 2.0)
|
58
|
+
ruby-progressbar (~> 1.7)
|
59
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
60
|
+
rubocop-ast (1.5.0)
|
61
|
+
parser (>= 3.0.1.1)
|
62
|
+
rubocop-performance (1.11.2)
|
63
|
+
rubocop (>= 1.7.0, < 2.0)
|
64
|
+
rubocop-ast (>= 0.4.0)
|
65
|
+
ruby-progressbar (1.11.0)
|
66
|
+
standard (1.1.1)
|
67
|
+
rubocop (= 1.14.0)
|
68
|
+
rubocop-performance (= 1.11.2)
|
69
|
+
standardrb (1.0.0)
|
70
|
+
standard
|
71
|
+
unicode-display_width (2.0.0)
|
72
|
+
webmock (3.12.2)
|
73
|
+
addressable (>= 2.3.6)
|
74
|
+
crack (>= 0.3.2)
|
75
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
76
|
+
|
77
|
+
PLATFORMS
|
78
|
+
ruby
|
79
|
+
x64-mingw32
|
80
|
+
|
81
|
+
DEPENDENCIES
|
82
|
+
dotenv (~> 2.7)
|
83
|
+
notion-sdk-ruby!
|
84
|
+
pry (~> 0.14.1)
|
85
|
+
rake (~> 12.0)
|
86
|
+
rspec (~> 3.0)
|
87
|
+
standardrb (~> 1.0)
|
88
|
+
webmock (~> 3.12)
|
89
|
+
|
90
|
+
BUNDLED WITH
|
91
|
+
2.1.4
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2021 Graham Marlow
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Graham Marlow
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,40 +1,263 @@
|
|
1
|
-
# Notion
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
+
- [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
|
+
## Installation
|
33
|
+
|
34
|
+
Add this line to your application's Gemfile:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
gem 'notion-sdk-ruby'
|
38
|
+
```
|
39
|
+
|
40
|
+
And then execute:
|
41
|
+
|
42
|
+
$ bundle install
|
43
|
+
|
44
|
+
## Usage
|
45
|
+
|
46
|
+
Initialize `Notion::Client` with your app's [integration secret](https://developers.notion.com/docs/getting-started#create-a-new-integration).
|
47
|
+
|
48
|
+
```rb
|
49
|
+
require "notion-sdk-ruby"
|
50
|
+
client = Notion::Client.new(token: ENV["NOTION_API_SECRET"])
|
51
|
+
```
|
52
|
+
|
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
|
+
## Development
|
244
|
+
|
245
|
+
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.
|
246
|
+
|
247
|
+
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).
|
248
|
+
|
249
|
+
```
|
250
|
+
cat > .env <<EOF
|
251
|
+
API_SECRET=<YOUR NOTION API SECRET HERE>
|
252
|
+
EOF
|
253
|
+
```
|
254
|
+
|
255
|
+
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).
|
256
|
+
|
257
|
+
## Contributing
|
258
|
+
|
259
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mgmarlow/notion-sdk-ruby.
|
260
|
+
|
261
|
+
## License
|
262
|
+
|
263
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require "rspec/core/rake_task"
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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,14 +1,11 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
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
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "forwardable"
|
3
|
+
|
4
|
+
require "notion-sdk-ruby/version"
|
5
|
+
|
6
|
+
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
|
+
require "notion-sdk-ruby/request_client"
|
14
|
+
require "notion-sdk-ruby/client"
|
15
|
+
|
16
|
+
module Notion
|
17
|
+
@config = Config.new
|
18
|
+
|
19
|
+
class << self
|
20
|
+
extend Forwardable
|
21
|
+
|
22
|
+
attr_reader :config
|
23
|
+
|
24
|
+
def_delegators :@config, :api_token, :api_token=
|
25
|
+
def_delegators :@config, :notion_version, :notion_version=
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Notion
|
2
|
+
class Client
|
3
|
+
include Operations::Search
|
4
|
+
|
5
|
+
def initialize(token:, notion_version: "2021-05-13")
|
6
|
+
Notion.api_token = token
|
7
|
+
Notion.notion_version = notion_version
|
8
|
+
end
|
9
|
+
|
10
|
+
def blocks
|
11
|
+
Blocks.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def databases
|
15
|
+
Databases.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def pages
|
19
|
+
Pages.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def users
|
23
|
+
Users.new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Sourced from notion-sdk-js:
|
2
|
+
# https://github.com/makenotion/notion-sdk-js/blob/main/src/errors.ts
|
3
|
+
module Notion
|
4
|
+
API_ERROR_CODE = {
|
5
|
+
unauthorized: "unauthorized",
|
6
|
+
restricted_resource: "restricted_resource",
|
7
|
+
object_not_found: "object_not_found",
|
8
|
+
rate_limited: "rate_limited",
|
9
|
+
invalid_json: "invalid_json",
|
10
|
+
invalid_request_url: "invalid_request_url",
|
11
|
+
invalid_request: "invalid_request",
|
12
|
+
validation_error: "validation_error",
|
13
|
+
conflict_error: "conflict_error",
|
14
|
+
internal_server_error: "internal_server_error",
|
15
|
+
service_unavailable: "service_unavailable"
|
16
|
+
}
|
17
|
+
|
18
|
+
class ErrorFactory
|
19
|
+
def self.create(error = {})
|
20
|
+
return NotionError.new("Unknown error.") if error["message"].nil?
|
21
|
+
|
22
|
+
if API_ERROR_CODE.value?(error["code"])
|
23
|
+
APIResponseError.new(error["message"], body: error)
|
24
|
+
elsif error["request"] && error["response"] && error["timings"]
|
25
|
+
HTTPResponseError.new(error["message"], body: error)
|
26
|
+
elsif error["request"] && error["timings"]
|
27
|
+
RequestTimeoutError.new(error["message"], body: error)
|
28
|
+
else
|
29
|
+
NotionError.new(error["message"])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class NotionError < StandardError
|
35
|
+
attr_reader :message, :body
|
36
|
+
|
37
|
+
def initialize(message = nil, body: nil)
|
38
|
+
@message = message
|
39
|
+
@body = body
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class RequestTimeoutError < NotionError; end
|
44
|
+
|
45
|
+
class HTTPResponseError < NotionError; end
|
46
|
+
|
47
|
+
class APIResponseError < NotionError
|
48
|
+
def code
|
49
|
+
body["code"]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Notion
|
2
|
+
class RequestClient
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
base_uri "https://api.notion.com"
|
6
|
+
headers "Content-Type": "application/json"
|
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)
|
20
|
+
end
|
21
|
+
|
22
|
+
def post(*args, &block)
|
23
|
+
response = self.class.post(*args, &block)
|
24
|
+
raise_on_failure(response)
|
25
|
+
end
|
26
|
+
|
27
|
+
def patch(*args, &block)
|
28
|
+
response = self.class.patch(*args, &block)
|
29
|
+
raise_on_failure(response)
|
30
|
+
end
|
31
|
+
|
32
|
+
def put(*args, &block)
|
33
|
+
response = self.class.put(*args, &block)
|
34
|
+
raise_on_failure(response)
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete(*args, &block)
|
38
|
+
response = self.class.delete(*args, &block)
|
39
|
+
raise_on_failure(response)
|
40
|
+
end
|
41
|
+
|
42
|
+
def raise_on_failure(response)
|
43
|
+
if response.success?
|
44
|
+
response
|
45
|
+
else
|
46
|
+
raise ErrorFactory.create(response)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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
|
@@ -0,0 +1,15 @@
|
|
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
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
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
|
data/notion-sdk-ruby.gemspec
CHANGED
@@ -1,26 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
spec.
|
7
|
-
spec.
|
8
|
-
|
9
|
-
spec.
|
10
|
-
|
11
|
-
spec.
|
12
|
-
spec.
|
13
|
-
|
14
|
-
spec.
|
15
|
-
|
16
|
-
spec.metadata["
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
spec.
|
26
|
-
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require_relative "lib/notion-sdk-ruby/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "notion-sdk-ruby"
|
7
|
+
spec.version = Notion::VERSION
|
8
|
+
spec.authors = ["Graham Marlow"]
|
9
|
+
spec.email = ["mgmarlow@hey.com"]
|
10
|
+
|
11
|
+
spec.summary = "Notion SDK"
|
12
|
+
spec.homepage = "https://github.com/mgmarlow/notion-sdk-ruby"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/mgmarlow/notion-sdk-ruby"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/mgmarlow/notion-sdk-ruby/blob/master/CHANGELOG.md"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency "httparty", "~> 0.18.1"
|
30
|
+
|
31
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
spec.add_development_dependency "standardrb", "~> 1.0"
|
34
|
+
spec.add_development_dependency "webmock", "~> 3.12"
|
35
|
+
spec.add_development_dependency "pry", "~> 0.14.1"
|
36
|
+
spec.add_development_dependency "dotenv", "~> 2.7"
|
37
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notion-sdk-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Graham Marlow
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
12
|
-
dependencies:
|
11
|
+
date: 2021-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.18.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.18.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: standardrb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.12'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.12'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.14.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.14.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dotenv
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.7'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.7'
|
13
111
|
description:
|
14
112
|
email:
|
15
113
|
- mgmarlow@hey.com
|
@@ -17,17 +115,29 @@ executables: []
|
|
17
115
|
extensions: []
|
18
116
|
extra_rdoc_files: []
|
19
117
|
files:
|
118
|
+
- ".github/workflows/ci.yml"
|
20
119
|
- ".gitignore"
|
21
120
|
- ".rspec"
|
22
121
|
- ".travis.yml"
|
122
|
+
- ".vscode/settings.json"
|
23
123
|
- Gemfile
|
124
|
+
- Gemfile.lock
|
24
125
|
- LICENSE.txt
|
25
126
|
- README.md
|
26
127
|
- Rakefile
|
27
128
|
- bin/console
|
28
129
|
- bin/setup
|
29
|
-
- lib/notion
|
30
|
-
- lib/notion
|
130
|
+
- lib/notion-sdk-ruby.rb
|
131
|
+
- lib/notion-sdk-ruby/client.rb
|
132
|
+
- lib/notion-sdk-ruby/config.rb
|
133
|
+
- lib/notion-sdk-ruby/error.rb
|
134
|
+
- lib/notion-sdk-ruby/operations/search.rb
|
135
|
+
- 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
|
+
- lib/notion-sdk-ruby/version.rb
|
31
141
|
- notion-sdk-ruby.gemspec
|
32
142
|
homepage: https://github.com/mgmarlow/notion-sdk-ruby
|
33
143
|
licenses:
|
@@ -51,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
161
|
- !ruby/object:Gem::Version
|
52
162
|
version: '0'
|
53
163
|
requirements: []
|
54
|
-
rubygems_version: 3.
|
164
|
+
rubygems_version: 3.1.2
|
55
165
|
signing_key:
|
56
166
|
specification_version: 4
|
57
167
|
summary: Notion SDK
|
data/lib/notion/sdk/ruby.rb
DELETED