def approve_another_topic_channel_subscription_request(
        session, domain_url, api_location, channel_name, owner_username,
        authorized_username, subscriber_jids):

    channel_name = obtainActualName(session, channel_name)
    owner_username = obtainActualName(session, owner_username)
    subscriber_jids = map(lambda x: obtainActualName(session, x),
                          subscriber_jids)

    data = [{
        'subscription': 'subscribed',
        'jid': jid + "@" + domain_url
    } for jid in subscriber_jids]

    if (authorized_username != None):
        authorized_username = obtainActualName(session, authorized_username)
        (status, response) = prepare_and_send_request(
            'POST',
            '%s%s@topics.%s/subscribers/posts/approve' %
            (api_location, channel_name, domain_url),
            payload=data,
            authorization=authorized_username)
    else:
        (status, response) = prepare_and_send_request(
            'POST',
            '%s%s@topics.%s/subscribers/posts/approve' %
            (api_location, channel_name, domain_url),
            payload=data)

    store = open('requests_made', 'a')
    store.write(str(response.ok) + " " + response.content + "\n")
    store.close()
    return status
def delete_topic_channel(session, domain_url, api_location, username, channel_name):

	username = obtainActualName(session, username)
	channel_name = obtainActualName(session, channel_name)

	(status, response) = prepare_and_send_request('DELETE', '%s%s@topics.%s' % (api_location, channel_name, domain_url), authorization=username)
	return status
def all_metadata_access(api_location, username, target_channel_name):

	target_channel_name = "%s@%s" % (obtainActualName(target_channel_name.split("@")[0]), target_channel_name.split("@")[1])

	if username != None:

		username = obtainActualName(username)

		(status, response) = prepare_and_send_request('GET', "%s%s/metadata/posts" % (api_location,
			target_channel_name), authorization=username)
	else:

		(status, response) = prepare_and_send_request('GET', "%s%s/metadata/posts" % (api_location,
			target_channel_name))

	if status:

		try:
			response = json.loads(response.content)
			return ( 'title' in response
			and 'description' in response
			and 'access_model' in response
			and 'creation_date' in response
			and 'channel_type' in response
			and 'default_affiliation' in response )
		except ValueError:
			pass

	return False
def change_topic_channel_subscriber_role(session, domain_url, api_location,
                                         authorized_username, username,
                                         channel_name, subscription):

    username = obtainActualName(session, username)
    channel_name = obtainActualName(session, channel_name)

    data = {username + "@" + domain_url: subscription}

    if (authorized_username != None):
        authorized_username = obtainActualName(session, authorized_username)
        (status, response) = prepare_and_send_request(
            'POST',
            '%s%s@topics.%s/subscribers/posts' %
            (api_location, channel_name, domain_url),
            payload=data,
            authorization=authorized_username)

    else:

        (status, response) = prepare_and_send_request(
            'POST',
            '%s%s@topics.%s/subscribers/posts' %
            (api_location, channel_name, domain_url),
            payload=data)

    store = open('requests_made', 'a')
    store.write(str(response.ok) + " " + response.content + "\n")
    store.close()
    return status
def banned_subscribers_access(session, api_location, username,
                              target_channel_name):

    target_channel_name = "%s@%s" % (obtainActualName(
        session,
        target_channel_name.split("@")[0]), target_channel_name.split("@")[1])

    if username != None:

        username = obtainActualName(session, username)

        (status, response) = prepare_and_send_request(
            'GET',
            "%s%s/subscribers/posts" % (api_location, target_channel_name),
            authorization=username)
    else:

        (status, response) = prepare_and_send_request(
            'GET',
            "%s%s/subscribers/posts" % (api_location, target_channel_name))

    if status:

        try:
            response = json.loads(response.content)
            for jid in response.keys():
                if response[jid] == 'outcast':
                    return True
        except ValueError:
            pass

    return False
def all_metadata_access(session, api_location, username, target_channel_name):

    target_channel_name = "%s@%s" % (obtainActualName(
        session,
        target_channel_name.split("@")[0]), target_channel_name.split("@")[1])

    if username != None:

        username = obtainActualName(session, username)

        (status, response) = prepare_and_send_request(
            'GET',
            "%s%s/metadata/posts" % (api_location, target_channel_name),
            authorization=username)
    else:

        (status, response) = prepare_and_send_request(
            'GET', "%s%s/metadata/posts" % (api_location, target_channel_name))

    if status:

        try:
            response = json.loads(response.content)
            return ('title' in response and 'description' in response
                    and 'access_model' in response
                    and 'creation_date' in response
                    and 'channel_type' in response
                    and 'default_affiliation' in response)
        except ValueError:
            pass

    return False
