def group_list(user_jwt, group_delete, GUID, MVID):
    #
    #	List all groups for the current account
    #	input:
    #		user_jwt - properly formed medvid.io JWT user; can be either for Application or Account User
    #		group_delete - If running as an Account User and the user should be able to delete a group, set to True; False otherwise (Boolean)
    #	output:
    #		Api Response Status (boolean)
    #		Group Data (row {"group_id":group_id,
    #			"group_name":group_name,
    #			"group_delete":group_delete,
    #			"GUID":GUID,
    #			"MVID":MVID}})
    #			or None
    #		Error Message (str) or None
    #		Api Message (dict)
    #
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + str(user_jwt)
    }

    # FIX ME: Add logic to handle pagination; fixed to only handle 100 groups per ACCOUNT
    uri = keys.mercury_root
    path = '/groups?limit=100'

    target = urlparse(uri + path)
    method = "GET"
    body = ""

    # Render human readable API message for output
    api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

    h = httplib2.Http()

    response, content = h.request(target.geturl(), method, body, headers)

    if not content:
        return False, None, str(response), api_msg

    try:
        MVID = int(MVID)
    except:
        MVID = str(MVID)

    data = json.loads(content)
    group_data = data.get('groups')
    output_data = []
    if group_data:
        for group_obj in group_data:
            output_data.append({
                "group_id": str(group_obj.get('id')),
                "group_name": str(group_obj.get('name')),
                "group_delete": group_delete,
                "GUID": GUID,
                "MVID": MVID
            })

    return True, output_data, None, api_msg
Esempio n. 2
0
def video_group_list(target_jwt, GUID, MVID, group_id):
    #
    #	List all videos for the user and group specified in the user_jwt / MVID / group_id. Lists all videos
    #	input:
    #		target_jwt - properly formed medvid.io JWT for Application User
    #		GUID - Unique ID (sub value in JWT) of Application User specified in target_jwt
    #		MVID - Unique medvid.io user ID of Application User specified in target_jwt
    #		group_id - Unique ID of group to list videos for
    #	output:
    #		Api Response Status (boolean)
    #		Video Data (row {"video_id":video_id,
    #			"video_title":video_title,
    #			"video_desc":video_desc,
    #			"video_location":video_location,
    #			"video_owner_id":video_owner_id,
    #			"video_subject_id":video_subject_id,
    #			"video_user_viewer_ids":video_user_viewer_ids,
    #			"video_group_viewer_ids":video_group_viewer_ids,
    #			"GUID":GUID,
    #			"MVID":MVID,
    #			"group_policies":group_policies})
    #			or None
    #		Error Message (str) or None
    #		Api Message (dict)
    #
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + str(target_jwt)
    }

    # FIX ME: Add logic to handle pagination; fixed to only handle 100 videos per user

    uri = keys.apollo_root
    path = '/videos/group/' + str(group_id) + "?limit=100"

    target = urlparse(uri + path)
    method = "GET"
    body = ""

    # Render human readable API message for output
    api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

    h = httplib2.Http()

    response, content = h.request(target.geturl(), method, body, headers)

    if response.get("status") != "200":
        return False, None, "Response: " + str(response) + " Content: " + str(
            content), api_msg

    group_policies = api_tools_policy.get_policy_for_group(
        target_jwt, GUID, MVID, group_id)

    data = json.loads(content)
    video_data = data.get('videos')
    output_data = video_parse_data(video_data, GUID, MVID, group_policies)

    return True, output_data, None, api_msg
def policy_list(target_jwt, GUID, MVID):
	#
	#	List all policies for the user specified in the user_jwt / MVID pair.
	#	input: 
	#		target_jwt - properly formed medvid.io JWT for Application User
	#		GUID - Unique ID (sub value in JWT) of Application User specified in target_jwt
	#		MVID - Unique medvid.io user ID of Application User specified in target_jwt
	#	output: 
	#		Api Response Status (boolean)
	#		Policy Data (row {"id":id, 
	#			"user_id":user_id, 
	#			"group_id":group_id, 
	#			"permissions":permissions}) 
	#			or None
	#		Error Message (str) or None
	#		Api Message (dict)
	#
	headers = {
	'Content-Type': 'application/json',
	'Accept': 'application/json',
	'Authorization': 'Bearer ' + str(target_jwt)
	}

	# FIX ME: Add logic to handle pagination; fixed to only handle 100 videos per user

	uri = keys.mercury_root
	path = '/users/' + str(MVID) + "/user_policies?limit=100"

	target = urlparse(uri+path)
	method = "GET"
	body = ""

	# Render human readable API message for output
	api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

	h = httplib2.Http()

	response, content = h.request(target.geturl(), method, body, headers)

	if not content:
		return False, None, str(response), api_msg

	# Handle odd corner case where more than one JSON object is returned; pick the last one and attempt to parse it
	temp_content = content.splitlines()
	if len(temp_content) > 1:
		content = temp_content[len(temp_content)-1]

	data = json.loads(content)
	policy_data = data.get('user_policies')
	output_data = []
	
	if policy_data:
		for p_obj in policy_data:
			output_data.append({"id":p_obj.get('id'), 
				"user_id":p_obj.get('user_id'), 
				"group_id":p_obj.get('group_id'), 
				"permissions":p_obj.get('permissions')})

	return True, output_data, None, api_msg
