diff --git a/README.rst b/README.rst index 865696f..5b7d74a 100644 --- a/README.rst +++ b/README.rst @@ -31,9 +31,9 @@ First, we need a client instance: .. code:: - >>> from httpnet.client import HttpNetClient + >>> from httpnet.client import HttpNetClient, PlatformBaseUrl >>> AUTH_TOKEN = '' - >>> api = HttpNetClient(auth_token=AUTH_TOKEN) + >>> api = HttpNetClient(auth_token=AUTH_TOKEN, base_url=PlatformBaseUrl.HTTP_NET) The client provides access to all service categories in the API. They are iterable: diff --git a/httpnet/_core.py b/httpnet/_core.py index b8fb2d0..36486f6 100644 --- a/httpnet/_core.py +++ b/httpnet/_core.py @@ -13,16 +13,25 @@ JsonObject = MutableMapping +class PlatformBaseUrl(Enum): + HTTP_NET = 'https://partner.http.net/api' + HOSTING_DE = 'https://secure.hosting.de/api' + + def __str__(self): + return self.value + + class Client: USER_AGENT = 'HTTP.NET Partner API Python client 1.0' - BASE_URL = 'https://partner.http.net/api' + BASE_URL = None VERSION = 'v1' FORMAT = 'json' DEFAULT_TIMEOUT = 180 - def __init__(self, auth_token: str, owner_account_id: Optional[str] = None, + def __init__(self, auth_token: str, base_url: PlatformBaseUrl, owner_account_id: Optional[str] = None, timeout: Optional[Union[float, Tuple[float, float]]] = None) -> None: self.auth_token = auth_token + Client.BASE_URL = base_url self.owner_account_id = owner_account_id self.timeout = timeout if timeout and timeout > 0 else Client.DEFAULT_TIMEOUT self.__session = requests.Session() diff --git a/httpnet/client.py b/httpnet/client.py index 53ba977..961fbcd 100644 --- a/httpnet/client.py +++ b/httpnet/client.py @@ -1,19 +1,23 @@ from typing import Optional, Tuple, Union +from enum import Enum from ._core import Client from .domain import ContactService, DomainService, JobService from .dns import ZoneConfigService, RecordService, ZoneService, NameserverSetService, TemplateService from .email import MailboxService, OrganizationService, DomainSettingsService +from ._core import PlatformBaseUrl + + class HttpNetClient: """ A client for the http.net Partner API """ - def __init__(self, auth_token: str, owner_account_id: Optional[str] = None, + def __init__(self, auth_token: str, base_url: PlatformBaseUrl, owner_account_id: Optional[str] = None, timeout: Optional[Union[float, Tuple[float, float]]] = None) -> None: - self.__client = Client(auth_token, owner_account_id=owner_account_id, timeout=timeout) + self.__client = Client(auth_token, base_url, owner_account_id=owner_account_id, timeout=timeout) # Domains self.domains = DomainService(self.__client)