Exemple #1
0
    async def deactivate_inline_hook(self, inlineHookId):
        """
        Deactivates the Inline Hook matching the provided id
        Args:
            inline_hook_id {str}
        Returns:
            InlineHook
        """
        http_method = "post".upper()
        api_url = format_url(f"""
            {self._base_url}
            /api/v1/inlineHooks/{inlineHookId}/lifecycle
                /deactivate
            """)

        body = {}
        headers = {}

        request, error = await self._request_executor.create_request(
            http_method, api_url, body, headers)

        if error:
            return (None, None, error)

        response, error = await self._request_executor\
            .execute(request, InlineHook)

        if error:
            return (None, response, error)

        try:
            result = InlineHook(self.form_response_body(response.get_body()))
        except Exception as error:
            return (None, response, error)
        return (result, response, None)
Exemple #2
0
    async def get_inline_hook(self, inlineHookId):
        """
        Gets an inline hook by ID
        Args:
            inline_hook_id {str}
        Returns:
            InlineHook
        """
        http_method = "get".upper()
        api_url = format_url(f"""
            {self._base_url}
            /api/v1/inlineHooks/{inlineHookId}
            """)

        body = {}
        headers = {}

        request, error = await self._request_executor.create_request(
            http_method, api_url, body, headers)

        if error:
            return (None, None, error)

        response, error = await self._request_executor\
            .execute(request, InlineHook)

        if error:
            return (None, response, error)

        try:
            result = InlineHook(self.form_response_body(response.get_body()))
        except Exception as error:
            return (None, response, error)
        return (result, response, None)
    async def update_inline_hook(
            self, inlineHookId, inline_hook,
            keep_empty_params=False
    ):
        """
        Updates an inline hook by ID
        Args:
            inline_hook_id {str}
            {inline_hook}
        Returns:
            InlineHook
        """
        http_method = "put".upper()
        api_url = format_url(f"""
            {self._base_url}
            /api/v1/inlineHooks/{inlineHookId}
            """)

        if isinstance(inline_hook, dict):
            body = inline_hook
        else:
            body = inline_hook.as_dict()
        headers = {
            "Accept": "application/json",
            "Content-Type": "application/json"
        }
        form = {}

        request, error = await self._request_executor.create_request(
            http_method, api_url, body, headers, form, keep_empty_params=keep_empty_params
        )

        if error:
            return (None, None, error)

        response, error = await self._request_executor\
            .execute(request, InlineHook)

        if error:
            return (None, response, error)

        try:
            result = InlineHook(
                self.form_response_body(response.get_body())
            )
        except Exception as error:
            return (None, response, error)
        return (result, response, None)
    async def list_inline_hooks(
            self, query_params={},
            keep_empty_params=False
    ):
        """
        Args:
            query_params {dict}: Map of query parameters for request
            [query_params.type] {str}
        Returns:
            list: Collection of InlineHook instances.
        """
        http_method = "get".upper()
        api_url = format_url(f"""
            {self._base_url}
            /api/v1/inlineHooks
            """)
        if query_params:
            encoded_query_params = urlencode(query_params)
            api_url += f"/?{encoded_query_params}"

        body = {}
        headers = {}
        form = {}

        request, error = await self._request_executor.create_request(
            http_method, api_url, body, headers, form, keep_empty_params=keep_empty_params
        )

        if error:
            return (None, None, error)

        response, error = await self._request_executor\
            .execute(request, InlineHook)

        if error:
            return (None, response, error)

        try:
            result = []
            for item in response.get_body():
                result.append(InlineHook(
                    self.form_response_body(item)
                    ))
        except Exception as error:
            return (None, response, error)
        return (result, response, None)
Exemple #5
0
    async def create_inline_hook(self, inline_hook):
        """
        Args:
            {inline_hook}
        Returns:
            InlineHook
        """
        http_method = "post".upper()
        api_url = format_url(f"""
            {self._base_url}
            /api/v1/inlineHooks
            """)

        if isinstance(inline_hook, dict):
            body = inline_hook
        else:
            body = inline_hook.as_dict()
        headers = {
            "Accept": "application/json",
            "Content-Type": "application/json"
        }

        request, error = await self._request_executor.create_request(
            http_method, api_url, body, headers)

        if error:
            return (None, None, error)

        response, error = await self._request_executor\
            .execute(request, InlineHook)

        if error:
            return (None, response, error)

        try:
            result = InlineHook(self.form_response_body(response.get_body()))
        except Exception as error:
            return (None, response, error)
        return (result, response, None)