def group_list(user_jwt, group_delete, GUID, MVID):
	#
	#	List all groups for the current account
	#	input: 
	#		user_jwt - properly formed medvid.io JWT user; can be either for Application or Account User
	#		group_delete - If running as an Account User and the user should be able to delete a group, set to True; False otherwise (Boolean)
	#	output: 
	#		Api Response Status (boolean)
	#		Group Data (row {"group_id":group_id, 
	#			"group_name":group_name,
	#			"group_delete":group_delete,
	#			"GUID":GUID,
	#			"MVID":MVID}})
	#			or None
	#		Error Message (str) or None
	#		Api Message (dict)
	#
	headers = {
	'Content-Type': 'application/json',
	'Accept': 'application/json',
	'Authorization': 'Bearer ' + str(user_jwt)
	}

	# FIX ME: Add logic to handle pagination; fixed to only handle 100 groups per ACCOUNT
	uri = keys.mercury_root
	path = '/groups?limit=100'

	target = urlparse(uri+path)
	method = "GET"
	body = ""

	# Render human readable API message for output
	api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

	h = httplib2.Http()

	response, content = h.request(target.geturl(), method, body, headers)

	if not content:
		return False, None, str(response), api_msg

	try:
		MVID = int(MVID)
	except:
		MVID = str(MVID)

	data = json.loads(content)
	group_data = data.get('groups')
	output_data = []
	if group_data:
		for group_obj in group_data:
			output_data.append({"group_id":str(group_obj.get('id')),
				"group_name":str(group_obj.get('name')),
				"group_delete":group_delete,
				"GUID":GUID,
				"MVID":MVID})

	return True, output_data, None, api_msg
def video_group_list(target_jwt, GUID, MVID, group_id):
	#
	#	List all videos for the user and group specified in the user_jwt / MVID / group_id. Lists all videos
	#	input: 
	#		target_jwt - properly formed medvid.io JWT for Application User
	#		GUID - Unique ID (sub value in JWT) of Application User specified in target_jwt
	#		MVID - Unique medvid.io user ID of Application User specified in target_jwt
	#		group_id - Unique ID of group to list videos for
	#	output: 
	#		Api Response Status (boolean)
	#		Video Data (row {"video_id":video_id, 
	#			"video_title":video_title, 
	#			"video_desc":video_desc,
	#			"video_location":video_location,	 
	#			"video_owner_id":video_owner_id,
	#			"video_subject_id":video_subject_id, 
	#			"video_user_viewer_ids":video_user_viewer_ids, 
	#			"video_group_viewer_ids":video_group_viewer_ids, 
	#			"GUID":GUID,
	#			"MVID":MVID,
	#			"group_policies":group_policies}) 
	#			or None
	#		Error Message (str) or None
	#		Api Message (dict)
	#
	headers = {
	'Content-Type': 'application/json',
	'Accept': 'application/json',
	'Authorization': 'Bearer ' + str(target_jwt)
	}

	# FIX ME: Add logic to handle pagination; fixed to only handle 100 videos per user

	uri = keys.apollo_root
	path = '/videos/group/' + str(group_id) + "?limit=100"

	target = urlparse(uri+path)
	method = "GET"
	body = ""

	# Render human readable API message for output
	api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

	h = httplib2.Http()

	response, content = h.request(target.geturl(), method, body, headers)

	if response.get("status") != "200":
		return False, None, "Response: " + str(response) + " Content: "+ str(content), api_msg

	group_policies = api_tools_policy.get_policy_for_group(target_jwt, GUID, MVID, group_id)

	data = json.loads(content)
	video_data = data.get('videos')
	output_data = video_parse_data(video_data, GUID, MVID, group_policies)

	return True, output_data, None, api_msg
Esempio n. 6
0
def user_list(account_jwt):
    #
    #	List all users for the current application, appends link to view videos for each user
    #	input:
    #		account_jwt - properly formed medvid.io JWT for Account User
    #	output:
    #		Api Response Status (boolean)
    #		User Data (row {"user_id":user_id,
    #			"app_user_id":app_user_id})
    #			or None
    #		Error Message (str) or None
    #		Api Message (dict)
    #
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + str(account_jwt)
    }

    # FIX ME: Add logic to handle pagination; fixed to only handle 100 users per ACCOUNT
    uri = keys.mercury_root
    path = '/users?limit=100'

    target = urlparse(uri + path)
    method = "GET"
    body = ""

    # Render human readable API message for output
    api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

    h = httplib2.Http()

    response, content = h.request(target.geturl(), method, body, headers)

    if not content:
        return False, None, str(response), api_msg

    data = json.loads(content)
    user_data = data.get('users')
    output_data = []
    if user_data:
        for user_obj in user_data:
            tmp_app_id = user_obj.get('app_id')
            if (tmp_app_id == keys.app_id):
                app_user_id = str(user_obj.get('app_user_id'))
                app_info, app_user_id = app_user_id.split('|', 1)
                temp_id = str(user_obj.get('id'))
                output_data.append({
                    "user_id": temp_id,
                    "app_user_id": app_user_id
                })

    return True, output_data, None, api_msg
def group_new(account_jwt, group_name):
	#
	#	Creates a group with for the account specified in the account_jwt with the name specified in group_name
	#	input: 
	#		account_jwt - properly formed medvid.io JWT for Account User
	#		group_name - name for new group
	#	output: 
	#		Api Response Status (boolean)
	#		new_group_id (str) or None
	#		new_group_name (str) or None
	#		Error Message (str) or None
	#		Api Message (dict)
	#
	headers = {
	'Content-Type': 'application/json',
	'Accept': 'application/json',
	'Authorization': 'Bearer ' + str(account_jwt)
	}

	uri = keys.mercury_root
	path = '/groups'

	target = urlparse(uri+path)
	method = "POST"
	body = {
	"group":{
	"name":group_name,
	"account_id":keys.account_id
	}
	}

	# Render human readable API message for output
	api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

	h = httplib2.Http()

	response, content = h.request(target.geturl(), method, json.dumps(body), headers)

	# Response error; return fail
	if not content:
		return False, None, None, str(response), api_msg
	elif response.get("status") != "201":
		return False, None, None, "Response: " + str(response) + " Content: "+ str(content), api_msg

	# Successful response; parse JSON data
	data = json.loads(content)
	group_data = data.get('group')
	group_id = str(group_data.get('id'))
	group_name = str(group_data.get('name'))

	return True, group_id, group_name, None, api_msg
