예제 #1
0
    def get(self, request, *args, **kwargs):
        """ Http handler to route v3/interface/channel/ for GET method """

        data = None
        channel_name = kwargs.get('channel_id')
        try:
            channel_id = int(channel_name)
            channel = ChannelV3()
            data = channel.retrieve_by_id(channel_id)

        except ValueError:  # In case we have a name instead of a ID
            channel = ChannelV3()
            data = channel.retrieve(channel_name)

        if data is None:
            error = {"error": "Channel not found: '%s'" % channel_name}
            return Response(error, status=status.HTTP_404_NOT_FOUND)

        return Response(data, status=status.HTTP_200_OK)
예제 #2
0
    def post(self, request, *args, **kwargs):
        """ Http handler to route v3/interface/channel for POST method """

        channels = request.DATA
        json_validate(SPECS.get('channel_post')).validate(channels)

        response = []
        for channel_data in channels:

            channel = ChannelV3()
            data = channel.create(channel_data)

            if "error" in data:
                return Response(data, status=status.HTTP_400_BAD_REQUEST)

            response.append({'id': channel.id})

        return Response(response, status=status.HTTP_201_CREATED)
예제 #3
0
    def delete(self, request, *args, **kwargs):
        """ Http handler to route v3/channel/id for DELETE method """

        channel_id = kwargs.get('channel_id')
        channels = channel_id.split(";")

        channel_obj = ChannelV3(request.user)

        deletion = dict()

        try:
            for channel in channels:
                deletion = channel_obj.delete(channel)
        except Exception as err:
            log.error(err)
            return Response({"error": str(err)},
                            status=status.HTTP_400_BAD_REQUEST)

        return Response(deletion, status=status.HTTP_200_OK)
예제 #4
0
    def put(self, request, *args, **kwargs):
        """ Http handler to route v3/interface/channel for PUT method """

        channels = request.DATA.get('channels')
        # json_validate(SPECS.get('channel_put_v3')).validate(channels)

        response = []
        try:
            for channel_data in channels:

                channel = ChannelV3(request.user)
                data = channel.update(channel_data)

                response.append({'id': data.get('channels')})
        except Exception as err:
            return Response({"error": str(err)},
                            status=status.HTTP_400_BAD_REQUEST)

        return Response(response, status=status.HTTP_200_OK)
예제 #5
0
    def delete(self, request, *args, **kwargs):
        """ Http handler to route v3/interface/channel/id for DELETE method """

        channel_id = kwargs.get('channel_id')

        channel = ChannelV3(request.user)

        deletion = {}
        try:
            deletion = channel.delete(channel_id)

        except InterfaceNotFoundError:
            return Response(
                {"error": "Could not find channel '%s'" % channel_id},
                status=status.HTTP_404_NOT_FOUND)

        if "error" in deletion:
            return Response(deletion, status=status.HTTP_400_BAD_REQUEST)

        return Response(deletion, status=status.HTTP_200_OK)
예제 #6
0
    def post(self, request, *args, **kwargs):
        """ Http handler to route v3/channel for POST method """

        log.info("POST - api_channel")

        channels = request.DATA

        # json_validate(SPECS.get('channel_post_v3')).validate(channels)

        response = []
        try:

            for channel_data in channels.get('channels'):

                channel = ChannelV3()
                data = channel.create(channel_data)

                response.append({'id': data.get('channels')})

        except api_exceptions.ObjectDoesNotExistException, e:
            raise api_exceptions.ObjectDoesNotExistException(e.detail)