def has_subscriber_role_in_topic_channel(session, domain_url, api_location,
                                         username, channel_name, subscription):

    username = obtainActualName(session, username)
    channel_name = obtainActualName(session, channel_name)

    (status,
     response) = prepare_and_send_request('GET',
                                          '%ssubscribed' % (api_location),
                                          authorization=username)

    store = open('requests_made', 'a')
    store.write(str(response.ok) + " " + response.content + "\n")
    store.close()

    if status == True:

        try:
            response = json.loads(response.content)
            channel_node = '%s@topics.%s/posts' % (channel_name, domain_url)
            return channel_node in response and response[
                channel_node] == subscription
        except ValueError:
            pass

    return False
def banned_subscribers_access(api_location, username, target_channel_name):

	target_channel_name = "%s@%s" % (obtainActualName(target_channel_name.split("@")[0]), target_channel_name.split("@")[1])

	if username != None:
	
		username = obtainActualName(username)

		(status, response) = prepare_and_send_request('GET', "%s%s/subscribers/posts" % (api_location,
			target_channel_name), authorization=username)
	else:

		(status, response) = prepare_and_send_request('GET', "%s%s/subscribers/posts" % (api_location,
			target_channel_name))

	if status:

		try:
			response = json.loads(response.content)
			for jid in response.keys():
				if response[jid] == 'outcast':
					return True
		except ValueError:
			pass

	return False
def approve_user_channel_subscription_request(session, domain_url, api_location, username, subscriber_jids):

	username = obtainActualName(session, username)
	subscriber_jids = map(lambda x: obtainActualName(session, x), subscriber_jids)

	data = [ {'subscription' : 'subscribed', 'jid' : jid + "@" + domain_url} for jid in subscriber_jids ]
	return prepare_and_send_request('POST', '%s%s@%s/subscribers/posts/approve' % (api_location, username, domain_url),
			payload=data, authorization=username)
def remove_post_created_by_moderator(session, api_location, username,
                                     target_channel_name):

    target_username = obtainActualName(session,
                                       target_channel_name.split("@")[0])
    domain_url = target_channel_name.split("@")[1]
    target_channel_name = "%s@%s" % (target_username, domain_url)

    owner_username = '******'
    owner_username = obtainActualName(session, owner_username)

    content_posted = "By the way, what happened to Waaaaaalt?"

    data = {"content": content_posted}

    (status, response) = prepare_and_send_request(
        'POST',
        "%s%s/content/posts" % (api_location, target_channel_name),
        payload=data,
        authorization=owner_username)

    if status:

        try:
            response = json.loads(response.content)

            post_id = response['id']
            post_author = response['author']
            content_obtained = response['content']

            if (post_author != "%s@%s" %
                (owner_username, domain_url.replace("topics.", ""))
                    or content_obtained != content_posted):

                return False

            if username != None:

                username = obtainActualName(session, username)

                (status, response) = prepare_and_send_request(
                    'DELETE',
                    "%s%s/content/posts/%s" %
                    (api_location, target_channel_name, post_id),
                    authorization=username)
            else:

                (status, response) = prepare_and_send_request(
                    'DELETE', "%s%s/content/posts/%s" %
                    (api_location, target_channel_name, post_id))

            return status

        except ValueError:
            pass

    return False
def update_metadata_info(api_location, username, target_channel_name, metadata_field, metadata_value):

	target_channel_name = "%s@%s" % (obtainActualName(target_channel_name.split("@")[0]), target_channel_name.split("@")[1])
	
	if username != None:

		username = obtainActualName(username)

		(status, response) = prepare_and_send_request('GET', "%s%s/metadata/posts" % (api_location,
			target_channel_name), authorization=username)
	else:

		(status, response) = prepare_and_send_request('GET', "%s%s/metadata/posts" % (api_location,
			target_channel_name))

	if status:

		try:
			response = json.loads(response.content)

			if metadata_value.startswith("*"):
				metadata_value = response[metadata_field] + metadata_value.replace("*", "")
			else:
				metadata_value = metadata_value.replace("/", "").replace(response[metadata_field], "")
		except ValueError:
			pass

	data = { metadata_field : metadata_value }

	if username != None:

		(status, response) = prepare_and_send_request('POST', "%s%s/metadata/posts" % (api_location,
			target_channel_name), payload=data, authorization=username)
	else:

		(status, response) = prepare_and_send_request('POST', "%s%s/metadata/posts" % (api_location,
			target_channel_name), payload=data)

	if status:

		if username != None:

			(status, response) = prepare_and_send_request('GET', "%s%s/metadata/posts" % (api_location,
				target_channel_name), authorization=username)
		else:

			(status, response) = prepare_and_send_request('GET', "%s%s/metadata/posts" % (api_location,
				target_channel_name))			

		if status:

			try:
				response = json.loads(response.content)
				return response[metadata_field] == metadata_value
			except ValueError:
				pass
	return False