Esempio n. 8
0
def user_profile(user_jwt):
    #
    #	Load user profile for user specified in user_jwt; if user does not exist this will create them
    #	input:
    #		user_jwt - properly formed medvid.io JWT for Application User
    #	output:
    #		Api Response Status (boolean)
    #		app_user_id (str) or None
    #		user_id (str) or None
    #		Error Message (str) or None
    #		Api Message (dict)
    #
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + str(user_jwt)
    }

    uri = keys.mercury_root
    path = '/profile'

    target = urlparse(uri + path)
    method = "GET"
    body = ""

    # Render human readable API message for output
    api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

    h = httplib2.Http()

    response, content = h.request(target.geturl(), method, body, headers)

    # Response error; return fail
    if not content:
        return False, None, None, str(response), api_msg
    elif response.get("status") != "200":
        return False, None, None, "Response: " + str(
            response) + " Content: " + str(content), api_msg

    # Successful response; parse JSON data
    data = json.loads(content)
    user_data = data.get('user')
    app_user_id = str(user_data.get('app_user_id'))
    if app_user_id:
        app_info, app_user_id = app_user_id.split('|')
        user_id = str(user_data.get('id'))
    else:
        return False, None, None, "Invalid User GUID", api_msg

    return True, app_user_id, user_id, None, api_msg
def user_list(account_jwt):
	#
	#	List all users for the current application, appends link to view videos for each user
	#	input: 
	#		account_jwt - properly formed medvid.io JWT for Account User
	#	output: 
	#		Api Response Status (boolean)
	#		User Data (row {"user_id":user_id, 
	#			"app_user_id":app_user_id}) 
	#			or None
	#		Error Message (str) or None
	#		Api Message (dict)
	#
	headers = {
	'Content-Type': 'application/json',
	'Accept': 'application/json',
	'Authorization': 'Bearer ' + str(account_jwt)
	}

	# FIX ME: Add logic to handle pagination; fixed to only handle 100 users per ACCOUNT
	uri = keys.mercury_root
	path = '/users?limit=100'

	target = urlparse(uri+path)
	method = "GET"
	body = ""

	# Render human readable API message for output
	api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

	h = httplib2.Http()

	response, content = h.request(target.geturl(), method, body, headers)

	if not content:
		return False, None, str(response), api_msg

	data = json.loads(content)
	user_data = data.get('users')
	output_data = []
	if user_data:
		for user_obj in user_data:
			tmp_app_id = user_obj.get('app_id')
			if(tmp_app_id == keys.app_id):
				app_user_id = str(user_obj.get('app_user_id'))
				app_info, app_user_id = app_user_id.split('|',1)
				temp_id = str(user_obj.get('id'))
				output_data.append({"user_id":temp_id, "app_user_id":app_user_id})

	return True, output_data, None, api_msg
def user_profile(user_jwt):
	#
	#	Load user profile for user specified in user_jwt; if user does not exist this will create them
	#	input: 
	#		user_jwt - properly formed medvid.io JWT for Application User
	#	output: 
	#		Api Response Status (boolean)
	#		app_user_id (str) or None
	#		user_id (str) or None
	#		Error Message (str) or None
	#		Api Message (dict)
	#
	headers = {
	'Content-Type': 'application/json',
	'Accept': 'application/json',
	'Authorization': 'Bearer ' + str(user_jwt)
	}

	uri = keys.mercury_root
	path = '/profile'

	target = urlparse(uri+path)
	method = "GET"
	body = ""

	# Render human readable API message for output
	api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

	h = httplib2.Http()

	response, content = h.request(target.geturl(), method, body, headers)

	# Response error; return fail
	if not content:
		return False, None, None, str(response), api_msg
	elif response.get("status") != "200":
		return False, None, None, "Response: " + str(response) + " Content: "+ str(content), api_msg

	# Successful response; parse JSON data
	data = json.loads(content)
	user_data = data.get('user')
	app_user_id = str(user_data.get('app_user_id'))
	if app_user_id:
		app_info, app_user_id = app_user_id.split('|')
		user_id = str(user_data.get('id'))
	else:
		return False, None, None, "Invalid User GUID", api_msg

	return True, app_user_id, user_id, None, api_msg
def group_new(account_jwt, group_name):
    #
    #	Creates a group with for the account specified in the account_jwt with the name specified in group_name
    #	input:
    #		account_jwt - properly formed medvid.io JWT for Account User
    #		group_name - name for new group
    #	output:
    #		Api Response Status (boolean)
    #		new_group_id (str) or None
    #		new_group_name (str) or None
    #		Error Message (str) or None
    #		Api Message (dict)
    #
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + str(account_jwt)
    }

    uri = keys.mercury_root
    path = '/groups'

    target = urlparse(uri + path)
    method = "POST"
    body = {"group": {"name": group_name, "account_id": keys.account_id}}

    # Render human readable API message for output
    api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

    h = httplib2.Http()

    response, content = h.request(target.geturl(), method, json.dumps(body),
                                  headers)

    # Response error; return fail
    if not content:
        return False, None, None, str(response), api_msg
    elif response.get("status") != "201":
        return False, None, None, "Response: " + str(
            response) + " Content: " + str(content), api_msg

    # Successful response; parse JSON data
    data = json.loads(content)
    group_data = data.get('group')
    group_id = str(group_data.get('id'))
    group_name = str(group_data.get('name'))

    return True, group_id, group_name, None, api_msg
Esempio n. 12
0
def video_play(target_jwt, file_id):
    #
    #	Generates the smil url for an adaptive bitrate stream for the Application User specified in the target_jwt
    #	and the video associated with the file_id
    #	input:
    #		target_jwt - properly formed medvid.io JWT for Application User
    #		file_id - Unique medvid.io ID of video file to be played
    #	output:
    #		Api Response Status (boolean),
    #		SMIL URL or None,
    #		Error message (str) or None
    #		Api Message (dict)
    #
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + str(target_jwt)
    }

    uri = keys.apollo_root
    path = '/video/' + str(file_id)

    target = urlparse(uri + path)
    method = "GET"
    body = ""

    # Render human readable API message for output
    api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

    h = httplib2.Http()

    response, content = h.request(target.geturl(), method, body, headers)

    if not content:
        return False, None, str(response), api_msg
    elif response.get("status") != "200":
        return False, None, "Response: " + str(response) + " Content: " + str(
            content), api_msg

    data = json.loads(content)
    smil_data = data.get('smil_url')

    return True, smil_data, None, api_msg
