Class: Lipdub::Resources::Audios
- Defined in:
- lib/lipdub/resources/audios.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#failure(audio_id) ⇒ Hash
Mark audio upload as failed.
-
#list(page: 1, page_size: 10) ⇒ Hash
List all audio files.
-
#status(audio_id) ⇒ Hash
Get audio processing status.
-
#success(audio_id) ⇒ Hash
Mark audio upload as successful.
-
#upload(size_bytes:, file_name:, content_type:, audio_source_url: nil) ⇒ Hash
Initiate audio upload process.
-
#upload_complete(file_path, content_type: nil) ⇒ Hash
Complete audio upload process with a file path.
-
#upload_file(upload_url, file_content, content_type) ⇒ Hash
Upload audio file to the provided upload URL.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Lipdub::Resources::Base
Instance Method Details
#failure(audio_id) ⇒ Hash
Mark audio upload as failed
123 124 125 |
# File 'lib/lipdub/resources/audios.rb', line 123 def failure(audio_id) post("/v1/audio/failure/#{audio_id}") end |
#list(page: 1, page_size: 10) ⇒ Hash
List all audio files
146 147 148 149 150 151 152 |
# File 'lib/lipdub/resources/audios.rb', line 146 def list(page: 1, page_size: 10) params = { page: page, page_size: page_size } get("/v1/audio", params) end |
#status(audio_id) ⇒ Hash
Get audio processing status
134 135 136 |
# File 'lib/lipdub/resources/audios.rb', line 134 def status(audio_id) get("/v1/audio/status/#{audio_id}") end |
#success(audio_id) ⇒ Hash
Mark audio upload as successful
112 113 114 |
# File 'lib/lipdub/resources/audios.rb', line 112 def success(audio_id) post("/v1/audio/success/#{audio_id}") end |
#upload(size_bytes:, file_name:, content_type:, audio_source_url: nil) ⇒ Hash
Initiate audio upload process
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lipdub/resources/audios.rb', line 28 def upload(size_bytes:, file_name:, content_type:, audio_source_url: nil) validate_audio_params!(size_bytes, content_type) body = { size_bytes: size_bytes, file_name: file_name, content_type: content_type } body[:audio_source_url] = audio_source_url if audio_source_url post("/v1/audio", body) end |
#upload_complete(file_path, content_type: nil) ⇒ Hash
Complete audio upload process with a file path
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/lipdub/resources/audios.rb', line 67 def upload_complete(file_path, content_type: nil) raise ArgumentError, "File does not exist: #{file_path}" unless File.exist?(file_path) file_content = File.read(file_path) file_name = File.basename(file_path) content_type ||= detect_content_type(file_path) size_bytes = File.size(file_path) # Step 1: Initiate upload upload_response = upload( size_bytes: size_bytes, file_name: file_name, content_type: content_type ) audio_id = upload_response.dig("data", "audio_id") if upload_response.is_a?(Hash) upload_url = upload_response.dig("data", "upload_url") if upload_response.is_a?(Hash) # Handle case where response might still be a string (fallback) if upload_response.is_a?(String) parsed = JSON.parse(upload_response) audio_id = parsed.dig("data", "audio_id") upload_url = parsed.dig("data", "upload_url") end begin # Step 2: Upload file upload_file(upload_url, file_content, content_type) # Step 3: Mark as successful success(audio_id) rescue => e # Step 3 (alternative): Mark as failed failure(audio_id) raise e end end |
#upload_file(upload_url, file_content, content_type) ⇒ Hash
Upload audio file to the provided upload URL
51 52 53 |
# File 'lib/lipdub/resources/audios.rb', line 51 def upload_file(upload_url, file_content, content_type) put_file(upload_url, file_content, content_type) end |