Class: RubyCoded::Strategies::APIKeyStrategy

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_coded/strategies/api_key_strategy.rb

Overview

This class is used to authenticate using an API key

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from RubyCoded::Strategies::Base

Instance Method Details

#authenticateObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ruby_coded/strategies/api_key_strategy.rb', line 10

def authenticate
  @prompt.say("Opening #{@provider.display_name} API key authentication in your browser...")
  open_browser(@provider.console_url)

  key = @prompt.ask("Please generate your API key and paste it here:")

  raise "No API key provided" if key.nil? || key.empty?
  raise "Invalid API key for #{@provider.display_name}" unless valid_format?(key)

  @prompt.say("API key validated successfully")

  { "auth_method" => "api_key", "key" => key }
end

#refresh(credentials) ⇒ Object



24
25
26
# File 'lib/ruby_coded/strategies/api_key_strategy.rb', line 24

def refresh(credentials)
  credentials
end

#validate(credentials) ⇒ Object



28
29
30
# File 'lib/ruby_coded/strategies/api_key_strategy.rb', line 28

def validate(credentials)
  credentials["auth_method"] == "api_key" && valid_format?(credentials["key"])
end