def video_play(target_jwt, file_id):
	#
	#	Generates the smil url for an adaptive bitrate stream for the Application User specified in the target_jwt 
	#	and the video associated with the file_id
	#	input: 
	#		target_jwt - properly formed medvid.io JWT for Application User
	#		file_id - Unique medvid.io ID of video file to be played
	#	output: 
	#		Api Response Status (boolean),
	#		SMIL URL or None,
	#		Error message (str) or None
	#		Api Message (dict)
	#
	headers = {
	'Content-Type': 'application/json',
	'Accept': 'application/json',
	'Authorization': 'Bearer ' + str(target_jwt)
	}

	uri = keys.apollo_root
	path = '/video/' + str(file_id)

	target = urlparse(uri+path)
	method = "GET"
	body = ""

	# Render human readable API message for output
	api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

	h = httplib2.Http()

	response, content = h.request(target.geturl(), method, body, headers)

	if not content:
		return False, None, str(response), api_msg
	elif response.get("status") != "200":
		return False, None, "Response: " + str(response) + " Content: "+ str(content), api_msg

	data = json.loads(content)
	smil_data = data.get('smil_url')

	return True, smil_data, None, api_msg
Esempio n. 14
0
def video_delete(target_jwt, file_id):
    #
    #	Deletes a video
    #	input:
    #		target_jwt - properly formed medvid.io JWT for Application User; must have rights to delete video
    #		file_id - medvid.io video id to be deleted
    #	output:
    #		Api Response Status (boolean),
    #		Video ID (str),
    #		Error Message (str) or None
    #		Api Message (dict)
    #
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + str(target_jwt)
    }

    uri = keys.apollo_root
    path = '/video/' + str(file_id)

    target = urlparse(uri + path)
    method = "DELETE"
    body = ""

    # Render human readable API message for output
    api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

    h = httplib2.Http()

    response, content = h.request(target.geturl(), method, body, headers)

    if response.get('errors'):
        return False, None, str(response), api_msg
    elif response.get("status") != "204":
        return False, None, "Response: " + str(response) + " Content: " + str(
            content), api_msg

    return True, str(file_id), None, api_msg
def video_delete(target_jwt, file_id):
	#
	#	Deletes a video
	#	input: 
	#		target_jwt - properly formed medvid.io JWT for Application User; must have rights to delete video
	#		file_id - medvid.io video id to be deleted
	#	output: 
	#		Api Response Status (boolean), 
	#		Video ID (str),
	#		Error Message (str) or None
	#		Api Message (dict)
	#
	headers = {
	'Content-Type': 'application/json',
	'Accept': 'application/json',
	'Authorization': 'Bearer ' + str(target_jwt)
	}

	uri = keys.apollo_root
	path = '/video/' + str(file_id)

	target = urlparse(uri+path)
	method = "DELETE"
	body = ""

	# Render human readable API message for output
	api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

	h = httplib2.Http()

	response, content = h.request(target.geturl(), method, body, headers)

	if response.get('errors'):
		return False, None, str(response), api_msg
	elif response.get("status") != "204":
		return False, None, "Response: " + str(response) + " Content: "+ str(content), api_msg

	return True, str(file_id), None, api_msg
def group_delete(account_jwt, group_id):
	#
	#	Deletes a group
	#	input: 
	#		account_jwt - properly formed medvid.io JWT for Account User
	#		group_id - medvid.io group id to be deleted
	#	output: 
	#		Api Response Status (boolean), 
	#		Group ID (str),
	#		Error Message (str) or None
	#		Api Message (dict)
	#
	headers = {
	'Content-Type': 'application/json',
	'Accept': 'application/json',
	'Authorization': 'Bearer ' + str(account_jwt)
	}

	uri = keys.mercury_root
	path = '/groups/' + str(group_id)

	target = urlparse(uri+path)
	method = "DELETE"
	body = ""

	# Render human readable API message for output
	api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

	h = httplib2.Http()

	response, content = h.request(target.geturl(), method, body, headers)

	if response.get('errors'):
		return False, None, str(response), api_msg

	return True, str(group_id), None, api_msg
def policy_delete(account_jwt, policy_id):
    #
    #	Deletes a policy
    #	input:
    #		account_jwt - properly formed medvid.io JWT for Account User
    #		policy_id - medvid.io of the policy id to be deleted
    #	output:
    #		Api Response Status (boolean),
    #		Policy ID (str),
    #		Error Message (str) or None
    #		Api Message (dict)
    #
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + str(account_jwt)
    }

    uri = keys.mercury_root
    path = '/user_policies/' + str(policy_id)

    target = urlparse(uri + path)
    method = "DELETE"
    body = ""

    # Render human readable API message for output
    api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

    h = httplib2.Http()

    response, content = h.request(target.geturl(), method, body, headers)

    if response.get('errors'):
        return False, None, str(response), api_msg

    return True, str(policy_id), None, api_msg
