Class: Rospatent::Configuration
- Inherits:
-
Object
- Object
- Rospatent::Configuration
- Defined in:
- lib/rospatent/configuration.rb
Overview
Configuration class for Rospatent API client
Constant Summary collapse
- ENVIRONMENTS =
%w[development staging production].freeze
Instance Attribute Summary collapse
-
#api_url ⇒ Object
Base URL for the Rospatent API.
-
#cache_enabled ⇒ Object
Cache configuration.
-
#cache_max_size ⇒ Object
Cache configuration.
-
#cache_ttl ⇒ Object
Cache configuration.
-
#connection_keep_alive ⇒ Object
Connection pooling.
-
#connection_pool_size ⇒ Object
Connection pooling.
-
#environment ⇒ Object
Current environment.
-
#log_level ⇒ Object
Logging configuration.
-
#log_requests ⇒ Object
Logging configuration.
-
#log_responses ⇒ Object
Logging configuration.
-
#retry_count ⇒ Object
Number of retries for failed requests.
-
#timeout ⇒ Object
Request timeout in seconds.
-
#token ⇒ Object
JWT token for authentication.
-
#token_expires_at ⇒ Object
Token management.
-
#token_refresh_callback ⇒ Object
Token management.
-
#user_agent ⇒ Object
User agent to be sent with requests.
-
#validation_limits ⇒ Object
Validation limits.
Instance Method Summary collapse
-
#configure_from_hash(options) ⇒ Object
Configure from hash.
-
#effective_api_url ⇒ String
Get environment-specific API URL if needed.
-
#initialize ⇒ Configuration
constructor
Initialize a new configuration with default values.
-
#reset! ⇒ Object
Reset configuration to defaults.
-
#token_valid? ⇒ Boolean
Check if the current token is still valid.
-
#valid_environment? ⇒ Boolean
Validate the current environment.
Constructor Details
#initialize ⇒ Configuration
Initialize a new configuration with default values
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rospatent/configuration.rb', line 34 def initialize @api_url = "https://searchplatform.rospatent.gov.ru" @token = ENV["ROSPATENT_TOKEN"] || ENV.fetch("ROSPATENT_API_TOKEN", nil) @timeout = 30 @retry_count = 3 @user_agent = "Rospatent Ruby Client/#{Rospatent::VERSION}" # Environment configuration @environment = ENV.fetch("ROSPATENT_ENV", "development") # Cache configuration @cache_enabled = ENV.fetch("ROSPATENT_CACHE_ENABLED", "true") == "true" @cache_ttl = ENV.fetch("ROSPATENT_CACHE_TTL", "300").to_i @cache_max_size = ENV.fetch("ROSPATENT_CACHE_MAX_SIZE", "1000").to_i # Logging configuration @log_level = ENV.fetch("ROSPATENT_LOG_LEVEL", "info").to_sym @log_requests = ENV.fetch("ROSPATENT_LOG_REQUESTS", "false") == "true" @log_responses = ENV.fetch("ROSPATENT_LOG_RESPONSES", "false") == "true" # Token management @token_expires_at = nil @token_refresh_callback = nil # Connection pooling @connection_pool_size = ENV.fetch("ROSPATENT_POOL_SIZE", "5").to_i @connection_keep_alive = ENV.fetch("ROSPATENT_KEEP_ALIVE", "true") == "true" # Validation limits @validation_limits = { query_max_length: 2000, natural_query_max_length: 2000, limit_max_value: 100, offset_max_value: 10_000, array_max_size: 10, string_max_length: 1000, pre_tag_max_length: 50, post_tag_max_length: 50, pre_tag_max_size: 10, post_tag_max_size: 10, classification_query_max_length: 1000, classification_code_max_length: 50, similar_text_min_words: 50, similar_text_max_length: 10_000, similar_count_max_value: 1000, batch_size_max_value: 50, batch_ids_max_size: 1000 } load_environment_config end |
Instance Attribute Details
#api_url ⇒ Object
Base URL for the Rospatent API
11 12 13 |
# File 'lib/rospatent/configuration.rb', line 11 def api_url @api_url end |
#cache_enabled ⇒ Object
Cache configuration
23 24 25 |
# File 'lib/rospatent/configuration.rb', line 23 def cache_enabled @cache_enabled end |
#cache_max_size ⇒ Object
Cache configuration
23 24 25 |
# File 'lib/rospatent/configuration.rb', line 23 def cache_max_size @cache_max_size end |
#cache_ttl ⇒ Object
Cache configuration
23 24 25 |
# File 'lib/rospatent/configuration.rb', line 23 def cache_ttl @cache_ttl end |
#connection_keep_alive ⇒ Object
Connection pooling
29 30 31 |
# File 'lib/rospatent/configuration.rb', line 29 def connection_keep_alive @connection_keep_alive end |
#connection_pool_size ⇒ Object
Connection pooling
29 30 31 |
# File 'lib/rospatent/configuration.rb', line 29 def connection_pool_size @connection_pool_size end |
#environment ⇒ Object
Current environment
21 22 23 |
# File 'lib/rospatent/configuration.rb', line 21 def environment @environment end |
#log_level ⇒ Object
Logging configuration
25 26 27 |
# File 'lib/rospatent/configuration.rb', line 25 def log_level @log_level end |
#log_requests ⇒ Object
Logging configuration
25 26 27 |
# File 'lib/rospatent/configuration.rb', line 25 def log_requests @log_requests end |
#log_responses ⇒ Object
Logging configuration
25 26 27 |
# File 'lib/rospatent/configuration.rb', line 25 def log_responses @log_responses end |
#retry_count ⇒ Object
Number of retries for failed requests
17 18 19 |
# File 'lib/rospatent/configuration.rb', line 17 def retry_count @retry_count end |
#timeout ⇒ Object
Request timeout in seconds
15 16 17 |
# File 'lib/rospatent/configuration.rb', line 15 def timeout @timeout end |
#token ⇒ Object
JWT token for authentication
13 14 15 |
# File 'lib/rospatent/configuration.rb', line 13 def token @token end |
#token_expires_at ⇒ Object
Token management
27 28 29 |
# File 'lib/rospatent/configuration.rb', line 27 def token_expires_at @token_expires_at end |
#token_refresh_callback ⇒ Object
Token management
27 28 29 |
# File 'lib/rospatent/configuration.rb', line 27 def token_refresh_callback @token_refresh_callback end |
#user_agent ⇒ Object
User agent to be sent with requests
19 20 21 |
# File 'lib/rospatent/configuration.rb', line 19 def user_agent @user_agent end |
#validation_limits ⇒ Object
Validation limits
31 32 33 |
# File 'lib/rospatent/configuration.rb', line 31 def validation_limits @validation_limits end |
Instance Method Details
#configure_from_hash(options) ⇒ Object
Configure from hash
122 123 124 125 126 127 |
# File 'lib/rospatent/configuration.rb', line 122 def configure_from_hash() .each do |key, value| setter = "#{key}=" send(setter, value) if respond_to?(setter) end end |
#effective_api_url ⇒ String
Get environment-specific API URL if needed
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/rospatent/configuration.rb', line 102 def effective_api_url case @environment when "development" ENV.fetch("ROSPATENT_DEV_API_URL", @api_url) when "staging" ENV.fetch("ROSPATENT_STAGING_API_URL", @api_url) when "production" @api_url else @api_url end end |
#reset! ⇒ Object
Reset configuration to defaults
116 117 118 |
# File 'lib/rospatent/configuration.rb', line 116 def reset! initialize end |
#token_valid? ⇒ Boolean
Check if the current token is still valid
88 89 90 91 92 |
# File 'lib/rospatent/configuration.rb', line 88 def token_valid? return true unless @token_expires_at Time.now < @token_expires_at end |
#valid_environment? ⇒ Boolean
Validate the current environment
96 97 98 |
# File 'lib/rospatent/configuration.rb', line 96 def valid_environment? ENVIRONMENTS.include?(@environment) end |