Exemple #1
0
    def __init__(self, api_base_url, access_token=None, json_schemas=None):

        self.api_base_url = api_base_url
        self.access_token = access_token

        self.http_client = http_client.PichayonHTTPClient(
            api_base_url, access_token)

        self.json_schemas = json_schemas

        if not self.json_schemas:
            self.json_schemas = self.get_json_schemas()

        def retrieve_schema(m):
            return self.schemas['definitions'].get(
                m.__resource_class__.__resource_name__, None)

        # self.users = users.UserManager(self,
        #         json_schema=retrieve_schema(users.UserManager))
        # self.rooms = rooms.RoomManager(self,
        #         json_schema=retrieve_schema(rooms.RoomManager))

        self.users = resources.UserManager(self, schema=schemas.UserSchema())
        self.groups = resources.GroupManager(self,
                                             schema=schemas.GroupSchema())
        self.rooms = resources.RoomManager(self, schema=schemas.RoomSchema())
Exemple #2
0
def get(room_id):
    room = None

    schema = schemas.RoomSchema()
    try:
        room = models.Room.objects.get(id=room_id)
    except Exception as e:
        response_dict = request.get_json()
        response_dict.update(e.messages)
        response = render_json(response_dict)
        response.status_code = 404
        abort(response)

    return render_json(schema.dump(room).data)
Exemple #3
0
def create():
    schema = schemas.RoomSchema()

    try:
        room_data = schema.load(request.get_json()).data
    except Exception as e:
        response_dict = request.get_json()
        response_dict.update(e.messages)
        response = render_json(response_dict)
        response.status_code = 400
        abort(response)

    user = current_user._get_current_object()
    room = models.Room(user=user, **room_data)
    room.save()
    return render_json(schema.dump(room).data)
Exemple #4
0
def update(room_id):
    schema = schemas.RoomSchema()

    try:
        room = models.Room.objects.get(id=room_id)
        room_data = schema.load(request.get_json()).data

        room_data.pop('id')
        room.update(**room_data)
    except Exception as e:
        response_dict = request.get_json()
        response_dict.update(e.messages)
        response = render_json(response_dict)
        response.status_code = 400
        abort(response)

    room.save()
    return render_json(schema.dump(room).data)
Exemple #5
0
def list():
    schema = schemas.RoomSchema()
    rooms = models.Room.objects()

    return render_json(schema.dump(rooms, many=True).data)