Skip to content

Commit 27aecd8

Browse files
authored
Feature/create (#9)
* remove controller * cleanup exception handling * implement create_entity method Implement method to create entities. Make creation of path as simple as possible.
1 parent ab902b0 commit 27aecd8

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

pyhpipam/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pkg_resources import get_distribution, DistributionNotFound
22

33
from pyhpipam.core.api import Api as api
4-
4+
from pyhpipam.core.exceptions import PyHPIPAMEntityNotFoundException
55

66
try:
77
__version__ = get_distribution(__name__).version

pyhpipam/controller/__init__.py

Whitespace-only changes.

pyhpipam/controller/sections.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

pyhpipam/core/api.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ def _query(self, **kwargs):
7070

7171
_url = '{}/api/{}/{}'.format(self._api_url, self._api_appid, _api_path)
7272

73-
if _data is not None:
74-
_data = json.dumps(_data)
75-
7673
resp = _method(
7774
_url,
7875
params=_params,
@@ -100,13 +97,20 @@ def _login(self):
10097
def get_token(self):
10198
return self._api_token
10299

103-
def get_entity(self, **kwargs):
104-
_controller = kwargs.pop('controller', None)
100+
def get_entity(self, controller, **kwargs):
101+
_path = controller
105102
_controller_path = kwargs.pop('controller_path', None)
106103

107-
if _controller_path is None and _controller:
108-
_path = '{}'.format(_controller)
109-
elif _controller and _controller_path:
110-
_path = '{}/{}'.format(_controller, _controller_path)
104+
if _controller_path:
105+
_path = '{}/{}'.format(_path, _controller_path)
111106

112107
return self._query(token=self._api_token, method=GET, path=_path)
108+
109+
def create_entity(self, controller, data, **kwargs):
110+
_path = controller
111+
_controller_path = kwargs.pop('controller_path', None)
112+
113+
if _controller_path:
114+
_path = '{}/{}'.format(_path, _controller_path)
115+
116+
return self._query(token=self._api_token, method=POST, path=_path, data=data)

pyhpipam/core/exceptions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, *args, **kwargs):
1616
raise PyHPIPAMInvalidSyntax(message=self._message)
1717
elif self._code == 404:
1818
if self._message == 'Not Found':
19-
raise EntityNotFoundException(self._message)
19+
raise PyHPIPAMEntityNotFoundException(self._message)
2020

2121
# super(PyHPIPAMException, self).__init__(*args, **kwargs)
2222

@@ -26,9 +26,9 @@ def __init__(self, *args, **kwargs):
2626
super(PyHPIPAMInvalidCredentials, self).__init__(*args, **kwargs)
2727

2828

29-
class EntityNotFoundException(Exception):
29+
class PyHPIPAMEntityNotFoundException(Exception):
3030
def __init__(self, *args, **kwargs):
31-
super(EntityNotFoundException, self).__init__(*args, **kwargs)
31+
super(PyHPIPAMEntityNotFoundException, self).__init__(*args, **kwargs)
3232

3333

3434
class PyHPIPAMInvalidSyntax(Exception):

0 commit comments

Comments
 (0)