def subscribe_to_topic_channel(session, domain_url, api_location, username, channel_name, subscription):

	username = obtainActualName(session, username)
	channel_name = obtainActualName(session, channel_name)

	data = {
		'%s@topics.%s/posts' % (channel_name, domain_url) : subscription
	}
	(status, response) = prepare_and_send_request('POST', '%ssubscribed' % (api_location), payload=data, authorization=username)
	return status
def change_user_channel_subscriber_role(session, domain_url, api_location, username, subscriber_username, subscription):

	username = obtainActualName(session, username)
	subscriber_username = obtainActualName(session, subscriber_username)

	data = {
		subscriber_username + "@" + domain_url : subscription
	}
	return prepare_and_send_request('POST', '%s%s@%s/subscribers/posts' % (api_location, username, domain_url),
			payload=data, authorization=username)
Exemplo n.º 14
0
def delete_topic_channel(session, domain_url, api_location, username, channel_name):

	username = obtainActualName(session, username)
	channel_name = obtainActualName(session, channel_name)

	(status, response) = prepare_and_send_request('DELETE', '%s%s@topics.%s' % (api_location, channel_name, domain_url), authorization=username)
	
	store = open('requests_made', 'a')
	store.write(str(response.ok) + " " + response.content + "\n")
	store.close()
	return status
def remove_post_created_by_owner(session, api_location, username, target_channel_name):

	target_username = obtainActualName(session, target_channel_name.split("@")[0])
	domain_url =  target_channel_name.split("@")[1]
	target_channel_name = "%s@%s" % (target_username, domain_url)

	if ( 'open' in target_username ):
		owner_username = '******'
	else:
		owner_username = '******'

	owner_username = obtainActualName(session, owner_username)

	content_posted = "By the way, what happened to Waaaaaalt?"

	data = {
		"content" : content_posted
	}

	(status, response) = prepare_and_send_request('POST', "%s%s/content/posts" % (api_location,
			target_channel_name), payload=data, authorization=owner_username)

	if status:

		try:
			response = json.loads(response.content)
			
			post_id = response['id']
			post_author = response['author']
			content_obtained = response['content']

			if ( post_author != "%s@%s" % (owner_username, domain_url.replace("topics.", "")) or content_obtained != content_posted ):

				return False

			if username != None:

				username = obtainActualName(session, username)
		
				(status, response) = prepare_and_send_request('DELETE', "%s%s/content/posts/%s" % (api_location,
					target_channel_name, post_id), authorization=username)
			else:
				
				(status, response) = prepare_and_send_request('DELETE', "%s%s/content/posts/%s" % (api_location,
					target_channel_name, post_id))

			return status

		except ValueError:
			pass

	return False
Exemplo n.º 16
0
def approve_user_channel_subscription_request(session, domain_url, api_location, username, subscriber_jids):

	username = obtainActualName(session, username)
	subscriber_jids = map(lambda x: obtainActualName(session, x), subscriber_jids)

	data = [ {'subscription' : 'subscribed', 'jid' : jid + "@" + domain_url} for jid in subscriber_jids ]
	(status, response) = prepare_and_send_request('POST', '%s%s@%s/subscribers/posts/approve' % (api_location, username, domain_url),
			payload=data, authorization=username)

	store = open('requests_made', 'a')
	store.write(str(response.ok) + " " + response.content + "\n")
	store.close()
	return status
def remove_own_post(session, api_location, username, target_channel_name):

	target_username = obtainActualName(session, target_channel_name.split("@")[0])
	domain_url =  target_channel_name.split("@")[1]
	target_channel_name = "%s@%s" % (target_username, domain_url)

	content_posted = "The Lost finale was pretty bad."

	data = {
		"content" : content_posted
	}

	if username != None:

		username = obtainActualName(session, username)

		(status, response) = prepare_and_send_request('POST', "%s%s/content/posts" % (api_location,
			target_channel_name), payload=data, authorization=username)
	else:

		(status, response) = prepare_and_send_request('POST', "%s%s/content/posts" % (api_location,
			target_channel_name), payload=data)

	if status:

		try:
			response = json.loads(response.content)
			
			post_id = response['id']
			post_author = response['author']
			content_obtained = response['content']

			if ( post_author != "%s@%s" % (username, domain_url.replace("topics.", "")) or content_obtained != content_posted ):

				return False

			if username != None:

				(status, response) = prepare_and_send_request('DELETE', "%s%s/content/posts/%s" % (api_location,
					target_channel_name, post_id), authorization=username)
			else:
				
				(status, response) = prepare_and_send_request('DELETE', "%s%s/content/posts/%s" % (api_location,
					target_channel_name, post_id))

			return status

		except ValueError:
			pass

	return False
