ask-notion 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8f2b7ca05f8f6271299178580e3660f4b5a014977845d79a21a442ba0dad5d33
4
+ data.tar.gz: 1fd261c3a9184fba6e88e372771a35f71aa33954b0dda99cbada5addd1a80d20
5
+ SHA512:
6
+ metadata.gz: 8d3c5718162b896aed53f44118403c2d470372ce2e305eb7e88315d52885a8c7a1f324c09dfe9d72ad783e8e20957feeab91dfb96d534ba728a5a4cc48534c9a
7
+ data.tar.gz: b2ae58df4217e6658378a3d3f6ba3d52b9002950b7c1df664a3bdf177022f02c45582e34462543616de77ae31c412cd46310b72e0c0f6ba60f2026d4250fd26d
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kaka Ruto
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # ask-notion
2
+
3
+ Notion service context for the ask-rb ecosystem.
4
+
5
+ Provides:
6
+ - `Ask::Notion.client` — authenticated Notion API client
7
+ - `Ask::Notion::DESCRIPTION` — context metadata for the system prompt
8
+ - `Ask::Notion::Errors` — structured error knowledge for AI agents
9
+
10
+ ## Installation
11
+
12
+ ```ruby
13
+ gem "ask-notion"
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```ruby
19
+ require "ask-notion"
20
+
21
+ # Returns an authenticated Notion::Client
22
+ client = Ask::Notion.client
23
+
24
+ # Query a database
25
+ results = client.database_query(database_id: "your-database-id")
26
+
27
+ # Get a page
28
+ page = client.page_retrieve(page_id: "your-page-id")
29
+
30
+ # Create a page in a database
31
+ client.page_create(
32
+ parent: { database_id: "your-database-id" },
33
+ properties: {
34
+ "Name" => { title: [{ text: { content: "New Task" } }] },
35
+ "Status" => { status: { name: "In Progress" } }
36
+ }
37
+ )
38
+
39
+ # Search across Notion
40
+ results = client.search(query: "project notes")
41
+ ```
42
+
43
+ ## Auth Setup
44
+
45
+ This gem uses `Ask::Auth` to resolve the `:notion_token` credential.
46
+
47
+ 1. Go to https://www.notion.so/my-integrations
48
+ 2. Create a new integration and copy the Internal Integration Secret
49
+ 3. Set the token in your environment:
50
+
51
+ ```bash
52
+ export NOTION_TOKEN="ntn_your_integration_token"
53
+ ```
54
+
55
+ Or add it to `~/.ask/credentials.yml`:
56
+
57
+ ```yaml
58
+ notion_token: ntn_your_integration_token
59
+ ```
60
+
61
+ ## Development
62
+
63
+ ```bash
64
+ bin/setup
65
+ bundle exec rake test
66
+ ```
67
+
68
+ ## License
69
+
70
+ MIT
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "notion-ruby-client"
4
+ require "ask/auth"
5
+
6
+ module Ask
7
+ module Notion
8
+ # Returns an authenticated Notion API client configured for an AI agent.
9
+ #
10
+ # Resolves the Notion token via +Ask::Auth.resolve(:notion_token)+ and
11
+ # wraps the client in a proxy that converts +Notion::Api::Errors::Unauthorized+
12
+ # into +Ask::Auth::InvalidCredential+.
13
+ #
14
+ # The client inherits default configuration from +Notion::Config+:
15
+ # - +token+: resolved via Ask::Auth
16
+ # - +logger+: default logger
17
+ #
18
+ # @example
19
+ # client = Ask::Notion.client
20
+ # client.database_query(database_id: "abc123")
21
+ #
22
+ # @return [::Notion::Client] an authenticated client
23
+ # @raise [Ask::Auth::MissingCredential] if no Notion token is configured
24
+ # @raise [Ask::Auth::InvalidCredential] if the token is rejected (401)
25
+ def self.client
26
+ token = Ask::Auth.resolve(:notion_token)
27
+
28
+ ClientProxy.new(::Notion::Client.new(token: token))
29
+ end
30
+
31
+ # Proxies method calls to a +::Notion::Client+, converting authentication
32
+ # errors into +Ask::Auth::InvalidCredential+.
33
+ class ClientProxy < BasicObject
34
+ def initialize(client)
35
+ @client = client
36
+ end
37
+
38
+ def method_missing(name, ...)
39
+ @client.public_send(name, ...)
40
+ rescue ::Notion::Api::Errors::Unauthorized
41
+ ::Kernel.raise ::Ask::Auth::InvalidCredential, :notion_token
42
+ end
43
+
44
+ def respond_to_missing?(name, include_private = false)
45
+ @client.respond_to?(name, include_private) || super
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ask
4
+ module Notion
5
+ # Human-readable description of the Notion service context.
6
+ DESCRIPTION = "Notion — pages, databases, blocks, comments, users, search"
7
+
8
+ # Base URL for Notion API documentation.
9
+ DOCS_URL = "https://developers.notion.com/"
10
+
11
+ # URL for the Notion API reference.
12
+ API_REF_URL = "https://developers.notion.com/reference"
13
+
14
+ # URL for the Notion OpenAPI specification.
15
+ OPENAPI_URL = "https://developers.notion.com/.well-known/openapi.json"
16
+
17
+ # Credential name used with Ask::Auth.resolve.
18
+ AUTH_NAME = :notion_token
19
+
20
+ # Instructions for obtaining a Notion Internal Integration Token.
21
+ AUTH_HOW = "https://www.notion.so/my-integrations — create an integration and copy the 'Internal Integration Secret' (starts with 'ntn_' or 'secret_')"
22
+
23
+ # Gem name for the Notion API client.
24
+ GEM_NAME = "notion-ruby-client"
25
+
26
+ # Required gem version constraint.
27
+ GEM_VERSION = "~> 1.2"
28
+
29
+ # URL for notion-ruby-client library documentation.
30
+ GEM_DOCS = "https://www.rubydoc.info/gems/notion-ruby-client"
31
+
32
+ # Quick-start Ruby code snippet for agents to copy-paste.
33
+ QUICK_START = <<~RUBY
34
+ client = Ask::Notion.client
35
+ client.database_query(database_id: "DB_ID")
36
+ client.page_retrieve(page_id: "PAGE_ID")
37
+ client.page_create(parent: { database_id: "DB_ID" }, properties: { "Name": { title: [{ text: { content: "New Page" } }] } })
38
+ client.page_update(page_id: "PAGE_ID", properties: { "Status": { status: { name: "Done" } } })
39
+ client.block_children_list(block_id: "BLOCK_ID")
40
+ client.append_block_children(block_id: "BLOCK_ID", children: [{ paragraph: { rich_text: [{ text: { content: "Hello!" } }] } }])
41
+ client.search(query: "project")
42
+ RUBY
43
+ end
44
+ end
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ask
4
+ module Notion
5
+ # Structured error knowledge for AI agents working with the Notion API.
6
+ #
7
+ # Provides human-readable guidance for common HTTP status codes, rate
8
+ # limiting, pagination, and authentication errors encountered when
9
+ # using the Notion API via the notion-ruby-client gem.
10
+ module Errors
11
+ # Rate limit information.
12
+ #
13
+ # - Authenticated requests: 3 requests per second (burst), 90 requests per minute
14
+ #
15
+ # When rate-limited, the API returns 429 and raises
16
+ # +Notion::Api::Errors::TooManyRequests+. The agent should respect the
17
+ # Retry-After header and back off.
18
+ RATE_LIMIT = {
19
+ burst: "3 requests per second (per integration)",
20
+ sustained: "90 requests per minute (per integration)",
21
+ error_class: "Notion::Api::Errors::TooManyRequests",
22
+ action: "Respect the Retry-After header and wait before retrying. Use exponential backoff."
23
+ }.freeze
24
+
25
+ # Common HTTP status codes returned by the Notion API and how to handle them.
26
+ STATUS_CODES = {
27
+ 200 => "OK — Request succeeded.",
28
+ 201 => "Created — Resource was created successfully.",
29
+ 204 => "No Content — Request succeeded, no response body.",
30
+ 400 => "Bad Request — Request body is malformed. Check JSON structure and field types.",
31
+ 401 => "Unauthorized — Integration token is missing, invalid, or revoked. Re-authenticate at https://www.notion.so/my-integrations.",
32
+ 403 => "Forbidden — Integration lacks access to the requested resource. Share the page or database with the integration in Notion.",
33
+ 404 => "Not Found — Resource does not exist or the integration does not have access to it.",
34
+ 409 => "Conflict — Resource state conflict. The resource may have been updated by another request.",
35
+ 412 => "Precondition Failed — Use the correct Notion-Version header (e.g., '2022-06-28').",
36
+ 429 => "Too Many Requests — Rate limit exceeded. Respect Retry-After header.",
37
+ 500 => "Internal Server Error — Notion server issue. Retry with backoff.",
38
+ 502 => "Bad Gateway — Notion upstream issue. Retry with backoff.",
39
+ 503 => "Service Unavailable — Notion is down for maintenance. Retry later."
40
+ }.freeze
41
+
42
+ # Pagination guidance for large result sets.
43
+ PAGINATION = {
44
+ cursor_based: "Notion uses cursor-based pagination. Supply a block to the client method to auto-paginate.",
45
+ page_size: "Maximum items per page is 100. The client uses this as the default.",
46
+ next_cursor: "Responses include a next_cursor key. Pass it as start_cursor in the next request.",
47
+ has_more: "Responses include a has_more boolean. When false, all results have been retrieved."
48
+ }.freeze
49
+
50
+ # Map of Notion exception classes to human-readable guidance.
51
+ EXCEPTIONS = {
52
+ "Notion::Api::Errors::Unauthorized" => {
53
+ message: "Your Notion integration token is invalid or has been revoked.",
54
+ action: "Generate a new token at https://www.notion.so/my-integrations. Tokens start with 'ntn_' or 'secret_'."
55
+ },
56
+ "Notion::Api::Errors::Forbidden" => {
57
+ message: "Your integration does not have access to this page or database.",
58
+ action: "In Notion, click 'Share' on the page/database and add your integration by name."
59
+ },
60
+ "Notion::Api::Errors::ObjectNotFound" => {
61
+ message: "The requested page, database, or block does not exist or is not shared with the integration.",
62
+ action: "Verify the ID is correct and that the resource is shared with your integration."
63
+ },
64
+ "Notion::Api::Errors::TooManyRequests" => {
65
+ message: "Notion API rate limit exceeded.",
66
+ action: "Check the Retry-After header, wait that many seconds, then retry. Limit: 3 req/s burst, 90 req/min sustained."
67
+ },
68
+ "Notion::Api::Errors::BadRequest" => {
69
+ message: "The request body is invalid or missing required fields.",
70
+ action: "Check the JSON structure, field names, and value types against the API reference at https://developers.notion.com/reference."
71
+ },
72
+ "Notion::Api::Errors::InvalidRequest" => {
73
+ message: "The request body failed validation against the Notion API schema.",
74
+ action: "Check required fields, property types, and data formats. Notion returns detailed error messages."
75
+ },
76
+ "Notion::Api::Errors::UnavailableError" => {
77
+ message: "Notion is temporarily unavailable or down for maintenance.",
78
+ action: "Retry with exponential backoff. If the issue persists, check https://status.notion.com."
79
+ },
80
+ "Notion::Api::Errors::TimeoutError" => {
81
+ message: "The request timed out.",
82
+ action: "Retry with exponential backoff. The Notion API may be experiencing high latency."
83
+ },
84
+ "Notion::Api::Errors::ParsingError" => {
85
+ message: "Failed to parse the Notion API response.",
86
+ action: "Retry the request. This is usually a transient issue."
87
+ },
88
+ "Notion::Api::Errors::ServerError" => {
89
+ message: "Notion encountered a server error.",
90
+ action: "Retry with exponential backoff. If the issue persists, check https://status.notion.com."
91
+ }
92
+ }.freeze
93
+
94
+ # Look up guidance for an exception class name.
95
+ #
96
+ # @param exception_class [String] The exception class name (e.g., "Notion::Api::Errors::ObjectNotFound")
97
+ # @return [Hash, nil] A hash with +:message+ and +:action+ keys, or nil if unknown
98
+ def self.for(exception_class)
99
+ EXCEPTIONS[exception_class]
100
+ end
101
+
102
+ # Describe an HTTP status code.
103
+ #
104
+ # @param code [Integer] HTTP status code
105
+ # @return [String, nil] Description of the status code
106
+ def self.status_code_description(code)
107
+ STATUS_CODES[code]
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ask
4
+ module Notion
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
data/lib/ask/notion.rb ADDED
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ # empty — all components loaded via ask-notion.rb entry point
data/lib/ask-notion.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ask/notion/version"
4
+ require_relative "ask/notion/context"
5
+ require_relative "ask/notion/client"
6
+ require_relative "ask/notion/error_guide"
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ask-notion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kaka Ruto
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: ask-auth
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '0.1'
26
+ - !ruby/object:Gem::Dependency
27
+ name: notion-ruby-client
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.2'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.2'
40
+ - !ruby/object:Gem::Dependency
41
+ name: minitest
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.25'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '5.25'
54
+ - !ruby/object:Gem::Dependency
55
+ name: mocha
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.1'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.1'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rake
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '13.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '13.0'
82
+ description: Provides authenticated Notion client, context metadata, and error guide
83
+ for AI agents.
84
+ email:
85
+ - kaka@myrrlabs.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE
91
+ - README.md
92
+ - lib/ask-notion.rb
93
+ - lib/ask/notion.rb
94
+ - lib/ask/notion/client.rb
95
+ - lib/ask/notion/context.rb
96
+ - lib/ask/notion/error_guide.rb
97
+ - lib/ask/notion/version.rb
98
+ homepage: https://github.com/ask-rb/ask-notion
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '3.2'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 4.0.3
117
+ specification_version: 4
118
+ summary: Notion service context for the ask-rb ecosystem
119
+ test_files: []