Esempio n. 18
0
def video_get(target_jwt, file_id):
    #
    #	Gathers all data on a video for the provided Application User specified in the target_jwt
    #	and the video associated with the file_id
    #	input:
    #		target_jwt - properly formed medvid.io JWT for Application User
    #		file_id - Unique medvid.io ID of video file to be loaded
    #	output:
    #		Api Response Status (boolean),
    #		Output Data ({"video_id":video_id,
    #			"video_title":video_title,
    #			"video_desc":video_desc,
    #			"video_location":video_location,
    #			"video_owner_id":video_owner_id,
    #			"video_subject_id":video_subject_id,
    #			"video_user_viewer_ids":video_user_viewer_ids,
    #			"video_group_viewer_ids":video_group_viewer_ids}) or None,
    #		Error message (str) or None
    #		Api Message (dict)
    #
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + str(target_jwt)
    }

    uri = keys.apollo_root
    path = '/video/' + str(file_id)

    target = urlparse(uri + path)
    method = "GET"
    body = ""

    # Render human readable API message for output
    api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

    h = httplib2.Http()

    response, content = h.request(target.geturl(), method, body, headers)

    if not content:
        return False, None, str(response), api_msg
    elif response.get("status") != "200":
        return False, None, "Response: " + str(response) + " Content: " + str(
            content), api_msg

    data = json.loads(content)
    video_data = data.get('video')
    output_data = {}

    if video_data:
        output_data.update({"video_id": str(video_data.get('id'))})
        output_data.update({"video_title": str(video_data.get('title'))})
        if video_data.get('description'):
            output_data.update(
                {"video_desc": str(video_data.get('description'))})
        else:
            output_data.update({"video_desc": ""})

        if video_data.get('location'):
            output_data.update(
                {"video_location": str(video_data.get('location'))})
        else:
            output_data.update({"video_location": ""})

        if video_data.get('owner_id'):
            output_data.update(
                {"video_owner_id": str(video_data.get('owner_id'))})
        else:
            output_data.update({"video_owner_id": ""})

        if video_data.get('subject_id'):
            output_data.update(
                {"video_subject_id": video_data.get('subject_id')})
        else:
            output_data.update({"video_subject_id": ""})

        if video_data.get('user_viewer_ids'):
            output_data.update({
                "video_user_viewer_ids":
                str(video_data.get('user_viewer_ids')).strip('[]')
            })
        else:
            output_data.update({"video_user_viewer_ids": ""})

        if video_data.get('group_viewer_ids'):
            output_data.update({
                "video_group_viewer_ids":
                str(video_data.get('group_viewer_ids')).strip('[]')
            })
        else:
            output_data.update({"video_group_viewer_ids": ""})
    else:
        output_data = None

    return True, output_data, None, api_msg
def policy_update(account_jwt, MVID, p_id, g_id, _create, _read, _update,
                  _delete, _list):
    #
    #	Creates / updates existing policy for a user / group
    #	input:
    #		account_jwt - properly formed medvid.io JWT for Account User
    #		MVID - Unique medvid.io user ID of Application User specified in target_jwt
    #		p_id - ID of policy to update, or "" if creating new policy
    #		g_id - ID of group to apply policy to
    #		_create - create right for policy
    #		_read - read right for policy
    #		_update - update right for policy
    #		_delete - delete right for policy
    #		_list - list right for policy
    #	output:
    #		Api Response Status (boolean)
    #		Policy Data (row {"user_id":user_id,
    #			"group_id":group_id,
    #			"permissions":permissions})
    #			or None
    #		Error Message (str) or None
    #		Api Message (dict)
    #
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + str(account_jwt)
    }

    uri = keys.mercury_root

    if p_id:
        # p_id provided; update existing policy
        path = '/user_policies/' + p_id
        target = urlparse(uri + path)
        method = "PUT"
    else:
        # no p_id; create new policy
        path = '/user_policies'
        target = urlparse(uri + path)
        method = "POST"

    # Attempt conversion to int; abondon and default to str if needed
    try:
        MVID = int(MVID)
    except:
        MVID = str(MVID)

    try:
        g_id = int(g_id)
    except:
        g_id = str(g_id)

    body = {
        'user_policy': {
            'user_id':
            MVID,
            'group_id':
            g_id,
            'permissions':
            policy_build_permissions(_create, _read, _update, _delete, _list)
        }
    }

    # Render human readable API message for output
    api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

    #return False, p_id, None, api_msg
    h = httplib2.Http()

    response, content = h.request(target.geturl(), method, json.dumps(body),
                                  headers)

    # Response error; return fail
    if not content:
        return False, None, str(response), api_msg
    elif response.get("status") == "201" or response.get("status") == "200":
        # Successful response; parse JSON data
        data = json.loads(content)
        policy_data = data.get('user_policy')

        output_data = {
            "user_id": policy_data.get('user_id'),
            "group_id": policy_data.get('group_id'),
            "permissions": policy_data.get('permissions')
        }

        return True, output_data, None, api_msg

    # invalid response
    return False, None, "Response: " + str(response) + " Content: " + str(
        content), api_msg

    # Successful response; parse JSON data
    data = json.loads(content)
    policy_data = data.get('user_policy')

    output_data = {
        "user_id": policy_data.get('user_id'),
        "group_id": policy_data.get('group_id'),
        "permissions": policy_data.get('permissions')
    }

    return True, output_data, None, api_msg
def policy_list(target_jwt, GUID, MVID):
    #
    #	List all policies for the user specified in the user_jwt / MVID pair.
    #	input:
    #		target_jwt - properly formed medvid.io JWT for Application User
    #		GUID - Unique ID (sub value in JWT) of Application User specified in target_jwt
    #		MVID - Unique medvid.io user ID of Application User specified in target_jwt
    #	output:
    #		Api Response Status (boolean)
    #		Policy Data (row {"id":id,
    #			"user_id":user_id,
    #			"group_id":group_id,
    #			"permissions":permissions})
    #			or None
    #		Error Message (str) or None
    #		Api Message (dict)
    #
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + str(target_jwt)
    }

    # FIX ME: Add logic to handle pagination; fixed to only handle 100 videos per user

    uri = keys.mercury_root
    path = '/users/' + str(MVID) + "/user_policies?limit=100"

    target = urlparse(uri + path)
    method = "GET"
    body = ""

    # Render human readable API message for output
    api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

    h = httplib2.Http()

    response, content = h.request(target.geturl(), method, body, headers)

    if not content:
        return False, None, str(response), api_msg

    # Handle odd corner case where more than one JSON object is returned; pick the last one and attempt to parse it
    temp_content = content.splitlines()
    if len(temp_content) > 1:
        content = temp_content[len(temp_content) - 1]

    data = json.loads(content)
    policy_data = data.get('user_policies')
    output_data = []

    if policy_data:
        for p_obj in policy_data:
            output_data.append({
                "id": p_obj.get('id'),
                "user_id": p_obj.get('user_id'),
                "group_id": p_obj.get('group_id'),
                "permissions": p_obj.get('permissions')
            })

    return True, output_data, None, api_msg
