notion-ruby-client 1.2.0 → 1.2.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: 8e4e676c9ca818a9cdcab31f6b085d00860bd74a102f668fdbe60cd209eaa442
4
- data.tar.gz: 57c19debac66cc452d441ce718bdd4f1d410c2884ac1b422d75cfe0fa228b043
3
+ metadata.gz: 8efd1d425881a003b3c1260955894754f4e9715c94351b3f626a274bd480b84f
4
+ data.tar.gz: 56dd489369c6920beb24de71efa8bf87a947ad6759d97d5b00354eab1e428bf9
5
5
  SHA512:
6
- metadata.gz: fb1a69701d1b81d3209f9b4d36fb73e204d60fd6239be0b922fa7ea6ebf5ac24ec62bf7949cbfee34867ec5da706d1446ccde8a733d46eefad3fe6dda9cd2929
7
- data.tar.gz: 38dde2575a611e67d4b6222f6c79299aef06869e72963765ba850ad567c1b36b77e5cb521c60c1ba9044537b6a4a7f781e276604e0770c61b69b96726596f97c
6
+ metadata.gz: 3f7c5bdfd8b31ba2715c72868df79bb0bda240c7a57a5bc499d643cf871fd71ee5243cdf92838ff4f6af3ef65de641d1803bcc4550d7b158f3ed3823d844edf2
7
+ data.tar.gz: d95c91aac3fa0e04529851a144ce21e3e28be1d9a03bcf4091b4970d81a3d6949a1b9cb396dd7aaaf6c2ffa18ebae29056acc8ce8abfca974c768d2feb206b3c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 1.2.1 (2023-02-26)
2
+
3
+ #### New
4
+
5
+ - Add support for creating a page as child of another page (thanks @TABeauchat!)
6
+
1
7
  ### 1.2.0 (2023-02-26)
2
8
 
3
9
  #### New
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- notion-ruby-client (1.2.0)
4
+ notion-ruby-client (1.2.1)
5
5
  dotenv
6
6
  faraday (>= 2.0)
7
7
  faraday-mashify (>= 0.1.1)
data/README.md CHANGED
@@ -283,6 +283,8 @@ If the parent is a page, the only valid property is `title`.
283
283
 
284
284
  The new page may include page content, described as [blocks](https://developers.notion.com/reference-link/block) in the children parameter.
285
285
 
286
+ The following example creates a new page within the specified database:
287
+
286
288
  ```ruby
287
289
  properties = {
288
290
  'Name': {
@@ -346,6 +348,54 @@ client.create_page(
346
348
  )
347
349
  ```
348
350
 
351
+ This example creates a new page as a child of an existing page.
352
+
353
+ ```ruby
354
+ properties = {
355
+ title: [
356
+ {
357
+ "type": "text",
358
+ "text": {
359
+ "content": "My favorite food",
360
+ "link": null
361
+ }
362
+ }
363
+ ]
364
+ }
365
+ children = [
366
+ {
367
+ 'object': 'block',
368
+ 'type': 'heading_2',
369
+ 'heading_2': {
370
+ 'rich_text': [{
371
+ 'type': 'text',
372
+ 'text': { 'content': 'Lacinato kale' }
373
+ }]
374
+ }
375
+ },
376
+ {
377
+ 'object': 'block',
378
+ 'type': 'paragraph',
379
+ 'paragraph': {
380
+ 'rich_text': [
381
+ {
382
+ 'type': 'text',
383
+ 'text': {
384
+ '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.',
385
+ 'link': { 'url': 'https://en.wikipedia.org/wiki/Lacinato_kale' }
386
+ }
387
+ }
388
+ ]
389
+ }
390
+ }
391
+ ]
392
+ client.create_page(
393
+ parent: { page_id: 'feb1cdfaab6a43cea4ecbc9e8de63ef7'},
394
+ properties: properties,
395
+ children: children
396
+ )
397
+ ```
398
+
349
399
  See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/post-page).
350
400
 
351
401
  #### Update page
@@ -38,7 +38,10 @@ module Notion
38
38
  # @option options [Object] :children
39
39
  # An optional array of Block objects representing the Page’s content
40
40
  def create_page(options = {})
