notion-ruby-client 0.0.3 → 0.0.4
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 +14 -0
- data/.rspec +2 -0
- data/.rspec_status +15 -0
- data/.rubocop.yml +46 -0
- data/.rubocop_todo.yml +86 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +91 -0
- data/README.md +163 -3
- data/Rakefile +18 -0
- data/lib/notion-ruby-client.rb +6 -7
- data/lib/notion/api/endpoints/databases.rb +19 -1
- data/lib/notion/api/endpoints/pages.rb +3 -0
- data/lib/notion/config.rb +3 -1
- data/lib/notion/pagination/cursor.rb +1 -1
- data/lib/notion/version.rb +1 -1
- data/spec/fixtures/notion/create_page.yml +137 -0
- data/spec/fixtures/notion/database.yml +133 -0
- data/spec/fixtures/notion/database_query.yml +137 -0
- data/spec/fixtures/notion/databases_list.yml +133 -0
- data/spec/fixtures/notion/page.yml +133 -0
- data/spec/fixtures/notion/paginated_database_query.yml +139 -0
- data/spec/fixtures/notion/paginated_databases_list.yml +133 -0
- data/spec/fixtures/notion/paginated_users_list.yml +133 -0
- data/spec/fixtures/notion/update_page.yml +136 -0
- data/spec/fixtures/notion/users.yml +132 -0
- data/spec/fixtures/notion/users_list.yml +133 -0
- data/spec/notion/api/endpoints/databases_spec.rb +40 -0
- data/spec/notion/api/endpoints/pages_spec.rb +64 -0
- data/spec/notion/api/endpoints/users_spec.rb +26 -0
- data/spec/notion/config_spec.rb +16 -0
- data/spec/notion/version_spec.rb +8 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/token.rb +10 -0
- data/spec/support/vcr.rb +16 -0
- metadata +48 -3
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe Notion::Api::Endpoints::Databases do
|
5
|
+
let(:client) { Notion::Client.new }
|
6
|
+
let(:database_id) { '89b30a70-ce51-4646-ab4f-5fdcb1d5e76c' }
|
7
|
+
|
8
|
+
context 'databases' do
|
9
|
+
it 'retrieves', vcr: { cassette_name: 'database' } do
|
10
|
+
response = client.database(id: database_id)
|
11
|
+
expect(response.title.first.plain_text).to eql 'A Notion database'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'queries', vcr: { cassette_name: 'database_query' } do
|
15
|
+
response = client.database_query(id: database_id)
|
16
|
+
expect(response.results.length).to be >= 1
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'paginated queries', vcr: { cassette_name: 'paginated_database_query' } do
|
20
|
+
pages = []
|
21
|
+
client.database_query(id: database_id, limit: 1) do |page|
|
22
|
+
pages.concat page.results
|
23
|
+
end
|
24
|
+
expect(pages.size).to be >= 1
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'lists', vcr: { cassette_name: 'databases_list' } do
|
28
|
+
response = client.databases_list
|
29
|
+
expect(response.results.length).to be >= 1
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'paginated lists', vcr: { cassette_name: 'paginated_databases_list' } do
|
33
|
+
databases = []
|
34
|
+
client.databases_list(limit: 1) do |page|
|
35
|
+
databases.concat page.results
|
36
|
+
end
|
37
|
+
expect(databases.size).to be >= 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe Notion::Api::Endpoints::Pages do
|
5
|
+
let(:client) { Notion::Client.new }
|
6
|
+
let(:database_id) { '89b30a70-ce51-4646-ab4f-5fdcb1d5e76c' }
|
7
|
+
let(:page_id) { '723578f1-6e51-450c-8ee1-09158c19fd4c' }
|
8
|
+
let(:properties) do
|
9
|
+
{
|
10
|
+
"Name": [
|
11
|
+
{
|
12
|
+
"text": {
|
13
|
+
"content": 'Another Notion page'
|
14
|
+
}
|
15
|
+
}
|
16
|
+
]
|
17
|
+
}
|
18
|
+
end
|
19
|
+
let(:children) do
|
20
|
+
[
|
21
|
+
{
|
22
|
+
"object": 'block',
|
23
|
+
"type": 'heading_2',
|
24
|
+
"heading_2": {
|
25
|
+
"text": [{ "type": 'text', "text": { "content": 'A heading' } }]
|
26
|
+
}
|
27
|
+
}
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'pages' do
|
32
|
+
it 'retrieves', vcr: { cassette_name: 'page' } do
|
33
|
+
response = client.page(id: page_id)
|
34
|
+
expect(response.properties.Name.type).to eql 'title'
|
35
|
+
expect(response.properties.Name.title.first.plain_text).to eql 'A Notion page'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'creates', vcr: { cassette_name: 'create_page' } do
|
39
|
+
response = client.create_page(
|
40
|
+
parent: { database_id: database_id },
|
41
|
+
properties: properties,
|
42
|
+
children: children
|
43
|
+
)
|
44
|
+
expect(response.properties.Name.title.first.plain_text).to eql 'Another Notion page'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'updates', vcr: { cassette_name: 'update_page' } do
|
48
|
+
properties = {
|
49
|
+
"Name": [
|
50
|
+
{
|
51
|
+
"text": {
|
52
|
+
"content": 'A Notion page'
|
53
|
+
}
|
54
|
+
}
|
55
|
+
]
|
56
|
+
}
|
57
|
+
response = client.update_page(
|
58
|
+
id: page_id,
|
59
|
+
properties: properties
|
60
|
+
)
|
61
|
+
expect(response.properties.Name.title.first.plain_text).to eql 'A Notion page'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe Notion::Api::Endpoints::Users do
|
5
|
+
let(:client) { Notion::Client.new }
|
6
|
+
|
7
|
+
context 'users' do
|
8
|
+
it 'lists', vcr: { cassette_name: 'users_list' } do
|
9
|
+
response = client.users_list
|
10
|
+
expect(response.results.size).to be 3
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'paginated list', vcr: { cassette_name: 'paginated_users_list' } do
|
14
|
+
members = []
|
15
|
+
client.users_list(limit: 2) do |page|
|
16
|
+
members.concat page.results
|
17
|
+
end
|
18
|
+
expect(members.size).to eq 3
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'retrieves', vcr: { cassette_name: 'users' } do
|
22
|
+
response = client.user(id: 'a8da8d30-c858-4c3d-87ad-3f2d477bd98d')
|
23
|
+
expect(response.name).to eql 'Nicolas Goutay'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Notion::Config do
|
5
|
+
describe '#configure' do
|
6
|
+
before do
|
7
|
+
Notion.configure do |config|
|
8
|
+
config.token = 'a token'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'sets token' do
|
13
|
+
expect(Notion.config.token).to eq 'a token'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rspec'
|
6
|
+
require 'timecop'
|
7
|
+
|
8
|
+
require 'notion_ruby_client'
|
9
|
+
|
10
|
+
|
11
|
+
Dir[File.join(File.dirname(__FILE__), 'support', '**/*.rb')].each do |file|
|
12
|
+
require file
|
13
|
+
end
|
14
|
+
|
15
|
+
Notion.configure do |config|
|
16
|
+
config.token = ENV['NOTION_API_TOKEN']
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# Enable flags like --only-failures and --next-failure
|
21
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
22
|
+
end
|
data/spec/support/vcr.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'vcr'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
VCR.configure do |config|
|
6
|
+
config.cassette_library_dir = 'spec/fixtures/notion'
|
7
|
+
config.hook_into :webmock
|
8
|
+
# config.default_cassette_options = { record: :new_episodes }
|
9
|
+
config.configure_rspec_metadata!
|
10
|
+
config.before_record do |i|
|
11
|
+
if ENV.key?('NOTION_API_TOKEN')
|
12
|
+
i.request.headers['Authorization'].first.gsub!(ENV['NOTION_API_TOKEN'], '<NOTION_API_TOKEN>')
|
13
|
+
end
|
14
|
+
i.response.body.force_encoding('UTF-8')
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notion-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Goutay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -170,10 +170,17 @@ executables: []
|
|
170
170
|
extensions: []
|
171
171
|
extra_rdoc_files: []
|
172
172
|
files:
|
173
|
+
- ".github/workflows/ci.yml"
|
174
|
+
- ".rspec"
|
175
|
+
- ".rspec_status"
|
176
|
+
- ".rubocop.yml"
|
177
|
+
- ".rubocop_todo.yml"
|
173
178
|
- CHANGELOG.md
|
174
179
|
- Gemfile
|
180
|
+
- Gemfile.lock
|
175
181
|
- LICENSE.md
|
176
182
|
- README.md
|
183
|
+
- Rakefile
|
177
184
|
- lib/notion-ruby-client.rb
|
178
185
|
- lib/notion.rb
|
179
186
|
- lib/notion/api/endpoints.rb
|
@@ -198,6 +205,25 @@ files:
|
|
198
205
|
- notion-ruby-client.gemspec
|
199
206
|
- scratchpad.rb
|
200
207
|
- screenshots/create_notion_bot.png
|
208
|
+
- spec/fixtures/notion/create_page.yml
|
209
|
+
- spec/fixtures/notion/database.yml
|
210
|
+
- spec/fixtures/notion/database_query.yml
|
211
|
+
- spec/fixtures/notion/databases_list.yml
|
212
|
+
- spec/fixtures/notion/page.yml
|
213
|
+
- spec/fixtures/notion/paginated_database_query.yml
|
214
|
+
- spec/fixtures/notion/paginated_databases_list.yml
|
215
|
+
- spec/fixtures/notion/paginated_users_list.yml
|
216
|
+
- spec/fixtures/notion/update_page.yml
|
217
|
+
- spec/fixtures/notion/users.yml
|
218
|
+
- spec/fixtures/notion/users_list.yml
|
219
|
+
- spec/notion/api/endpoints/databases_spec.rb
|
220
|
+
- spec/notion/api/endpoints/pages_spec.rb
|
221
|
+
- spec/notion/api/endpoints/users_spec.rb
|
222
|
+
- spec/notion/config_spec.rb
|
223
|
+
- spec/notion/version_spec.rb
|
224
|
+
- spec/spec_helper.rb
|
225
|
+
- spec/support/token.rb
|
226
|
+
- spec/support/vcr.rb
|
201
227
|
homepage: http://github.com/orbit-love/notion-ruby-client
|
202
228
|
licenses:
|
203
229
|
- MIT
|
@@ -221,4 +247,23 @@ rubygems_version: 3.1.4
|
|
221
247
|
signing_key:
|
222
248
|
specification_version: 4
|
223
249
|
summary: Notion API client for Ruby.
|
224
|
-
test_files:
|
250
|
+
test_files:
|
251
|
+
- spec/fixtures/notion/create_page.yml
|
252
|
+
- spec/fixtures/notion/database.yml
|
253
|
+
- spec/fixtures/notion/database_query.yml
|
254
|
+
- spec/fixtures/notion/databases_list.yml
|
255
|
+
- spec/fixtures/notion/page.yml
|
256
|
+
- spec/fixtures/notion/paginated_database_query.yml
|
257
|
+
- spec/fixtures/notion/paginated_databases_list.yml
|
258
|
+
- spec/fixtures/notion/paginated_users_list.yml
|
259
|
+
- spec/fixtures/notion/update_page.yml
|
260
|
+
- spec/fixtures/notion/users.yml
|
261
|
+
- spec/fixtures/notion/users_list.yml
|
262
|
+
- spec/notion/api/endpoints/databases_spec.rb
|
263
|
+
- spec/notion/api/endpoints/pages_spec.rb
|
264
|
+
- spec/notion/api/endpoints/users_spec.rb
|
265
|
+
- spec/notion/config_spec.rb
|
266
|
+
- spec/notion/version_spec.rb
|
267
|
+
- spec/spec_helper.rb
|
268
|
+
- spec/support/token.rb
|
269
|
+
- spec/support/vcr.rb
|