blob: 1861d88bbfc84ef95d8f3c070ac5e27b32f884e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#ifndef CEPIS_CEPIS_HPP
#define CEPIS_CEPIS_HPP
/// C++ client for the public CEP API at https://cep.is — official Correios
/// data (DNE), refreshed every two weeks.
///
/// Quick use — for a script, the free functions are enough:
///
/// ```cpp
/// #include <cepis/cepis.hpp>
///
/// const cepis::Address a = cepis::lookup("01001-000");
/// std::cout << a.localidade << ' ' << a.uf << '\n'; // São Paulo SP
/// ```
///
/// In an application, build a `cepis::Client` once and reuse it:
///
/// ```cpp
/// cepis::Config config;
/// config.base_url = "http://localhost:8080";
/// config.timeout = std::chrono::seconds{5};
/// const cepis::Client client(config);
/// const cepis::Address a = client.lookup("01001000");
/// ```
///
/// Errors are explicit and split by decision — whether retrying helps or not:
///
/// ```cpp
/// try {
/// const cepis::Address a = cepis::lookup(cep_from_form);
/// } catch (const cepis::CepNotFound& error) {
/// // the CEP does not exist: ask the user for another. `error.faixa()`
/// // often names the municipality it would have belonged to — context for
/// // the message, never an address.
/// } catch (const cepis::Error&) {
/// // network, server, rate limit: retry later
/// }
/// ```
///
/// Note on field names: the API surface is English, but the **data fields keep
/// the API's own Portuguese names** (`logradouro`, `bairro`, `localidade`).
/// What you read in the JSON is what you access on the object.
#include "cepis/client.hpp"
#include "cepis/errors.hpp"
#include "cepis/json.hpp"
#include "cepis/models.hpp"
#endif // CEPIS_CEPIS_HPP
|