Exemplo n.º 18
0
def subscribe_to_topic_channel(session, domain_url, api_location, username, channel_name, subscription):

	username = obtainActualName(session, username)
	channel_name = obtainActualName(session, channel_name)

	data = {
		'%s@topics.%s/posts' % (channel_name, domain_url) : subscription
	}
	(status, response) = prepare_and_send_request('POST', '%ssubscribed' % (api_location), payload=data, authorization=username)
	
	store = open('requests_made', 'a')
	store.write(str(response.ok) + " " + response.content + "\n")
	store.close()
	return status
Exemplo n.º 19
0
def delete_topic_channel(session, domain_url, api_location, username,
                         channel_name):

    username = obtainActualName(session, username)
    channel_name = obtainActualName(session, channel_name)

    (status, response) = prepare_and_send_request(
        'DELETE',
        '%s%s@topics.%s' % (api_location, channel_name, domain_url),
        authorization=username)

    store = open('requests_made', 'a')
    store.write(str(response.ok) + " " + response.content + "\n")
    store.close()
    return status
Exemplo n.º 20
0
def change_user_channel_subscriber_role(session, domain_url, api_location, username, subscriber_username, subscription):

	username = obtainActualName(session, username)
	subscriber_username = obtainActualName(session, subscriber_username)

	data = {
		subscriber_username + "@" + domain_url : subscription
	}
	(status, response) = prepare_and_send_request('POST', '%s%s@%s/subscribers/posts' % (api_location, username, domain_url),
			payload=data, authorization=username)

	store = open('requests_made', 'a')
	store.write(str(response.ok) + " " + response.content + "\n")
	store.close()
	return status
def outside_roles_access(api_location, username, target_channel_name):
	
	target_channel_name = "%s@%s" % (obtainActualName(target_channel_name.split("@")[0]), target_channel_name.split("@")[1])
	
	if username != None:

		username = obtainActualName(username)
		
		(status, response) = prepare_and_send_request('GET', "%ssubscribed" % (api_location), authorization=username)

	else:

		(status, response) = prepare_and_send_request('GET', "%ssubscribed" % (api_location))

	return status
def posts_read_access(api_location, username, target_channel_name):

	target_channel_name = "%s@%s" % (obtainActualName(target_channel_name.split("@")[0]), target_channel_name.split("@")[1])
	
	if username != None:

		username = obtainActualName(username)

		(status, response) = prepare_and_send_request('GET', "%s%s/content/posts" % (api_location,
			target_channel_name), authorization=username)
	else:

		(status, response) = prepare_and_send_request('GET', "%s%s/content/posts" % (api_location,
			target_channel_name))

	return status
Exemplo n.º 23
0
def subscribe_to_topic_channel(session, domain_url, api_location, username,
                               channel_name, subscription):

    username = obtainActualName(session, username)
    channel_name = obtainActualName(session, channel_name)

    data = {'%s@topics.%s/posts' % (channel_name, domain_url): subscription}
    (status,
     response) = prepare_and_send_request('POST',
                                          '%ssubscribed' % (api_location),
                                          payload=data,
                                          authorization=username)

    store = open('requests_made', 'a')
    store.write(str(response.ok) + " " + response.content + "\n")
    store.close()
    return status
def has_subscriber_role_in_topic_channel(session, domain_url, api_location, username, channel_name, subscription):

	username = obtainActualName(session, username)
	channel_name = obtainActualName(session, channel_name)

	(status, response) = prepare_and_send_request('GET', '%ssubscribed' % (api_location), authorization=username)

	if status == True:

		try:
			response = json.loads(response.content)
			channel_node = '%s@topics.%s/posts' % (channel_name, domain_url)
			return channel_node in response and response[channel_node] == subscription
		except ValueError:
			pass

	return False
Exemplo n.º 25
0
def close_this_user_channel(session, domain_url, api_location, username):

	username = obtainActualName(session, username)

	data = {
		'access_model' : 'authorize'
	}
	return prepare_and_send_request('POST', '%s%s@%s/metadata/posts' % (api_location, username, domain_url),
			payload=data, authorization=username)
Exemplo n.º 26
0
def change_user_channel_subscriber_role(session, domain_url, api_location,
                                        username, subscriber_username,
                                        subscription):

    username = obtainActualName(session, username)
    subscriber_username = obtainActualName(session, subscriber_username)

    data = {subscriber_username + "@" + domain_url: subscription}
    (status, response) = prepare_and_send_request(
        'POST',
        '%s%s@%s/subscribers/posts' % (api_location, username, domain_url),
        payload=data,
        authorization=username)

    store = open('requests_made', 'a')
    store.write(str(response.ok) + " " + response.content + "\n")
    store.close()
    return status
