notion-ruby-client 0.0.2 → 0.0.3

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: f21b181770c49f8d02f34bdcf949fbc19ccbbd7e7cb62bee02163abf64fd80f5
4
- data.tar.gz: 599580c1772892e31227fe369fdb478408442c12320f8fb6109da32f58f516ca
3
+ metadata.gz: 20e1bb5a2a25417881a39465bc72a003d9f8a3fc59ab0fcfd3378a6c87759753
4
+ data.tar.gz: dfd32ada283cb93a62e8e9358abe25aadf56d1693ddd0b94e75d5a133669ed3c
5
5
  SHA512:
6
- metadata.gz: 59d8fe6a3a90b9286cb5a09561263d4bb48330727d0c3daa0752aa11d5caeadeb02a66287e64dd9efa25dc72c31e0dc28aa91d233974ce93b3dda68734fabd75
7
- data.tar.gz: 8d9c80c3d970fcb0e3715d325c091d3f95b85172850cc671c4a4f651e507e4b3adb8886aabd2a1288035be82f415013a26a5a3c583fc3db1e68d6926a2ebb3b9
6
+ metadata.gz: 937c7196eced3be3cd9cd811242bccae35e8101dd6a5194bf35a39184b02aa810854dc5dd925e2f10af62df3206a6388c8757723cb762d1179cab07952e85f9c
7
+ data.tar.gz: b651fdf6d3901fed41ebae4570267ca4641f6e84dd0b899622b02a5089dc98cedec5cbee005e523205f0c3d3824091ea2cb4f21947bf6edbb8a8450441ade347
@@ -0,0 +1,12 @@
1
+ ### 0.0.3 (2020-01-30)
2
+
3
+ - The gem now covers all available endpoints to date
4
+ - Better error handling and logging
5
+
6
+ ### 0.0.2 (2020-01-29)
7
+
8
+ - Fixed blocking bug present in 0.0.1
9
+
10
+ ### 0.0.1 (2020-01-29)
11
+
12
+ - Initial alpha public release. Suffers from a bug that prevents installation.
@@ -1,10 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'endpoints/databases'
4
+ require_relative 'endpoints/pages'
3
5
  require_relative 'endpoints/users'
4
6
 
5
7
  module Notion
6
8
  module Api
7
9
  module Endpoints
10
+ include Databases
11
+ include Pages
8
12
  include Users
9
13
  end
