Class: Awslive::ScheduleAction
- Inherits:
-
Object
- Object
- Awslive::ScheduleAction
show all
- Includes:
- ActionType, StartType
- Defined in:
- lib/awslive-scheduler/schedule_action.rb
Constant Summary
Constants included
from StartType
StartType::FIXED, StartType::FOLLOW, StartType::IMMEDIATE
Constants included
from ActionType
ActionType::INPUT_PREPARE, ActionType::INPUT_SWITCH, ActionType::PAUSE, ActionType::SCTE35_SPLICE_INSERT, ActionType::UNPAUSE
Instance Method Summary
collapse
-
#create(channel_id, start_type, action_type, data) ⇒ Object
-
#create_schedule(channel_id, scheduled_actions) ⇒ Object
-
#delete(channel_id, action_names) ⇒ Object
-
#delete_all(channel_id) ⇒ Object
-
#get_action_id ⇒ Object
-
#get_action_url(channel_id, action_name) ⇒ Object
-
#get_follow_action_url(channel_id, action_name) ⇒ Object
-
#get_follow_schedule(channel_id, action_name) ⇒ Object
-
#get_schedule_action(channel_id, action_name) ⇒ Object
-
#get_schedule_action_type(schedule_action) ⇒ Object
-
#get_schedule_actions(channel_id, action_type = nil, start_type = nil) ⇒ Object
-
#get_schedule_start_type(schedule_action) ⇒ Object
-
#get_type_duration(url) ⇒ Object
-
#initialize(mediaclient = nil) ⇒ ScheduleAction
constructor
A new instance of ScheduleAction.
Constructor Details
#initialize(mediaclient = nil) ⇒ ScheduleAction
Returns a new instance of ScheduleAction.
Instance Method Details
#create(channel_id, start_type, action_type, data) ⇒ Object
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
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/awslive-scheduler/schedule_action.rb', line 89
def create(channel_id, start_type, action_type, data)
scheduled_action = []
ad_scheduled_action = []
create_response = []
if action_type == INPUT_SWITCH
if start_type == IMMEDIATE
scheduled_action << @input_switch_schedule_action.get_immediate_schedule_action(data[:input_ref_name], data[:url_path])
type, duration = get_type_duration(data[:url_path])
if !type.nil? && !duration.nil? && type == "ad_marker"
ad_scheduled_action << @ad_marker_schedule_action.get_immediate_schedule_action(duration)
end
elsif start_type == FOLLOW
scheduled_action << @input_switch_schedule_action.get_follow_schedule_action(data[:follow_input], data[:trigger_input], data[:url_path])
type, duration = get_type_duration(data[:url_path])
if !type.nil? && !duration.nil? && type == "ad_marker"
puts "ad marker provisioned for duration => #{duration}"
ad_scheduled_action << @ad_marker_schedule_action.get_follow_schedule_action(data[:follow_input], duration.to_i)
end
end
elsif action_type == PAUSE
if start_type == FIXED
scheduled_action << @pause_schedule_action.get_pause_schedule_action(data[:channel_class])
end
elsif action_type == UNPAUSE
if start_type == FIXED
scheduled_action << @pause_schedule_action.get_unpause_schedule_action
end
elsif action_type == INPUT_PREPARE
if start_type == IMMEDIATE
scheduled_action << @input_prepare_schedule_action.get_immediate_schedule_action(data[:input_ref_name])
end
end
unless scheduled_action.empty?
create_response << create_schedule(channel_id, scheduled_action)
unless ad_scheduled_action.empty?
puts "Ad Schedule Action #{ad_scheduled_action}"
create_response << create_schedule(channel_id, ad_scheduled_action) rescue nil
end
end
create_response
end
|
#create_schedule(channel_id, scheduled_actions) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/awslive-scheduler/schedule_action.rb', line 30
def create_schedule(channel_id, scheduled_actions )
payload = {
channel_id: "#{channel_id}",
creates: {
schedule_actions: scheduled_actions
}
}
@mediaclient.batch_update_schedule( payload )
end
|
#delete(channel_id, action_names) ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/awslive-scheduler/schedule_action.rb', line 40
def delete(channel_id, action_names)
@mediaclient.batch_update_schedule( {
channel_id: "#{channel_id}",
deletes: {
action_names: action_names
}
} )
end
|
#delete_all(channel_id) ⇒ Object
219
220
221
|
# File 'lib/awslive-scheduler/schedule_action.rb', line 219
def delete_all(channel_id)
@mediaclient.delete_schedule({ channel_id: channel_id })
end
|
#get_action_id ⇒ Object
215
216
217
|
# File 'lib/awslive-scheduler/schedule_action.rb', line 215
def get_action_id
Time.now.to_i
end
|
#get_action_url(channel_id, action_name) ⇒ Object
208
209
210
211
212
213
|
# File 'lib/awslive-scheduler/schedule_action.rb', line 208
def get_action_url(channel_id, action_name)
url = nil
follow_schedule = get_schedule_action(channel_id, action_name)
url = follow_schedule[:schedule_action_settings][:input_switch_settings][:url_path] unless follow_schedule.nil?
url
end
|
#get_follow_action_url(channel_id, action_name) ⇒ Object
201
202
203
204
205
206
|
# File 'lib/awslive-scheduler/schedule_action.rb', line 201
def get_follow_action_url(channel_id, action_name)
url = nil
follow_schedule = get_follow_schedule(channel_id, action_name)
url = follow_schedule[:schedule_action_settings][:input_switch_settings][:url_path] unless follow_schedule.nil?
url
end
|
#get_follow_schedule(channel_id, action_name) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/awslive-scheduler/schedule_action.rb', line 50
def get_follow_schedule(channel_id, action_name)
puts "Follow for action Name : #{action_name}"
follow_schedule = nil
response = @mediaclient.describe_schedule({channel_id: "#{channel_id}", max_results: 100 } )
loop do
response[:schedule_actions].each do | schedule_action |
unless schedule_action[:schedule_action_start_settings][:follow_mode_schedule_action_start_settings].nil?
if schedule_action[:schedule_action_start_settings][:follow_mode_schedule_action_start_settings][:reference_action_name] == action_name
puts "Scheduled Action #{schedule_action}"
if schedule_action[:schedule_action_settings][:input_switch_settings].nil?
next
end
follow_schedule = schedule_action
break
end
end
end
break if !follow_schedule.nil? || response[:next_token].nil?
response = @mediaclient.describe_schedule({channel_id: "#{channel_id}", max_results: 100, next_token: response[:next_token] } )
end
follow_schedule
end
|
#get_schedule_action(channel_id, action_name) ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/awslive-scheduler/schedule_action.rb', line 136
def get_schedule_action(channel_id, action_name)
sc_action = nil
response = @mediaclient.describe_schedule({
channel_id: "#{channel_id}", max_results: 100
})
loop do
response[:schedule_actions].each do | schedule_action |
if schedule_action[:action_name] == action_name
sc_action = schedule_action
break
end
end
break if !sc_action.nil? || response[:next_token].nil?
response = @mediaclient.describe_schedule({channel_id: "#{channel_id}", max_results: 100, next_token: response[:next_token] } )
end
sc_action
end
|
#get_schedule_action_type(schedule_action) ⇒ Object
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/awslive-scheduler/schedule_action.rb', line 154
def get_schedule_action_type(schedule_action)
action_type = nil
schedule_action[:schedule_action_settings].each_pair do | key, value |
if !value.nil?
action_type = key.to_s.sub!("_settings","")
break
end
end
action_type
end
|
#get_schedule_actions(channel_id, action_type = nil, start_type = nil) ⇒ Object
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
# File 'lib/awslive-scheduler/schedule_action.rb', line 176
def get_schedule_actions(channel_id, action_type = nil, start_type = nil)
sc_actions = []
response = @mediaclient.describe_schedule({
channel_id: "#{channel_id}", max_results: 100
})
loop do
response[:schedule_actions].each do | schedule_action |
if !action_type.nil?
current_action_type = get_schedule_action_type(schedule_action)
next if current_action_type != action_type.to_s
end
if !start_type.nil?
current_start_type = get_schedule_start_type(schedule_action)
next if current_start_type.to_s != start_type.to_s
end
sc_actions << schedule_action
end
break if response[:next_token].nil?
response = @mediaclient.describe_schedule({channel_id: "#{channel_id}", max_results: 100, next_token: response[:next_token] } )
end
sc_actions
end
|
#get_schedule_start_type(schedule_action) ⇒ Object
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/awslive-scheduler/schedule_action.rb', line 165
def get_schedule_start_type(schedule_action)
start_type = nil
schedule_action[:schedule_action_start_settings].each_pair do | key, value |
if !value.nil?
start_type = key.to_s.sub!("_mode_schedule_action_start_settings","")
break
end
end
start_type
end
|
#get_type_duration(url) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/awslive-scheduler/schedule_action.rb', line 75
def get_type_duration(url)
type = nil
duration = nil
if !url.nil?
uri = URI.parse(url) rescue nil
params = CGI.parse(uri.query) unless uri.nil?
if !params.nil?
type = params["type"].first rescue nil
duration = params["duration"].first rescue nil
end
end
return type, duration
end
|