Exemplo n.º 27
0
def close_this_user_channel(session, domain_url, api_location, username):

    username = obtainActualName(session, username)

    data = {'access_model': 'authorize'}
    return prepare_and_send_request('POST',
                                    '%s%s@%s/metadata/posts' %
                                    (api_location, username, domain_url),
                                    payload=data,
                                    authorization=username)
def posts_read_access(session, api_location, username, target_channel_name):

    target_channel_name = "%s@%s" % (obtainActualName(
        session,
        target_channel_name.split("@")[0]), target_channel_name.split("@")[1])

    if username != None:

        username = obtainActualName(session, username)

        (status, response) = prepare_and_send_request(
            'GET',
            "%s%s/content/posts" % (api_location, target_channel_name),
            authorization=username)
    else:

        (status, response) = prepare_and_send_request(
            'GET', "%s%s/content/posts" % (api_location, target_channel_name))

    return status
def create_user_channel(session, domain_url, api_location, username):

	username = obtainActualName(session, username)
	
	data = {
		'username' : username,
		'password' : TEST_USER_PASSWORD,
		'email' : TEST_USER_EMAIL
	}
	(status, response) = prepare_and_send_request('POST', '%saccount' % (api_location), payload=data)
	return status
def topic_channel_exists(session, domain_url, api_location, channel_name):

	channel_name = obtainActualName(session, channel_name)
	
	(status, response) = prepare_and_send_request('GET', '%s%s@topics.%s/metadata/posts' % (api_location, channel_name, domain_url))

	try:
		response = json.loads(response.content)
		return status
	except ValueError:
		return False
Exemplo n.º 31
0
def has_subscriber_role_in_user_channel(session, domain_url, api_location, username, channel_name, subscription):

	username = obtainActualName(session, username)
	channel_name = obtainActualName(session, channel_name)

	(status, response) = prepare_and_send_request('GET', '%ssubscribed' % (api_location), authorization=username)
	
	store = open('requests_made', 'a')
	store.write(str(response.ok) + " " + response.content + "\n")
	store.close()

	if status == True:

		try:
			response = json.loads(response.content)
			channel_node = '%s@%s/posts' % (channel_name, domain_url)
			return channel_node in response and response[channel_node] == subscription
		except ValueError:
			pass

	return False
def outside_roles_access(session, api_location, username, target_channel_name):

    target_channel_name = "%s@%s" % (obtainActualName(
        session,
        target_channel_name.split("@")[0]), target_channel_name.split("@")[1])

    if username != None:

        username = obtainActualName(session, username)

        (status,
         response) = prepare_and_send_request('GET',
                                              "%ssubscribed" % (api_location),
                                              authorization=username)

    else:

        (status,
         response) = prepare_and_send_request('GET',
                                              "%ssubscribed" % (api_location))

    return status
Exemplo n.º 33
0
def change_topic_channel_subscriber_role(session, domain_url, api_location, authorized_username, username, channel_name, subscription):

	username = obtainActualName(session, username)
	channel_name = obtainActualName(session, channel_name)

	data = {
		username + "@" + domain_url : subscription
	}
	
	if ( authorized_username != None ):
		authorized_username = obtainActualName(session, authorized_username)
		(status, response) = prepare_and_send_request('POST', '%s%s@topics.%s/subscribers/posts' % (api_location, channel_name, domain_url),
				payload=data, authorization=authorized_username)

	else:
		
		(status, response) = prepare_and_send_request('POST', '%s%s@topics.%s/subscribers/posts' % (api_location, channel_name, domain_url),
				payload=data)

	store = open('requests_made', 'a')
	store.write(str(response.ok) + " " + response.content + "\n")
	store.close()
	return status
Exemplo n.º 34
0
def create_user_channel(session, domain_url, api_location, username):

	username = obtainActualName(session, username)
	
	data = {
		'username' : username,
		'password' : TEST_USER_PASSWORD,
		'email' : TEST_USER_EMAIL
	}
	(status, response) = prepare_and_send_request('POST', '%saccount' % (api_location), payload=data)
	
	store = open('requests_made', 'a')
	store.write(str(response.ok) + " " + response.content + "\n")
	store.close()
	return status
Exemplo n.º 35
0
def topic_channel_exists(session, domain_url, api_location, channel_name):

	channel_name = obtainActualName(session, channel_name)
	
	(status, response) = prepare_and_send_request('GET', '%s%s@topics.%s/metadata/posts' % (api_location, channel_name, domain_url))
	
	store = open('requests_made', 'a')
	store.write(str(response.ok) + " " + response.content + "\n")
	store.close()

	try:
		response = json.loads(response.content)
		return status
	except ValueError:
		return False
