From 7db4557b17e48d4774e582e653373a09f0582a9e Mon Sep 17 00:00:00 2001 From: Kevin Hellemun Date: Tue, 21 Nov 2017 21:43:39 +0100 Subject: [PATCH] Register adapters for all anchored objects. (bunq/sdk_python#42) --- bunq/__init__.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/bunq/__init__.py b/bunq/__init__.py index 04253ee..2369de9 100644 --- a/bunq/__init__.py +++ b/bunq/__init__.py @@ -14,6 +14,8 @@ def initialize_converter(): from bunq.sdk.json import adapters from bunq.sdk.json import converter from bunq.sdk.model.generated import object_ + from bunq.sdk.model.generated import endpoint + import inspect converter.register_adapter(core.Installation, adapters.InstallationAdapter) converter.register_adapter( @@ -37,6 +39,32 @@ def initialize_converter(): converter.register_adapter(object_.ShareDetail, adapters.ShareDetailAdapter) converter.register_adapter(datetime.datetime, adapters.DateTimeAdapter) converter.register_adapter(client.Pagination, adapters.PaginationAdapter) + # converter.register_adapter(core.AnchoredObjectInterface, + # adapters.AnchoredObjectModelAdapter) + + for class_string in dir(object_): + class_ = getattr(object_, class_string) + + if not inspect.isclass(class_): + continue + + if issubclass(class_, core.AnchoredObjectInterface): + converter.register_adapter( + class_, + adapters.AnchoredObjectModelAdapter + ) + + for class_string in dir(endpoint): + class_ = getattr(endpoint, class_string) + + if not inspect.isclass(class_): + continue + + if issubclass(class_, core.AnchoredObjectInterface): + converter.register_adapter( + class_, + adapters.AnchoredObjectModelAdapter + ) converter.set_initializer_function(initialize_converter)