forked from muxinc/mux-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathingest.rb
executable file
·37 lines (31 loc) · 1.05 KB
/
ingest.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env ruby
require 'mux_ruby'
require 'solid_assert'
SolidAssert.enable_assertions
# Authentication Setup
openapi = MuxRuby.configure do |config|
config.username = ENV['MUX_TOKEN_ID']
config.password = ENV['MUX_TOKEN_SECRET']
end
# API Client Initialization
assets_api = MuxRuby::AssetsApi.new
# Create an Asset
car = MuxRuby::CreateAssetRequest.new
car.input = 'https://storage.googleapis.com/muxdemofiles/mux-video-intro.mp4'
car.playback_policy = [MuxRuby::PlaybackPolicy::PUBLIC]
create_response = assets_api.create_asset(car)
puts "Created Asset ID: #{create_response.data.id}"
# Wait for the asset to become ready, then print its URL
if create_response.data.status != 'ready'
puts "Waiting for asset to become ready..."
while true do
asset = assets_api.get_asset(create_response.data.id)
if asset.data.status != 'ready'
puts "Asset not ready yet, sleeping..."
sleep(1)
else
puts "Asset ready! Playback URL: https://stream.mux.com/#{create_response.data.playback_ids.first.id}.m3u8"
break
end
end
end