Skip to content

Commit 332cd62

Browse files
authored
Merge pull request #21 from roaldnefs/develop
2 parents d3fc60d + e5ddb96 commit 332cd62

8 files changed

Lines changed: 273 additions & 80 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
# Retrieve a list of VPSs
1717
>>> for vps in client.vpss.list():
1818
... print(vps)
19-
<class 'transip.v6.services.vps.Vps'> => {'name': 'transipdemo-vps', 'productName': 'vps-bladevps-x1', ... }
19+
<class 'transip.v6.objects.Vps'> => {'name': 'transipdemo-vps', 'productName': 'vps-bladevps-x1', ... }
2020
# Retrieve a domain and list its DNS-records
2121
>>> domain = client.domains.get('transipdemo.net')
2222
>>> for entry in domain.dns.list():
2323
... print(entry)
24-
<class 'transip.v6.services.domain.DnsEntry'> => {'name': '*', 'expire': 300, 'type': 'A', 'content': '95.170.70.223'}
25-
<class 'transip.v6.services.domain.DnsEntry'> => {'name': '@', 'expire': 300, 'type': 'A', 'content': '95.170.70.223'}
24+
<class 'transip.v6.objects.DnsEntry'> => {'name': '*', 'expire': 300, 'type': 'A', 'content': '95.170.70.223'}
25+
<class 'transip.v6.objects.DnsEntry'> => {'name': '@', 'expire': 300, 'type': 'A', 'content': '95.170.70.223'}
2626
# Add a new DNS-record
2727
>>> domain.dns.create({'name': '@', 'expire': 300, 'type': 'TXT', 'content': 'Python'})
2828
```

docs/index.rst

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,45 @@
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
55
6-
Welcome to python-transip's documentation!
7-
==========================================
6+
.. image:: https://github.com/roaldnefs/python-transip/blob/main/logo.png?raw=true
7+
:target: https://github.com/roaldnefs/python-transip
88

99
Release v\ |version|. (:ref:`Installation <install>`)
1010

11-
.. image:: https://pepy.tech/badge/python-transip/month
12-
:target: https://pepy.tech/project/python-transip
13-
14-
.. image:: https://img.shields.io/pypi/l/python-transip.svg
11+
.. image:: https://img.shields.io/pypi/pyversions/python-transip?color=187dc1&logo=python&logoColor=white&style=for-the-badge
1512
:target: https://pypi.org/project/python-transip/
16-
17-
.. image:: https://img.shields.io/pypi/pyversions/python-transip.svg
13+
.. image:: https://img.shields.io/pypi/dm/python-transip?color=187dc1&logo=python&logoColor=white&style=for-the-badge
14+
:target: https://pypi.org/project/python-transip/
15+
.. image:: https://img.shields.io/pypi/format/python-transip?color=187dc1&logo=python&logoColor=white&style=for-the-badge
1816
:target: https://pypi.org/project/python-transip/
17+
.. image:: https://img.shields.io/github/license/roaldnefs/python-transip?color=187dc1&style=for-the-badge
18+
:target: https://raw.githubusercontent.com/roaldnefs/python-transip/main/COPYING
19+
.. image:: https://img.shields.io/github/workflow/status/roaldnefs/python-transip/tests?color=187dc1&label=CI&logo=github&style=for-the-badge
20+
:target: https://github.com/roaldnefs/python-transip/actions
21+
.. image:: https://img.shields.io/github/contributors/roaldnefs/python-transip?color=187dc1&logo=github&style=for-the-badge
22+
:target: https://github.com/roaldnefs/python-transip/graphs/contributors
1923

2024
**python-transip** is an Python wrapper for the TransIP REST API.
2125

2226
-------------------
2327

2428
**Example usage**::
2529

26-
>>> from transip import TransIP
27-
>>> client = TransIP(access_token="REDACTED")
28-
>>> domains = client.domains.list()
29-
>>> domain = domains[0]
30-
>>> domain.registrationDate
31-
'2011-04-29'
30+
>>> import transip
31+
# Initialize a TransIP API client
32+
>>> client = transip.TransIP(access_token="TOKEN")
33+
# Retrieve a list of VPSs
34+
>>> for vps in client.vpss.list():
35+
... print(vps)
36+
<class 'transip.v6.objects.Vps'> => {'name': 'transipdemo-vps', 'productName': 'vps-bladevps-x1', ... }
37+
# Retrieve a domain and list its DNS-records
38+
>>> domain = client.domains.get('transipdemo.net')
39+
>>> for entry in domain.dns.list():
40+
... print(entry)
41+
<class 'transip.v6.objects.DnsEntry'> => {'name': '*', 'expire': 300, 'type': 'A', 'content': '95.170.70.223'}
42+
<class 'transip.v6.objects.DnsEntry'> => {'name': '@', 'expire': 300, 'type': 'A', 'content': '95.170.70.223'}
43+
# Add a new DNS-record
44+
>>> domain.dns.create({'name': '@', 'expire': 300, 'type': 'TXT', 'content': 'Python'})
3245

3346
**python-transip** allows you to create, read and update resources on TransIP
3447
with ease.

docs/user/quickstart.rst

Lines changed: 52 additions & 52 deletions
Large diffs are not rendered by default.

tests/services/test_domains.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
from typing import Type, List, Dict, Any, Union
2525

2626
from transip import TransIP
27-
from transip.v6.services.domain import (
28-
Domain, WhoisContact, Nameserver, DnsEntry
29-
)
27+
from transip.v6.objects import Domain, WhoisContact, Nameserver, DnsEntry
3028
from tests.utils import load_responses_fixture
3129

3230

tests/services/test_invoices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import responses # type: ignore
2222

2323
from transip import TransIP
24-
from transip.v6.services.invoice import Invoice
24+
from transip.v6.objects import Invoice
2525

2626

2727
@responses.activate

tests/services/test_ssh_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import unittest
2525

2626
from transip import TransIP
27-
from transip.v6.services.ssh_key import SshKey
27+
from transip.v6.objects import SshKey
2828
from tests.utils import load_responses_fixture
2929

3030

transip/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ def __init__(
6262
self.session: requests.Session = requests.Session()
6363

6464
# Dynamically import the services for the specified API version
65-
services = importlib.import_module(f"transip.v{api_version}.services")
65+
objects = importlib.import_module(f"transip.v{api_version}.objects")
6666

6767
self.availability_zones: Type[Any] = (
68-
services.AvailabilityZoneService(self) # type: ignore
68+
objects.AvailabilityZoneService(self) # type: ignore
6969
)
70-
self.domains: Type[Any] = services.DomainService(self) # type: ignore
70+
self.domains: Type[Any] = objects.DomainService(self) # type: ignore
7171
self.invoices: Type[Any] = (
72-
services.InvoiceService(self) # type: ignore
72+
objects.InvoiceService(self) # type: ignore
7373
)
74-
self.ssh_keys: Type[Any] = services.SshKeyService(self) # type: ignore
75-
self.vpss: Type[Any] = services.VpsService(self) # type: ignore
74+
self.ssh_keys: Type[Any] = objects.SshKeyService(self) # type: ignore
75+
self.vpss: Type[Any] = objects.VpsService(self) # type: ignore
7676

7777
@property
7878
def url(self) -> str:

transip/v6/objects.py

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright (C) 2020, 2021 Roald Nefs <info@roaldnefs.com>
4+
#
5+
# This file is part of python-transip.
6+
7+
# python-transip is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Lesser General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
12+
# python-transip is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Lesser General Public License for more details.
16+
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with python-transip. If not, see <https://www.gnu.org/licenses/>.
19+
20+
from typing import Optional, Type
21+
22+
from transip.base import ApiService, ApiObject
23+
from transip.mixins import (
24+
GetMixin, DeleteMixin, ListMixin, CreateMixin, UpdateMixin,
25+
CreateAttrsTuple, UpdateAttrsTuple
26+
)
27+
28+
29+
class AvailabilityZone(ApiObject):
30+
31+
_id_attr: str = "name"
32+
33+
34+
class AvailabilityZoneService(ListMixin, ApiService):
35+
36+
_path: str = "/availability-zones"
37+
_obj_cls: Optional[Type[ApiObject]] = AvailabilityZone
38+
39+
_resp_list_attr: str = "availabilityZones"
40+
41+
42+
class SshKey(ApiObject):
43+
44+
_id_attr: str = "id"
45+
46+
47+
class SshKeyService(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, ListMixin,
48+
ApiService):
49+
50+
_path: str = "/ssh-keys"
51+
_obj_cls: Optional[Type[ApiObject]] = SshKey
52+
53+
_resp_list_attr: str = "sshKeys"
54+
_resp_get_attr: str = "sshKey"
55+
56+
_create_attrs: Optional[CreateAttrsTuple] = (
57+
("sshKey",), # required
58+
("description",) # optional
59+
)
60+
_update_attrs: Optional[UpdateAttrsTuple] = (
61+
("description",), # required
62+
tuple() # optional
63+
)
64+
65+
66+
class WhoisContact(ApiObject):
67+
68+
_id_attr: Optional[str] = None
69+
70+
71+
class WhoisContactService(ListMixin, ApiService):
72+
"""Service to manage domain contacts of a domain."""
73+
74+
_path: str = "/domains/{parent_id}/contacts"
75+
_obj_cls: Optional[Type[ApiObject]] = WhoisContact
76+
77+
_resp_list_attr: str = "contacts"
78+
79+
80+
class DnsEntry(ApiObject):
81+
82+
_id_attr: Optional[str] = None
83+
84+
85+
class DnsEntryService(CreateMixin, ListMixin, ApiService):
86+
"""Service to manage DNS entries of a domain."""
87+
88+
_path: str = "/domains/{parent_id}/dns"
89+
_obj_cls: Optional[Type[ApiObject]] = DnsEntry
90+
91+
_resp_list_attr: str = "dnsEntries"
92+
_req_create_attr: str = "dnsEntry"
93+
_create_attrs: Optional[CreateAttrsTuple] = (
94+
("name", "expire", "type", "content"), # required
95+
tuple() # optional
96+
)
97+
98+
99+
class Nameserver(ApiObject):
100+
101+
_id_attr: Optional[str] = "hostname"
102+
103+
104+
class NameserverService(ListMixin, ApiService):
105+
"""Service to nameservers of a domain."""
106+
107+
_path: str = "/domains/{parent_id}/nameservers"
108+
_obj_cls: Optional[Type[ApiObject]] = Nameserver
109+
110+
_resp_list_attr: str = "nameservers"
111+
112+
113+
class Domain(ApiObject):
114+
115+
_id_attr: str = "name"
116+
117+
@property
118+
def contacts(self) -> WhoisContactService:
119+
"""Return the service to manage the WHOIS contacts of the domain."""
120+
return WhoisContactService(
121+
self.service.client,
122+
parent=self # type: ignore
123+
)
124+
125+
@property
126+
def dns(self) -> DnsEntryService:
127+
"""Return the service to manage the DNS entries of the domain."""
128+
return DnsEntryService(
129+
self.service.client,
130+
parent=self # type: ignore
131+
)
132+
133+
@property
134+
def nameservers(self) -> NameserverService:
135+
"""Return the service to manage the nameservers of the domain."""
136+
return NameserverService(
137+
self.service.client,
138+
parent=self # type: ignore
139+
)
140+
141+
142+
class DomainService(CreateMixin, GetMixin, DeleteMixin, ListMixin, ApiService):
143+
"""Service to manage domains."""
144+
145+
_path: str = "/domains"
146+
_obj_cls: Optional[Type[ApiObject]] = Domain
147+
148+
_resp_list_attr: str = "domains"
149+
_resp_get_attr: str = "domain"
150+
151+
_create_attrs: Optional[CreateAttrsTuple] = (
152+
("domainName",), # required
153+
("contacts", "nameservers", "dnsEntries") # optional
154+
)
155+
156+
157+
class Invoice(ApiObject):
158+
159+
_id_attr: str = "invoiceNumber"
160+
161+
162+
class InvoiceService(GetMixin, ListMixin, ApiService):
163+
164+
_path: str = "/invoices"
165+
_obj_cls: Optional[Type[ApiObject]] = Invoice
166+
167+
_resp_list_attr: str = "invoices"
168+
_resp_get_attr: str = "invoice"
169+
170+
171+
class Vps(ApiObject):
172+
173+
_id_attr: str = "name"
174+
175+
176+
class VpsService(GetMixin, DeleteMixin, ListMixin, ApiService):
177+
178+
_path: str = "/vps"
179+
_obj_cls: Optional[Type[ApiObject]] = Vps
180+
181+
_resp_list_attr: str = "vpss"
182+
_resp_get_attr: str = "vps"

0 commit comments

Comments
 (0)