Class: Notion::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/notion/config.rb

Constant Summary collapse

API_VERSIONS =
%w[2022-06-28 2025-09-03 2026-03-11].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/notion/config.rb', line 14

def initialize
  @token = ENV.fetch("NOTION_TOKEN", nil)
  @notion_version = ENV.fetch("NOTION_API_VERSION", "2026-03-11")
  @betas = []
  @open_timeout = 5
  @read_timeout = 65
  @max_attempts = 5
  @retry_cap = 30
  @rate = 3.0
  @burst = 6
  @log_level = :info
  @user_agent = "notion-client-ruby/#{Notion::VERSION} (ruby/#{RUBY_VERSION})"
  @strict = false
  @token_key = :default
  @auto_refresh = false
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



9
10
11
# File 'lib/notion/config.rb', line 9

def adapter
  @adapter
end

#auto_refreshObject

Returns the value of attribute auto_refresh.



9
10
11
# File 'lib/notion/config.rb', line 9

def auto_refresh
  @auto_refresh
end

#betasObject

Returns the value of attribute betas.



9
10
11
# File 'lib/notion/config.rb', line 9

def betas
  @betas
end

#burstObject

Returns the value of attribute burst.



9
10
11
# File 'lib/notion/config.rb', line 9

def burst
  @burst
end

#ca_fileObject

Returns the value of attribute ca_file.



9
10
11
# File 'lib/notion/config.rb', line 9

def ca_file
  @ca_file
end

#cacheObject

Returns the value of attribute cache.



9
10
11
# File 'lib/notion/config.rb', line 9

def cache
  @cache
end

#log_levelObject

Returns the value of attribute log_level.



9
10
11
# File 'lib/notion/config.rb', line 9

def log_level
  @log_level
end

#loggerObject

Returns the value of attribute logger.



9
10
11
# File 'lib/notion/config.rb', line 9

def logger
  @logger
end

#max_attemptsObject

Returns the value of attribute max_attempts.



9
10
11
# File 'lib/notion/config.rb', line 9

def max_attempts
  @max_attempts
end

#notion_versionObject

Returns the value of attribute notion_version.



9
10
11
# File 'lib/notion/config.rb', line 9

def notion_version
  @notion_version
end

#oauth_clientObject

Returns the value of attribute oauth_client.



9
10
11
# File 'lib/notion/config.rb', line 9

def oauth_client
  @oauth_client
end

#open_timeoutObject

Returns the value of attribute open_timeout.



9
10
11
# File 'lib/notion/config.rb', line 9

def open_timeout
  @open_timeout
end

#proxyObject

Returns the value of attribute proxy.



9
10
11
# File 'lib/notion/config.rb', line 9

def proxy
  @proxy
end

#rateObject

Returns the value of attribute rate.



9
10
11
# File 'lib/notion/config.rb', line 9

def rate
  @rate
end

#rate_limit_storeObject

Returns the value of attribute rate_limit_store.



9
10
11
# File 'lib/notion/config.rb', line 9

def rate_limit_store
  @rate_limit_store
end

#read_timeoutObject

Returns the value of attribute read_timeout.



9
10
11
# File 'lib/notion/config.rb', line 9

def read_timeout
  @read_timeout
end

#retry_capObject

Returns the value of attribute retry_cap.



9
10
11
# File 'lib/notion/config.rb', line 9

def retry_cap
  @retry_cap
end

#strictObject

Returns the value of attribute strict.



9
10
11
# File 'lib/notion/config.rb', line 9

def strict
  @strict
end

#tokenObject

Returns the value of attribute token.



9
10
11
# File 'lib/notion/config.rb', line 9

def token
  @token
end

#token_keyObject

Returns the value of attribute token_key.



9
10
11
# File 'lib/notion/config.rb', line 9

def token_key
  @token_key
end

#token_storeObject

Returns the value of attribute token_store.



9
10
11
# File 'lib/notion/config.rb', line 9

def token_store
  @token_store
end

#user_agentObject

Returns the value of attribute user_agent.



9
10
11
# File 'lib/notion/config.rb', line 9

def user_agent
  @user_agent
end

Instance Method Details

#merge(**options) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/notion/config.rb', line 60

def merge(**options)
  copy = dup
  options.each do |name, value|
    writer = "#{name}="
    raise ConfigurationError, "unknown option: #{name}" unless copy.respond_to?(writer)

    copy.public_send(writer, value)
  end
  copy.validate!
end

#rate_limit=(values) ⇒ Object



41
42
43
44
45
# File 'lib/notion/config.rb', line 41

def rate_limit=(values)
  self.rate = values.fetch(:rate, rate)
  self.burst = values.fetch(:burst, burst)
  self.rate_limit_store = values[:store] == :memory ? nil : values[:store] if values.key?(:store)
end

#retry=(values) ⇒ Object



36
37
38
39
# File 'lib/notion/config.rb', line 36

def retry=(values)
  self.max_attempts = values.fetch(:max_attempts, max_attempts)
  self.retry_cap = values.fetch(:cap, retry_cap)
end

#timeout=(values) ⇒ Object



31
32
33
34
# File 'lib/notion/config.rb', line 31

def timeout=(values)
  self.open_timeout = values.fetch(:open, open_timeout)
  self.read_timeout = values.fetch(:read, read_timeout)
end

#validate!(require_token: false) ⇒ Object

Raises:



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/notion/config.rb', line 47

def validate!(require_token: false)
  raise ConfigurationError, "token is required" if require_token && blank?(@token) && !@token_store
  unless API_VERSIONS.include?(@notion_version)
    raise ConfigurationError, "unsupported Notion API version: #{@notion_version}"
  end

  positive_values.each do |name, value|
    raise ConfigurationError, "#{name} must be positive" unless value.to_f.positive?
  end

  self
end