Class: Notion::Config
- Inherits:
-
Object
- Object
- Notion::Config
- 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
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#auto_refresh ⇒ Object
Returns the value of attribute auto_refresh.
-
#betas ⇒ Object
Returns the value of attribute betas.
-
#burst ⇒ Object
Returns the value of attribute burst.
-
#ca_file ⇒ Object
Returns the value of attribute ca_file.
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_attempts ⇒ Object
Returns the value of attribute max_attempts.
-
#notion_version ⇒ Object
Returns the value of attribute notion_version.
-
#oauth_client ⇒ Object
Returns the value of attribute oauth_client.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#rate ⇒ Object
Returns the value of attribute rate.
-
#rate_limit_store ⇒ Object
Returns the value of attribute rate_limit_store.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#retry_cap ⇒ Object
Returns the value of attribute retry_cap.
-
#strict ⇒ Object
Returns the value of attribute strict.
-
#token ⇒ Object
Returns the value of attribute token.
-
#token_key ⇒ Object
Returns the value of attribute token_key.
-
#token_store ⇒ Object
Returns the value of attribute token_store.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #merge(**options) ⇒ Object
- #rate_limit=(values) ⇒ Object
- #retry=(values) ⇒ Object
- #timeout=(values) ⇒ Object
- #validate!(require_token: false) ⇒ Object
Constructor Details
#initialize ⇒ Config
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
#adapter ⇒ Object
Returns the value of attribute adapter.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def adapter @adapter end |
#auto_refresh ⇒ Object
Returns the value of attribute auto_refresh.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def auto_refresh @auto_refresh end |
#betas ⇒ Object
Returns the value of attribute betas.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def betas @betas end |
#burst ⇒ Object
Returns the value of attribute burst.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def burst @burst end |
#ca_file ⇒ Object
Returns the value of attribute ca_file.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def ca_file @ca_file end |
#cache ⇒ Object
Returns the value of attribute cache.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def cache @cache end |
#log_level ⇒ Object
Returns the value of attribute log_level.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def log_level @log_level end |
#logger ⇒ Object
Returns the value of attribute logger.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def logger @logger end |
#max_attempts ⇒ Object
Returns the value of attribute max_attempts.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def max_attempts @max_attempts end |
#notion_version ⇒ Object
Returns the value of attribute notion_version.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def notion_version @notion_version end |
#oauth_client ⇒ Object
Returns the value of attribute oauth_client.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def oauth_client @oauth_client end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def open_timeout @open_timeout end |
#proxy ⇒ Object
Returns the value of attribute proxy.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def proxy @proxy end |
#rate ⇒ Object
Returns the value of attribute rate.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def rate @rate end |
#rate_limit_store ⇒ Object
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_timeout ⇒ Object
Returns the value of attribute read_timeout.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def read_timeout @read_timeout end |
#retry_cap ⇒ Object
Returns the value of attribute retry_cap.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def retry_cap @retry_cap end |
#strict ⇒ Object
Returns the value of attribute strict.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def strict @strict end |
#token ⇒ Object
Returns the value of attribute token.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def token @token end |
#token_key ⇒ Object
Returns the value of attribute token_key.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def token_key @token_key end |
#token_store ⇒ Object
Returns the value of attribute token_store.
9 10 11 |
# File 'lib/notion/config.rb', line 9 def token_store @token_store end |
#user_agent ⇒ Object
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(**) copy = dup .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
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 |