import functools


def httpmethod(func):
    """ Higher Order Function to wrap the GET, POST, PATCH, PUT, DELETE methods
        Takes care of:
        - encoding of url and payload
        - verifying response. Throws TM1pyException if StatusCode of Response is not OK
    """

    @functools.wraps(func)
    def wrapper(self, request, data='', odata_escape_single_quotes_in_object_names=True):
        # Encoding
        request, data = self._url_and_body(
            request=request,
            data=data,
            odata_escape_single_quotes_in_object_names=odata_escape_single_quotes_in_object_names)
        # Do Request
        response = func(self, request, data)
        # Verify
        self.verify_response(response=response)
        return response

    return wrapper