def urls(self, player_id, option=None, url_id=None, param_dict=None): """ Used to interact with the /players/:id/urls/ endpoint """ path = self.base_url + player_id + '/urls/' if option: if option.upper() == "NEW": # Option 'new' means create a new player URL required_params = [ 'url', 'bitrate' ] for param in required_params: if param not in param_dict: raise MissingParameter({ 'message': 'Missing [{}] parameter from parameter \ dictionary.' }) param_dict = { 'url': param_dict } response = session.post(path, data=json.dumps(param_dict), headers=self.headers) elif url_id and not option: # No option + URL ID = GET on that URL by ID response = session.get(path, headers=self.headers) elif option.upper() == 'delete'.upper(): # DELETE is a keyword if not url_id: raise MissingParameter({ 'message': 'URL_ID needs to be provided when deleting a player URL.' }) path = path + url_id response = session.delete(path, headers=self.headers) return response elif option.upper() == 'update'.upper(): # UPDATE is a keyword missing_params = [ 'URL ID' if not url_id else None, 'Parameter Dictionary' if not param_dict else None ] while None in missing_params: missing_params.remove(None) if missing_params: raise MissingParameter({ 'message': '{} needs to be provided when updating a player URL.'\ .format(missing_params) }) path = path + url_id param_dict = { 'url': param_dict } response = session.patch(path, json.dumps(param_dict),headers=self.headers) else: if url_id: path = path + url_id response = session.get(path, headers=self.headers) return response.json()
def create(self, param_dict): """ Used to create a new live stream. Valid parameters: name, transcoder_type, billing_mode, broadcast_location, encoder, delivery_method, aspect_ratio_width, aspect_ratio_height """ required_params = [ 'name', 'broadcast_location', 'encoder', 'aspect_ratio_height', 'aspect_ratio_width' ] for key in required_params: if key not in param_dict: raise MissingParameter({ 'message': 'Missing parameter [{}]. Cannot create \ live stream.'.format(key) }) param_dict = { 'live_stream': param_dict } path = self.base_url + 'live_streams/' response = session.post( path, json.dumps(param_dict), headers=self.headers ) return response.json()
def info(self, sched_id=None, option=None): """ Used to get information on all schedules or a particular schedule. Can also be used to get the state of a particular schedule. """ path = self.base_url path = path + sched_id if sched_id else path if option: if not sched_id: raise MissingParameter({ 'message': 'Need schedule ID if getting the state of a schedule.' }) path = path + "/state" response = session.get(path, headers=self.headers) return response.json()
def info(self, rec_id=None, option=None): """ Used to get information on all recordings or on one recording """ path = self.base_url + rec_id if rec_id else self.base_url if option and option == 'state': if rec_id: path = path + '/state' else: raise MissingParameter({ 'message': 'Recording ID needs to be provided when \ getting the state of a recording.' }) response = session.get(path, headers=self.headers) return response.json()
def create(self, param_dict): """ Used to create a transcoder. """ path = self.base_url for parameter in ['name', 'transcoder_type', 'billing_mode', 'broadcast_location', 'protocol', 'delivery_method']: if parameter not in param_dict: raise MissingParameter({ 'message': 'Parameter [{}] missing from the parameter \ dictionary.'.format(parameter) }) param_dict = { 'transcoder': param_dict } response = session.post(path, json.dumps(param_dict), headers=self.headers) return response.json()
def update(self, player_id, param_dict): """ Used to update parameters on a given player """ missing_params = [ 'Player ID' if not player_id else None, 'Parameter Dictionary' if not param_dict else None ] while None in missing_params: missing_params.remove(None) if missing_params: raise MissingParameter( {'message': 'Missing {}.'.format(missing_params)}) param_dict = {'player': param_dict} path = "{}{}".format(self.base_url, player_id) response = session.patch(path, json.dumps(param_dict), headers=self.headers) return response.json()
def info(self, tran_id=None, option=None, uptime_id=None): """ Get information on all transcoders or a specific transcoder Valid options: recordings, schedules, state, stats, thumbnail_url """ path = self.base_url + tran_id if tran_id else self.base_url valid_options = [ 'recordings', 'schedules', 'state', 'stats', 'thumbnail_url' ] if option: if not tran_id: raise MissingParameter({ 'message': 'Transcoder ID is also needed when passing in an \ option' }) if option not in valid_options: raise InvalidParameter({ 'message': 'Option provided is invalid. Valid options are: {}'\ .format(valid_options) }) path = path + option response = session.get(path, headers=self.headers) return response.json()