def authenticate() -> Dict:
    """
       API to test AUTH.
       :return: JSON Response
    """
    user = json.loads(get_jwt_identity())
    return success(data=user, message="Authenticated")
def login() -> Dict:
    """
       API to login user.
       :return: JSON response
    """
    payload = request.get_json()
    error, result = get_auth_token(**payload)
    return success(data=result) if not error else failure(message=error)
def signup() -> Dict:
    """
       API to Sign up with a new user.
       :return: JSON response
    """
    payload = request.get_json()
    error, result = create_user(**payload)
    return success(data=result) if not error else failure(message=error)
def get_single_item(obj_id) -> Dict:
    """
    This method will return the
    single item with given object id.
    :param obj_id: Object ID
    :return: JSON response
    """
    error, item = fetch_single(obj_id)
    return success(data=item) if not error else failure(message=error)
def get_all_items() -> Dict:
    """
    This method will return all
    the items available.
    :return: JSON response
    """
    filters = request.args
    error, items = fetch_all(filters)
    return success(data=items) if not error else failure(message=error)
Example #6
0
def get_initial_news_response() -> Response:
    """
    This method fetches the top 10 news from various sources
    And returns to the API
    :return: JSON response
    """
    channel_name = request.get_json()['channelName']
    news = get_news(channel_name)
    return success(data=json.dumps(news))
Example #7
0
def get_users() -> Response:
    """
    This method returns a list of all the friends and rooms the user is in
    Based on the provided token
    :return: Response containing list of friends and rooms
    """
    data = request.get_json()
    token = data['token']
    users = []
    user_id = get_user_from_token(token)

    # get all the friends and rooms the user is attached to
    friends = get_my_friends(user_id)
    rooms = get_my_rooms(user_id)

    users.extend(friends)
    users.extend(rooms)

    return success(data=json.dumps(users))