notion-sdk-ruby 0.3.0 → 0.5.0

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: 646301fd9a326d4b9d74cb514b948f85ff38dc0c7f001edd5c94285510029088
4
- data.tar.gz: a544ddbd17c26ba618082eb04dc2e3e268da12b1b9d729fbf9109c8d642fc803
3
+ metadata.gz: b40512cee112cf660970e4dc0f41d9b2396435c0d0af1b4d360ab17d643fcce6
4
+ data.tar.gz: 05d7805fdafc25fc3537a4853e61f136c9fbcc49a404559c55288b157c989b0c
5
5
  SHA512:
6
- metadata.gz: 256824b18cfead3ab2630a96906022a5d8e936c3323824c5dd72e6605592c67fc2fa94d59f71796365e3639ced885b7f3344f6f39300fa7b74211be1ee618506
7
- data.tar.gz: e7ec55aea773b32cead4f0ce0a788435abdd7e45f7a7050f9541a0c3514d612786f4be6661fa1fb35ddc904ca8961d363120d02a57035e14683f3c6d7c20eb80
6
+ metadata.gz: '08740b69d9ecdcba0c13e0401095cff74fdfa0be56993061bce45b89b9f8b5d42bbbe1d02dc04e5554b021b1b27b0bc8c183a9c425fb00ed9be6bcc4d84cc184'
7
+ data.tar.gz: 327b799e2eeb70ed8b1a48296853972579749baeba824f05f10ba506388b1527f1eecb6ad7f774918259bd4bf673748525bfdc56ae7da08787aa266d5b9344bf
@@ -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,29 +1,55 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- notion-sdk-ruby (0.3.0)
5
- httparty (~> 0.18.1)
4
+ notion-sdk-ruby (0.5.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.8.0)
27
+ faraday-em_http (~> 1.0)
28
+ faraday-em_synchrony (~> 1.0)
29
+ faraday-excon (~> 1.1)
30
+ faraday-httpclient (~> 1.0.1)
31
+ faraday-net_http (~> 1.0)
32
+ faraday-net_http_persistent (~> 1.1)
33
+ faraday-patron (~> 1.0)
34
+ faraday-rack (~> 1.0)
35
+ multipart-post (>= 1.2, < 3)
36
+ ruby2_keywords (>= 0.0.4)
37
+ faraday-em_http (1.0.0)
38
+ faraday-em_synchrony (1.0.0)
39
+ faraday-excon (1.1.0)
40
+ faraday-httpclient (1.0.1)
41
+ faraday-net_http (1.0.1)
42
+ faraday-net_http_persistent (1.2.0)
43
+ faraday-patron (1.0.0)
44
+ faraday-rack (1.0.0)
45
+ faraday_middleware (1.1.0)
46
+ faraday (~> 1.0)
18
47
  hashdiff (1.0.1)
19
- httparty (0.18.1)
20
- mime-types (~> 3.0)
21
- multi_xml (>= 0.5.2)
48
+ i18n (1.8.10)
49
+ concurrent-ruby (~> 1.0)
22
50
  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)
51
+ minitest (5.14.4)
52
+ multipart-post (2.1.1)
27
53
  parallel (1.20.1)
28
54
  parser (3.0.1.1)
29
55
  ast (~> 2.4.1)
@@ -63,22 +89,27 @@ GEM
63
89
  rubocop (>= 1.7.0, < 2.0)
64
90
  rubocop-ast (>= 0.4.0)
65
91
  ruby-progressbar (1.11.0)
92
+ ruby2_keywords (0.0.5)
66
93
  standard (1.1.1)
67
94
  rubocop (= 1.14.0)
68
95
  rubocop-performance (= 1.11.2)
69
96
  standardrb (1.0.0)
70
97
  standard
98
+ tzinfo (2.0.4)
99
+ concurrent-ruby (~> 1.0)
71
100
  unicode-display_width (2.0.0)
72
101
  webmock (3.12.2)
73
102
  addressable (>= 2.3.6)
74
103
  crack (>= 0.3.2)
75
104
  hashdiff (>= 0.4.0, < 2.0.0)
105
+ zeitwerk (2.4.2)
76
106
 