def is_authorized_user_channel(domain_url, api_location, username):

	username = obtainActualName(session, username)

	(status, response) = prepare_and_send_request('GET', '%s%s@%s/metadata/posts' % (api_location, username, domain_url))

	if status == True:

		try:
			response = json.loads(response.content)
			return 'access_model' in response and response['access_model'] == 'authorize'
		except ValueError:
			pass

	return False
Exemplo n.º 37
0
def user_channel_exists(session, domain_url, api_location, username):

    username = obtainActualName(session, username)

    (status, response) = prepare_and_send_request(
        'GET', '%s%s@%s/metadata/posts' % (api_location, username, domain_url))

    store = open('requests_made', 'a')
    store.write(str(response.ok) + " " + response.content + "\n")
    store.close()

    try:
        response = json.loads(response.content)
        return status
    except ValueError:
        return False
Exemplo n.º 38
0
def create_user_channel(session, domain_url, api_location, username):

    username = obtainActualName(session, username)

    data = {
        'username': username,
        'password': TEST_USER_PASSWORD,
        'email': TEST_USER_EMAIL
    }
    (status, response) = prepare_and_send_request('POST',
                                                  '%saccount' % (api_location),
                                                  payload=data)

    store = open('requests_made', 'a')
    store.write(str(response.ok) + " " + response.content + "\n")
    store.close()
    return status
Exemplo n.º 39
0
def is_open_user_channel(domain_url, api_location, username):

	username = obtainActualName(session, username)

	(status, response) = prepare_and_send_request('GET', '%s%s@%s/metadata/posts' % (api_location, username, domain_url))
	
	store = open('requests_made', 'a')
	store.write(str(response.ok) + " " + response.content + "\n")
	store.close()

	if status == True:

		try:
			response = json.loads(response.content)
			return 'access_model' in response and response['access_model'] == 'open'
		except ValueError:
			pass

	return False
Exemplo n.º 40
0
def is_authorized_user_channel(domain_url, api_location, username):

    username = obtainActualName(session, username)

    (status, response) = prepare_and_send_request(
        'GET', '%s%s@%s/metadata/posts' % (api_location, username, domain_url))

    store = open('requests_made', 'a')
    store.write(str(response.ok) + " " + response.content + "\n")
    store.close()

    if status == True:

        try:
            response = json.loads(response.content)
            return 'access_model' in response and response[
                'access_model'] == 'authorize'
        except ValueError:
            pass

    return False
Exemplo n.º 41
0
def add_new_status_and_check(session, api_location, username, target_channel_name):

	target_username = obtainActualName(session, target_channel_name.split("@")[0])
	domain_url =  target_channel_name.split("@")[1]
	target_channel_name = "%s@%s" % (target_username, domain_url)

	new_mood = "I'm sad that Lost is over."

	data = {
		"content" : new_mood
	}

	if username != None:

		username = obtainActualName(session, username)

		(status, response) = prepare_and_send_request('POST', "%s%s/content/status" % (api_location,
			target_channel_name), payload=data, authorization=username)
	else:

		(status, response) = prepare_and_send_request('POST', "%s%s/content/status" % (api_location,
			target_channel_name), payload=data)

	if status:

		try:
			response = json.loads(response.content)
			
			new_mood_id = response['id']
			new_mood_author = response['author']
			current_mood = response['content']

			if ( new_mood_author != "%s@%s" % (username, domain_url.replace("topics.", "")) or current_mood != new_mood ):

				return False

			if username != None:

				(status, response) = prepare_and_send_request('GET', "%s%s/content/status/%s" % (api_location,
					target_channel_name, new_mood_id), authorization=username)
			else:
				
				(status, response) = prepare_and_send_request('GET', "%s%s/content/status/%s" % (api_location,
					target_channel_name, new_mood_id))

			if status:

				try:

					response = json.loads(response.content)
					return ( new_mood_id == response['id']
					and new_mood_author == response['author']
					and current_mood == response['content'] )

				except ValueError:
					pass

		except ValueError:
			pass

	return False
def delete_user_channel(session, domain_url, api_location, username):

	username = obtainActualName(session, username)

	(status, response) = prepare_and_send_request('DELETE', '%saccount' % (api_location), authorization=username)
	return status
