Module: Ask::Notion

Defined in:
lib/ask/notion/client.rb,
lib/ask/notion/context.rb,
lib/ask/notion/version.rb,
lib/ask/notion/error_guide.rb

Defined Under Namespace

Modules: Errors Classes: ClientProxy

Constant Summary collapse

DESCRIPTION =

Human-readable description of the Notion service context.

"Notion — pages, databases, blocks, comments, users, search"
DOCS_URL =

Base URL for Notion API documentation.

"https://developers.notion.com/"
API_REF_URL =

URL for the Notion API reference.

"https://developers.notion.com/reference"
OPENAPI_URL =

URL for the Notion OpenAPI specification.

"https://developers.notion.com/.well-known/openapi.json"
AUTH_NAME =

Credential name used with Ask::Auth.resolve.

:notion_token
AUTH_HOW =

Instructions for obtaining a Notion Internal Integration Token.

"https://www.notion.so/my-integrations — create an integration and copy the 'Internal Integration Secret' (starts with 'ntn_' or 'secret_')"
GEM_NAME =

Gem name for the Notion API client.

"notion-ruby-client"
GEM_VERSION =

Required gem version constraint.

"~> 1.2"
GEM_DOCS =

URL for notion-ruby-client library documentation.

"https://www.rubydoc.info/gems/notion-ruby-client"
QUICK_START =

Quick-start Ruby code snippet for agents to copy-paste.

<<~RUBY
  client = Ask::Notion.client
  client.database_query(database_id: "DB_ID")
  client.page_retrieve(page_id: "PAGE_ID")
  client.page_create(parent: { database_id: "DB_ID" }, properties: { "Name": { title: [{ text: { content: "New Page" } }] } })
  client.page_update(page_id: "PAGE_ID", properties: { "Status": { status: { name: "Done" } } })
  client.block_children_list(block_id: "BLOCK_ID")
  client.append_block_children(block_id: "BLOCK_ID", children: [{ paragraph: { rich_text: [{ text: { content: "Hello!" } }] } }])
  client.search(query: "project")
RUBY
VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.client::Notion::Client

Returns an authenticated Notion API client configured for an AI agent.

Resolves the Notion token via Ask::Auth.resolve(:notion_token) and wraps the client in a proxy that converts Notion::Api::Errors::Unauthorized into Ask::Auth::InvalidCredential.

The client inherits default configuration from Notion::Config:

  • token: resolved via Ask::Auth

  • logger: default logger

Examples:

client = Ask::Notion.client
client.database_query(database_id: "abc123")

Returns:

  • (::Notion::Client)

    an authenticated client

Raises:

  • (Ask::Auth::MissingCredential)

    if no Notion token is configured

  • (Ask::Auth::InvalidCredential)

    if the token is rejected (401)



25
26
27
28
29
# File 'lib/ask/notion/client.rb', line 25

def self.client
  token = Ask::Auth.resolve(:notion_token)

  ClientProxy.new(::Notion::Client.new(token: token))
end