@matheustrres/brasilapi
Version:
Lightweight, easy-to-use & free of dependencies wrapper for BrasilAPI
61 lines • 2.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BrasilAPIIBGE = void 0;
const source_1 = require("./source");
const http_client_1 = require("../clients/http-client");
const paginator_1 = require("../utils/paginator");
/**
* Represents the source from BrasilAPI IBGE's endpoint responses
*/
class BrasilAPIIBGE extends source_1.Source {
URL = 'https://brasilapi.com.br/api/ibge';
/**
* Gets state information from the acronym or code
*
* @param {String | Number} code - The state acronym or code
* @returns {Promise<Result<State>>}
*/
async getState(code) {
const res = await (0, http_client_1.makeGET)(`${this.URL}/uf/v1/${code}`);
return this.followUp(res);
}
/**
* Lists the municipalities of the federative unit
*
* @param {String} siglaUF - The acronym of the federal unit (e.g. `SP`, `RJ`, `SC`)
* @param {Array<String>} [providers] - The list of providers (`dados-abertos-br`, `gov`, `wikipedia`)
* @param {ListParams} [params] - The listing parameters
* @param {Number} [params.itemsPerPage] - The limit of items per page
* @param {Number} [params.page] - The page number to start with
* @param {Number} [params.skip] - The amount of items to skip
* @param {Number} [params.take] - The amount of items to take
* @returns {Promise<Result<Paginator<State>>>}
*/
async listFederativeUnitMinicipalities(siglaUF, providers, params) {
const activeProviders = providers?.join(',') || '';
const res = await (0, http_client_1.makeGET)(`${this.URL}/municipios/v1/${siglaUF}?providers=${activeProviders}`);
return this.followUp(new paginator_1.Paginator({
items: res,
...params,
}));
}
/**
* Lists all brazilian states information
*
* @param {ListParams} [params] - The listing parameters
* @param {Number} [params.itemsPerPage] - The limit of items per page
* @param {Number} [params.page] - The page number to start with
* @param {Number} [params.skip] - The amount of items to skip
* @param {Number} [params.take] - The amount of items to take
* @returns {Promise<Result<Paginator<State>>>}
*/
async listStates(params) {
const res = await (0, http_client_1.makeGET)(`${this.URL}/uf/v1`);
return this.followUp(new paginator_1.Paginator({
items: res,
...params,
}));
}
}
exports.BrasilAPIIBGE = BrasilAPIIBGE;
//# sourceMappingURL=ibge.js.map