Class: Kward::OpenRouterAPIKey
- Inherits:
-
Object
- Object
- Kward::OpenRouterAPIKey
- Defined in:
- lib/kward/auth/openrouter_api_key.rb
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.
8 9 10 |
# File 'lib/kward/auth/openrouter_api_key.rb', line 8 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.
6 7 8 |
# File 'lib/kward/auth/openrouter_api_key.rb', line 6 def config_path @config_path end |
Instance Method Details
#api_key ⇒ Object
12 13 14 |
# File 'lib/kward/auth/openrouter_api_key.rb', line 12 def api_key ENV["OPENROUTER_API_KEY"].to_s.empty? ? ConfigFiles.config_value(config, "openrouter_api_key") : ENV["OPENROUTER_API_KEY"] end |
#configured? ⇒ Boolean
16 17 18 |
# File 'lib/kward/auth/openrouter_api_key.rb', line 16 def configured? !api_key.to_s.empty? end |
#login(prompt:) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/kward/auth/openrouter_api_key.rb', line 20 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
28 29 30 |
# File 'lib/kward/auth/openrouter_api_key.rb', line 28 def logout ConfigFiles.delete_config_key("openrouter_api_key", @config_path) end |