1
1
# -*- coding: utf-8 -*-
2
2
# (c) Christian Meißner 2020
3
3
4
- import json
5
4
import re
6
5
import requests
7
6
16
15
17
16
18
17
class Api (object ):
18
+
19
19
""" The main class. It generates tha API object where you can run
20
20
different actions again to `create`, `update` and `delete` entities.
21
21
It also provides functions with informational character only.
22
22
"""
23
23
24
24
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
26
25
26
+ """ contructor method
27
27
:param url: The URL to a phpIPAM instance. It includes the protocol (`http` or `https`).
28
28
:type url: str
29
29
: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
66
66
self ._login ()
67
67
68
68
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
70
69
70
+ """ Sends queries to phpIPAM API in a generalistic manner
71
71
:param path: Path to the controler and possibly to function to use., defaults to 'user'
72
72
:type path: str, optional
73
73
: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,
124
124
return result ['data' ]
125
125
126
126
def _login (self ):
127
+
127
128
""" Login method
128
129
"""
129
130
@@ -133,17 +134,17 @@ def _login(self):
133
134
self ._api_token = resp ['token' ]
134
135
135
136
def get_token (self ):
136
- """ Method to grap last login token
137
137
138
+ """ Method to grap last login token
138
139
:return: Returns the api token from the last successful login.
139
140
:rtype: str
140
141
"""
141
142
142
143
return self ._api_token
143
144
144
145
def get_entity (self , controller , controller_path = None , params = None ):
145
- """ Method to get an existing entity
146
146
147
+ """ Method to get an existing entity
147
148
:param controller: Name of the controller to request entity from.
148
149
:type controller: str
149
150
: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):
165
166
return self ._query (token = self ._api_token , method = GET , path = _path , params = _params )
166
167
167
168
def create_entity (self , controller , controller_path = None , data = None , params = None ):
168
- """ Create an entity
169
169
170
+ """ Create an entity
170
171
:param controller: Name of the controller to use.
171
172
:type controller: str
172
173
: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
190
191
return self ._query (token = self ._api_token , method = POST , path = _path , data = data , params = _params )
191
192
192
193
def delete_entity (self , controller , controller_path , params = None ):
193
- """ This method is used to delete an entity.
194
194
195
+ """ This method is used to delete an entity.
195
196
:param controller: Name of the controller to use.
196
197
:type controller: str
197
198
: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):
209
210
return self ._query (token = self ._api_token , method = DELETE , path = _path , params = _params )
210
211
211
212
def update_entity (self , controller , controller_path = None , data = None , params = None ):
212
- """ This method is used to update an entity.
213
213
214
+ """ This method is used to update an entity.
214
215
:param controller: Name of the controller to use.
215
216
:type controller: str
216
217
: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
234
235
return self ._query (token = self ._api_token , method = PATCH , path = _path , data = data , params = _params )
235
236
236
237
def controllers (self ):
238
+
237
239
""" This method is used to report all known controllers of phpIPAM API.
238
240
Unfortunately the API doesn't report all nor the correct paths for all 'controllers'.
239
-
240
241
:return: Returns a tuple of controller paths.
241
242
:rtype: tuple
242
243
"""
0 commit comments