from fansifter_common.adapters.stripo.exceptions import StripoClientError from fansifter_common.adapters.stripo.models import ( AuthResponse, CompressResponse, ) from fansifter_common.httpclient.base import HTTPClient class StripoClient(HTTPClient): exception_class = StripoClientError def __init__( self, base_url: str, client_id: str, client_secret: str, ) -> None: super().__init__( client_options={ "base_url": base_url, "headers": { "Content-Type": "application/json", "Accept": "application/json", }, } ) self.client_id = client_id self.client_secret = client_secret def compress(self, html: str, css: str) -> str: auth_token = self.generate_auth_token() payload = { "html": html, "css": css, "minimize": True, } response_obj = self.request( "POST", "/api/v1/cleaner/v1/compress", json=payload, headers={"ES-PLUGIN-AUTH": f"Bearer {auth_token}"}, type=CompressResponse, ) return response_obj.html def generate_auth_token(self) -> str: response = self.request( "POST", "/api/v1/auth", json={ "pluginId": self.client_id, "secretKey": self.client_secret, }, type=AuthResponse, ) return response.token