Skip to content

Commit c493cff

Browse files
authored
meet flake8-docstring recommendations (#32)
* meet flake8-docstring lint suggestions * remove unused import
1 parent a405f2a commit c493cff

File tree

4 files changed

+38
-22
lines changed

4 files changed

+38
-22
lines changed

phpypam/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Package that provides phpIPAM API interface."""
12
from pkg_resources import get_distribution, DistributionNotFound
23

34
from phpypam.core.api import Api as api

phpypam/core/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Core package provide api and exception classes."""

phpypam/core/api.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# (c) Christian Meißner 2020
3-
3+
"""Default class to handle all api interactions with phpIPAM server."""
44
import re
55
import requests
66

@@ -15,14 +15,18 @@
1515

1616

1717
class Api(object):
18+
"""The main class.
1819
19-
""" The main class. It generates tha API object where you can run
20+
It generates tha API object where you can run
2021
different actions again to `create`, `update` and `delete` entities.
2122
It also provides functions with informational character only.
2223
"""
24+
2325
def __init__(self, url, app_id, username=None, password=None, token=None, encryption=False, timeout=None, ssl_verify=True, user_agent=None):
26+
"""Generate the api object.
27+
28+
The costructor collects all data to connect to phpIPAM API. If all data is there it makes the connection to the given server.
2429
25-
""" contructor method
2630
:param url: The URL to a phpIPAM instance. It includes the protocol (`http` or `https`).
2731
:type url: str
2832
:param app_id: The app_id which is used for the API operations.
@@ -64,8 +68,8 @@ def __init__(self, url, app_id, username=None, password=None, token=None, encryp
6468
self._login()
6569

6670
def _query(self, path='user', headers=None, method=GET, data=None, params=None, auth=None, token=None):
71+
"""Send queries to phpIPAM API in a generalistic manner.
6772
68-
""" Sends queries to phpIPAM API in a generalistic manner
6973
:param path: Path to the controler and possibly to function to use., defaults to 'user'
7074
:type path: str, optional
7175
:param headers: Optional request headers, defaults to None
@@ -121,23 +125,26 @@ def _query(self, path='user', headers=None, method=GET, data=None, params=None,
121125
return result['data']
122126

123127
def _login(self):
124-
""" Login method """
128+
"""Login to phpIPAM API and return token."""
125129
_auth = HTTPBasicAuth(self._api_username, self._api_password)
126130
resp = self._query(method=POST, auth=_auth)
127131

128132
self._api_token = resp['token']
129133

130134
def get_token(self):
135+
"""Return last login token.
131136
132-
""" Method to grap last login token
133137
:return: Returns the api token from the last successful login.
134138
:rtype: str
135139
"""
136140
return self._api_token
137141

138142
def get_entity(self, controller, controller_path=None, params=None):
143+
"""Get existing entity from phpIPAM server.
144+
145+
This method query for existing entity. It there a result it will be returned otherwise
146+
an PhpIPAMEntityNotFound exception is raised from underlying method.
139147
140-
""" Method to get an existing entity
141148
:param controller: Name of the controller to request entity from.
142149
:type controller: str
143150
:param controller_path: The path which is used to query for entities, defaults to None
@@ -158,8 +165,8 @@ def get_entity(self, controller, controller_path=None, params=None):
158165
return self._query(token=self._api_token, method=GET, path=_path, params=_params)
159166

160167
def create_entity(self, controller, controller_path=None, data=None, params=None):
168+
"""Create an entity.
161169
162-
""" Create an entity
163170
:param controller: Name of the controller to use.
164171
:type controller: str
165172
:param controller_path: The path which is used to query for entities, defaults to None
@@ -182,8 +189,8 @@ def create_entity(self, controller, controller_path=None, data=None, params=None
182189
return self._query(token=self._api_token, method=POST, path=_path, data=data, params=_params)
183190

184191
def delete_entity(self, controller, controller_path, params=None):
192+
"""Delete an entity.
185193
186-
""" This method is used to delete an entity.
187194
:param controller: Name of the controller to use.
188195
:type controller: str
189196
:param controller_path: The path wich is used to access the entity to delete.
@@ -200,8 +207,8 @@ def delete_entity(self, controller, controller_path, params=None):
200207
return self._query(token=self._api_token, method=DELETE, path=_path, params=_params)
201208

202209
def update_entity(self, controller, controller_path=None, data=None, params=None):
210+
"""Update an entity.
203211
204-
""" This method is used to update an entity.
205212
:param controller: Name of the controller to use.
206213
:type controller: str
207214
:param controller_path: The path which is used to access the entity to update., defaults to None
@@ -224,9 +231,11 @@ def update_entity(self, controller, controller_path=None, data=None, params=None
224231
return self._query(token=self._api_token, method=PATCH, path=_path, data=data, params=_params)
225232

226233
def controllers(self):
234+
"""Report all controllers from phpIPAM API.
227235
228-
""" This method is used to report all known controllers of phpIPAM API.
236+
This method is used to report all known controllers of phpIPAM API.
229237
Unfortunately the API doesn't report all nor the correct paths for all 'controllers'.
238+
230239
:return: Returns a tuple of controller paths.
231240
:rtype: tuple
232241
"""

phpypam/core/exceptions.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
# provides the main query methods.
2-
3-
import json
1+
"""Class to provided different Exceptions."""
42

53

64
class PHPyPAMException(Exception):
7-
""" PHPyPAMExeption, children of :class:`Exception`.
5+
"""PHPyPAMExeption, children of :class:`Exception`.
6+
87
This exception is raised if anythings in :class:`phpypam.api` doesn't work out.
98
"""
9+
1010
def __init__(self, *args, code=None, message=None):
11-
""" Constructor method.
11+
"""Generate PHPyPAMException.
12+
13+
This Exception takes 'code' and 'message' and decided on it which special Exception can be raised.
1214
1315
:param code: Status code which comes from caller., defaults to None
1416
:type code: int, optional
@@ -44,32 +46,35 @@ def __init__(self, *args, code=None, message=None):
4446

4547

4648
class PHPyPAMInvalidCredentials(Exception):
49+
"""Exception PHPyPAMInvalidCredentials, children of :class:`Exception`.
4750
48-
""" Exception PHPyPAMInvalidCredentials, children of :class:`Exception`.
4951
This Exception is raised if there are any issues with the authentication against phpIPAM api.
5052
"""
53+
5154
def __init__(self, *args, **kwargs):
52-
""" constructor method """
55+
"""Generate PHPyPAMInvalidCredentials exception."""
5356
super(PHPyPAMInvalidCredentials, self).__init__(*args, **kwargs)
5457

5558

5659
class PHPyPAMEntityNotFoundException(Exception):
60+
"""Exception PHPyPAMEntityNotFoundException, children of :class:`Exception`.
5761
58-
""" Exception PHPyPAMEntityNotFoundException, children of :class:`Exception`.
5962
This Exception is raised if an entity was not found.
6063
"""
64+
6165
def __init__(self, *args, **kwargs):
62-
""" constructor method """
66+
"""Generate PHPyPAMEntityNotFoundException."""
6367
super(PHPyPAMEntityNotFoundException, self).__init__(*args, **kwargs)
6468

6569

6670
class PHPyPAMInvalidSyntax(Exception):
71+
"""Exception PHPyPAMInvalidSyntax, children of :class:`Exception`.
6772
68-
""" Exception PHPyPAMInvalidSyntax, children of :class:`Exception`.
6973
This Exception is raised if there are any issues with syntax of request against phpIPAM api.
7074
"""
75+
7176
def __init__(self, *args, **kwargs):
72-
""" constructor method """
77+
"""Generate PHPyPAMInvalidSyntax exception."""
7378
self._message = kwargs.pop('message', '')
7479

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

0 commit comments

Comments
 (0)