41
- throw ArgumentError.new('Required argument :parent.database_id missing') if options.dig(:parent, :database_id).nil?
41
+ if options.dig(:parent, :database_id).nil? && options.dig(:parent, :page_id).nil?
42
+ throw ArgumentError.new('Required argument :parent.database_id or :parent.page_id required')
43
+ end
44
+
42
45
  post("pages", options)
43
46
  end
44
47
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Notion
3
- VERSION = '1.2.0'
3
+ VERSION = '1.2.1'
4
4
  NOTION_REQUEST_VERSION = '2022-02-22'
5
5
  end
@@ -0,0 +1,128 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.notion.com/v1/pages
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"parent":{"page_id":"0593a719ff2e44aaa14a2bf169429284"},"properties":{"title":[{"text":{"content":"Another
9
+ Notion page"}}]},"children":[{"object":"block","type":"heading_2","heading_2":{"rich_text":[{"type":"text","text":{"content":"My
10
+ Heading 2"}}]}}]}'
11
+ headers:
12
+ Accept:
13
+ - application/json; charset=utf-8
14
+ User-Agent:
15
+ - Notion Ruby Client/1.2.0
16
+ Authorization:
17
+ - Bearer <NOTION_API_TOKEN>
18
+ Notion-Version:
19
+ - '2022-02-22'
20
+ Content-Type:
21
+ - application/json
22
+ Accept-Encoding:
23
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
24
+ response:
25
+ status:
26
+ code: 200
27
+ message: OK
28
+ headers:
29
+ Date:
30
+ - Sun, 26 Feb 2023 17:21:54 GMT
31
+ Content-Type:
32
+ - application/json; charset=utf-8
33
+ Transfer-Encoding:
34
+ - chunked
35
+ Connection:
36
+ - keep-alive
37
+ Set-Cookie:
38
+ - __cf_bm=3uGTzmXnS9NSPlzB6MC25WX5a50pZafwabcoIG1k3mg-1677432114-0-AcTcZQhFHvWa2oYDeQ8RwgCXQcgn4zIPacEQnLYxg9MB0SGg74A/jZJePnsEBSNvZvZk9t9E1pL0T1zkr/KLHZE=;
39
+ path=/; expires=Sun, 26-Feb-23 17:51:54 GMT; domain=.notion.com; HttpOnly;
40
+ Secure; SameSite=None
41
+ - notion_browser_id=1d39e7da-f4cd-4161-ac33-b489ee848b04; Domain=www.notion.so;
42
+ Path=/; Expires=Mon, 26 Feb 2024 17:21:53 GMT; Secure
43
+ - notion_check_cookie_consent=false; Domain=www.notion.so; Path=/; Expires=Mon,
44
+ 27 Feb 2023 17:21:53 GMT; Secure
45
+ Content-Security-Policy:
46
+ - "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://gist.github.com https://apis.google.com
47
+ https://www.google.com https://www.gstatic.com https://cdn.amplitude.com https://api.amplitude.com
48
+ http://dev-embed.notion.co http://embed.notion.co https://widget.intercom.io
49
+ https://js.intercomcdn.com https://static.zdassets.com https://api.smooch.io\t
50
+ https://logs-01.loggly.com https://http-inputs-notion.splunkcloud.com https://cdn.segment.com
51
+ https://analytics.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com
52
+ https://js.stripe.com https://embed.typeform.com https://admin.typeform.com
53
+ https://public.profitwell.com https://static.profitwell.com js.sentry-cdn.com
54
+ https://js.chilipiper.com https://platform.twitter.com https://cdn.syndication.twimg.com
55
+ https://accounts.google.com https://www.googletagmanager.com https://www.googleadservices.com
56
+ https://googleads.g.doubleclick.net https://api-v2.mutinyhq.io https://client-registry.mutinycdn.com
57
+ https://client.mutinycdn.com https://user-data.mutinycdn.com https://cdn.metadata.io
58
+ https://platformapi.metadata.io https://d2hrivdxn8ekm8.cloudfront.net https://d1lu3pmaz2ilpx.cloudfront.net
59
+ https://dvqigh9b7wa32.cloudfront.net https://d330aiyvva2oww.cloudfront.net
60
+ https://cdn.transcend.io https://cdn01.boxcdn.net https://cdn.sprig.com assets.customer.io
61
+ code.gist.build;connect-src 'self' data: blob: https://msgstore.www.notion.so
62
+ wss://msgstore.www.notion.so ws://localhost:* ws://127.0.0.1:* https://notion-emojis.s3-us-west-2.amazonaws.com
63
+ https://s3-us-west-2.amazonaws.com https://s3.us-west-2.amazonaws.com https://notion-production-snapshots-2.s3.us-west-2.amazonaws.com
64
+ https://cdn.amplitude.com https://api.amplitude.com https://www.notion.so
65
+ https://api.embed.ly http://dev-embed.notion.co http://embed.notion.co https://js.intercomcdn.com
66
+ https://api-iam.intercom.io https://uploads.intercomcdn.com wss://nexus-websocket-a.intercom.io
67
+ https://ekr.zdassets.com https://ekr.zendesk.com\t https://makenotion.zendesk.com\t
68
+ https://api.smooch.io\t wss://api.smooch.io\t https://logs-01.loggly.com https://http-inputs-notion.splunkcloud.com
69
+ https://cdn.segment.com https://api.segment.io https://analytics.pgncs.notion.so
70
+ https://api.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com
71
+ https://js.stripe.com https://cdn.contentful.com https://preview.contentful.com
72
+ https://images.ctfassets.net https://www2.profitwell.com https://tracking.chilipiper.com
73
+ https://api.chilipiper.com https://api.unsplash.com https://boards-api.greenhouse.io
74
+ https://accounts.google.com https://oauth2.googleapis.com https://www.googletagmanager.com
75
+ https://analytics.google.com https://www.googleadservices.com https://googleads.g.doubleclick.net
76
+ https://region1.google-analytics.com https://region1.analytics.google.com
77
+ https://www.google-analytics.com https://api-v2.mutinyhq.io https://client-registry.mutinycdn.com
78
+ https://client.mutinycdn.com https://user-data.mutinycdn.com https://cdn.metadata.io
79
+ https://platformapi.metadata.io https://d2hrivdxn8ekm8.cloudfront.net https://d1lu3pmaz2ilpx.cloudfront.net
80
+ https://dvqigh9b7wa32.cloudfront.net https://d330aiyvva2oww.cloudfront.net
81
+ https://cdn.transcend.io https://telemetry.transcend.io https://api.statuspage.io
82
+ https://pgncd.notion.so https://api.statsig.com https://statsigapi.net https://exp.notion.so
83
+ https://file.notion.so notion://file.notion.so https://api.box.com https://*.mux.com
84
+ https://api.sprig.com https://storage.googleapis.com https://cdn.sprig.com
85
+ https://cdn.userleap.com track.customer.io *.api.gist.build *.cloud.gist.build;font-src
86
+ 'self' data: https://cdnjs.cloudflare.com https://js.intercomcdn.com https://cdn01.boxcdn.net;img-src
87
+ 'self' data: blob: https: https://platform.twitter.com https://syndication.twitter.com
88
+ https://pbs.twimg.com https://ton.twimg.com https://region1.google-analytics.com
89
+ https://region1.analytics.google.com https://file.notion.so notion://file.notion.so
90
+ https://*.mux.com track.customer.io;style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com
91
+ https://github.githubassets.com https://js.chilipiper.com https://platform.twitter.com
92
+ https://ton.twimg.com https://accounts.google.com https://cdn.transcend.io
93
+ https://cdn01.boxcdn.net code.gist.build;media-src blob: https: http: https://file.notion.so
94
+ notion://file.notion.so https://*.mux.com;worker-src blob:;frame-src https:
95
+ http: https://accounts.google.com renderer.gist.build code.gist.build"
96
+ X-Dns-Prefetch-Control:
97
+ - 'off'
98
+ X-Frame-Options:
99
+ - SAMEORIGIN
100
+ Strict-Transport-Security:
101
+ - max-age=5184000; includeSubDomains
102
+ X-Download-Options:
103
+ - noopen
104
+ X-Content-Type-Options:
105
+ - nosniff
106
+ X-Permitted-Cross-Domain-Policies:
107
+ - none
108
+ Referrer-Policy:
109
+ - strict-origin-when-cross-origin
110
+ X-Xss-Protection:
111
+ - '0'
112
+ Etag:
113
+ - W/"31f-hsLSu/ULQ6imEDuQTPedr2r+doc"
114
+ Vary:
115
+ - Accept-Encoding
116
+ Cf-Cache-Status:
117
+ - DYNAMIC
118
+ Server:
119
+ - cloudflare
120
+ Cf-Ray:
121
+ - 79fa5c17e98d82f8-IAD
122
+ body:
123
+ encoding: UTF-8
124
+ string: '{"object":"page","id":"c40d2199-e67f-4e07-875d-29f6259e7101","created_time":"2023-02-26T17:21:00.000Z","last_edited_time":"2023-02-26T17:21:00.000Z","created_by":{"object":"user","id":"baa602ec-7138-420d-bce4-a7c6cf125aa4"},"last_edited_by":{"object":"user","id":"baa602ec-7138-420d-bce4-a7c6cf125aa4"},"cover":null,"icon":null,"parent":{"type":"page_id","page_id":"0593a719-ff2e-44aa-a14a-2bf169429284"},"archived":false,"properties":{"title":{"id":"title","type":"title","title":[{"type":"text","text":{"content":"Another
125
+ Notion page","link":null},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"Another
126
+ Notion page","href":null}]}},"url":"https://www.notion.so/Another-Notion-page-c40d2199e67f4e07875d29f6259e7101"}'
127
+ recorded_at: Sun, 26 Feb 2023 17:21:54 GMT
128
+ recorded_with: VCR 6.0.0
@@ -47,6 +47,47 @@ RSpec.describe Notion::Api::Endpoints::Pages do
47
47
  expect(response.properties.Name.title.first.plain_text).to eql 'Another Notion page'
48
48
  end
49
49
 
50
+ context 'when creating under parent page' do
51
+ let(:parent_page) { '0593a719-ff2e-44aa-a14a-2bf169429284' }
52
+ let(:properties) do
53
+ {
54
+ "title": [
55
+ {
56
+ "text": {
57
+ "content": 'Another Notion page'
58
+ }
59
+ }
60
+ ]
61
+ }
62
+ end
63
+ let(:children) do
64
+ [
65
+ {
66
+ "object": 'block',
67
+ "type": 'heading_2',
68
+ "heading_2": {
69
+ rich_text: [
70
+ {
71
+ type: 'text',
72
+ text: { content: 'My Heading 2' }
73
+ }
74
+ ]
75
+ }
76
+ }
77
+ ]
78
+ end
79
+
80
+ it 'creates', vcr: { cassette_name: 'create_page_with_parent_page' } do
81
+ response = client.create_page(
82
+ parent: { page_id: parent_page },
83
+ properties: properties,
84
+ children: children
85
+ )
86
+ expect(response.parent.page_id).to eql parent_page
87
+ expect(response.properties.title.title.first.plain_text).to eql 'Another Notion page'
88
+ end
89
+ end
90
+
50
91
  it 'updates', vcr: { cassette_name: 'update_page' } do
51
92
  properties = {
52
93
  "Name": [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Goutay
@@ -249,6 +249,7 @@ files:
249
249
  - spec/fixtures/notion/create_discussion_comment.yml
250
250
  - spec/fixtures/notion/create_page.yml
251
251
  - spec/fixtures/notion/create_page_comment.yml
252
+ - spec/fixtures/notion/create_page_with_parent_page.yml
252
253
  - spec/fixtures/notion/database.yml
253
254
  - spec/fixtures/notion/database_query.yml
254
255
  - spec/fixtures/notion/delete_block.yml
@@ -311,6 +312,7 @@ test_files:
311
312
  - spec/fixtures/notion/create_discussion_comment.yml
312
313
  - spec/fixtures/notion/create_page.yml
313
314
  - spec/fixtures/notion/create_page_comment.yml
315
+ - spec/fixtures/notion/create_page_with_parent_page.yml
314
316
  - spec/fixtures/notion/database.yml
315
317
  - spec/fixtures/notion/database_query.yml
316
318
  - spec/fixtures/notion/delete_block.yml