Total Complexity | 3 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class CepLa |
||
8 | { |
||
9 | private $endPoint = "http://cep.la"; |
||
10 | |||
11 | public function getAddressFromZipcode($zipCode) |
||
12 | { |
||
13 | $zipCode = preg_replace('/[^0-9]/im', '', $zipCode); |
||
14 | |||
15 | $headers = [ |
||
16 | "Accept" => "application/json", |
||
17 | ]; |
||
18 | |||
19 | $client = new Client(['base_uri' => "{$this->endPoint}/{$zipCode}"]); |
||
20 | |||
21 | $response = $client->get( |
||
22 | '', |
||
23 | [ |
||
24 | 'headers' => $headers, |
||
25 | 'connect_timeout' => 5, // seconds |
||
26 | 'debug' => false, |
||
27 | ] |
||
28 | ); |
||
29 | |||
30 | $response = $response->getBody()->getContents(); |
||
31 | $response = json_decode($response); |
||
32 | |||
33 | return $this->normalizeResponse((array)$response); |
||
34 | } |
||
35 | |||
36 | private function normalizeResponse($address) |
||
55 | ]; |
||
56 | } |
||
59 |