def video_update(user_jwt, video_id, videoName, videoDesc, videoLoc, videoOwner, videoSubject, videoViewers, videoGroups):
	#
	#	Updates a specified video file in the medvid.io API
	#	input: 
	#		user_jwt - properly formed medvid.io JWT for Application User updating the video (will be set as owner)
	#		MVID - Unique medvid.io user ID of Application User specified in user_jwt (will be set as 'owner_id')
	#		videoName - Name of video file to be uploaded (will be set as 'title')
	#		videoDesc - Description of video file to be uploaded (will be set as 'description')
	#		videoLoc - "Filming Location" of video file to be uploaded (will be set as 'location')
	#		videoPath - Path to file to be uploaded
	#		videoSubject - Subject of video
	#		videoViewers - Comma seperated list of video viewers medvid.io IDs
	#		videoGroups - Comma seperated list of video group 
	#	output: 
	#		Api Reponse Status (boolean),
	#		New Video Data {"video_title":video_title, 
	#			"video_id":video_id, 
	#			"MVID":MVID, 
	#			"video_created_at":video_created_at} 
	#			or None
	#		Error Message (str) or None
	#		Api Message (dict)
	#
	headers = {
	'Content-Type': 'application/json',
	'Accept': 'application/json',
	'Authorization': 'Bearer ' + str(user_jwt)
	}

	uri = keys.apollo_root
	path = '/video/' + str(video_id)

	target = urlparse(uri+path)
	method = "PUT"

	user_viewer_ids = None
	if videoViewers:
		parsedVideoViewers = api_tools.api_parse_csv(videoViewers)
		if parsedVideoViewers and len(parsedVideoViewers) > 0:
			user_viewer_ids = parsedVideoViewers

	group_viewer_ids = None
	if videoGroups:
		parsedGroupViewers = api_tools.api_parse_csv(videoGroups)
		if parsedGroupViewers and len(parsedGroupViewers) > 0:
			group_viewer_ids = parsedGroupViewers

	body = {
	'video':{
	'title':videoName,
	'description':videoDesc,
	'location':videoLoc,
	'user_viewer_ids':user_viewer_ids,
	'group_viewer_ids':group_viewer_ids
	}
	}

	# Render human readable API message for output
	api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

	#return False, p_id, None, api_msg
	h = httplib2.Http()

	response, content = h.request(target.geturl(), method, json.dumps(body), headers)
	
	# Response error; return fail
	if not content:
		return False, None, str(response), api_msg
	elif response.get("status") == "200":
		# Successful response; parse JSON data
		data = json.loads(content)
		video_data = data.get('video')

		output_data = {
		"video_id":video_data.get('id')
		}

		return True, output_data, None, api_msg

	# invalid response
	return False, None, "Response: " + str(response) + " Content: "+ str(content), api_msg
def policy_update(account_jwt, MVID, p_id, g_id, _create, _read, _update, _delete, _list):
	#
	#	Creates / updates existing policy for a user / group
	#	input: 
	#		account_jwt - properly formed medvid.io JWT for Account User
	#		MVID - Unique medvid.io user ID of Application User specified in target_jwt
	#		p_id - ID of policy to update, or "" if creating new policy
	#		g_id - ID of group to apply policy to
	#		_create - create right for policy
	#		_read - read right for policy
	#		_update - update right for policy
	#		_delete - delete right for policy
	#		_list - list right for policy
	#	output: 
	#		Api Response Status (boolean)
	#		Policy Data (row {"user_id":user_id, 
	#			"group_id":group_id, 
	#			"permissions":permissions}) 
	#			or None
	#		Error Message (str) or None
	#		Api Message (dict)
	#
	headers = {
	'Content-Type': 'application/json',
	'Accept': 'application/json',
	'Authorization': 'Bearer ' + str(account_jwt)
	}

	uri = keys.mercury_root

	if p_id:
		# p_id provided; update existing policy
		path = '/user_policies/'+p_id
		target = urlparse(uri+path)
		method = "PUT"
	else:
		# no p_id; create new policy
		path = '/user_policies'
		target = urlparse(uri+path)
		method = "POST"

	# Attempt conversion to int; abondon and default to str if needed
	try:
		MVID = int(MVID)
	except:
		MVID = str(MVID)

	try:
		g_id = int(g_id)
	except:
		g_id = str(g_id)

	body = {
	'user_policy':{
	'user_id':MVID,
	'group_id':g_id,
	'permissions':policy_build_permissions(_create, _read, _update, _delete, _list)
	}
	}

	# Render human readable API message for output
	api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

	#return False, p_id, None, api_msg
	h = httplib2.Http()

	response, content = h.request(target.geturl(), method, json.dumps(body), headers)
	
	# Response error; return fail
	if not content:
		return False, None, str(response), api_msg
	elif response.get("status") == "201" or response.get("status") == "200":
		# Successful response; parse JSON data
		data = json.loads(content)
		policy_data = data.get('user_policy')

		output_data = {
		"user_id":policy_data.get('user_id'),
		"group_id":policy_data.get('group_id'),
		"permissions":policy_data.get('permissions')
		}

		return True, output_data, None, api_msg

	# invalid response
	return False, None, "Response: " + str(response) + " Content: "+ str(content), api_msg

	# Successful response; parse JSON data
	data = json.loads(content)
	policy_data = data.get('user_policy')

	output_data = {
	"user_id":policy_data.get('user_id'),
	"group_id":policy_data.get('group_id'),
	"permissions":policy_data.get('permissions')
	}

	return True, output_data, None, api_msg
