def __init__(self, project_id, write_key=None, read_key=None, persistence_strategy=None): """ Initializes a KeenClient object. :param project_id: the Keen IO project ID :param write_key: a Keen IO Scoped Key for Writes :param read_key: a Keen IO Scoped Key for Reads :param persistence_strategy: optional, the strategy to use to persist the event """ super(KeenClient, self).__init__() # do some validation if not project_id or not isinstance(project_id, str): raise exceptions.InvalidProjectIdError(project_id) # Set up an api client to be used for querying and optionally passed # into a default persistence strategy. self.api = KeenApi(project_id, write_key=write_key, read_key=read_key) if persistence_strategy: # validate the given persistence strategy if not isinstance(persistence_strategy, BasePersistenceStrategy): raise exceptions.InvalidPersistenceStrategyError() if not persistence_strategy: # setup a default persistence strategy persistence_strategy = persistence_strategies \ .DirectPersistenceStrategy(self.api) self.project_id = project_id self.persistence_strategy = persistence_strategy
def check_project_id(project_id): ''' Python 3.x-compatible string typecheck. ''' if not project_id or not isinstance(project_id, str): raise exceptions.InvalidProjectIdError(project_id)