10
14
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Notion
4
+ module Api
5
+ module Endpoints
6
+ module Databases
7
+ #
8
+ # Retrieves a Database object using the ID specified in the request.
9
+ #
10
+ # Returns a 404 HTTP response if the database doesn't exist, or if the bot
11
+ # doesn't have access to the database. Returns a 429 HTTP response if the
12
+ # request exceeds Notion's Request limits.
13
+ #
14
+ # @option options [id] :id
15
+ # Database to get info on.
16
+ def database(options = {})
17
+ throw ArgumentError.new('Required arguments :id missing') if options[:id].nil?
18
+ get("databases/#{options[:id]}")
19
+ end
20
+
21
+ #
22
+ # Gets a paginated array of Page object s contained in the requested database,
23
+ # filtered and ordered according to the filter and sort objects provided in the request.
24
+ #
25
+ # Filters are similar to the filters provided in the Notion UI. Filters operate
26
+ # on database properties and can be combined. If no filter is provided, all the
27
+ # pages in the database will be returned with pagination.
28
+ #
29
+ # Sorts are similar to the sorts provided in the Notion UI. Sorts operate on
30
+ # database properties and can be combined. The order of the sorts in the request
31
+ # matter, with earlier sorts taking precedence over later ones.
32
+ #
33
+ # @option options [id] :id
34
+ # Database to query.
35
+ #
36
+ # @option options [Object] :filter
37
+ # When supplied, limits which pages are returned based on the provided criteria.
38
+ #
39
+ # @option options [[Object]] :sorts
40
+ # When supplied, sorts the results based on the provided criteria.
41
+ #
42
+ # @option options [UUID] :start_cursor
43
+ # Paginate through collections of data by setting the cursor parameter
44
+ # to a start_cursor attribute returned by a previous request's next_cursor.
45
+ # Default value fetches the first "page" of the collection.
46
+ # See pagination for more detail.
47
+ def database_query(options = {})
48
+ throw ArgumentError.new('Required arguments :id missing') if options[:id].nil?
49
+ if block_given?
50
+ Pagination::Cursor.new(self, :database_query, options).each do |page|
51
+ yield page
52
+ end
53
+ else
54
+ post("databases/#{options[:id]}", options)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Notion
4
+ module Api
5
+ module Endpoints
6
+ module Pages
7
+ #
8
+ # Retrieves a 📄Page object using the ID specified in the request path.
9
+ # Note that this version of the API only exposes page properties, not page content
10
+ #
11
+ # @option options [id] :id
12
+ # Page to get info on.
13
+ #
14
+ # @option options [bool] :archived
15
+ # Set to true to retrieve an archived page; must be false or omitted to
16
+ # retrieve a page that has not been archived. Defaults to false.
17
+ def page(options = {})
18
+ throw ArgumentError.new('Required arguments :id missing') if options[:id].nil?
19
+ get("pages/#{options[:id]}?archived=#{options[:archived]}")
20
+ end
21
+
22
+ #
23
+ # Creates a new page in the specified database.
24
+ # Later iterations of the API will support creating pages outside databases.
25
+ # Note that this iteration of the API will only expose page properties, not
26
+ # page content, as described in the data model.
27
+ #
28
+ # @option options [Object] :parent
29
+ # Parent of the page, which is always going to be a database in this version of the API.
30
+ #
31
+ # @option options [Object] :properties
32
+ # Properties of this page.
33
+ # The schema for the page's keys and values is described by the properties of
34
+ # the database this page belongs to. key string Name of a property as it
35
+ # appears in Notion, or property ID. value object Object containing a value
36
+ # specific to the property type, e.g. {"checkbox": true}.
37
+ def create_page(options = {})
38
+ throw ArgumentError.new('Required arguments :parent.database_id missing') if options.dig(:parent, :database_id).nil?
39
+ post("pages", options)
40
+ end
41
+
42
+ #
43
+ # Updates a page by setting the values of any properties specified in the
44
+ # JSON body of the request. Properties that are not set via parameters will
45
+ # remain unchanged.
46
+ #
47
+ # Note that this iteration of the API will only expose page properties, not page
48
+ # content, as described in the data model.
49
+ #
50
+ # @option options [id] :id
51
+ # Page to get info on.
52
+ #
53
+ # @option options [Object] :properties
54
+ # Properties of this page.
55
+ # The schema for the page's keys and values is described by the properties of
56
+ # the database this page belongs to. key string Name of a property as it
57
+ # appears in Notion, or property ID. value object Object containing a value
58
+ # specific to the property type, e.g. {"checkbox": true}.
59
+ def update_page(options = {})
60
+ throw ArgumentError.new('Required arguments :id missing') if options[:id].nil?
61
+ patch("pages/#{options[:id]}", options)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -16,15 +16,19 @@ module Notion
16
16
 
17
17
  #
18
18
  # Returns a paginated list of User objects for the workspace.
19
- # @option options [Object] :start_cursor
20
- # Paginate through collections of data by setting the cursor parameter to a start_cursor attribute returned by a previous request's next_cursor. Default value fetches the first "page" of the collection. See pagination for more detail.
19
+ #
20
+ # @option options [UUID] :start_cursor
21
+ # Paginate through collections of data by setting the cursor parameter
22
+ # to a start_cursor attribute returned by a previous request's next_cursor.
23
+ # Default value fetches the first "page" of the collection.
24
+ # See pagination for more detail.
21
25
  def users_list(options = {})
22
26
  if block_given?
23
27
  Pagination::Cursor.new(self, :users_list, options).each do |page|
24
28
  yield page
25
29
  end