Esempio n. 23
0
def video_update(user_jwt, video_id, videoName, videoDesc, videoLoc,
                 videoOwner, videoSubject, videoViewers, videoGroups):
    #
    #	Updates a specified video file in the medvid.io API
    #	input:
    #		user_jwt - properly formed medvid.io JWT for Application User updating the video (will be set as owner)
    #		MVID - Unique medvid.io user ID of Application User specified in user_jwt (will be set as 'owner_id')
    #		videoName - Name of video file to be uploaded (will be set as 'title')
    #		videoDesc - Description of video file to be uploaded (will be set as 'description')
    #		videoLoc - "Filming Location" of video file to be uploaded (will be set as 'location')
    #		videoPath - Path to file to be uploaded
    #		videoSubject - Subject of video
    #		videoViewers - Comma seperated list of video viewers medvid.io IDs
    #		videoGroups - Comma seperated list of video group
    #	output:
    #		Api Reponse Status (boolean),
    #		New Video Data {"video_title":video_title,
    #			"video_id":video_id,
    #			"MVID":MVID,
    #			"video_created_at":video_created_at}
    #			or None
    #		Error Message (str) or None
    #		Api Message (dict)
    #
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + str(user_jwt)
    }

    uri = keys.apollo_root
    path = '/video/' + str(video_id)

    target = urlparse(uri + path)
    method = "PUT"

    user_viewer_ids = None
    if videoViewers:
        parsedVideoViewers = api_tools.api_parse_csv(videoViewers)
        if parsedVideoViewers and len(parsedVideoViewers) > 0:
            user_viewer_ids = parsedVideoViewers

    group_viewer_ids = None
    if videoGroups:
        parsedGroupViewers = api_tools.api_parse_csv(videoGroups)
        if parsedGroupViewers and len(parsedGroupViewers) > 0:
            group_viewer_ids = parsedGroupViewers

    body = {
        'video': {
            'title': videoName,
            'description': videoDesc,
            'location': videoLoc,
            'user_viewer_ids': user_viewer_ids,
            'group_viewer_ids': group_viewer_ids
        }
    }

    # Render human readable API message for output
    api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

    #return False, p_id, None, api_msg
    h = httplib2.Http()

    response, content = h.request(target.geturl(), method, json.dumps(body),
                                  headers)

    # Response error; return fail
    if not content:
        return False, None, str(response), api_msg
    elif response.get("status") == "200":
        # Successful response; parse JSON data
        data = json.loads(content)
        video_data = data.get('video')

        output_data = {"video_id": video_data.get('id')}

        return True, output_data, None, api_msg

    # invalid response
    return False, None, "Response: " + str(response) + " Content: " + str(
        content), api_msg
def video_post(user_jwt, MVID, videoName, videoDesc, videoLoc, videoPath, videoSubject, videoViewers, videoGroups):
	#
	#	Uploads a server side video file to the medvid.io API
	#	input: 
	#		user_jwt - properly formed medvid.io JWT for Application User uploading the video (will be set as owner)
	#		MVID - Unique medvid.io user ID of Application User specified in user_jwt (will be set as 'owner_id')
	#		videoName - Name of video file to be uploaded (will be set as 'title')
	#		videoDesc - Description of video file to be uploaded (will be set as 'description')
	#		videoLoc - "Filming Location" of video file to be uploaded (will be set as 'location')
	#		videoPath - Path to file to be uploaded
	#		videoSubject - Subject of video
	#		videoViewers - Comma seperated list of video viewers medvid.io IDs
	#		videoGroups - Comma seperated list of video group 
	#	output: 
	#		Api Reponse Status (boolean),
	#		New Video Data {"video_title":video_title, 
	#			"video_id":video_id, 
	#			"MVID":MVID, 
	#			"video_created_at":video_created_at} 
	#			or None
	#		Error Message (str) or None
	#		Api Message (dict)
	#
	headers = {
	'Accept': 'application/json',
	'Authorization': 'Bearer ' + str(user_jwt)
	}

	uri = keys.apollo_root
	path = '/video'
	url = uri + path

	# Attempt conversion to int; abondon and default to str if needed
	try:
		MVID = int(MVID)
	except:
		MVID = str(MVID)

	try:
		videoSubject = int(videoSubject)
	except:
		videoSubject = str(videoSubject)

	json_data = {
	"owner_id":MVID,
	"title":videoName,
	}

	if videoDesc:
		json_data.update({"description":videoDesc})

	if videoLoc:
		json_data.update({"location":videoLoc})

	if videoSubject:
		json_data.update({"subject_id":videoSubject})

	if videoViewers:
		parsedVideoViewers = api_tools.api_parse_csv(videoViewers)
		if parsedVideoViewers and len(parsedVideoViewers) > 0:
			json_data.update({"user_viewer_ids":parsedVideoViewers})

	if videoGroups:
		parsedVideoGroups = api_tools.api_parse_csv(videoGroups)
		if parsedVideoGroups and len(parsedVideoGroups) > 0:
			json_data.update({"group_viewer_ids":parsedVideoGroups})

	# Assemble data for human readable cURL info
	temp_body = {
	'--form':"json=%s" % json.dumps(json_data),
	'-F':"media=@%s" % videoPath
	}

	# Render human readable API message for output
	api_msg = api_tools.api_msg_render(headers, temp_body, None, url)

	try:
		response = requests.post(url,
			data={"json":json.dumps(json_data)}, 
			files={"media": open(videoPath, 'rb')}, 
			headers=headers)
	except:
		return False, None, "Error: Request exception", api_msg

	if response.status_code != 201:
		return False, None, "Response: " + str(response.status_code) + " Content: "+ str(response.text), api_msg

	# Successful Upload, parse JSON
	temp_data = response.json()
	output_data = {
	"video_title":str(temp_data['video']['title']),
	"video_id":str(temp_data['video']['id']),
	"MVID":str(MVID),
	"video_created_at":str(temp_data['video']['created_at'])
	}
	return True, output_data, None, api_msg
