Class: Kie::SunoTask

Inherits:
Object
  • Object
show all
Includes:
Task
Defined in:
lib/kie/suno_task.rb

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

Task::NORMALIZED_STATUSES

Instance Attribute Summary collapse

Instance Method Summary collapse

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_urlsObject (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_codeObject (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_messageObject (readonly)

Returns the value of attribute error_message.



24
25
26
# File 'lib/kie/suno_task.rb', line 24

def error_message
  @error_message
end

#image_urlsObject (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_statusObject (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_dataObject (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_idObject (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

Raises:

  • (error_class)


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

#statusObject

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

#urlsObject

Returns array of audio URLs (implements Task interface)



53
54
55
# File 'lib/kie/suno_task.rb', line 53

def urls
  @audio_urls
end