Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ First, we need a client instance:

.. code::

>>> from httpnet.client import HttpNetClient
>>> from httpnet.client import HttpNetClient, PlatformBaseUrl
>>> AUTH_TOKEN = '<your 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:

Expand Down
13 changes: 11 additions & 2 deletions httpnet/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions httpnet/client.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down