def _get_api_context(cls): """ Calls IsSessionActive to check if the session token is still active and returns the context.ApiContext. Catches ApiException if the session is inactive. Catches BunqException if the conf file does not exist. :rtype: context.ApiContext """ filename_bunq_config_full = (cls._get_directory_test_root() + cls._FILENAME_BUNQ_CONFIG) try: api_context = context.ApiContext.restore(filename_bunq_config_full) except FileNotFoundError: api_context = context.ApiContext( context.ApiEnvironmentType.SANDBOX, cls._API_KEY, cls._DEVICE_DESCRIPTION, []) else: api_context.ensure_session_active() api_context.save(filename_bunq_config_full) return api_context
def bunq_setup_configuration(api_key, description, proxy_url, is_production): env_type = bunqContext.ApiEnvironmentType.PRODUCTION if is_production else bunqContext.ApiEnvironmentType.SANDBOX api_context = bunqContext.ApiContext(env_type, api_key, description, proxy_url=proxy_url) api_context.save(BUNQ_CONF)
def _register_user(self): api_context = context.ApiContext( self._get_environment(), Config.get_option('API_KEY'), Config.get_option('DEVICE_DESCRIPTION'), [Config.get_option('PERMITTED_IP')]) api_context.save(Config.get_option('API_CONTEXT_FILE_PATH')) BunqContext.load_api_context(api_context) self._pin_certificate()
def run(): ctx = context.ApiContext( context.ApiEnvironmentType.SANDBOX, '### YOUR_API_KEY ###', # Put your API key here 'test device python') ctx.save() ctx_restored = context.ApiContext.restore() print( 'Is original context equal the one saved and restored?:', converter.class_to_json(ctx) == converter.class_to_json(ctx_restored))
def generate_bunq_conf(api_key, output_path, sandbox): """ Generate a bunq conf file from an API key and save it. See github.com/bunq/sdk_python/blob/develop/examples/api_context_save_example.py for more details. """ if sandbox: env = context.ApiEnvironmentType.SANDBOX else: env = context.ApiEnvironmentType.PRODUCTION ctx = context.ApiContext(env, api_key, 'Subsidy Service') ctx.save(output_path) click.echo(f'Bunq conf saved to {output_path}')
def create_context(api_key, device_description, sandbox): try: return context.ApiContext.restore() except Exception as e: print(e) if sandbox: environment_type = context.ApiEnvironmentType.SANDBOX else: environment_type = context.ApiEnvironmentType.PRODUCTION from pprint import pprint pprint([environment_type, api_key, device_description]) api_context = context.ApiContext(environment_type, api_key, device_description) api_context.save() return api_context
def setup_api_context(cls, environment, api_key, description): """ Parameters ---------- environment : context.ApiEnvironmentType api_key : str The api key you got from the bunq app. description : str Description of the device you are connecting the the bunq api. Returns ------- context.ApiContext """ try: return context.ApiContext.restore() except (FileNotFoundError, JSONDecodeError): ctx = context.ApiContext(environment, api_key, description) ctx.save()
def setup_api_context(cls, environment, api_key, description): try: return context.ApiContext.restore() except (FileNotFoundError, JSONDecodeError): ctx = context.ApiContext(environment, api_key, description) ctx.save()