def __init__(self, api_key: str = None, access_token: str = None, refresh_token: str = None, client_id: str = None, client_secret: str = None, oauth2_token_getter: Optional[ Callable[[Literal["access_token", "refresh_token"], str], str]] = None, oauth2_token_setter: Optional[Callable[ [Literal["access_token", "refresh_token"], str, str], None]] = None, timeout: int = 10, mixins: List = None, api_base: str = "api.hubapi.com", debug: bool = False, disable_auth: bool = False, **extra_options) -> None: super(BaseClient, self).__init__() # reverse so that the first one in the list because the first parent if not mixins: mixins = [] mixins.reverse() for mixin_class in mixins: if mixin_class not in self.__class__.__bases__: self.__class__.__bases__ = ( mixin_class, ) + self.__class__.__bases__ self.api_key = api_key # These are used as fallbacks if there aren't setters/getters, or if no remote tokens can be # found. The properties without `__` prefixes should generally be used instead of these. self.__access_token = access_token self.__refresh_token = refresh_token self.client_id = client_id self.client_secret = client_secret if (oauth2_token_getter is None) != (oauth2_token_setter is None): raise HubspotBadConfig( "You must either specify both the oauth2 token setter and getter, or neither." ) self.oauth2_token_getter = oauth2_token_getter self.oauth2_token_setter = oauth2_token_setter self.log = utils.get_log("hubspot3") if not disable_auth: if self.api_key and self.access_token: raise HubspotBadConfig( "Cannot use both api_key and access_token.") if not (self.api_key or self.access_token or self.refresh_token): raise HubspotNoConfig("Missing required credentials.") self.options = { "api_base": api_base, "debug": debug, "disable_auth": disable_auth, "timeout": timeout, } self.options.update(extra_options) self._prepare_connection_type()
def get_sync_errors_for_app_and_account(self, include_resolved: bool = False, error_type: str = None, object_type: str = None, limit: int = None, starting_page: int = None, **options): """ Retrieve a list of error dictionaries for an app in specific portal, optionally filtered/limited, and ordered by recency. This method and the endpoint it calls can only be used with OAuth tokens and both the app and the portal are determined from the tokens used. :see: https://developers.hubspot.com/docs/methods/ecommerce/v2/get-all-sync-errors-for-an-app-and-account # noqa """ if not self.access_token: raise HubspotBadConfig( "The sync errors for a specific account from a specific app " "can only be retrieved using an access token.") return self._get_sync_errors("sync/errors", include_resolved=include_resolved, error_type=error_type, object_type=object_type, limit=limit, starting_page=starting_page, **options)
def get_sync_errors_for_app(self, app_id: int, include_resolved: bool = False, error_type: str = None, object_type: str = None, limit: int = None, starting_page: int = None, **options) -> List: """ Retrieve a list of error dictionaries for the app with the given ID, optionally filtered/limited, and ordered by recency. This method and the endpoint it calls can only be used with the developer API key of the developer portal that created the app. :see: https://developers.hubspot.com/docs/methods/ecommerce/v2/get-all-sync-errors-for-an-app # noqa """ if not self.api_key: raise HubspotBadConfig( "The portal-independent sync errors for an app can only be " "retrieved using the corresponding developer API key.") return self._get_sync_errors( "sync/errors/app/{app_id}".format(app_id=app_id), include_resolved=include_resolved, error_type=error_type, object_type=object_type, limit=limit, starting_page=starting_page, **options)
def get_sync_errors_for_account(self, include_resolved: bool = False, error_type: str = None, object_type: str = None, limit: int = None, starting_page: int = None, **options) -> List: """ Retrieve a list of error dictionaries for an account, optionally filtered/limited, and ordered by recency. This method and the endpoint it calls can only be used with a portal API key and the portal is determined from that key. :see: https://developers.hubspot.com/docs/methods/ecommerce/v2/get-all-sync-errors-for-a-specific-account # noqa """ if not self.api_key: raise HubspotBadConfig( "The app-independent sync errors for a specific account can " "only be retrieved using the corresponding portal API key.") return self._get_sync_errors("sync/errors/portal", include_resolved=include_resolved, error_type=error_type, object_type=object_type, limit=limit, starting_page=starting_page, **options)
def __init__(self, api_key: str = None, access_token: str = None, refresh_token: str = None, client_id: str = None, client_secret: str = None, timeout: int = 10, mixins: List = None, api_base: str = "api.hubapi.com", debug: bool = False, disable_auth: bool = False, **extra_options) -> None: super(BaseClient, self).__init__() # reverse so that the first one in the list because the first parent if not mixins: mixins = [] mixins.reverse() for mixin_class in mixins: if mixin_class not in self.__class__.__bases__: self.__class__.__bases__ = ( mixin_class, ) + self.__class__.__bases__ self.api_key = api_key self.access_token = access_token self.refresh_token = refresh_token self.client_id = client_id self.client_secret = client_secret self.log = utils.get_log("hubspot3") if not disable_auth: if self.api_key and self.access_token: raise HubspotBadConfig( "Cannot use both api_key and access_token.") if not (self.api_key or self.access_token or self.refresh_token): raise HubspotNoConfig("Missing required credentials.") self.options = { "api_base": api_base, "debug": debug, "disable_auth": disable_auth, "timeout": timeout, } self.options.update(extra_options) self._prepare_connection_type()
def __init__( self, api_key: str = None, access_token: str = None, refresh_token: str = None, client_id: str = None, client_secret: str = None, timeout: int = 10, api_base: str = "api.hubapi.com", debug: bool = False, disable_auth: bool = False, **extra_options: Any ) -> None: """full client constructor""" self.api_key = api_key self.access_token = access_token self.refresh_token = refresh_token self.client_id = client_id self.client_secret = client_secret if not disable_auth: if self.api_key and self.access_token: raise HubspotBadConfig("Cannot use both api_key and access_token.") if not (self.api_key or self.access_token or self.refresh_token): raise HubspotNoConfig("Missing required credentials.") self.auth = { "access_token": self.access_token, "api_key": self.api_key, "client_id": self.client_id, "client_secret": self.client_secret, "refresh_token": self.refresh_token, } self.options = { "api_base": api_base, "debug": debug, "disable_auth": disable_auth, "timeout": timeout, } self.options.update(extra_options) # rate limiting related stuff self._usage_limits = Hubspot3UsageLimits()