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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20e1bb5a2a25417881a39465bc72a003d9f8a3fc59ab0fcfd3378a6c87759753
4
- data.tar.gz: dfd32ada283cb93a62e8e9358abe25aadf56d1693ddd0b94e75d5a133669ed3c
3
+ metadata.gz: da15ba6b2f024300114602bd828c15ca06e04366336e3414b6c8a557011672ff
4
+ data.tar.gz: b729ffdea1ce51e5381a2dc1a296180bf4ae396ae1be526433fd8059f3a974a8
5
5
  SHA512:
6
- metadata.gz: 937c7196eced3be3cd9cd811242bccae35e8101dd6a5194bf35a39184b02aa810854dc5dd925e2f10af62df3206a6388c8757723cb762d1179cab07952e85f9c
7
- data.tar.gz: b651fdf6d3901fed41ebae4570267ca4641f6e84dd0b899622b02a5089dc98cedec5cbee005e523205f0c3d3824091ea2cb4f21947bf6edbb8a8450441ade347
6
+ metadata.gz: 2d6c904bc63780d5ce10688ac6033e7c62dacb72baaf5d451d7a2332ad4bf39719cb5f02b52e82f8b358543081c9008010f0cf1394e67f04aa047bbc9727cfc3
7
+ data.tar.gz: b29c7cbb03715c3d4390e0d0a94d36fecf175e8d38fb4713e82785ee8a240cf3a834b2fc157504040a546922ed039a0fe9d92b50896a61d034b9b0d44d9fda0d
@@ -0,0 +1,14 @@
1
+ on: [push, pull_request]
2
+ jobs:
3
+ test:
4
+ strategy:
5
+ matrix:
6
+ ruby: [2.5, 2.6, 2.7]
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - uses: ruby/setup-ruby@v1
11
+ with:
12
+ bundler-cache: true
13
+ ruby-version: ${{ matrix.ruby }}
14
+ - run: bundle exec rake
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rspec_status ADDED
@@ -0,0 +1,15 @@
1
+ example_id | status | run_time |
2
+ ---------------------------------------------------- | ------ | --------------- |
3
+ ./spec/notion/api/endpoints/databases_spec.rb[1:1:1] | passed | 0.01164 seconds |
4
+ ./spec/notion/api/endpoints/databases_spec.rb[1:1:2] | passed | 0.007 seconds |
5
+ ./spec/notion/api/endpoints/databases_spec.rb[1:1:3] | passed | 0.00692 seconds |
6
+ ./spec/notion/api/endpoints/databases_spec.rb[1:1:4] | passed | 0.00666 seconds |
7
+ ./spec/notion/api/endpoints/databases_spec.rb[1:1:5] | passed | 0.85972 seconds |
8
+ ./spec/notion/api/endpoints/pages_spec.rb[1:1:1] | passed | 0.00676 seconds |
9
+ ./spec/notion/api/endpoints/pages_spec.rb[1:1:2] | passed | 0.0063 seconds |
10
+ ./spec/notion/api/endpoints/pages_spec.rb[1:1:3] | passed | 0.00628 seconds |
11
+ ./spec/notion/api/endpoints/users_spec.rb[1:1:1] | passed | 0.00722 seconds |
12
+ ./spec/notion/api/endpoints/users_spec.rb[1:1:2] | passed | 0.00731 seconds |
13
+ ./spec/notion/api/endpoints/users_spec.rb[1:1:3] | passed | 0.00678 seconds |
14
+ ./spec/notion/config_spec.rb[1:1:1] | passed | 0.00009 seconds |
15
+ ./spec/notion/version_spec.rb[1:1] | passed | 0.00006 seconds |
data/.rubocop.yml ADDED
@@ -0,0 +1,46 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ require:
4
+ - rubocop-performance
5
+ - rubocop-rspec
6
+
7
+ AllCops:
8
+ DisplayCopNames: true
9
+ Exclude:
10
+ - bin/**/*
11
+ - vendor/**/*
12
+ - lib/notion/web/api/notion-api-ref/**/*
13
+ - lib/notion/web/api/endpoints/* # Auto-generated
14
+ - lib/notion/web/api/errors.rb # Auto-generated
15
+ - spec/notion/web/api/endpoints/* # Auto-generated
16
+
17
+ Layout/EmptyLineAfterMagicComment:
18
+ Enabled: false
19
+
20
+ Metrics/BlockLength:
21
+ Enabled: false
22
+
23
+ Metrics/ClassLength:
24
+ Max: 250
25
+
26
+ Layout/LineLength:
27
+ Max: 128
28
+
29
+ RSpec/ContextWording:
30
+ Enabled: false
31
+
32
+ RSpec/ExampleLength:
33
+ Enabled: false
34
+
35
+ RSpec/MultipleExpectations:
36
+ Enabled: false
37
+
38
+ Style/Documentation:
39
+ Enabled: false
40
+
41
+ Style/ModuleFunction:
42
+ Enabled: false
43
+
44
+ Naming/FileName:
45
+ Exclude:
46
+ - lib/notion-ruby-client.rb # Required to match gemspec name
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,86 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2021-04-25 19:55:01 +0200 using RuboCop version 0.82.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 3
10
+ # Cop supports --auto-correct.
11
+ Layout/EmptyLines:
12
+ Exclude:
13
+ - 'scratchpad.rb'
14
+ - 'spec/spec_helper.rb'
15
+
16
+ # Offense count: 5
17
+ # Configuration parameters: EnforcedStyle.
18
+ # SupportedStyles: native, lf, crlf
19
+ Layout/EndOfLine:
20
+ Exclude:
21
+ - 'Rakefile'
22
+ - 'spec/notion/config_spec.rb'
23
+ - 'spec/notion/version_spec.rb'
24
+ - 'spec/spec_helper.rb'
25
+ - 'spec/support/token.rb'
26
+
27
+ # Offense count: 26
28
+ # Cop supports --auto-correct.
29
+ # Configuration parameters: EnforcedStyle.
30
+ # SupportedStyles: final_newline, final_blank_line
31
+ Layout/TrailingEmptyLines:
32
+ Enabled: false
33
+
34
+ # Offense count: 1
35
+ # Cop supports --auto-correct.
36
+ Lint/NonDeterministicRequireOrder:
37
+ Exclude:
38
+ - 'spec/spec_helper.rb'
39
+
40
+ # Offense count: 1
41
+ Lint/UselessAssignment:
42
+ Exclude:
43
+ - 'scratchpad.rb'
44
+
45
+ # Offense count: 2
46
+ # Configuration parameters: IgnoredMethods.
47
+ Metrics/AbcSize:
48
+ Max: 30
49
+
50
+ # Offense count: 2
51
+ # Configuration parameters: IgnoredMethods.
52
+ Metrics/CyclomaticComplexity:
53
+ Max: 9
54
+
55
+ # Offense count: 4
56
+ # Configuration parameters: CountComments, ExcludedMethods.
57
+ Metrics/MethodLength:
58
+ Max: 23
59
+
60
+ # Offense count: 2
61
+ # Configuration parameters: IgnoredMethods.
62
+ Metrics/PerceivedComplexity:
63
+ Max: 9
64
+
65
+ # Offense count: 2
66
+ # Configuration parameters: AllowedChars.
67
+ Style/AsciiComments:
68
+ Exclude:
69
+ - 'lib/notion/api/endpoints/pages.rb'
70
+
71
+ # Offense count: 1
72
+ # Cop supports --auto-correct.
73
+ # Configuration parameters: EnforcedStyle.
74
+ # SupportedStyles: always, always_true, never
75
+ Style/FrozenStringLiteralComment:
76
+ Exclude:
77
+ - 'scratchpad.rb'
78
+
79
+ # Offense count: 2
80
+ # Cop supports --auto-correct.
81
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
82
+ # SupportedStyles: single_quotes, double_quotes
83
+ Style/StringLiterals:
84
+ Exclude:
85
+ - 'lib/notion/api/endpoints/pages.rb'
86
+ - 'lib/notion/api/endpoints/users.rb'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.0.4 (2020-04-25)
2
+
3
+ - Added specs and a CI process with GitHub Actions
4
+ - Add support for GET /databases, POST /databases/<:id>/query endpoints
5
+ - Add support for `content` when creating a page
6
+
1
7
  ### 0.0.3 (2020-01-30)
2
8
 
3
9
  - The gem now covers all available endpoints to date
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ notion-ruby-client (0.0.3)
5
+ faraday (>= 1.0)
6
+ faraday_middleware
7
+ hashie
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ addressable (2.7.0)
13
+ public_suffix (>= 2.0.2, < 5.0)
14
+ ast (2.4.2)
15
+ crack (0.4.5)
16
+ rexml
17
+ diff-lcs (1.4.4)
18
+ faraday (1.4.1)
19
+ faraday-excon (~> 1.1)
20
+ faraday-net_http (~> 1.0)
21
+ faraday-net_http_persistent (~> 1.1)
22
+ multipart-post (>= 1.2, < 3)
23
+ ruby2_keywords (>= 0.0.4)
24
+ faraday-excon (1.1.0)
25
+ faraday-net_http (1.0.1)
26
+ faraday-net_http_persistent (1.1.0)
27
+ faraday_middleware (1.0.0)
28
+ faraday (~> 1.0)
29
+ hashdiff (1.0.1)
30
+ hashie (4.1.0)
31
+ jaro_winkler (1.5.4)
32
+ multipart-post (2.1.1)
33
+ parallel (1.20.1)
34
+ parser (3.0.1.0)
35
+ ast (~> 2.4.1)
36
+ public_suffix (4.0.6)
37
+ rainbow (3.0.0)
38
+ rake (10.5.0)
39
+ rexml (3.2.5)
40
+ rspec (3.10.0)
41
+ rspec-core (~> 3.10.0)
42
+ rspec-expectations (~> 3.10.0)
43
+ rspec-mocks (~> 3.10.0)
44
+ rspec-core (3.10.1)
45
+ rspec-support (~> 3.10.0)
46
+ rspec-expectations (3.10.1)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.10.0)
49
+ rspec-mocks (3.10.2)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.10.0)
52
+ rspec-support (3.10.2)
53
+ rubocop (0.82.0)
54
+ jaro_winkler (~> 1.5.1)
55
+ parallel (~> 1.10)
56
+ parser (>= 2.7.0.1)
57
+ rainbow (>= 2.2.2, < 4.0)
58
+ rexml
59
+ ruby-progressbar (~> 1.7)
60
+ unicode-display_width (>= 1.4.0, < 2.0)
61
+ rubocop-performance (1.5.2)
62
+ rubocop (>= 0.71.0)
63
+ rubocop-rspec (1.39.0)
64
+ rubocop (>= 0.68.1)
65
+ ruby-progressbar (1.11.0)
66
+ ruby2_keywords (0.0.4)
67
+ timecop (0.9.4)
68
+ unicode-display_width (1.7.0)
69
+ vcr (6.0.0)
70
+ webmock (3.12.2)
71
+ addressable (>= 2.3.6)
72
+ crack (>= 0.3.2)
73
+ hashdiff (>= 0.4.0, < 2.0.0)
74
+
75
+ PLATFORMS
76
+ arm64-darwin-20
77
+ x86_64-linux
78
+
79
+ DEPENDENCIES
80
+ notion-ruby-client!
81
+ rake (~> 10)
82
+ rspec
83
+ rubocop (~> 0.82.0)
84
+ rubocop-performance (~> 1.5.2)
85
+ rubocop-rspec (~> 1.39.0)
86
+ timecop
87
+ vcr
88
+ webmock
89
+
90
+ BUNDLED WITH
91
+ 2.2.5
data/README.md CHANGED
@@ -24,7 +24,7 @@ Run `bundle install`.
24
24
 
25
25
  ### Create a New Bot Integration
26
26
 
27
- To integrate your bot with Notion, you must first create a new Notion Bot. (**TODO**: link to the docs)
27
+ To integrate your bot with Notion, you must first [create a new Notion Bot](https://www.notion.so/Getting-started-da32a6fc1bcc4403a6126ee735710d89).
28
28
 
29
29
  1. Log into the workspace that you want your integration to be associated with.
30
30
  2. Confirm that you are an Admin in the workspace (see Settings & Members > Members).
@@ -34,12 +34,172 @@ To integrate your bot with Notion, you must first create a new Notion Bot. (**TO
34
34
 
35
35
  ### Declare the API token
36
36
 
37
- ```
37
+ ```ruby
38
38
  Notion.configure do |config|
39
39
  config.token = ENV['NOTION_API_TOKEN']
40
40
  end
41
41
  ```
42
42
 
43
+ For Rails projects, the snippet above would go to `config/application.rb`.
44
+
43
45
  ### API Client
44
46
 
45
- TODO: document endpoints
47
+ #### Instanciating a new Notion API client
48
+
49
+ ```ruby
50
+ client = Notion::Client.new
51
+ ```
52
+
53
+ You can specify the token or logger on a per-client basis:
54
+
55
+ ```ruby
56
+ client = Notion::Client.new(token: '<secret Notion API token>')
57
+ ```
58
+
59
+ #### Users
60
+
61
+ Get a paginated list of [User objects](https://www.notion.so/User-object-4f8d1a2fc1e54680b5f810ed0c6903a6) for the workspace:
62
+
63
+ ```ruby
64
+ client.users_list # retrieves the first page
65
+
66
+ client.users_list(start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')
67
+
68
+ client.users_list do |page|
69
+ # paginate through all users
70
+ end
71
+ ```
72
+
73
+ Get a single User:
74
+
75
+ ```ruby
76
+ client.user(id: 'd40e767c-d7af-4b18-a86d-55c61f1e39a4')
77
+ ```
78
+
79
+ #### Databases
80
+
81
+ Gets a paginated array of Page objects contained in the requested database, filtered and ordered according to the filter and sort references provided in the request.
82
+
83
+ ```ruby
84
+ client.database_query(id: 'e383bcee-e0d8-4564-9c63-900d307abdb0') # retrieves the first page
85
+
86
+ client.database_query(id: 'e383bcee-e0d8-4564-9c63-900d307abdb0', start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')
87
+
88
+ client.database_query((id: 'e383bcee-e0d8-4564-9c63-900d307abdb0') do |page|
89
+ # paginate through all pages
90
+ end
91
+
92
+ # Filter and sort the database
93
+ sort = [
94
+ {
95
+ "property": "Last ordered",
96
+ "direction": "ascending"
97
+ }
98
+ ]
99
+ filter = {
100
+ "or": [
101
+ {
102
+ "property": "In stock",
103
+ "checkbox": {
104
+ "equals": true
105
+ }
106
+ },
107
+ {
108
+ "property": "Cost of next trip",
109
+ "number": {
110
+ "greater_than_or_equal_to": 2
111
+ }
112
+ }
113
+ ]
114
+ }
115
+ client.database_query(id: 'e383bcee-e0d8-4564-9c63-900d307abdb0', sort: sort, filter: filter)
116
+ ```
117
+
118
+ Get a single Database:
119
+
120
+ ```ruby
121
+ client.database(id: 'e383bcee-e0d8-4564-9c63-900d307abdb0')
122
+ ```
123
+
124
+ Lists databases:
125
+
126
+ ```ruby
127
+ client.databases_list # retrieves the first page
128
+
129
+ client.databases_list(start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')
130
+
131
+ client.databases_list do |page|
132
+ # paginate through all databases
133
+ end
134
+ ```
135
+
136
+ #### Pages
137
+
138
+ Create a page:
139
+
140
+ ```ruby
141
+ properties = {
142
+ "Name": [
143
+ {
144
+ "text": {
145
+ "content": "Tuscan Kale"
146
+ }
147
+ }
148
+ ],
149
+ "Description": [
150
+ {
151
+ "text": {
152
+ "content": "A dark green leafy vegetable"
153
+ }
154
+ }
155
+ ],
156
+ "Food group": {
157
+ "name": "🥦 Vegetable"
158
+ },
159
+ "Price": 2.5
160
+ }
161
+ children = [
162
+ {
163
+ "object": "block",
164
+ "type": "heading_2",
165
+ "heading_2": {
166
+ "text": [{ "type": "text", "text": { "content": "Lacinato kale" } }]
167
+ }
168
+ },
169
+ {
170
+ "object": "block",
171
+ "type": "paragraph",
172
+ "paragraph": {
173
+ "text": [
174
+ {
175
+ "type": "text",
176
+ "text": {
177
+ "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.",
178
+ "link": { "url": "https://en.wikipedia.org/wiki/Lacinato_kale" }
179
+ }
180
+ }
181
+ ]
182
+ }
183
+ }
184
+ ]
185
+ client.create_page(
186
+ parent: { database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0'},
187
+ properties: properties,
188
+ children: children
189
+ )
190
+ ```
191
+
192
+ Retrieve a page:
193
+
194
+ ```ruby
195
+ client.page(id: 'b55c9c91-384d-452b-81db-d1ef79372b75')
196
+ ```
197
+
198
+ Update page properties:
199
+
200
+ ```ruby
201
+ properties = {
202
+ "In stock": true
203
+ }
204
+ client.update_page(id: 'b55c9c91-384d-452b-81db-d1ef79372b75', properties: properties)
205
+ ```