80 |
80 |
class APIEntreprise(BaseResource):
|
81 |
81 |
log_requests_errors = False
|
82 |
82 |
|
83 |
|
url = models.URLField(_('API URL'), max_length=256, default='https://entreprise.api.gouv.fr/v2/')
|
|
83 |
url = models.URLField(_('API URL'), max_length=256, default='https://entreprise.api.gouv.fr/')
|
84 |
84 |
token = models.CharField(max_length=1024, verbose_name=_('API token'))
|
85 |
85 |
recipient = models.CharField(
|
86 |
86 |
max_length=1024, verbose_name=_('Recipient'), blank=False, help_text=_('default value')
|
... | ... | |
194 |
194 |
)
|
195 |
195 |
def documents_associations(self, request, association_id, **kwargs):
|
196 |
196 |
data = []
|
197 |
|
resp = self.get('documents_associations/%s/' % association_id, **kwargs)
|
|
197 |
resp = self.get('v2/documents_associations/%s/' % association_id, **kwargs)
|
198 |
198 |
for item in resp['data'].get('documents', []):
|
199 |
199 |
# ignore documents with no type
|
200 |
200 |
if not item.get('type'):
|
... | ... | |
268 |
268 |
)
|
269 |
269 |
def get_last_document_of_type(self, request, association_id, document_type, **kwargs):
|
270 |
270 |
document = None
|
271 |
|
resp = self.get('documents_associations/%s/' % association_id, **kwargs)
|
|
271 |
resp = self.get('v2/documents_associations/%s/' % association_id, **kwargs)
|
272 |
272 |
documents = [item for item in resp['data'].get('documents', []) if item.get('type') == document_type]
|
273 |
273 |
if documents:
|
274 |
274 |
documents.sort(key=lambda doc: doc['timestamp'])
|
... | ... | |
288 |
288 |
},
|
289 |
289 |
)
|
290 |
290 |
def extraits_rcs(self, request, siren, **kwargs):
|
291 |
|
return self.get('extraits_rcs_infogreffe/%s/' % siren, **kwargs)
|
|
291 |
return self.get('v2/extraits_rcs_infogreffe/%s/' % siren, **kwargs)
|
292 |
292 |
|
293 |
293 |
@endpoint(
|
294 |
294 |
perm='can_access',
|
... | ... | |
303 |
303 |
},
|
304 |
304 |
)
|
305 |
305 |
def associations(self, request, association_id, **kwargs):
|
306 |
|
return self.get('associations/%s/' % association_id, **kwargs)
|
|
306 |
return self.get('v2/associations/%s/' % association_id, **kwargs)
|
307 |
307 |
|
308 |
308 |
@endpoint(
|
309 |
309 |
perm='can_access',
|
... | ... | |
323 |
323 |
raise APIError(_('invalid SIREN length (must be 9 characters)'))
|
324 |
324 |
if include_private:
|
325 |
325 |
kwargs['non_diffusables'] = True
|
326 |
|
return self.get('entreprises/%s/' % siren, **kwargs)
|
|
326 |
return self.get('v2/entreprises/%s/' % siren, **kwargs)
|
327 |
327 |
|
328 |
328 |
@endpoint(
|
329 |
329 |
perm='can_access',
|
... | ... | |
339 |
339 |
},
|
340 |
340 |
)
|
341 |
341 |
def etablissements(self, request, siret, **kwargs):
|
342 |
|
return self.get('etablissements/%s/' % siret, **kwargs)
|
|
342 |
return self.get('v2/etablissements/%s/' % siret, **kwargs)
|
343 |
343 |
|
344 |
344 |
@endpoint(
|
345 |
345 |
perm='can_access',
|
... | ... | |
355 |
355 |
},
|
356 |
356 |
)
|
357 |
357 |
def exercices(self, request, siret, **kwargs):
|
358 |
|
return self.get('exercices/%s/' % siret, **kwargs)
|
|
358 |
return self.get('v2/exercices/%s/' % siret, **kwargs)
|
359 |
359 |
|
360 |
360 |
@endpoint(
|
361 |
361 |
perm='can_access',
|
... | ... | |
372 |
372 |
def effectifs_annuels_acoss_covid(self, request, siren, **kwargs):
|
373 |
373 |
if len(siren) != 9:
|
374 |
374 |
raise APIError(_('invalid SIREN length (must be 9 characters)'))
|
375 |
|
return self.get('effectifs_annuels_acoss_covid/%s/' % siren, **kwargs)
|
|
375 |
return self.get('v2/effectifs_annuels_acoss_covid/%s/' % siren, **kwargs)
|
376 |
376 |
|
377 |
377 |
@endpoint(
|
378 |
378 |
perm='can_access',
|
... | ... | |
392 |
392 |
raise APIError(_('invalid SIREN length (must be 9 characters)'))
|
393 |
393 |
month = month.zfill(2)
|
394 |
394 |
return self.get(
|
395 |
|
'effectifs_mensuels_acoss_covid/%s/%s/entreprise/%s/' % (year, month, siren), **kwargs
|
|
395 |
'v2/effectifs_mensuels_acoss_covid/%s/%s/entreprise/%s/' % (year, month, siren), **kwargs
|
396 |
396 |
)
|
397 |
397 |
|
398 |
398 |
@endpoint(
|
... | ... | |
411 |
411 |
def etablissement_effectifs_mensuels_acoss_covid(self, request, year, month, siret, **kwargs):
|
412 |
412 |
month = month.zfill(2)
|
413 |
413 |
return self.get(
|
414 |
|
'effectifs_mensuels_acoss_covid/%s/%s/etablissement/%s/' % (year, month, siret), **kwargs
|
|
414 |
'v2/effectifs_mensuels_acoss_covid/%s/%s/etablissement/%s/' % (year, month, siret), **kwargs
|
415 |
415 |
)
|
416 |
416 |
|
417 |
417 |
@endpoint(
|
... | ... | |
435 |
435 |
self, request, siren, first_name, last_name, birthdate, method='simple', **kwargs
|
436 |
436 |
):
|
437 |
437 |
entreprise = self.get(
|
438 |
|
'entreprises/%s/' % siren,
|
|
438 |
'v2/entreprises/%s/' % siren,
|
439 |
439 |
**kwargs,
|
440 |
440 |
)
|
441 |
441 |
methods = {
|
442 |
|
-
|