Esempio n. 25
0
def video_post(user_jwt, MVID, videoName, videoDesc, videoLoc, videoPath,
               videoSubject, videoViewers, videoGroups):
    #
    #	Uploads a server side video file to the medvid.io API
    #	input:
    #		user_jwt - properly formed medvid.io JWT for Application User uploading the video (will be set as owner)
    #		MVID - Unique medvid.io user ID of Application User specified in user_jwt (will be set as 'owner_id')
    #		videoName - Name of video file to be uploaded (will be set as 'title')
    #		videoDesc - Description of video file to be uploaded (will be set as 'description')
    #		videoLoc - "Filming Location" of video file to be uploaded (will be set as 'location')
    #		videoPath - Path to file to be uploaded
    #		videoSubject - Subject of video
    #		videoViewers - Comma seperated list of video viewers medvid.io IDs
    #		videoGroups - Comma seperated list of video group
    #	output:
    #		Api Reponse Status (boolean),
    #		New Video Data {"video_title":video_title,
    #			"video_id":video_id,
    #			"MVID":MVID,
    #			"video_created_at":video_created_at}
    #			or None
    #		Error Message (str) or None
    #		Api Message (dict)
    #
    headers = {
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + str(user_jwt)
    }

    uri = keys.apollo_root
    path = '/video'
    url = uri + path

    # Attempt conversion to int; abondon and default to str if needed
    try:
        MVID = int(MVID)
    except:
        MVID = str(MVID)

    try:
        videoSubject = int(videoSubject)
    except:
        videoSubject = str(videoSubject)

    json_data = {
        "owner_id": MVID,
        "title": videoName,
    }

    if videoDesc:
        json_data.update({"description": videoDesc})

    if videoLoc:
        json_data.update({"location": videoLoc})

    if videoSubject:
        json_data.update({"subject_id": videoSubject})

    if videoViewers:
        parsedVideoViewers = api_tools.api_parse_csv(videoViewers)
        if parsedVideoViewers and len(parsedVideoViewers) > 0:
            json_data.update({"user_viewer_ids": parsedVideoViewers})

    if videoGroups:
        parsedVideoGroups = api_tools.api_parse_csv(videoGroups)
        if parsedVideoGroups and len(parsedVideoGroups) > 0:
            json_data.update({"group_viewer_ids": parsedVideoGroups})

    # Assemble data for human readable cURL info
    temp_body = {
        '--form': "json=%s" % json.dumps(json_data),
        '-F': "media=@%s" % videoPath
    }

    # Render human readable API message for output
    api_msg = api_tools.api_msg_render(headers, temp_body, None, url)

    try:
        response = requests.post(url,
                                 data={"json": json.dumps(json_data)},
                                 files={"media": open(videoPath, 'rb')},
                                 headers=headers)
    except:
        return False, None, "Error: Request exception", api_msg

    if response.status_code != 201:
        return False, None, "Response: " + str(
            response.status_code) + " Content: " + str(response.text), api_msg

    # Successful Upload, parse JSON
    temp_data = response.json()
    output_data = {
        "video_title": str(temp_data['video']['title']),
        "video_id": str(temp_data['video']['id']),
        "MVID": str(MVID),
        "video_created_at": str(temp_data['video']['created_at'])
    }
    return True, output_data, None, api_msg
def video_get(target_jwt, file_id):
	#
	#	Gathers all data on a video for the provided Application User specified in the target_jwt 
	#	and the video associated with the file_id
	#	input: 
	#		target_jwt - properly formed medvid.io JWT for Application User
	#		file_id - Unique medvid.io ID of video file to be loaded
	#	output: 
	#		Api Response Status (boolean),
	#		Output Data ({"video_id":video_id, 
	#			"video_title":video_title, 
	#			"video_desc":video_desc, 
	#			"video_location":video_location, 
	#			"video_owner_id":video_owner_id,
	#			"video_subject_id":video_subject_id, 
	#			"video_user_viewer_ids":video_user_viewer_ids, 
	#			"video_group_viewer_ids":video_group_viewer_ids}) or None,
	#		Error message (str) or None
	#		Api Message (dict)
	#
	headers = {
	'Content-Type': 'application/json',
	'Accept': 'application/json',
	'Authorization': 'Bearer ' + str(target_jwt)
	}

	uri = keys.apollo_root
	path = '/video/' + str(file_id)

	target = urlparse(uri+path)
	method = "GET"
	body = ""

	# Render human readable API message for output
	api_msg = api_tools.api_msg_render(headers, body, method, target.geturl())

	h = httplib2.Http()

	response, content = h.request(target.geturl(), method, body, headers)

	if not content:
		return False, None, str(response), api_msg
	elif response.get("status") != "200":
		return False, None, "Response: " + str(response) + " Content: "+ str(content), api_msg

	data = json.loads(content)
	video_data = data.get('video')
	output_data = {}

	if video_data:
		output_data.update({"video_id":str(video_data.get('id'))})
		output_data.update({"video_title":str(video_data.get('title'))})
		if video_data.get('description'):
			output_data.update({"video_desc":str(video_data.get('description'))})
		else:
			output_data.update({"video_desc":""})
		
		if video_data.get('location'):
			output_data.update({"video_location":str(video_data.get('location'))})
		else:
			output_data.update({"video_location":""})

		if video_data.get('owner_id'):
			output_data.update({"video_owner_id":str(video_data.get('owner_id'))})
		else:
			output_data.update({"video_owner_id":""})
		
		if video_data.get('subject_id'):
			output_data.update({"video_subject_id":video_data.get('subject_id')})
		else:
			output_data.update({"video_subject_id":""})
		
		if video_data.get('user_viewer_ids'):
			output_data.update({"video_user_viewer_ids":str(video_data.get('user_viewer_ids')).strip('[]')})
		else:
			output_data.update({"video_user_viewer_ids":""})
		
		if video_data.get('group_viewer_ids'):
			output_data.update({"video_group_viewer_ids":str(video_data.get('group_viewer_ids')).strip('[]')})
		else:
			output_data.update({"video_group_viewer_ids":""})
	else:
		output_data = None

	return True, output_data, None, api_msg