nsarchive 3.0.0b1__py3-none-any.whl → 3.0.0b2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nsarchive/__init__.py +3 -1
- nsarchive/errors/__init__.py +1 -0
- nsarchive/errors/_globals.py +29 -0
- nsarchive/interfaces/_economy.py +0 -252
- nsarchive/interfaces/_entities.py +100 -14
- nsarchive/interfaces/_justice.py +173 -21
- nsarchive/interfaces/_state.py +177 -34
- nsarchive/mandate.py +21 -2
- nsarchive/models/base.py +108 -69
- nsarchive/models/economy.py +80 -151
- nsarchive/models/entities.py +305 -68
- nsarchive/models/justice.py +23 -2
- nsarchive/models/republic.py +44 -4
- nsarchive/models/state.py +43 -4
- nsarchive-3.0.0b2.dist-info/METADATA +90 -0
- nsarchive-3.0.0b2.dist-info/RECORD +21 -0
- nsarchive-3.0.0b1.dist-info/METADATA +0 -21
- nsarchive-3.0.0b1.dist-info/RECORD +0 -19
- {nsarchive-3.0.0b1.dist-info → nsarchive-3.0.0b2.dist-info}/LICENSE +0 -0
- {nsarchive-3.0.0b1.dist-info → nsarchive-3.0.0b2.dist-info}/WHEEL +0 -0
nsarchive/__init__.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
"""
|
2
2
|
nsarchive - API-wrapper pour récupérer des données liées à Nation.
|
3
3
|
|
4
|
-
Version: 3.0.0-beta.
|
4
|
+
Version: 3.0.0-beta.2
|
5
5
|
Date de sortie: 2025-08-06
|
6
6
|
License: GPL-3.0
|
7
7
|
Auteur : happex <110610727+okayhappex@users.noreply.github.com>
|
@@ -24,6 +24,8 @@ from .models.justice import *
|
|
24
24
|
|
25
25
|
from .models.scale import *
|
26
26
|
|
27
|
+
from . import errors
|
28
|
+
|
27
29
|
# Import des interfaces
|
28
30
|
from .models.base import Interface
|
29
31
|
from .interfaces._entities import EntityInterface
|
@@ -0,0 +1 @@
|
|
1
|
+
from . import _globals as globals
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class ServerDownError(Exception):
|
2
|
+
def __init__(self, *args):
|
3
|
+
super().__init__(*args)
|
4
|
+
|
5
|
+
# 4XX
|
6
|
+
|
7
|
+
class MissingParamError(Exception): # 400
|
8
|
+
def __init__(self, *args):
|
9
|
+
super().__init__(*args)
|
10
|
+
|
11
|
+
class InvalidParamError(Exception): # 400
|
12
|
+
def __init__(self, *args):
|
13
|
+
super().__init__(*args)
|
14
|
+
|
15
|
+
class AuthError(Exception): # 401
|
16
|
+
def __init__(self, *args):
|
17
|
+
super().__init__(*args)
|
18
|
+
|
19
|
+
class PermissionError(Exception): # 403
|
20
|
+
def __init__(self, *args):
|
21
|
+
super().__init__(*args)
|
22
|
+
|
23
|
+
class NotFoundError(Exception): # 404
|
24
|
+
def __init__(self, *args):
|
25
|
+
super().__init__(*args)
|
26
|
+
|
27
|
+
class ConflictError(Exception): # 409
|
28
|
+
def __init__(self, *args):
|
29
|
+
super().__init__(*args)
|
nsarchive/interfaces/_economy.py
CHANGED
@@ -108,256 +108,4 @@ class EconomyInterface(Interface):
|
|
108
108
|
|
109
109
|
res.append(account)
|
110
110
|
|
111
|
-
return res
|
112
|
-
|
113
|
-
"""
|
114
|
-
---- INVENTAIRES ----
|
115
|
-
"""
|
116
|
-
|
117
|
-
def get_inventory(self, id: NSID) -> Inventory:
|
118
|
-
"""
|
119
|
-
Récupère les informations d'un inventaire.
|
120
|
-
|
121
|
-
## Paramètres
|
122
|
-
id: `NSID`\n
|
123
|
-
ID de l'inventaire.
|
124
|
-
|
125
|
-
## Renvoie
|
126
|
-
- `.Inventory`
|
127
|
-
"""
|
128
|
-
|
129
|
-
id = NSID(id)
|
130
|
-
res = requests.get(f"{self.url}/bank/inventories/{id}", headers = self.default_headers)
|
131
|
-
|
132
|
-
if res.status_code == 200:
|
133
|
-
_data = res.json()
|
134
|
-
else:
|
135
|
-
res.raise_for_status()
|
136
|
-
return
|
137
|
-
|
138
|
-
if _data is None:
|
139
|
-
return None
|
140
|
-
|
141
|
-
inventory = Inventory(id)
|
142
|
-
inventory._load(_data, self.url, self.default_headers)
|
143
|
-
|
144
|
-
return inventory
|
145
|
-
|
146
|
-
def save_inventory(self, inventory: Inventory) -> str:
|
147
|
-
"""
|
148
|
-
Sauvegarde un inventaire dans la base de données.
|
149
|
-
|
150
|
-
## Paramètres
|
151
|
-
- inventory: `.Inventory`\n
|
152
|
-
Inventaire à sauvegarder
|
153
|
-
"""
|
154
|
-
|
155
|
-
_data = inventory.__dict__
|
156
|
-
|
157
|
-
res = requests.put(f"{self.url}/bank/register_inventory?owner={_data['owner_id']}", headers = self.default_headers, json = _data)
|
158
|
-
|
159
|
-
if res.status_code == 200:
|
160
|
-
inventory._url = f"{self.url}/bank/inventories/{inventory.id}"
|
161
|
-
inventory.id = res.json()['id']
|
162
|
-
|
163
|
-
return res.json()['digicode']
|
164
|
-
else:
|
165
|
-
res.raise_for_status()
|
166
|
-
|
167
|
-
def fetch_inventories(self, **query: typing.Any) -> list[Inventory]:
|
168
|
-
"""
|
169
|
-
Récupère une liste d'inventaires en fonction d'une requête.
|
170
|
-
|
171
|
-
## Paramètres
|
172
|
-
query: `**dict`\n
|
173
|
-
La requête pour filtrer les inventaires.
|
174
|
-
|
175
|
-
## Renvoie
|
176
|
-
- `list[.Inventory]`
|
177
|
-
"""
|
178
|
-
|
179
|
-
query = "&".join(f"{k}={ urllib.parse.quote(v) }" for k, v in query.items())
|
180
|
-
|
181
|
-
_res = requests.get(f"{self.url}/fetch/inventories?{query}", headers = self.default_headers)
|
182
|
-
|
183
|
-
if _res.status_code == 200:
|
184
|
-
_data = _res.json()
|
185
|
-
else:
|
186
|
-
_res.raise_for_status()
|
187
|
-
return []
|
188
|
-
|
189
|
-
res = []
|
190
|
-
|
191
|
-
for _inv in _data:
|
192
|
-
if not _inv: continue
|
193
|
-
|
194
|
-
inventory = Inventory(_inv["owner_id"])
|
195
|
-
|
196
|
-
inventory.id = NSID(_inv['id'])
|
197
|
-
inventory._load(_inv, self.url, self.default_headers)
|
198
|
-
|
199
|
-
res.append(inventory)
|
200
|
-
|
201
|
-
return res
|
202
|
-
|
203
|
-
"""
|
204
|
-
---- ITEMS ----
|
205
|
-
"""
|
206
|
-
|
207
|
-
def get_item(self, id: NSID) -> Item:
|
208
|
-
"""
|
209
|
-
Récupère les informations d'un item.
|
210
|
-
|
211
|
-
## Paramètres
|
212
|
-
id: `NSID`\n
|
213
|
-
ID de l'item.
|
214
|
-
|
215
|
-
## Renvoie
|
216
|
-
- `.Item`
|
217
|
-
"""
|
218
|
-
|
219
|
-
id = NSID(id)
|
220
|
-
res = requests.get(f"{self.url}/marketplace/items/{id}", headers = self.default_headers)
|
221
|
-
|
222
|
-
if res.status_code == 200:
|
223
|
-
_data = res.json()
|
224
|
-
else:
|
225
|
-
res.raise_for_status()
|
226
|
-
return
|
227
|
-
|
228
|
-
if _data is None:
|
229
|
-
return None
|
230
|
-
|
231
|
-
item = Item()
|
232
|
-
|
233
|
-
item.id = id
|
234
|
-
item._load(_data, self.url, self.default_headers)
|
235
|
-
|
236
|
-
return item
|
237
|
-
|
238
|
-
def save_item(self, item: Item) -> None:
|
239
|
-
"""
|
240
|
-
Sauvegarde un item dans le marketplace.
|
241
|
-
|
242
|
-
## Paramètres
|
243
|
-
- item: `.Item`\n
|
244
|
-
Item à sauvegarder
|
245
|
-
"""
|
246
|
-
|
247
|
-
_data = item.__dict__
|
248
|
-
|
249
|
-
res = requests.put(f"{self.url}/marketplace/register_item", headers = self.default_headers, json = _data)
|
250
|
-
|
251
|
-
if res.status_code == 200:
|
252
|
-
item._url = f"{self.url}/bank/inventories/{item.id}"
|
253
|
-
item.id = res.json()['id']
|
254
|
-
else:
|
255
|
-
res.raise_for_status()
|
256
|
-
|
257
|
-
def fetch_items(self, **query: typing.Any) -> list[Item]:
|
258
|
-
"""
|
259
|
-
Récupère une liste d'items en fonction d'une requête.
|
260
|
-
|
261
|
-
## Paramètres
|
262
|
-
query: `**dict`\n
|
263
|
-
La requête pour filtrer les items.
|
264
|
-
|
265
|
-
## Renvoie
|
266
|
-
- `list[.Item]`
|
267
|
-
"""
|
268
|
-
|
269
|
-
query = "&".join(f"{k}={ urllib.parse.quote(v) }" for k, v in query.items())
|
270
|
-
|
271
|
-
_res = requests.get(f"{self.url}/fetch/items?{query}", headers = self.default_headers)
|
272
|
-
|
273
|
-
if _res.status_code == 200:
|
274
|
-
_data = _res.json()
|
275
|
-
else:
|
276
|
-
_res.raise_for_status()
|
277
|
-
return []
|
278
|
-
|
279
|
-
res = []
|
280
|
-
|
281
|
-
for _item in _data:
|
282
|
-
if not _item: continue
|
283
|
-
|
284
|
-
item = Item()
|
285
|
-
|
286
|
-
item.id = NSID(_item['id'])
|
287
|
-
item._load(_item, self.url, self.default_headers)
|
288
|
-
|
289
|
-
res.append(item)
|
290
|
-
|
291
|
-
return res
|
292
|
-
|
293
|
-
|
294
|
-
"""
|
295
|
-
---- VENTES ----
|
296
|
-
"""
|
297
|
-
|
298
|
-
def get_sale(self, id: NSID) -> Sale:
|
299
|
-
"""
|
300
|
-
Récupère les informations d'une annonce.
|
301
|
-
|
302
|
-
## Paramètres
|
303
|
-
id: `NSID`\n
|
304
|
-
ID de la annonce.
|
305
|
-
|
306
|
-
## Renvoie
|
307
|
-
- `.Sale`
|
308
|
-
"""
|
309
|
-
|
310
|
-
id = NSID(id)
|
311
|
-
res = requests.get(f"{self.url}/marketplace/sales/{id}", headers = self.default_headers)
|
312
|
-
|
313
|
-
if res.status_code == 200:
|
314
|
-
_data = res.json()
|
315
|
-
else:
|
316
|
-
res.raise_for_status()
|
317
|
-
return
|
318
|
-
|
319
|
-
if _data is None:
|
320
|
-
return None
|
321
|
-
|
322
|
-
sale = Sale()
|
323
|
-
|
324
|
-
sale.id = id
|
325
|
-
sale._load(_data, self.url, self.default_headers)
|
326
|
-
|
327
|
-
return sale
|
328
|
-
|
329
|
-
def fetch_sales(self, **query: typing.Any) -> list[Sale]:
|
330
|
-
"""
|
331
|
-
Récupère une liste d'annonces en fonction d'une requête.
|
332
|
-
|
333
|
-
## Paramètres
|
334
|
-
query: `**dict`\n
|
335
|
-
La requête pour filtrer les annonces.
|
336
|
-
|
337
|
-
## Renvoie
|
338
|
-
- `list[.Sale]`
|
339
|
-
"""
|
340
|
-
|
341
|
-
query = "&".join(f"{k}={ urllib.parse.quote(v) }" for k, v in query.items())
|
342
|
-
|
343
|
-
_res = requests.get(f"{self.url}/fetch/sales?{query}", headers = self.default_headers)
|
344
|
-
|
345
|
-
if _res.status_code == 200:
|
346
|
-
_data = _res.json()
|
347
|
-
else:
|
348
|
-
_res.raise_for_status()
|
349
|
-
return []
|
350
|
-
|
351
|
-
res = []
|
352
|
-
|
353
|
-
for _sale in _data:
|
354
|
-
if not _sale: continue
|
355
|
-
|
356
|
-
sale = Sale()
|
357
|
-
|
358
|
-
sale.id = NSID(_sale['id'])
|
359
|
-
sale._load(_sale, self.url, self.default_headers)
|
360
|
-
|
361
|
-
res.append(sale)
|
362
|
-
|
363
111
|
return res
|
@@ -1,6 +1,8 @@
|
|
1
1
|
from ..models.base import *
|
2
2
|
from ..models.entities import *
|
3
3
|
|
4
|
+
from .. import errors
|
5
|
+
|
4
6
|
from ..models import entities # Pour les default_headers
|
5
7
|
|
6
8
|
class EntityInterface(Interface):
|
@@ -41,20 +43,35 @@ class EntityInterface(Interface):
|
|
41
43
|
id = NSID(id)
|
42
44
|
|
43
45
|
if _class == "user":
|
44
|
-
|
46
|
+
res = requests.get(f"{self.url}/model/individuals/{id}", headers = self.default_headers, json = {})
|
45
47
|
elif _class == "group":
|
46
|
-
|
48
|
+
res = requests.get(f"{self.url}/model/organisations/{id}", headers = self.default_headers, json = {})
|
47
49
|
else:
|
48
|
-
|
50
|
+
res = requests.get(f"{self.url}/model/entities/{id}", headers = self.default_headers, json = {})
|
51
|
+
|
52
|
+
|
53
|
+
# ERREURS
|
54
|
+
|
55
|
+
if res.status_code == 404:
|
56
|
+
return
|
57
|
+
|
58
|
+
if 500 <= res.status_code < 600:
|
59
|
+
res.raise_for_status()
|
60
|
+
|
61
|
+
if not 200 <= res.status_code < 300:
|
62
|
+
print(res.json()['message'])
|
63
|
+
return
|
64
|
+
|
49
65
|
|
50
|
-
|
51
|
-
|
66
|
+
# TRAITEMENT
|
67
|
+
|
68
|
+
_data = res.json()
|
52
69
|
|
53
70
|
if _data['_class'] == 'individuals':
|
54
71
|
entity = User(id)
|
55
72
|
elif _data['_class'] == 'organizations':
|
56
73
|
entity = Organization(id)
|
57
|
-
else:
|
74
|
+
else:
|
58
75
|
entity = Entity(id)
|
59
76
|
|
60
77
|
entity._load(_data, self.url, self.default_headers)
|
@@ -82,12 +99,37 @@ class EntityInterface(Interface):
|
|
82
99
|
else:
|
83
100
|
return
|
84
101
|
|
85
|
-
|
86
|
-
f"/new_model/{_class}?id={id}&name={name}&position={position}&zone={zone}",
|
102
|
+
res = requests.put(
|
103
|
+
f"{self.url}/new_model/{_class}?id={id}&name={name}&position={position}&zone={zone}",
|
87
104
|
headers = self.default_headers,
|
88
|
-
|
105
|
+
json = {}
|
89
106
|
)
|
90
107
|
|
108
|
+
|
109
|
+
# ERREURS
|
110
|
+
|
111
|
+
if 500 <= res.status_code < 600:
|
112
|
+
raise errors.globals.ServerDownError()
|
113
|
+
|
114
|
+
_data = res.json()
|
115
|
+
|
116
|
+
if res.status_code == 400:
|
117
|
+
if _data['message'] == "MissingParam":
|
118
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
119
|
+
elif _data['message'] == "InvalidParam":
|
120
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
121
|
+
elif _data['message'] == "InvalidToken":
|
122
|
+
raise errors.globals.AuthError("Token is not valid.")
|
123
|
+
|
124
|
+
elif res.status_code == 401:
|
125
|
+
raise errors.globals.AuthError(_data['message'])
|
126
|
+
|
127
|
+
elif res.status_code == 403:
|
128
|
+
raise errors.globals.PermissionError(_data['message'])
|
129
|
+
|
130
|
+
|
131
|
+
# TRAITEMENT
|
132
|
+
|
91
133
|
entity = self.get_entity(id)
|
92
134
|
|
93
135
|
if _class == "individuals":
|
@@ -112,8 +154,27 @@ class EntityInterface(Interface):
|
|
112
154
|
|
113
155
|
res = requests.post(f"{entity._url}/delete", headers = self.default_headers)
|
114
156
|
|
115
|
-
if res.status_code
|
116
|
-
|
157
|
+
if 200 <= res.status_code < 300:
|
158
|
+
return
|
159
|
+
|
160
|
+
if 500 <= res.status_code < 600:
|
161
|
+
raise errors.globals.ServerDownError()
|
162
|
+
|
163
|
+
_data = res.json()
|
164
|
+
|
165
|
+
if res.status_code == 400:
|
166
|
+
if _data['message'] == "MissingParam":
|
167
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
168
|
+
elif _data['message'] == "InvalidParam":
|
169
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
170
|
+
elif _data['message'] == "InvalidToken":
|
171
|
+
raise errors.globals.AuthError("Token is not valid.")
|
172
|
+
|
173
|
+
elif res.status_code == 401:
|
174
|
+
raise errors.globals.AuthError(_data['message'])
|
175
|
+
|
176
|
+
elif res.status_code == 403:
|
177
|
+
raise errors.globals.PermissionError(_data['message'])
|
117
178
|
|
118
179
|
def fetch_entities(self, **query: typing.Any) -> list[ Entity | User | Organization ]:
|
119
180
|
"""
|
@@ -172,10 +233,35 @@ class EntityInterface(Interface):
|
|
172
233
|
- `.Position`
|
173
234
|
"""
|
174
235
|
|
175
|
-
|
236
|
+
res = requests.get(f"{self.url}/model/positions/{id}", headers = self.default_headers)
|
237
|
+
|
238
|
+
|
239
|
+
# ERREURS
|
240
|
+
|
241
|
+
if 500 <= res.status_code < 600:
|
242
|
+
raise errors.globals.ServerDownError()
|
243
|
+
|
244
|
+
_data = res.json()
|
245
|
+
|
246
|
+
if res.status_code == 400:
|
247
|
+
if _data['message'] == "MissingParam":
|
248
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
249
|
+
elif _data['message'] == "InvalidParam":
|
250
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
251
|
+
elif _data['message'] == "InvalidToken":
|
252
|
+
raise errors.globals.AuthError("Token is not valid.")
|
253
|
+
|
254
|
+
elif res.status_code == 401:
|
255
|
+
raise errors.globals.AuthError(_data['message'])
|
256
|
+
|
257
|
+
elif res.status_code == 403:
|
258
|
+
raise errors.globals.PermissionError(_data['message'])
|
259
|
+
|
260
|
+
elif res.status_code == 404:
|
261
|
+
return
|
262
|
+
|
176
263
|
|
177
|
-
|
178
|
-
return None
|
264
|
+
# TRAITEMENT
|
179
265
|
|
180
266
|
position = Position(id)
|
181
267
|
position._load(_data, self.url, self.default_headers)
|