Skip to content

Commit cfac7d2

Browse files
authored
Merge pull request #30 from cmeissner/code_style_fixes
fix issues from codacy report
2 parents 306e107 + 9dec5a3 commit cfac7d2

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

phpypam/core/api.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# (c) Christian Meißner 2020
33

4-
import json
54
import re
65
import requests
76

@@ -16,14 +15,15 @@
1615

1716

1817
class Api(object):
18+
1919
""" The main class. It generates tha API object where you can run
2020
different actions again to `create`, `update` and `delete` entities.
2121
It also provides functions with informational character only.
2222
"""
2323

2424
def __init__(self, url, app_id, username=None, password=None, token=None, encryption=False, timeout=None, ssl_verify=True, user_agent=None):
25-
""" contructor method
2625

26+
""" contructor method
2727
:param url: The URL to a phpIPAM instance. It includes the protocol (`http` or `https`).
2828
:type url: str
2929
:param app_id: The app_id which is used for the API operations.
@@ -66,8 +66,8 @@ def __init__(self, url, app_id, username=None, password=None, token=None, encryp
6666
self._login()
6767

6868
def _query(self, path='user', headers=None, method=GET, data=None, params=None, auth=None, token=None):
69-
""" Sends queries to phpIPAM API in a generalistic manner
7069

70+
""" Sends queries to phpIPAM API in a generalistic manner
7171
:param path: Path to the controler and possibly to function to use., defaults to 'user'
7272
:type path: str, optional
7373
:param headers: Optional request headers, defaults to None
@@ -124,6 +124,7 @@ def _query(self, path='user', headers=None, method=GET, data=None, params=None,
124124
return result['data']
125125

126126
def _login(self):
127+
127128
""" Login method
128129
"""
129130

@@ -133,17 +134,17 @@ def _login(self):
133134
self._api_token = resp['token']
134135

135136
def get_token(self):
136-
""" Method to grap last login token
137137

138+
""" Method to grap last login token
138139
:return: Returns the api token from the last successful login.
139140
:rtype: str
140141
"""
141142

142143
return self._api_token
143144

144145
def get_entity(self, controller, controller_path=None, params=None):
145-
""" Method to get an existing entity
146146

147+
""" Method to get an existing entity
147148
:param controller: Name of the controller to request entity from.
148149
:type controller: str
149150
:param controller_path: The path which is used to query for entities, defaults to None
@@ -165,8 +166,8 @@ def get_entity(self, controller, controller_path=None, params=None):
165166
return self._query(token=self._api_token, method=GET, path=_path, params=_params)
166167

167168
def create_entity(self, controller, controller_path=None, data=None, params=None):
168-
""" Create an entity
169169

170+
""" Create an entity
170171
:param controller: Name of the controller to use.
171172
:type controller: str
172173
:param controller_path: The path which is used to query for entities, defaults to None
@@ -190,8 +191,8 @@ def create_entity(self, controller, controller_path=None, data=None, params=None
190191
return self._query(token=self._api_token, method=POST, path=_path, data=data, params=_params)
191192

192193
def delete_entity(self, controller, controller_path, params=None):
193-
""" This method is used to delete an entity.
194194

195+
""" This method is used to delete an entity.
195196
:param controller: Name of the controller to use.
196197
:type controller: str
197198
:param controller_path: The path wich is used to access the entity to delete.
@@ -209,8 +210,8 @@ def delete_entity(self, controller, controller_path, params=None):
209210
return self._query(token=self._api_token, method=DELETE, path=_path, params=_params)
210211

211212
def update_entity(self, controller, controller_path=None, data=None, params=None):
212-
""" This method is used to update an entity.
213213

214+
""" This method is used to update an entity.
214215
:param controller: Name of the controller to use.
215216
:type controller: str
216217
:param controller_path: The path which is used to access the entity to update., defaults to None
@@ -234,9 +235,9 @@ def update_entity(self, controller, controller_path=None, data=None, params=None
234235
return self._query(token=self._api_token, method=PATCH, path=_path, data=data, params=_params)
235236

236237
def controllers(self):
238+
237239
""" This method is used to report all known controllers of phpIPAM API.
238240
Unfortunately the API doesn't report all nor the correct paths for all 'controllers'.
239-
240241
:return: Returns a tuple of controller paths.
241242
:rtype: tuple
242243
"""

phpypam/core/exceptions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class PHPyPAMInvalidCredentials(Exception):
4848
This Exception is raised if there are any issues with the authentication against phpIPAM api.
4949
"""
5050
def __init__(self, *args, **kwargs):
51+
52+
""" constructor method
53+
"""
5154
super(PHPyPAMInvalidCredentials, self).__init__(*args, **kwargs)
5255

5356

@@ -56,6 +59,9 @@ class PHPyPAMEntityNotFoundException(Exception):
5659
This Exception is raised if an entity was not found.
5760
"""
5861
def __init__(self, *args, **kwargs):
62+
63+
""" constructor method
64+
"""
5965
super(PHPyPAMEntityNotFoundException, self).__init__(*args, **kwargs)
6066

6167

@@ -64,6 +70,9 @@ class PHPyPAMInvalidSyntax(Exception):
6470
This Exception is raised if there are any issues with syntax of request against phpIPAM api.
6571
"""
6672
def __init__(self, *args, **kwargs):
73+
74+
""" constructor method
75+
"""
6776
self._message = kwargs.pop('message', '')
6877

6978
super(PHPyPAMInvalidSyntax, self).__init__(self._message, *args, **kwargs)

tests/api_connection.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
#!/usr/bin/env python
22

33
import phpypam
4-
import json
54
import yaml
65

76
with open('tests/vars/server.yml') as c:
87
server = yaml.safe_load(c)
98

10-
from phpypam import PHPyPAMEntityNotFoundException
11-
129

1310
if __name__ == '__main__':
1411
pi = phpypam.api(

tests/controllers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
22

33
import phpypam
4-
import json
54
import yaml
65

76
with open('tests/vars/server.yml') as c:

0 commit comments

Comments
 (0)