Exemplo n.º 43
0
def update_metadata_info(session, api_location, username, target_channel_name,
                         metadata_field, metadata_value):

    target_channel_name = "%s@%s" % (obtainActualName(
        session,
        target_channel_name.split("@")[0]), target_channel_name.split("@")[1])

    if username != None:

        username = obtainActualName(session, username)

        (status, response) = prepare_and_send_request(
            'GET',
            "%s%s/metadata/posts" % (api_location, target_channel_name),
            authorization=username)
    else:

        (status, response) = prepare_and_send_request(
            'GET', "%s%s/metadata/posts" % (api_location, target_channel_name))

    if status:

        try:
            response = json.loads(response.content)

            if metadata_value.startswith("*"):
                metadata_value = response[
                    metadata_field] + metadata_value.replace("*", "")
            else:
                metadata_value = metadata_value.replace("/", "").replace(
                    response[metadata_field], "")
        except ValueError:
            pass

    data = {metadata_field: metadata_value}

    if username != None:

        (status, response) = prepare_and_send_request(
            'POST',
            "%s%s/metadata/posts" % (api_location, target_channel_name),
            payload=data,
            authorization=username)
    else:

        (status, response) = prepare_and_send_request(
            'POST',
            "%s%s/metadata/posts" % (api_location, target_channel_name),
            payload=data)

    if status:

        if username != None:

            (status, response) = prepare_and_send_request(
                'GET',
                "%s%s/metadata/posts" % (api_location, target_channel_name),
                authorization=username)
        else:

            (status, response) = prepare_and_send_request(
                'GET',
                "%s%s/metadata/posts" % (api_location, target_channel_name))

        if status:

            try:
                response = json.loads(response.content)
                return response[metadata_field] == metadata_value
            except ValueError:
                pass
    return False
def add_new_post_and_get_by_id_direct_access(session, api_location, username, target_channel_name):

	target_username = obtainActualName(session, target_channel_name.split("@")[0])
	domain_url =  target_channel_name.split("@")[1]
	target_channel_name = "%s@%s" % (target_username, domain_url)

	content_posted = "'You all everybody' by Drive Shaft is the best song ever."

	data = {
		"content" : content_posted
	}

	if username != None:

		username = obtainActualName(session, username)

		(status, response) = prepare_and_send_request('POST', "%s%s/content/posts" % (api_location,
			target_channel_name), payload=data, authorization=username)
	else:

		(status, response) = prepare_and_send_request('POST', "%s%s/content/posts" % (api_location,
			target_channel_name), payload=data)

	if status:

		try:
			response = json.loads(response.content)
			
			post_id = response['id']
			post_author = response['author']
			content_obtained = response['content']

			if ( post_author != "%s@%s" % (username, domain_url.replace("topics.", "")) or content_obtained != content_posted ):

				return False

			if username != None:

				(status, response) = prepare_and_send_request('GET', "%s%s/content/posts/%s" % (api_location,
					target_channel_name, post_id), authorization=username)
			else:
				
				(status, response) = prepare_and_send_request('GET', "%s%s/content/posts/%s" % (api_location,
					target_channel_name, post_id))

			if status:

				try:

					response = json.loads(response.content)
					return ( post_id == response['id']
					and post_author == response['author']
					and content_obtained == response['content'] )

				except ValueError:
					pass

		except ValueError:
			pass

	return False
def add_new_post_and_get_by_matching_id(session, api_location, username, target_channel_name):

	target_username = obtainActualName(session, target_channel_name.split("@")[0])
	domain_url =  target_channel_name.split("@")[1]
	target_channel_name = "%s@%s" % (target_username, domain_url)

	content_posted = "'Don't tell me what I can't do' is a frequently spoken phrase on Lost."

	data = {
		"content" : content_posted
	}

	if username != None:

		username = obtainActualName(session, username)

		(status, response) = prepare_and_send_request('POST', "%s%s/content/posts" % (api_location,
			target_channel_name), payload=data, authorization=username)
	else:

		(status, response) = prepare_and_send_request('POST', "%s%s/content/posts" % (api_location,
			target_channel_name), payload=data)

	if status:

		try:
			response = json.loads(response.content)
			
			post_id = response['id']
			post_author = response['author']
			content_obtained = response['content']

			if ( post_author != "%s@%s" % (username, domain_url.replace("topics.", "")) or content_obtained != content_posted ):

				return False

			if username != None:

				(status, response) = prepare_and_send_request('GET', "%s%s/content/posts" % (api_location,
					target_channel_name), authorization=username)
			else:
				
				(status, response) = prepare_and_send_request('GET', "%s%s/content/posts" % (api_location,
					target_channel_name))

			if status:

				try:

					response = json.loads(response.content)
					
					for item in response:

						if ( item['id'] == post_id
						and  item['author'] == post_author
						and  item['content'] == content_obtained ):

							return True

				except ValueError:
					pass

		except ValueError:
			pass

	return False
