diff --git a/incognia/api.py b/incognia/api.py index 8814d60..c4c4339 100644 --- a/incognia/api.py +++ b/incognia/api.py @@ -6,11 +6,12 @@ from .exceptions import IncogniaHTTPError, IncogniaError from .json_util import encode from .models import Coordinates, StructuredAddress, TransactionAddress, PaymentValue, PaymentMethod +from .singleton import Singleton from .token_manager import TokenManager from .base_request import BaseRequest, JSON_CONTENT_HEADER -class IncogniaAPI: +class IncogniaAPI(metaclass=Singleton): def __init__(self, client_id: str, client_secret: str): self.__token_manager = TokenManager(client_id, client_secret) self.__request = BaseRequest() diff --git a/incognia/singleton.py b/incognia/singleton.py new file mode 100644 index 0000000..399f727 --- /dev/null +++ b/incognia/singleton.py @@ -0,0 +1,7 @@ + +class Singleton(type): + _instances = {} + def __call__(cls, *args, **kwargs): + if cls not in cls._instances: + cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) + return cls._instances[cls] \ No newline at end of file