11# -*- coding: utf-8 -*-
22# (c) Christian Meißner 2020
33
4- import json
54import re
65import requests
76
1615
1716
1817class 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 """
0 commit comments