Skip to content

Instantly share code, notes, and snippets.

@tchak
Created July 2, 2018 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tchak/245c717500d1ba8eae4338368d599920 to your computer and use it in GitHub Desktop.
Save tchak/245c717500d1ba8eae4338368d599920 to your computer and use it in GitHub Desktop.
demarches-simplifiees.fr exemple api
<?php
class DemarchesSimplifiees {
function __construct($token) {
$this->token = $token;
}
function procedure($procedure_id) {
return $this->request("procedures/$procedure_id");
}
function dossiers($procedure_id, $options = []) {
$options = array_intersect_key($options, array_flip(['page', 'resultats_par_page']));
return $this->request("procedures/$procedure_id/dossiers?" . http_build_query($options));
}
function dossier($procedure_id, $dossier_id) {
return $this->request("procedures/$procedure_id/dossiers/$dossier_id");
}
private function request($path) {
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.demarches-simplifiees.fr/api/v1/$path",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer {$this->token}"]
]);
return json_decode(curl_exec($curl), true);
}
}
$api = new DemarchesSimplifiees('92d2bc79beed12cae17c4fbee5bb91de611b872a');
var_dump($api->procedure(3329));
var_dump($api->dossiers(3329));
var_dump($api->dossiers(3329, ['page' => 2]));
var_dump($api->dossier(3329, 43811));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment