Пример #1
0
def _make_api_response(data: dict, meta, message, headers: dict, cookies: dict,
                       status_code: int, status):

    response_body = simplejson.dumps({
        'api_ref': get_current_api_ref(),
        'meta': meta,
        'message': message,
        'status': status,
        'your_request': {
            'url': get_current_request_url(),
            'query_args': get_current_request_args(),
            'payload': get_current_request_data()
        },
        'your_response': data
    })

    resp = make_response(response_body, status_code)

    if headers is not None:
        for key, value in headers.items():
            resp.headers[key] = value

    if cookies is not None:
        for key, value in cookies.items():
            resp.set_cookie(key, value)

    return resp
    def post(self):
        request_data = get_current_request_data()

        params = self.__validate_user_creation_params(request_data)

        user = self.create_new_user(params)

        return api_created_response(user.as_json())
    def post(self):
        request_data = get_current_request_data()

        params = self.__validate_location_creation_params(request_data)

        location = self.create_location(params)

        return location.as_json()
    def post(self):
        """Create a conversation"""
        request_data = get_current_request_data()

        params = self.__validate_conversation_creation_params(request_data)

        conversation = self.create_conversation(params)

        return api_created_response(conversation.as_json())
Пример #5
0
    def post(self):
        """Create a post"""
        request_data = get_current_request_data()

        params = self.__validate_post_creation_params(request_data)

        post = self.create_post(params)

        return api_created_response(post.as_json())
Пример #6
0
    def post(self):
        """Add to a user's story"""
        request_data = get_current_request_data()

        params = self.__validate_story_creation_params(request_data)

        story = self.create_new_story(params)

        return api_created_response(story.as_json())
    def patch(self, conversation_uid):
        """Update a conversation"""
        request_data = get_current_request_data()

        params = self.__validate_conversation_edit_params(request_data)

        conversation = Conversation.get_not_deleted(uid=conversation_uid)
        if conversation is None:
            raise ResourceNotFound('Conversation not found')

        self.edit_conversation(conversation, params)
def create_api_log():
    """Record API call and metadata."""
    from utils.contexts import get_current_request_data

    request_data = {'args': request.args, 'body': get_current_request_data()}

    api_log = APILog(request_data=str(request_data),
                     request_headers=str(request.headers))
    api_log.save()

    return api_log
    def patch(self, username):
        request_data = get_current_request_data()

        params = self.__validate_user_update_params(request_data)

        user = User.get_active(username=username)
        if user is None:
            raise ResourceNotFound('User not found')

        user = self.edit_existing_user(user, params)

        return api_success_response(user.as_json())
    def patch(self, location_uid):
        request_data = get_current_request_data()

        location = Location.get_active(uid=location_uid)
        if location is None:
            raise ResourceNotFound('Location not found')

        params = self.__validate_location_update_params(request_data)

        location = self.edit_location(location, params)

        return location.as_json()
Пример #11
0
    def patch(self, collection_uid):
        request_data = get_current_request_data()

        collection = Collection.get_active(collection_uid)
        if collection is None:
            raise ResourceNotFound('Collection not found')

        params = self.__validate_collection_update_params(request_data)

        collection = self.edit_collection(collection, params)

        return api_success_response(collection.as_json())
Пример #12
0
    def patch(self, post_uid):
        """Edit a post"""
        request_data = get_current_request_data()

        post = Post.get_active(uid=post_uid)
        if post is None:
            raise ResourceNotFound('Post not found')

        if post.user != get_current_user():
            raise UnauthorizedError()

        params = self.__validate_post_edit_params(request_data)

        self.edit_post(post, params)

        return api_success_response(post.as_json())