@@ -42,20 +42,20 @@ def __init__(self, url, validate=False, access_token=None, language=None):
42
42
self ._url = url .rstrip ('/' )
43
43
self ._validate = validate
44
44
self ._classification_systems = {}
45
- self ._access_token = f'? access_token= { access_token } ' if access_token else ''
45
+ self ._access_token = access_token if access_token else ''
46
46
self ._support_l = self ._support_language ()
47
47
self ._language = self ._validate_language (language ) if language else ''
48
48
49
49
def _support_language (self ):
50
50
"""Get the support language from service."""
51
51
import enum
52
- data = Utils ._get (f'{ self ._url } /' )
52
+ data = Utils ._get (f'{ self ._url } /' , access_token = self . _access_token )
53
53
return enum .Enum ('Language' , {i ['language' ]: i ['language' ] for i in data ['supported_language' ]}, type = str )
54
54
55
55
def _validate_language (self , language ):
56
56
"""Get the support language from service."""
57
57
if language in [e .value for e in self ._support_l ]:
58
- return f'& language={ language } '
58
+ return f'? language={ language } '
59
59
else :
60
60
s = ', ' .join ([e for e in self .allowed_language ])
61
61
raise KeyError (f'Language not supported! Use: { s } ' )
@@ -67,8 +67,8 @@ def _get_format_identifier(self, name):
67
67
68
68
def _get_classification_systems (self ):
69
69
"""Return the Classification Systems available in service."""
70
- url = f'{ self ._url } /classification_systems{ self ._access_token } { self . _language } '
71
- data = Utils ._get (url )
70
+ url = f'{ self ._url } /classification_systems{ self ._language } '
71
+ data = Utils ._get (url , access_token = self . _access_token )
72
72
result = list ()
73
73
74
74
[result .append (i ['identifier' ]) for i in data ]
@@ -110,8 +110,8 @@ def classification_system(self, system: str) -> ClassificationSystem:
110
110
:rtype: dict
111
111
"""
112
112
try :
113
- url = f'{ self ._url } /classification_systems/{ system } { self ._access_token } { self . _language } '
114
- data = Utils ._get (url )
113
+ url = f'{ self ._url } /classification_systems/{ system } { self ._language } '
114
+ data = Utils ._get (url , access_token = self . _access_token )
115
115
return ClassificationSystem (data , self ._validate )
116
116
except Exception :
117
117
raise KeyError (f'Could not retrieve information for classification_system: { system } ' )
@@ -129,7 +129,7 @@ def available_mappings(self, system_source: str) -> list:
129
129
result = list ()
130
130
131
131
try :
132
- data = Utils ._get (f'{ self ._url } /mappings/{ system_source } { self ._access_token } { self . _language } ' )
132
+ data = Utils ._get (f'{ self ._url } /mappings/{ system_source } { self ._language } ' , access_token = self . _access_token )
133
133
except Exception :
134
134
raise KeyError (f'Could not retrieve any available mapping for { system_source } ' )
135
135
@@ -153,7 +153,7 @@ def mappings(self, system_source: str, system_target: str) -> MappingGroup:
153
153
:rtype: list
154
154
"""
155
155
try :
156
- data = Utils ._get (f'{ self ._url } /mappings/{ system_source } /{ system_target } { self ._access_token } ' )
156
+ data = Utils ._get (f'{ self ._url } /mappings/{ system_source } /{ system_target } ' , access_token = self ._access_token )
157
157
except Exception :
158
158
raise KeyError (f'Could not retrieve mappings for { system_source } and { system_target } ' )
159
159
@@ -171,14 +171,14 @@ def available_style_formats(self) -> list:
171
171
result = list ()
172
172
173
173
try :
174
- data = Utils ._get (f'{ self ._url } /style_formats{ self ._access_token } ' )
174
+ data = Utils ._get (f'{ self ._url } /style_formats' , access_token = self ._access_token )
175
175
except Exception :
176
176
raise KeyError ('Could not retrieve any style format' )
177
177
178
178
for i in data :
179
179
for links in i ['links' ]:
180
180
if links ['rel' ] == 'items' :
181
- data = Utils ._get (f"{ links ['href' ]} " )
181
+ data = Utils ._get (f"{ links ['href' ]} " , access_token = self . _access_token )
182
182
result .append (StyleFormats (data ))
183
183
184
184
return result
@@ -195,12 +195,12 @@ def style_formats(self, system) -> List[StyleFormats]:
195
195
"""
196
196
result = list ()
197
197
try :
198
- data = Utils ._get (f'{ self ._url } /classification_systems/{ system } /style_formats{ self ._access_token } ' )
198
+ data = Utils ._get (f'{ self ._url } /classification_systems/{ system } /style_formats' , access_token = self ._access_token )
199
199
except Exception :
200
200
raise KeyError (f'Could not retrieve any style format for { system } ' )
201
201
for i in data :
202
202
if i ['rel' ] == 'style' :
203
- data = Utils ._get (f'{ self ._url } /style_formats/{ i ["href" ].split ("/" )[- 1 ]} ' )
203
+ data = Utils ._get (f'{ self ._url } /style_formats/{ i ["href" ].split ("/" )[- 1 ]} ' , access_token = self . _access_token )
204
204
result .append (StyleFormats (data ))
205
205
206
206
return result
@@ -222,7 +222,7 @@ def get_style(self, system, style_format, path=None):
222
222
:rtype: File
223
223
"""
224
224
try :
225
- file_name , data = Utils ._get (f'{ self ._url } /classification_systems/{ system } /styles/{ style_format } { self ._access_token } ' )
225
+ file_name , data = Utils ._get (f'{ self ._url } /classification_systems/{ system } /styles/{ style_format } ' , access_token = self ._access_token )
226
226
except Exception :
227
227
raise KeyError (f'Could not retrieve any style for { system } ' )
228
228
@@ -234,7 +234,7 @@ def get_style(self, system, style_format, path=None):
234
234
def add_classification_system (self , name : str , authority_name : str , description : dict , title : dict ,
235
235
version : str ) -> dict :
236
236
"""Add a new classification system."""
237
- url = f'{ self ._url } /classification_systems{ self . _access_token } '
237
+ url = f'{ self ._url } /classification_systems'
238
238
239
239
data = dict ()
240
240
data ["name" ] = name
@@ -244,22 +244,22 @@ def add_classification_system(self, name: str, authority_name: str, description:
244
244
data ["title" ] = title
245
245
246
246
try :
247
- retval = Utils ._post (url , json = data )
247
+ retval = Utils ._post (url , access_token = self . _access_token , json = data )
248
248
except RuntimeError as e :
249
249
raise ValueError (f'Could not insert classification system { name } !' )
250
250
251
251
return retval
252
252
253
253
def add_classes (self , system : str , classes : str ) -> List [dict ]:
254
254
"""Add new classes to an classification system."""
255
- url = f'{ self ._url } /classification_systems/{ system } /classes{ self . _access_token } '
255
+ url = f'{ self ._url } /classification_systems/{ system } /classes'
256
256
257
257
if type (classes ) == str :
258
258
with open (classes ) as file :
259
259
classes = json .load (file )
260
260
261
261
try :
262
- retval = Utils ._post (url , json = classes )
262
+ retval = Utils ._post (url , access_token = self . _access_token , json = classes )
263
263
except RuntimeError :
264
264
raise ValueError ('Could not insert classes!' )
265
265
@@ -268,7 +268,7 @@ def add_classes(self, system: str, classes: str) -> List[dict]:
268
268
def add_style (self , system : str , style_format : str , style_path : str = None , style_tex : str = None ,
269
269
style_name : str = None , style_extension : str = None ) -> List [dict ]:
270
270
"""Add a new style to a system."""
271
- url = f'{ self ._url } /classification_systems/{ system } /styles{ self . _access_token } '
271
+ url = f'{ self ._url } /classification_systems/{ system } /styles'
272
272
273
273
if style_path :
274
274
try :
@@ -283,34 +283,34 @@ def add_style(self, system: str, style_format: str, style_path: str = None, styl
283
283
data = dict (style_format = style_format )
284
284
285
285
try :
286
- retval = Utils ._post (url , data = data , files = style )
286
+ retval = Utils ._post (url , access_token = self . _access_token , data = data , files = style )
287
287
except RuntimeError :
288
288
raise ValueError ('Could not insert style!' )
289
289
290
290
return retval
291
291
292
292
def add_mapping (self , system_source : str , system_target : str , mappings ) -> list :
293
293
"""Add new classification system mapping."""
294
- url = f'{ self ._url } /mappings/{ system_source } /{ system_target } { self . _access_token } '
294
+ url = f'{ self ._url } /mappings/{ system_source } /{ system_target } '
295
295
296
296
if type (mappings ) == str :
297
297
with open (mappings ) as file :
298
298
mappings = json .load (file )
299
299
try :
300
- retval = Utils ._post (url , json = mappings )
300
+ retval = Utils ._post (url , access_token = self . _access_token , json = mappings )
301
301
except RuntimeError :
302
302
raise ValueError ('Could not insert mappings!' )
303
303
304
304
return retval
305
305
306
306
def add_style_format (self , name : str ) -> dict :
307
307
"""Add a new style format."""
308
- url = f'{ self ._url } /style_formats{ self . _access_token } '
308
+ url = f'{ self ._url } /style_formats'
309
309
310
310
data = {"name" : name }
311
311
312
312
try :
313
- retval = Utils ._post (url , json = data )
313
+ retval = Utils ._post (url , access_token = self . _access_token , json = data )
314
314
except RuntimeError :
315
315
raise ValueError (f'Could not insert style format { name } !' )
316
316
@@ -319,7 +319,7 @@ def add_style_format(self, name: str) -> dict:
319
319
def delete_classification_system (self , system : str ) -> int :
320
320
"""Delete a specific classification system."""
321
321
try :
322
- retval = Utils ._delete (f'{ self ._url } /classification_systems/{ system } { self ._access_token } ' )
322
+ retval = Utils ._delete (f'{ self ._url } /classification_systems/{ system } ' , access_token = self ._access_token )
323
323
except RuntimeError :
324
324
raise ValueError (f'Could not remove classification system { system } !' )
325
325
@@ -328,7 +328,7 @@ def delete_classification_system(self, system: str) -> int:
328
328
def delete_class (self , system : str , class_name_or_id : str ) -> int :
329
329
"""Delete a specific class."""
330
330
try :
331
- retval = Utils ._delete (f'{ self ._url } /classification_systems/{ system } /classes/{ class_name_or_id } { self ._access_token } ' )
331
+ retval = Utils ._delete (f'{ self ._url } /classification_systems/{ system } /classes/{ class_name_or_id } ' , access_token = self ._access_token )
332
332
except RuntimeError :
333
333
raise ValueError (f'Could not remove class { class_name_or_id } of classification system { system } !' )
334
334
@@ -337,7 +337,7 @@ def delete_class(self, system: str, class_name_or_id: str) -> int:
337
337
def delete_style_format (self , style_format : str ) -> int :
338
338
"""Delete a specific style format."""
339
339
try :
340
- retval = Utils ._delete (f'{ self ._url } /style_formats/{ style_format } { self ._access_token } ' )
340
+ retval = Utils ._delete (f'{ self ._url } /style_formats/{ style_format } ' , access_token = self ._access_token )
341
341
except RuntimeError :
342
342
raise ValueError (f'Could not remove style format { style_format } !' )
343
343
@@ -346,7 +346,7 @@ def delete_style_format(self, style_format: str) -> int:
346
346
def delete_style (self , system : str , style_format : str ) -> int :
347
347
"""Delete the style of a classification system."""
348
348
try :
349
- retval = Utils ._delete (f'{ self ._url } /classification_systems/{ system } /styles/{ style_format } { self ._access_token } ' )
349
+ retval = Utils ._delete (f'{ self ._url } /classification_systems/{ system } /styles/{ style_format } ' , access_token = self ._access_token )
350
350
except RuntimeError :
351
351
raise ValueError (f'Could not remove style { style_format } of classification system { system } !' )
352
352
@@ -355,7 +355,7 @@ def delete_style(self, system: str, style_format: str) -> int:
355
355
def delete_mapping (self , system_source : str , system_target : str ) -> int :
356
356
"""Delete the mapping."""
357
357
try :
358
- retval = Utils ._delete (f'{ self ._url } /mappings/{ system_source } /{ system_target } { self ._access_token } ' )
358
+ retval = Utils ._delete (f'{ self ._url } /mappings/{ system_source } /{ system_target } ' , access_token = self ._access_token )
359
359
except RuntimeError :
360
360
raise ValueError (f'Could not remove mapping of { system_source } and { system_target } !' )
361
361
0 commit comments