-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧(dashboard) add AnnuaireEntrepriseAPI client for enterprise data ret…
…rieval Introduced a new API client to communicate with the Annuaire Entreprise API. The client includes methods for fetching enterprise information using SIREN, with placeholder values for token and context.
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"""Dashboard core annuaire entreprise API.""" | ||
import requests | ||
|
||
|
||
class CompanyInformationWrapper: | ||
"""Company information wrapper.""" | ||
def __init__(self, company_info): | ||
"""Initialize the wrapper.""" | ||
self.company_info = company_info | ||
|
||
class CompanyAddressWrapper: | ||
def __init__(self, company_info): | ||
"""Initialize the wrapper.""" | ||
self.company_info = company_info | ||
|
||
class AnnuaireEntrepriseAPI: | ||
"""Annuaire entreprise API client.""" | ||
|
||
def __init__(self): | ||
"""Initialize the API client.""" | ||
# todo : add in settings | ||
self.api_url = "https://staging.entreprise.api.gouv.fr/v3/" | ||
self.token = "" | ||
# todo config context - recipient must be a SIREN | ||
self.context = "?context=test+API&object=test+API&recipient=10000001700010" | ||
|
||
def _make_request(self, endpoint, params=None): | ||
"""Make a request to the API.""" | ||
headers = {"Authorization": f"Bearer {self.token}"} | ||
url = f"{self.api_url}/{endpoint}" | ||
response = requests.get(url, headers=headers, params=params) | ||
return response.json() | ||
|
||
def get_entreprise_info(self, siren): | ||
"""Get the enterprise information from the API.""" | ||
endpoint = f"insee/sirene/unites_legales/{siren}{self.context}" | ||
return self._make_request(endpoint) | ||
|
||
def get_entreprise_address(self, siret): | ||
"""Get the enterprise information from the API.""" | ||
# todo config context - recipient must be a SIREN | ||
endpoint = f"insee/sirene/etablissements/{siret}/adresse{self.context}" | ||
return self._make_request(endpoint) | ||
|
||
|
||
# TEST ... | ||
# api = AnnuaireEntrepriseAPI() | ||
# _siren = "55204944776279" | ||
# _siret = "552049447" | ||
# | ||
# entreprise_info = api.get_entreprise_info(_siret) | ||
# | ||
# print(entreprise_info) | ||
# print(entreprise_info['data']["siren"]) #siren | ||
# print(entreprise_info['data']["siret_siege_social"]) #siret_siege_social | ||
# siret_siege = entreprise_info['data']["siret_siege_social"] | ||
# print(entreprise_info['data']['activite_principale']["code"]) #naf | ||
# print(entreprise_info['data']["personne_morale_attributs"]["raison_sociale"]) #name | ||
# print(entreprise_info['data']["forme_juridique"]["libelle"]) #legal_form | ||
# | ||
# | ||
# address = api.get_entreprise_address(siret_siege) | ||
# print(address) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters