Class: Kie::Client
- Inherits:
-
Object
- Object
- Kie::Client
- Defined in:
- lib/kie/client.rb
Overview
HTTP client for Kie.ai API
Constant Summary collapse
- BASE_URL =
"https://api.kie.ai"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
- #connection ⇒ Object
- #general ⇒ Object
-
#initialize(api_key: nil) ⇒ Client
constructor
A new instance of Client.
- #suno ⇒ Object
Constructor Details
#initialize(api_key: nil) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 |
# File 'lib/kie/client.rb', line 12 def initialize(api_key: nil) @api_key = api_key || ENV.fetch("KIE_API_KEY", nil) return unless @api_key.nil? || @api_key.empty? raise ConfigurationError, "API key is required. Pass it as an argument or set KIE_API_KEY environment variable." end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
10 11 12 |
# File 'lib/kie/client.rb', line 10 def api_key @api_key end |
Instance Method Details
#connection ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/kie/client.rb', line 20 def connection @connection ||= Faraday.new(url: BASE_URL) do |conn| conn.headers["Authorization"] = "Bearer #{api_key}" conn.headers["Content-Type"] = "application/json" conn.use Middleware::RaiseError end end |
#general ⇒ Object
28 29 30 |
# File 'lib/kie/client.rb', line 28 def general @general ||= GeneralEngine.new(client: self) end |
#suno ⇒ Object
32 33 34 |
# File 'lib/kie/client.rb', line 32 def suno @suno ||= SunoEngine.new(client: self) end |