Class: Lipdub::Resources::Videos
- Defined in:
- lib/lipdub/resources/videos.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#failure(video_id) ⇒ Hash
Mark video upload as failed.
-
#status(video_id) ⇒ Hash
Get video processing status.
-
#success(video_id) ⇒ Hash
Mark video upload as successful.
-
#upload(size_bytes:, file_name:, content_type:, video_source_url: nil) ⇒ Hash
Initiate video upload process.
-
#upload_complete(file_path, content_type: nil) ⇒ Hash
Complete video upload process with a file path.
-
#upload_file(upload_url, file_content, content_type) ⇒ Hash
Upload video 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(video_id) ⇒ Hash
Mark video upload as failed
127 128 129 |
# File 'lib/lipdub/resources/videos.rb', line 127 def failure(video_id) post("/v1/video/failure/#{video_id}") end |
#status(video_id) ⇒ Hash
Get video processing status
138 139 140 |
# File 'lib/lipdub/resources/videos.rb', line 138 def status(video_id) get("/v1/video/status/#{video_id}") end |
#success(video_id) ⇒ Hash
Mark video upload as successful
116 117 118 |
# File 'lib/lipdub/resources/videos.rb', line 116 def success(video_id) post("/v1/video/success/#{video_id}") end |
#upload(size_bytes:, file_name:, content_type:, video_source_url: nil) ⇒ Hash
Initiate video upload process
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/lipdub/resources/videos.rb', line 28 def upload(size_bytes:, file_name:, content_type:, video_source_url: nil) body = { size_bytes: size_bytes, file_name: file_name, content_type: content_type } body[:video_source_url] = video_source_url if video_source_url post("/v1/video", body) end |
#upload_complete(file_path, content_type: nil) ⇒ Hash
Complete video upload process with a file path
65 66 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 |
# File 'lib/lipdub/resources/videos.rb', line 65 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 ) video_id = upload_response.dig("data", "video_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) video_id = parsed.dig("data", "video_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(video_id) rescue => e # Step 3 (alternative): Mark as failed failure(video_id) raise e end end |
#upload_file(upload_url, file_content, content_type) ⇒ Hash
Upload video file to the provided upload URL
49 50 51 |
# File 'lib/lipdub/resources/videos.rb', line 49 def upload_file(upload_url, file_content, content_type) put_file(upload_url, file_content, content_type) end |