forked from muxinc/mux-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise-assets.rb
executable file
·121 lines (106 loc) · 4.64 KB
/
exercise-assets.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/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-asset ==========
car = MuxRuby::CreateAssetRequest.new
car.input = [{:url => 'https://storage.googleapis.com/muxdemofiles/mux-video-intro.mp4'}, {:url => "https://tears-of-steel-subtitles.s3.amazonaws.com/tears-fr.vtt", :type => "text", :text_type => "subtitles", :name => "French", :language_code => "fr", :closed_captions => false}]
create_response = assets_api.create_asset(car)
assert create_response != nil
assert create_response.data.id != nil
puts "create-asset OK ✅"
# ========== list-assets ==========
assets = assets_api.list_assets()
assert assets != nil
assert assets.data.first.id == create_response.data.id
puts "list-assets OK ✅"
# Wait for the asset to become ready...
if create_response.data.status != 'ready'
puts " waiting for asset to become ready..."
while true do
# ========== get-asset ==========
asset = assets_api.get_asset(create_response.data.id)
assert asset != nil
assert asset.data.id == create_response.data.id
if asset.data.status != 'ready'
puts "Asset not ready yet, sleeping..."
sleep(1)
else
puts "Asset ready checking input info."
# ========== get-asset-input-info ==========
input_info = assets_api.get_asset_input_info(asset.data.id)
assert input_info != nil
assert input_info.data != nil
break
end
end
end
puts "get-asset OK ✅"
puts "get-asset-input-info OK ✅"
# ========== create-asset-playback-id ==========
cpbr = MuxRuby::CreatePlaybackIDRequest.new
cpbr.policy = MuxRuby::PlaybackPolicy::PUBLIC
pb_id_c = assets_api.create_asset_playback_id(create_response.data.id, cpbr)
assert pb_id_c != nil
assert pb_id_c.data != nil
puts "create-asset-playback-id OK ✅"
# ========== get-asset-playback-id ==========
pb_id = assets_api.get_asset_playback_id(create_response.data.id, pb_id_c.data.id)
assert pb_id != nil
assert pb_id.data != nil
assert pb_id.data.id == pb_id_c.data.id
puts "get-asset-playback-id OK ✅"
# ========== update-asset-mp4-support ==========
mp4_req = MuxRuby::UpdateAssetMP4SupportRequest.new
mp4_req.mp4_support = 'standard'
mp4_asset = assets_api.update_asset_mp4_support(create_response.data.id, mp4_req)
assert mp4_asset != nil
assert mp4_asset.data != nil
assert mp4_asset.data.id == create_response.data.id
assert mp4_asset.data.mp4_support == 'standard'
puts "update-asset-mp4-support OK ✅"
# ========== update-asset-master-access ==========
master_req = MuxRuby::UpdateAssetMasterAccessRequest.new
master_req.master_access = 'temporary'
master_asset = assets_api.update_asset_master_access(create_response.data.id, master_req)
assert master_asset != nil
assert master_asset.data != nil
assert master_asset.data.id == create_response.data.id
assert master_asset.data.master_access == 'temporary'
puts "update-asset-master-access OK ✅"
# ========== create-asset-track ==========
cat = MuxRuby::CreateTrackRequest.new(:url => "https://tears-of-steel-subtitles.s3.amazonaws.com/tears-en.vtt", :type => "text", :text_type => "subtitles", :language_code => "en", :name => "English", :closed_captions => false)
subtitles_track = assets_api.create_asset_track(create_response.data.id, cat)
assert subtitles_track != nil
assert subtitles_track.data.id != nil
assert subtitles_track.data.name == 'English'
asset_with_2_captions = assets_api.get_asset(create_response.data.id)
assert asset_with_2_captions.data.tracks.length == 4 # Audio, Video, French that we ingested with the asset, and the English we added here!
puts "create-asset-track OK ✅"
# ========== delete-asset-track ==========
assets_api.delete_asset_track(create_response.data.id, subtitles_track.data.id)
asset_with_1_captions = assets_api.get_asset(create_response.data.id)
assert asset_with_1_captions.data.tracks.length == 3 # Audio, Video, French that we ingested with the asset
puts "delete-asset-track OK ✅"
# ========== delete-asset-playback-id ==========
assets_api.delete_asset_playback_id(create_response.data.id, pb_id_c.data.id)
deleted_playback_id_asset = assets_api.get_asset(create_response.data.id)
assert deleted_playback_id_asset.data.playback_ids == nil
puts "delete-asset-playback-id OK ✅"
# ========== delete-asset ==========
assets_api.delete_asset(create_response.data.id)
begin
assets_api.get_asset(create_response.data.id)
puts 'Should have errored here.'
exit 255
rescue MuxRuby::NotFoundError => e
assert e != nil
end
puts "delete-asset OK ✅"