26
30
  else
27
- get("users?start_cursor=#{options[:start_cursor]}")
31
+ get("users", options)
28
32
  end
29
33
  end
30
34
  end
@@ -3,16 +3,22 @@
3
3
  module Notion
4
4
  module Api
5
5
  module Errors
6
+ class BadRequest < NotionError; end
7
+ class Forbidden < NotionError; end
6
8
  class InternalError < NotionError; end
7
9
  class InvalidRequest < NotionError; end
8
10
  class ObjectNotFound < NotionError; end
9
11
  class TooManyRequests < NotionError; end
12
+ class Unauthorized < NotionError; end
10
13
 
11
14
  ERROR_CLASSES = {
15
+ 'bad_request' => BadRequest,
16
+ 'forbidden' => Forbidden,
12
17
  'internal_error' => InternalError,
13
18
  'invalid_request' => InvalidRequest,
14
19
  'object_not_found' => ObjectNotFound,
15
- 'rate_limited' => TooManyRequests
20
+ 'rate_limited' => TooManyRequests,
21
+ 'unauthorized' => Unauthorized
16
22
  }.freeze
17
23
  end
18
24
  end
@@ -5,8 +5,8 @@ module Notion
5
5
  class NotionError < ::Faraday::Error
6
6
  attr_reader :response
7
7
 
8
- def initialize(message, response = nil)
9
- super message
8
+ def initialize(message, details, response = nil)
9
+ super("#{message} #{details}")
10
10
  @response = response
11
11
  end
12
12
  end
@@ -6,6 +6,10 @@ module Notion
6
6
  request(:get, path, options)
7
7
  end
8
8
 
9
+ def patch(path, options = {})
10
+ request(:patch, path, options)
11
+ end
12
+
9
13
  def post(path, options = {})
10
14
  request(:post, path, options)
11
15
  end
@@ -26,9 +30,10 @@ module Notion
26
30
  case method
27
31
  when :get, :delete
28
32
  request.url(path, options)
29
- when :post, :put
33
+ when :post, :put, :patch
34
+ request.headers['Content-Type'] = 'application/json'
30
35
  request.path = path
31
- request.body = options unless options.empty?
36
+ request.body = options.to_json unless options.empty?
32
37
  end
33
38
  request.options.merge!(options.delete(:request)) if options.key?(:request)
34
39
  end
@@ -6,19 +6,18 @@ module Notion
6
6
  def on_complete(env)
7
7
  raise Notion::Api::Errors::TooManyRequests, env.response if env.status == 429
8
8
 
9
- return unless env.success?
9
+ return if env.success?
10
10
 
11
11
  body = env.body
12
12
  return unless body
13
- return if env.status == 200
14
13
 
15
14
  error_code = body['code']
16
15
  error_message = body['message']
17
- error_message = body['details']
16
+ error_details = body['details']
18
17
 
19
18
  error_class = Notion::Api::Errors::ERROR_CLASSES[error_code]
20
19
  error_class ||= Notion::Api::Errors::NotionError
21
- raise error_class.new(error_message, env.response)
20
+ raise error_class.new(error_message, error_details, env.response)
22
21
  end
23
22
 
24
23
  def call(env)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Notion
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  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.2
4
+ version: 0.0.3
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-01-29 00:00:00.000000000 Z
11
+ date: 2021-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -170,12 +170,15 @@ executables: []
170
170
  extensions: []
171
171
  extra_rdoc_files: []
172
172
  files:
173
+ - CHANGELOG.md
173
174
  - Gemfile
174
175
  - LICENSE.md
175
176
  - README.md
176
177
  - lib/notion-ruby-client.rb
177
178
  - lib/notion.rb
178
179
  - lib/notion/api/endpoints.rb
180
+ - lib/notion/api/endpoints/databases.rb
181
+ - lib/notion/api/endpoints/pages.rb
179
182
  - lib/notion/api/endpoints/users.rb
180
183
  - lib/notion/api/error.rb
181
184
  - lib/notion/api/errors.rb