Created
July 2, 2018 09:01
-
-
Save tchak/245c717500d1ba8eae4338368d599920 to your computer and use it in GitHub Desktop.
demarches-simplifiees.fr exemple api
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
<?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