77
107
  PLATFORMS
78
108
  ruby
79
109
  x64-mingw32
80
110
 
81
111
  DEPENDENCIES
112
+ activesupport (~> 6.1)
82
113
  dotenv (~> 2.7)
83
114
  notion-sdk-ruby!
84
115
  pry (~> 0.14.1)
@@ -88,4 +119,4 @@ DEPENDENCIES
88
119
  webmock (~> 3.12)
89
120
 
90
121
  BUNDLED WITH
91
- 2.1.4
122
+ 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,7 +1,38 @@
1
1
  # Notion Ruby SDK
2
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
+
3
6
  Unofficial Ruby client for the [Notion APIs](https://developers.notion.com/).
4
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
+
5
36
  ## Installation
6
37
 
7
38
  Add this line to your application's Gemfile:
@@ -49,31 +80,81 @@ client.databases.list
49
80
 
50
81
  ```rb
51
82
  client.databases.query("668d797c-76fa-4934-9b05-ad288df2d136", {
52
- "filter": {
53
- "or": [
83
+ filter: {
84
+ or: [
54
85
  {
55
- "property": "In stock",
56
- "checkbox": {
57
- "equals": true
86
+ property: "In stock",
87
+ checkbox: {
88
+ equals: true
58
89
  }
59
90
  },
60
91
  {
61
- "property": "Cost of next trip",
62
- "number": {
63
- "greater_than_or_equal_to": 2
92
+ property: "Cost of next trip",
93
+ number: {
94
+ greater_than_or_equal_to: 2
64
95
  }
65
96
  }
66
97
  ]
67
98
  },
68
- "sorts": [
99
+ sorts: [
69
100
  {
70
- "property": "Last ordered",
71
- "direction": "ascending"
101
+ property: "Last ordered",
102
+ direction: "ascending"
72
103
  }
73
104
  ]
74
105
  })
75
106
  ```
76
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
+
77
158
  ### Pages
78
159
 
79
160
  #### pages#retrieve
@@ -90,34 +171,34 @@ client.pages.retrieve("b55c9c91-384d-452b-81db-d1ef79372b75")
90
171
 
91
172
  ```rb
92
173
  client.pages.create({
93
- "parent": { "database_id": "48f8fee9cd794180bc2fec0398253067" },
94
- "properties": {
95
- "Name": {
96
- "title": [
174
+ parent: { database_id: "48f8fee9cd794180bc2fec0398253067" },
175
+ properties: {
176
+ Name: {
177
+ title: [
97
178
  {
98
- "text": {
99
- "content": "Tuscan Kale"
179
+ text: {
180
+ content: "Tuscan Kale"
100
181
  }
101
182
  }
102
183
  ]
103
184
  },
104
- "Description": {
105
- "rich_text": [
185
+ Description: {
186
+ rich_text: [
106
187
  {
107
- "text": {
108
- "content": "A dark green leafy vegetable"
188
+ text: {
189
+ content: "A dark green leafy vegetable"
109
190
  }
110
191
  }
111
192
  ]
112
193
  },
113
- "Food group": {
114
- "select": {
115
- "name": "Vegetable"
194
+ Food group: {
195
+ select: {
196
+ name: "Vegetable"
116
197
  }
117
198
  },
118
- "Price": { "number": 2.5 }
199
+ Price: { number: 2.5 }
119
200
  },
120
- "children": []
201
+ children: []
121
202
  })
122
203
  ```
123
204
 
@@ -127,14 +208,37 @@ client.pages.create({
127
208
 
128
209
  ```rb
129
210
  client.pages.update("b55c9c91-384d-452b-81db-d1ef79372b75", {
130
- "properties": {
131
- "In stock": { "checkbox": true }
211
+ properties: {
212
+ "In stock": { checkbox: true }
132
213
  }
133
214
  })
134
215
  ```
135
216
 
136
217
  ### Blocks
137
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
+
138
242
  #### blocks#children#list
139
243
 
140
244
  [API reference](https://developers.notion.com/reference/get-block-children)
@@ -151,24 +255,24 @@ client.blocks.children.list("b55c9c91-384d-452b-81db-d1ef79372b75", {
151
255
 
152
256
  ```rb
153
257
  client.blocks.children.append("b54c9c91-384d-452b-81db-d1ef79372b75", {
154
- "children": [
258
+ children: [
155
259
  {
156
- "object": "block",
157
- "type": "heading_1",
158
- "heading_1": {
159
- "text": [{ "type": "text", "text": { "content": "Lacinato kale" } }]
260
+ object: "block",
261
+ type: "heading_1",
262
+ heading_1: {
263
+ text: [{ type: "text", text: { content: "Lacinato kale" } }]
160
264
  }
161
265
  },
162
266
  {
163
- "object": "block",
164
- "type": "paragraph",
165
- "paragraph": {
166
- "text": [
267
+ object: "block",
268
+ type: "paragraph",
269
+ paragraph: {
270
+ text: [
167
271
  {
168
- "type": "text",
169
- "text": {
170
- "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.",
171
- "link": { "url": "https://en.wikipedia.org/wiki/Lacinato_kale" }
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" }
172
276
  }
173
277
  }
174
278
  ]
@@ -204,19 +308,26 @@ client.users.list
204
308
 
205
309
  ```rb
206
310
  client.search({
207
- "query":"External tasks",
208
- "sort":{
209
- "direction":"ascending",
210
- "timestamp":"last_edited_time"
211
- }
311
+ query: "External tasks",
312
+ sort: {
313
+ direction: "ascending",
314
+ timestamp: "last_edited_time"
212
315
  }
213
- )
316
+ })
214
317
  ```
215
318
 
216
319
  ## Development
217
320
 
218
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.
219
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
+
220
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).
221
332
 
222
333
  ## Contributing
data/bin/console CHANGED
@@ -7,6 +7,5 @@ require 'dotenv/load'
7
7
  require "notion-sdk-ruby"
8
8
 
9
9
  $client = Notion::Client.new(token: ENV["API_SECRET"])
10
- $client2 = Notion::Client.new(token: ENV["API_SECRET"])
11
10
 
12
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,9 +1,11 @@
1
1
  module Notion
2
2
  class Client
3
+ include RequestClient
3
4
  include Operations::Search
4
5
 
5
- def initialize(token:)
6
+ def initialize(token:, notion_version: "2021-08-16")
6
7
  Notion.api_token = token
8
+ Notion.notion_version = notion_version
7
9
  end
8
10
 
9
11
  def blocks
@@ -1,5 +1,5 @@
1
1
  module Notion
2
2
  class Config
3
- attr_accessor :api_token
3
+ attr_accessor :api_token, :notion_version
4
4
  end
5
5
  end
@@ -0,0 +1,4 @@
1
+ module Notion
2
+ class Block < OpenStruct
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Notion
2
+ class Database < OpenStruct
3
+ end
4
+ end
@@ -0,0 +1,27 @@
1
+ module Notion
2
+ class List
3
+ attr_reader :data, :next_cursor, :has_more
4
+
5
+ def initialize(response_body)
6
+ @data = response_body["results"].map do |d|
7
+ get_model(d["object"]).new(d)
8
+ end
9
+
10
+ @next_cursor = response_body["next_cursor"]
11
+ @has_more = response_body["has_more"]
12
+ end
13
+
14
+ def get_model(object_name)
15
+ case object_name
16
+ when "block"
17
+ Block
18
+ when "database"
19
+ Database
20
+ when "page"
21
+ Page
22
+ when "user"
23
+ User
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ module Notion
2
+ class Page < OpenStruct
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Notion
2
+ class User < OpenStruct
3
+ end
4
+ end
@@ -1,8 +1,11 @@
1
1
  module Notion
2
2
  module Operations
3
3
  module Search
4
+ include RequestClient
5
+
4
6
  def search(body)
5
- RequestClient.active_client.post("/v1/search", body: body.to_json)
7
+ response = post("/v1/search", body.to_json)
8
+ List.new(response.body)
6
9
  end
7
10
  end
8
11
  end
@@ -1,48 +1,44 @@
1
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)
2
+ module RequestClient
3
+ def get(*args)
4
+ handle_request(:get, *args)
10
5
  end
11
6
 
12
- def initialize(config)
13
- self.class.headers Authorization: "Bearer #{config.api_token}"
7
+ def post(*args)
8
+ handle_request(:post, *args)
14
9
  end
15
10
 
16
- def get(*args, &block)
17
- response = self.class.get(*args, &block)
18
- raise_on_failure(response)
11
+ def patch(*args)
12
+ handle_request(:patch, *args)
19
13
  end
20
14
 
21
- def post(*args, &block)
22
- response = self.class.post(*args, &block)
23
- raise_on_failure(response)
15
+ def delete(*args)
16
+ handle_request(:delete, *args)
24
17
  end
25
18
 
26
- def patch(*args, &block)
27
- response = self.class.patch(*args, &block)
28
- raise_on_failure(response)
29
- end
30
-
31
- def put(*args, &block)
32
- response = self.class.put(*args, &block)
33
- raise_on_failure(response)
34
- end
19
+ private
35
20
 
36
- def delete(*args, &block)
37
- response = self.class.delete(*args, &block)
38
- raise_on_failure(response)
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)
39
28
  end
40
29
 
41
- def raise_on_failure(response)
42
- if response.success?
43
- response
44
- else
45
- raise ErrorFactory.create(response)
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
46
42
  end
47
43
  end
48
44
  end
@@ -1,17 +1,33 @@
1
1
  module Notion
2
2
  class Blocks
3
+ include RequestClient
4
+
3
5
  def children
4
6
  Children.new
5
7
  end
8
+
9
+ def retrieve(block_id)
10
+ response = get("/v1/blocks/#{block_id}")
11
+ Block.new(response.body)
12
+ end
13
+
14
+ def update(block_id, body)
15
+ response = patch("/v1/blocks/#{block_id}", body.to_json)
16
+ Block.new(response.body)
17
+ end
6
18
  end
7
19
 
8
20
  class Children
21
+ include RequestClient
22
+
9
23
  def list(block_id, query: {})
10
- RequestClient.active_client.get("/v1/blocks/#{block_id}/children", query: query)
24
+ response = get("/v1/blocks/#{block_id}/children", query: query)
25
+ List.new(response.body)
11
26
  end
12
27
 
13
28
  def append(block_id, body)
14
- RequestClient.active_client.patch("/v1/blocks/#{block_id}/children", body: body.to_json)
29
+ response = patch("/v1/blocks/#{block_id}/children", body.to_json)
30
+ Block.new(response.body)
15
31
  end
16
32
  end
17
33
  end
@@ -1,15 +1,32 @@
1
1
  module Notion
2
2
  class Databases
3
+ include RequestClient
4
+
3
5
  def retrieve(id)
4
- RequestClient.active_client.get("/v1/databases/#{id}")
6
+ response = get("/v1/databases/#{id}")
7
+ Database.new(response.body)
5
8
  end
6
9
 
10
+ # DEPRECATED
7
11
  def list
8
- RequestClient.active_client.get("/v1/databases")
12
+ warn "DEPRECATED: client.databases.list is deprecated."
13
+ response = get("/v1/databases")
14
+ List.new(response.body)
9
15
  end
10
16
 
11
17
  def query(id, body)
12
- RequestClient.active_client.post("/v1/databases/#{id}/query", body: body.to_json)
18
+ response = post("/v1/databases/#{id}/query", body.to_json)
19
+ List.new(response.body)
20
+ end
21
+
22
+ def create(body)
23
+ response = post("/v1/databases", body.to_json)
24
+ Database.new(response.body)
25
+ end
26
+
27
+ def update(id, body)
28
+ response = patch("/v1/databases/#{id}", body.to_json)
29
+ Database.new(response.body)
13
30
  end
14
31
  end
15
32
  end
@@ -1,15 +1,20 @@
1
1
  module Notion
2
2
  class Pages
3
+ include RequestClient
4
+
3
5
  def retrieve(id)
4
- RequestClient.active_client.get("/v1/pages/#{id}")
6
+ response = get("/v1/pages/#{id}")
7
+ Page.new(response.body)
5
8
  end
6
9
 
7
10
  def create(body)
8
- RequestClient.active_client.post("/v1/pages", body: body.to_json)
11
+ response = post("/v1/pages", body.to_json)
12
+ Page.new(response.body)
9
13
  end
10
14
 
11
15
  def update(id, body)
12
- RequestClient.active_client.patch("/v1/pages/#{id}", body: body.to_json)
16
+ response = patch("/v1/pages/#{id}", body.to_json)
17
+ Page.new(response.body)
13
18
  end
14
19
  end
15
20
  end
@@ -1,11 +1,15 @@
1
1
  module Notion
2
2
  class Users
3
+ include RequestClient
4
+
3
5
  def list
4
- RequestClient.active_client.get("/v1/users")
6
+ response = get("/v1/users")
7
+ List.new(response.body)
5
8
  end
6
9
 
7
10
  def retrieve(id)
8
- RequestClient.active_client.get("/v1/users/#{id}")
11
+ response = get("/v1/users/#{id}")
12
+ User.new(response.body)
9
13
  end
10
14
  end
11
15
  end
@@ -1,3 +1,3 @@
1
1
  module Notion
2
- VERSION = "0.3.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -1,17 +1,23 @@
1
- require "httparty"
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"
8
+ require "notion-sdk-ruby/request_client"
7
9
  require "notion-sdk-ruby/resources/blocks"
8
10
  require "notion-sdk-ruby/resources/databases"
9
11
  require "notion-sdk-ruby/resources/pages"
10
12
  require "notion-sdk-ruby/resources/users"
11
13
  require "notion-sdk-ruby/operations/search"
12
14
  require "notion-sdk-ruby/error"
13
- require "notion-sdk-ruby/request_client"
14
15
  require "notion-sdk-ruby/client"
16
+ require "notion-sdk-ruby/models/user"
17
+ require "notion-sdk-ruby/models/list"
18
+ require "notion-sdk-ruby/models/block"
19
+ require "notion-sdk-ruby/models/database"
20
+ require "notion-sdk-ruby/models/page"
15
21
 
16
22
  module Notion
17
23
  @config = Config.new
@@ -22,5 +28,6 @@ module Notion
22
28
  attr_reader :config
23
29
 
24
30
  def_delegators :@config, :api_token, :api_token=
31
+ def_delegators :@config, :notion_version, :notion_version=
25
32
  end
26
33
  end
@@ -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 "httparty", "~> 0.18.1"
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,5 @@ 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"
37
39
  end
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.3.0
4
+ version: 0.5.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: 2021-05-23 00:00:00.000000000 Z
11
+ date: 2021-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: httparty
14
+ name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.18.1
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: 0.18.1
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,20 @@ 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'
111
139
  description:
112
140
  email:
113
141
  - mgmarlow@hey.com
@@ -115,7 +143,7 @@ executables: []
115
143
  extensions: []
116
144
  extra_rdoc_files: []
117
145
  files:
118
- - ".github/workflows/ruby.yml"
146
+ - ".github/workflows/ci.yml"
119
147
  - ".gitignore"
120
148
  - ".rspec"
121
149
  - ".travis.yml"
@@ -131,6 +159,11 @@ files:
131
159
  - lib/notion-sdk-ruby/client.rb
132
160
  - lib/notion-sdk-ruby/config.rb
133
161
  - lib/notion-sdk-ruby/error.rb
162
+ - lib/notion-sdk-ruby/models/block.rb
163
+ - lib/notion-sdk-ruby/models/database.rb
164
+ - lib/notion-sdk-ruby/models/list.rb
165
+ - lib/notion-sdk-ruby/models/page.rb
166
+ - lib/notion-sdk-ruby/models/user.rb
134
167
  - lib/notion-sdk-ruby/operations/search.rb
135
168
  - lib/notion-sdk-ruby/request_client.rb
136
169
  - lib/notion-sdk-ruby/resources/blocks.rb
@@ -161,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
194
  - !ruby/object:Gem::Version
162
195
  version: '0'
163
196
  requirements: []
164
- rubygems_version: 3.0.3
197
+ rubygems_version: 3.1.2
165
198
  signing_key:
166
199
  specification_version: 4
167
200
  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