Class: Kie::SunoTask
Overview
Represents an asynchronous task for Suno API endpoints (Suno music generation)
Constant Summary collapse
- RECORD_INFO_ENDPOINT =
"/api/v1/generate/record-info"- STATUS_MAP =
Status mapping from Suno API raw states to normalized statuses
{ PENDING: :processing, TEXT_SUCCESS: :processing, FIRST_SUCCESS: :processing, SUCCESS: :success, CREATE_TASK_FAILED: :failed, GENERATE_AUDIO_FAILED: :failed, CALLBACK_EXCEPTION: :failed, SENSITIVE_WORD_ERROR: :failed }.freeze
Constants included from Task
Instance Attribute Summary collapse
-
#audio_urls ⇒ Object
readonly
Returns the value of attribute audio_urls.
-
#error_code ⇒ Object
readonly
Returns the value of attribute error_code.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#image_urls ⇒ Object
readonly
Returns the value of attribute image_urls.
-
#raw_status ⇒ Object
readonly
Returns the value of attribute raw_status.
-
#suno_data ⇒ Object
readonly
Returns the value of attribute suno_data.
-
#task_id ⇒ Object
(also: #id)
readonly
Returns the value of attribute task_id.
Instance Method Summary collapse
-
#initialize(client:, task_id:) ⇒ SunoTask
constructor
A new instance of SunoTask.
-
#raise_task_error! ⇒ Object
Raises the appropriate exception based on the failure reason.
- #refresh! ⇒ Object
-
#status ⇒ Object
Returns normalized status (:processing, :success, :failed).
-
#urls ⇒ Object
Returns array of audio URLs (implements Task interface).
Methods included from Task
#completed?, #failed?, #processing?, #success?, #wait
Constructor Details
#initialize(client:, task_id:) ⇒ SunoTask
Returns a new instance of SunoTask.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/kie/suno_task.rb', line 28 def initialize(client:, task_id:) @client = client @task_id = task_id @raw_status = nil @suno_data = [] @audio_urls = [] @image_urls = [] @error_code = nil @error_message = nil end |
Instance Attribute Details
#audio_urls ⇒ Object (readonly)
Returns the value of attribute audio_urls.
24 25 26 |
# File 'lib/kie/suno_task.rb', line 24 def audio_urls @audio_urls end |
#error_code ⇒ Object (readonly)
Returns the value of attribute error_code.
24 25 26 |
# File 'lib/kie/suno_task.rb', line 24 def error_code @error_code end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
24 25 26 |
# File 'lib/kie/suno_task.rb', line 24 def @error_message end |
#image_urls ⇒ Object (readonly)
Returns the value of attribute image_urls.
24 25 26 |
# File 'lib/kie/suno_task.rb', line 24 def image_urls @image_urls end |
#raw_status ⇒ Object (readonly)
Returns the value of attribute raw_status.
24 25 26 |
# File 'lib/kie/suno_task.rb', line 24 def raw_status @raw_status end |
#suno_data ⇒ Object (readonly)
Returns the value of attribute suno_data.
24 25 26 |
# File 'lib/kie/suno_task.rb', line 24 def suno_data @suno_data end |
#task_id ⇒ Object (readonly) Also known as: id
Returns the value of attribute task_id.
24 25 26 |
# File 'lib/kie/suno_task.rb', line 24 def task_id @task_id end |
Instance Method Details
#raise_task_error! ⇒ Object
Raises the appropriate exception based on the failure reason
58 59 60 61 |
# File 'lib/kie/suno_task.rb', line 58 def raise_task_error! error_class = @raw_status == :SENSITIVE_WORD_ERROR ? ContentPolicyError : TaskFailedError raise error_class.new(@error_message, fail_code: @raw_status.to_s) end |
#refresh! ⇒ Object
39 40 41 42 43 |
# File 'lib/kie/suno_task.rb', line 39 def refresh! response = @client.connection.get(RECORD_INFO_ENDPOINT, taskId: @task_id) handle_response(response) self end |
#status ⇒ Object
Returns normalized status (:processing, :success, :failed)
46 47 48 49 50 |
# File 'lib/kie/suno_task.rb', line 46 def status return :processing if @raw_status.nil? STATUS_MAP.fetch(@raw_status, :processing) end |
#urls ⇒ Object
Returns array of audio URLs (implements Task interface)
53 54 55 |
# File 'lib/kie/suno_task.rb', line 53 def urls @audio_urls end |