def remove_own_post(session, api_location, username, target_channel_name):

    target_username = obtainActualName(session,
                                       target_channel_name.split("@")[0])
    domain_url = target_channel_name.split("@")[1]
    target_channel_name = "%s@%s" % (target_username, domain_url)

    content_posted = "The Lost finale was pretty bad."

    data = {"content": content_posted}

    if username != None:

        username = obtainActualName(session, username)

        (status, response) = prepare_and_send_request(
            'POST',
            "%s%s/content/posts" % (api_location, target_channel_name),
            payload=data,
            authorization=username)
    else:

        (status, response) = prepare_and_send_request(
            'POST',
            "%s%s/content/posts" % (api_location, target_channel_name),
            payload=data)

    if status:

        try:
            response = json.loads(response.content)

            post_id = response['id']
            post_author = response['author']
            content_obtained = response['content']

            if (post_author != "%s@%s" %
                (username, domain_url.replace("topics.", ""))
                    or content_obtained != content_posted):

                return False

            if username != None:

                (status, response) = prepare_and_send_request(
                    'DELETE',
                    "%s%s/content/posts/%s" %
                    (api_location, target_channel_name, post_id),
                    authorization=username)
            else:

                (status, response) = prepare_and_send_request(
                    'DELETE', "%s%s/content/posts/%s" %
                    (api_location, target_channel_name, post_id))

            return status

        except ValueError:
            pass

    return False
def add_new_post_and_get_by_id_direct_access(session, api_location, username,
                                             target_channel_name):

    target_username = obtainActualName(session,
                                       target_channel_name.split("@")[0])
    domain_url = target_channel_name.split("@")[1]
    target_channel_name = "%s@%s" % (target_username, domain_url)

    content_posted = "'You all everybody' by Drive Shaft is the best song ever."

    data = {"content": content_posted}

    if username != None:

        username = obtainActualName(session, username)

        (status, response) = prepare_and_send_request(
            'POST',
            "%s%s/content/posts" % (api_location, target_channel_name),
            payload=data,
            authorization=username)
    else:

        (status, response) = prepare_and_send_request(
            'POST',
            "%s%s/content/posts" % (api_location, target_channel_name),
            payload=data)

    if status:

        try:
            response = json.loads(response.content)

            post_id = response['id']
            post_author = response['author']
            content_obtained = response['content']

            if (post_author != "%s@%s" %
                (username, domain_url.replace("topics.", ""))
                    or content_obtained != content_posted):

                return False

            if username != None:

                (status, response) = prepare_and_send_request(
                    'GET',
                    "%s%s/content/posts/%s" %
                    (api_location, target_channel_name, post_id),
                    authorization=username)
            else:

                (status, response) = prepare_and_send_request(
                    'GET', "%s%s/content/posts/%s" %
                    (api_location, target_channel_name, post_id))

            if status:

                try:

                    response = json.loads(response.content)
                    return (post_id == response['id']
                            and post_author == response['author']
                            and content_obtained == response['content'])

                except ValueError:
                    pass

        except ValueError:
            pass

    return False
def add_new_post_and_get_by_matching_id(session, api_location, username,
                                        target_channel_name):

    target_username = obtainActualName(session,
                                       target_channel_name.split("@")[0])
    domain_url = target_channel_name.split("@")[1]
    target_channel_name = "%s@%s" % (target_username, domain_url)

    content_posted = "'Don't tell me what I can't do' is a frequently spoken phrase on Lost."

    data = {"content": content_posted}

    if username != None:

        username = obtainActualName(session, username)

        (status, response) = prepare_and_send_request(
            'POST',
            "%s%s/content/posts" % (api_location, target_channel_name),
            payload=data,
            authorization=username)
    else:

        (status, response) = prepare_and_send_request(
            'POST',
            "%s%s/content/posts" % (api_location, target_channel_name),
            payload=data)

    if status:

        try:
            response = json.loads(response.content)

            post_id = response['id']
            post_author = response['author']
            content_obtained = response['content']

            if (post_author != "%s@%s" %
                (username, domain_url.replace("topics.", ""))
                    or content_obtained != content_posted):

                return False

            if username != None:

                (status, response) = prepare_and_send_request(
                    'GET',
                    "%s%s/content/posts" % (api_location, target_channel_name),
                    authorization=username)
            else:

                (status, response) = prepare_and_send_request(
                    'GET',
                    "%s%s/content/posts" % (api_location, target_channel_name))

            if status:

                try:

                    response = json.loads(response.content)

                    for item in response:

                        if (item['id'] == post_id
                                and item['author'] == post_author
                                and item['content'] == content_obtained):

                            return True

                except ValueError:
                    pass

        except ValueError:
            pass

    return False