notion-sdk-ruby 0.2.3 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7e21c20b56990d0f42d1df0130e4e3f3d7835727d4802cd230b7bb5daaa4109
4
- data.tar.gz: 1ad409bdc5168dac0f604e62efda59ca5b1d343a353b6492f42f9daaf650fe57
3
+ metadata.gz: 264919d7cc99bb5460d6a900a69b5c4875f93e523f518f2ec30b965af04e0b7e
4
+ data.tar.gz: 790b82c77a361b0b04f5715d4e545c695e3f8ea11696dda5d234ff8ea74ea7e3
5
5
  SHA512:
6
- metadata.gz: cd38bbbb96dd0c1fbf80bf419032a9e00be069de0c5e74ed921f1d6fb06846064d773fe0ad046cd2b8f7d38b9496247a307f48ac485c720e4877d20b52b9b1b0
7
- data.tar.gz: 3beaf308945c7e566a74a63068f078bc211e07a74e0d677beb0788c2073c3d360f583204648bb522f54f012fad877e4dd92e2c0ebf585afda878bc2fd2071d9f
6
+ metadata.gz: 525cb12a872f7e9d950f9e8c3f1faf928c5cb0e54a8dfa950895e01898c9eaaf4d40242db33d41954ef08bca139be192225cd5ea67c2da118e828f647825911f
7
+ data.tar.gz: 3baf444a17c65f6c859018ea6ef8d95c45b16dbfa88e9941282de746f89554102fed5c290a840abcd9f0423da65574ff725f918a6185aa2f32ac3787e6e99b63
@@ -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,13 +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
12
-
13
- .env
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
@@ -1,4 +1,4 @@
1
- {
2
- "editor.formatOnSave": true,
3
- "editor.tabSize": 2
1
+ {
2
+ "editor.formatOnSave": true,
3
+ "editor.tabSize": 2
4
4
  }
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- notion-sdk-ruby (0.2.3)
4
+ notion-sdk-ruby (0.4.1)
5
5
  httparty (~> 0.18.1)
6
6
 
7
7
  GEM
@@ -22,7 +22,7 @@ GEM
22
22
  method_source (1.0.0)
23
23
  mime-types (3.3.1)
24
24
  mime-types-data (~> 3.2015)
25
- mime-types-data (3.2021.0225)
25
+ mime-types-data (3.2021.0901)
26
26
  multi_xml (0.6.0)
27
27
  parallel (1.20.1)
28
28
  parser (3.0.1.1)
@@ -88,4 +88,4 @@ DEPENDENCIES
88
88
  webmock (~> 3.12)
89
89
 
90
90
  BUNDLED WITH
91
- 2.1.4
91
+ 2.2.3
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,211 +1,339 @@
1
- # Notion Ruby SDK
2
-
3
- Unofficial Ruby client for the [Notion APIs](https://developers.notion.com/).
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'notion-sdk-ruby'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle install
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install notion-sdk-ruby
20
-
21
- ## Usage
22
-
23
- Initialize `Notion::Client` with your app's [integration secret](https://developers.notion.com/docs/getting-started#create-a-new-integration).
24
-
25
- ```rb
26
- require "notion-sdk-ruby"
27
- client = Notion::Client.new(token: ENV["NOTION_API_SECRET"])
28
-
29
- # get users
30
- client.get_users
31
- ```
32
-
33
- ### Databases
34
-
35
- #### #get_database
36
-
37
- ```rb
38
- client.get_database("668d797c-76fa-4934-9b05-ad288df2d136")
39
- ```
40
-
41
- #### #get_databases
42
-
43
- ```rb
44
- client.get_databases
45
- ```
46
-
47
- #### #query_database
48
-
49
- ```rb
50
- client.query_database("668d797c-76fa-4934-9b05-ad288df2d136", {
51
- "filter": {
52
- "or": [
53
- {
54
- "property": "In stock",
55
- "checkbox": {
56
- "equals": true
57
- }
58
- },
59
- {
60
- "property": "Cost of next trip",
61
- "number": {
62
- "greater_than_or_equal_to": 2
63
- }
64
- }
65
- ]
66
- },
67
- "sorts": [
68
- {
69
- "property": "Last ordered",
70
- "direction": "ascending"
71
- }
72
- ]
73
- })
74
- ```
75
-
76
- ### Pages
77
-
78
- #### #get_page
79
-
80
- ```rb
81
- client.get_page("b55c9c91-384d-452b-81db-d1ef79372b75")
82
- ```
83
-
84
- #### #create_page
85
-
86
- ```rb
87
- client.create_page({
88
- "parent": { "database_id": "48f8fee9cd794180bc2fec0398253067" },
89
- "properties": {
90
- "Name": {
91
- "title": [
92
- {
93
- "text": {
94
- "content": "Tuscan Kale"
95
- }
96
- }
97
- ]
98
- },
99
- "Description": {
100
- "rich_text": [
101
- {
102
- "text": {
103
- "content": "A dark green leafy vegetable"
104
- }
105
- }
106
- ]
107
- },
108
- "Food group": {
109
- "select": {
110
- "name": "Vegetable"
111
- }
112
- },
113
- "Price": { "number": 2.5 }
114
- },
115
- "children": []
116
- })
117
- ```
118
-
119
- #### #update_page
120
-
121
- ```rb
122
- client.update_page("b55c9c91-384d-452b-81db-d1ef79372b75", {
123
- "properties": {
124
- "In stock": { "checkbox": true }
125
- }
126
- })
127
- ```
128
-
129
- ### Blocks
130
-
131
- #### #get_block_children
132
-
133
- ```rb
134
- client.get_block_children("b55c9c91-384d-452b-81db-d1ef79372b75", {
135
- page_size: 100
136
- })
137
- ```
138
-
139
- #### #append_block_children
140
-
141
- ```rb
142
- client.append_block_children("b54c9c91-384d-452b-81db-d1ef79372b75", {
143
- "children": [
144
- {
145
- "object": "block",
146
- "type": "heading_1",
147
- "heading_1": {
148
- "text": [{ "type": "text", "text": { "content": "Lacinato kale" } }]
149
- }
150
- },
151
- {
152
- "object": "block",
153
- "type": "paragraph",
154
- "paragraph": {
155
- "text": [
156
- {
157
- "type": "text",
158
- "text": {
159
- "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.",
160
- "link": { "url": "https://en.wikipedia.org/wiki/Lacinato_kale" }
161
- }
162
- }
163
- ]
164
- }
165
- }
166
- ]
167
- })
168
- ```
169
-
170
- ### Users
171
-
172
- #### #get_user
173
-
174
- ```rb
175
- client.get_user("d40e767c-d7af-4b18-a86d-55c61f1e39a4")
176
- ```
177
-
178
- #### #get_users
179
-
180
- ```rb
181
- client.get_users
182
- ```
183
-
184
- ### Search
185
-
186
- #### #search
187
-
188
- ```rb
189
- client.search({
190
- "query":"External tasks",
191
- "sort":{
192
- "direction":"ascending",
193
- "timestamp":"last_edited_time"
194
- }
195
- }
196
- )
197
- ```
198
-
199
- ## Development
200
-
201
- 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.
202
-
203
- 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).
204
-
205
- ## Contributing
206
-
207
- Bug reports and pull requests are welcome on GitHub at https://github.com/mgmarlow/notion-sdk-ruby.
208
-
209
- ## License
210
-
211
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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/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"
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
@@ -1,12 +1,26 @@
1
1
  module Notion
2
2
  class Client
3
- include Endpoints
4
- include HTTParty
5
- headers 'Content-Type': "application/json"
6
- base_uri "https://api.notion.com"
3
+ include Operations::Search
7
4
 
8
- def initialize(token:)
9
- self.class.headers({Authorization: "Bearer #{token}"})
5
+ def initialize(token:, notion_version: "2021-08-16")
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
10
24
  end
11
25
  end
12
26
  end
@@ -0,0 +1,5 @@
1
+ module Notion
2
+ class Config
3
+ attr_accessor :api_token, :notion_version
4
+ end
5
+ 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,9 @@
1
+ module Notion
2
+ module Operations
3
+ module Search
4
+ def search(body)
5
+ RequestClient.active_client.post("/v1/search", body: body.to_json)
6
+ end
7
+ end
8
+ end
9
+ 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,25 @@
1
+ module Notion
2
+ class Blocks
3
+ def children
4
+ Children.new
5
+ end
6
+
7
+ def retrieve(block_id)
8
+ RequestClient.active_client.get("/v1/blocks/#{block_id}")
9
+ end
10
+
11
+ def update(block_id, body)
12
+ RequestClient.active_client.patch("/v1/blocks/#{block_id}", body: body.to_json)
13
+ end
14
+ end
15
+
16
+ class Children
17
+ def list(block_id, query: {})
18
+ RequestClient.active_client.get("/v1/blocks/#{block_id}/children", query: query)
19
+ end
20
+
21
+ def append(block_id, body)
22
+ RequestClient.active_client.patch("/v1/blocks/#{block_id}/children", body: body.to_json)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module Notion
2
+ class Databases
3
+ def retrieve(id)
4
+ RequestClient.active_client.get("/v1/databases/#{id}")
5
+ end
6
+
7
+ # DEPRECATED
8
+ def list
9
+ warn "DEPRECATED: client.databases.list is deprecated."
10
+ RequestClient.active_client.get("/v1/databases")
11
+ end
12
+
13
+ def query(id, body)
14
+ RequestClient.active_client.post("/v1/databases/#{id}/query", body: body.to_json)
15
+ end
16
+
17
+ def create(body)
18
+ RequestClient.active_client.post("/v1/databases", body: body.to_json)
19
+ end
20
+
21
+ def update(id, body)
22
+ RequestClient.active_client.patch("/v1/databases/#{id}", body: body.to_json)
23
+ end
24
+ end
25
+ 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
@@ -0,0 +1,11 @@
1
+ module Notion
2
+ class Users
3
+ def list
4
+ RequestClient.active_client.get("/v1/users")
5
+ end
6
+
7
+ def retrieve(id)
8
+ RequestClient.active_client.get("/v1/users/#{id}")
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Notion
2
- VERSION = "0.2.3"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -1,13 +1,27 @@
1
1
  require "httparty"
2
+ require "forwardable"
3
+
2
4
  require "notion-sdk-ruby/version"
3
- require "notion-sdk-ruby/endpoints/blocks"
4
- require "notion-sdk-ruby/endpoints/databases"
5
- require "notion-sdk-ruby/endpoints/pages"
6
- require "notion-sdk-ruby/endpoints/search"
7
- require "notion-sdk-ruby/endpoints/users"
8
- require "notion-sdk-ruby/endpoints"
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"
9
14
  require "notion-sdk-ruby/client"
10
15
 
11
16
  module Notion
12
- class Error < StandardError; end
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
13
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion-sdk-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.4.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-05-17 00:00:00.000000000 Z
11
+ date: 2021-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -115,7 +115,7 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
- - ".github/workflows/ruby.yml"
118
+ - ".github/workflows/ci.yml"
119
119
  - ".gitignore"
120
120
  - ".rspec"
121
121
  - ".travis.yml"
@@ -129,12 +129,14 @@ files:
129
129
  - bin/setup
130
130
  - lib/notion-sdk-ruby.rb
131
131
  - lib/notion-sdk-ruby/client.rb
132
- - lib/notion-sdk-ruby/endpoints.rb
133
- - lib/notion-sdk-ruby/endpoints/blocks.rb
134
- - lib/notion-sdk-ruby/endpoints/databases.rb
135
- - lib/notion-sdk-ruby/endpoints/pages.rb
136
- - lib/notion-sdk-ruby/endpoints/search.rb
137
- - lib/notion-sdk-ruby/endpoints/users.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
138
140
  - lib/notion-sdk-ruby/version.rb
139
141
  - notion-sdk-ruby.gemspec
140
142
  homepage: https://github.com/mgmarlow/notion-sdk-ruby
@@ -159,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
161
  - !ruby/object:Gem::Version
160
162
  version: '0'
161
163
  requirements: []
162
- rubygems_version: 3.0.3
164
+ rubygems_version: 3.1.2
163
165
  signing_key:
164
166
  specification_version: 4
165
167
  summary: Notion SDK
@@ -1,35 +0,0 @@
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: Ruby
9
-
10
- on:
11
- push:
12
- branches: [ main ]
13
- pull_request:
14
- branches: [ main ]
15
-
16
- jobs:
17
- test:
18
-
19
- runs-on: ubuntu-latest
20
- strategy:
21
- matrix:
22
- ruby-version: ['2.6', '2.7', '3.0']
23
-
24
- steps:
25
- - uses: actions/checkout@v2
26
- - name: Set up Ruby
27
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
- # uses: ruby/setup-ruby@v1
30
- uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
31
- with:
32
- ruby-version: ${{ matrix.ruby-version }}
33
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
- - name: Run tests
35
- run: bundle exec rake
@@ -1,13 +0,0 @@
1
- module Notion
2
- module Endpoints
3
- module Blocks
4
- def get_block_children(id, params: {})
5
- self.class.get("/v1/blocks/#{id}/children", query: params)
6
- end
7
-
8
- def append_block_children(id, body)
9
- self.class.patch("/v1/blocks/#{id}/children", body: body.to_json)
10
- end
11
- end
12
- end
13
- end
@@ -1,17 +0,0 @@
1
- module Notion
2
- module Endpoints
3
- module Databases
4
- def get_database(id)
5
- self.class.get("/v1/databases/#{id}")
6
- end
7
-
8
- def get_databases
9
- self.class.get("/v1/databases")
10
- end
11
-
12
- def query_database(id, body)
13
- self.class.post("/v1/databases/#{id}/query", body: body.to_json)
14
- end
15
- end
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- module Notion
2
- module Endpoints
3
- module Pages
4
- def get_page(id)
5
- self.class.get("/v1/pages/#{id}")
6
- end
7
-
8
- def create_page(body)
9
- self.class.post("/v1/pages", body: body.to_json)
10
- end
11
-
12
- def update_page(id, body)
13
- self.class.patch("/v1/pages/#{id}", body: body.to_json)
14
- end
15
- end
16
- end
17
- end
@@ -1,9 +0,0 @@
1
- module Notion
2
- module Endpoints
3
- module Search
4
- def search(body)
5
- self.class.post("/v1/search", body: body.to_json)
6
- end
7
- end
8
- end
9
- end
@@ -1,13 +0,0 @@
1
- module Notion
2
- module Endpoints
3
- module Users
4
- def get_users
5
- self.class.get("/v1/users")
6
- end
7
-
8
- def get_user(id)
9
- self.class.get("/v1/users/#{id}")
10
- end
11
- end
12
- end
13
- end
@@ -1,9 +0,0 @@
1
- module Notion
2
- module Endpoints
3
- include Databases
4
- include Pages
5
- include Blocks
6
- include Users
7
- include Search
8
- end
9
- end