Class: Kward::OpenRouterAPIKey
- Inherits:
-
Object
- Object
- Kward::OpenRouterAPIKey
- Defined in:
- lib/kward/auth/openrouter_api_key.rb
Overview
Config helper for storing and removing OpenRouter API keys.
Instance Attribute Summary collapse
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
Instance Method Summary collapse
- #api_key ⇒ Object
- #configured? ⇒ Boolean
-
#initialize(config_path: OpenAIOAuth.default_config_path) ⇒ OpenRouterAPIKey
constructor
A new instance of OpenRouterAPIKey.
- #login(prompt:) ⇒ Object
- #logout ⇒ Object
Constructor Details
#initialize(config_path: OpenAIOAuth.default_config_path) ⇒ OpenRouterAPIKey
Returns a new instance of OpenRouterAPIKey.
10 11 12 |
# File 'lib/kward/auth/openrouter_api_key.rb', line 10 def initialize(config_path: OpenAIOAuth.default_config_path) @config_path = File.(config_path) end |
Instance Attribute Details
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
8 9 10 |
# File 'lib/kward/auth/openrouter_api_key.rb', line 8 def config_path @config_path end |
Instance Method Details
#api_key ⇒ Object
14 15 16 |
# File 'lib/kward/auth/openrouter_api_key.rb', line 14 def api_key ENV["OPENROUTER_API_KEY"].to_s.empty? ? ConfigFiles.config_value(config, "openrouter_api_key") : ENV["OPENROUTER_API_KEY"] end |
#configured? ⇒ Boolean
18 19 20 |
# File 'lib/kward/auth/openrouter_api_key.rb', line 18 def configured? !api_key.to_s.empty? end |
#login(prompt:) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/kward/auth/openrouter_api_key.rb', line 22 def login(prompt:) api_key = prompt.ask("OpenRouter API key:").to_s.strip raise "OpenRouter API key must be a non-empty string" if api_key.empty? ConfigFiles.update_config({ "openrouter_api_key" => api_key }, @config_path) @config_path end |
#logout ⇒ Object
30 31 32 |
# File 'lib/kward/auth/openrouter_api_key.rb', line 30 def logout ConfigFiles.delete_config_key("openrouter_api_key", @config_path) end |