nibblelab/ibgeapiclient-php
Composer 安装命令:
composer require nibblelab/ibgeapiclient-php
包简介
client for IBGE's REST API
README 文档
README
A especificação da API pode ser encontrada em https://servicodados.ibge.gov.br/api/docs/localidades?versao=1
Sumário
Pré requisitos
- PHP >= 7.1.0
- libcurl
- composer
Instalação
Instale pelo composer
$ composer require nibblelab/ibgeapiclient-php
Inicialização
Inclua o composer e o namespace.
include './vendor/autoload.php';
use \IBGEApiClient\IBGEApiClient;
Regiões
Todas as regiões
try
{
$api = new IBGEApiClient();
$response = $api->buscarRegioes();
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Região por ID
try
{
$api = new IBGEApiClient();
$response = $api->buscarRegiaoById('1');
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Regiões por IDs
try
{
$api = new IBGEApiClient();
$response = $api->buscarRegioesByIds(array('1','3'));
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
UFs
Todas as UF's
try
{
$api = new IBGEApiClient();
$response = $api->buscarUFs();
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
UF por ID
try
{
$api = new IBGEApiClient();
$response = $api->buscarUFById('31');
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
UFs por IDs
try
{
$api = new IBGEApiClient();
$response = $api->buscarUFsByIds(array('31','32'));
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
UF por região
try
{
$api = new IBGEApiClient();
$response = $api->buscarUFsByRegiao('3');
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
UF por regiões
try
{
$api = new IBGEApiClient();
$response = $api->buscarUFsByRegioes(array('2','3'));
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Mesorregiões
Todas as Mesorregiões
try
{
$api = new IBGEApiClient();
$response = $api->buscarMesoRegioes();
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Mesorregião por ID
try
{
$api = new IBGEApiClient();
$response = $api->buscarMesoRegiaoById('1101');
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Mesorregiões por IDs
try
{
$api = new IBGEApiClient();
$response = $api->buscarMesoRegioesByIds(array('1101','1102'));
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Mesorregiões por Região
try
{
$api = new IBGEApiClient();
$response = $api->buscarMesoRegioesByRegiao('1');
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Mesorregiões por Regiões
try
{
$api = new IBGEApiClient();
$response = $api->buscarMesoRegioesByRegioes(array('1','2'));
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Mesorregiões por UF
try
{
$api = new IBGEApiClient();
$response = $api->buscarMesoRegioesByUF('31');
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Mesorregiões por UFs
try
{
$api = new IBGEApiClient();
$response = $api->buscarMesoRegioesByUFs(array('31','27'));
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Microrregiões
Todas as Microrregiões
try
{
$api = new IBGEApiClient();
$response = $api->buscarMicroRegioes();
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Microrregião por ID
try
{
$api = new IBGEApiClient();
$response = $api->buscarMicroRegiaoById('11001');
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Microrregiões por IDs
try
{
$api = new IBGEApiClient();
$response = $api->buscarMicroRegioesByIds(array('11001','11002'));
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Microrregiões por Região
try
{
$api = new IBGEApiClient();
$response = $api->buscarMicroRegioesByRegiao('1');
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Microrregiões por Regiões
try
{
$api = new IBGEApiClient();
$response = $api->buscarMicroRegioesByRegioes(array('1','2'));
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Microrregiões por UF
try
{
$api = new IBGEApiClient();
$response = $api->buscarMicroRegioesByUF('31');
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Microrregiões por UFs
try
{
$api = new IBGEApiClient();
$response = $api->buscarMicroRegioesByUFs(array('31','27'));
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Microrregiões por Mesorregião
try
{
$api = new IBGEApiClient();
$response = $api->buscarMicroRegioesByMesoRegiao('1102');
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Microrregiões por Mesorregiões
try
{
$api = new IBGEApiClient();
$response = $api->buscarMicroRegioesByMesoRegioes(array('1101','1102'));
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Municípios
Todos os Municípios
try
{
$api = new IBGEApiClient();
$response = $api->buscarMunicipios();
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Município por ID
try
{
$api = new IBGEApiClient();
$response = $api->buscarMunicipioById('3170206');
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Municípios por IDs
try
{
$api = new IBGEApiClient();
$response = $api->buscarMunicipiosByIds(array('3170206','5108352'));
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Municípios por Região
try
{
$api = new IBGEApiClient();
$response = $api->buscarMunicipiosByRegiao('1');
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Municípios por Regiões
try
{
$api = new IBGEApiClient();
$response = $api->buscarMunicipiosByRegioes(array('1','2'));
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Municípios por UF
try
{
$api = new IBGEApiClient();
$response = $api->buscarMunicipiosByUF('31');
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Municípios por UFs
try
{
$api = new IBGEApiClient();
$response = $api->buscarMunicipiosByUFs(array('31','27'));
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Municípios por Mesorregião
try
{
$api = new IBGEApiClient();
$response = $api->buscarMunicipiosByMesoRegiao('1102');
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Municípios por Mesorregiões
try
{
$api = new IBGEApiClient();
$response = $api->buscarMunicipiosByMesoRegioes(array('1101','1102'));
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Municípios por Microrregião
try
{
$api = new IBGEApiClient();
$response = $api->buscarMunicipiosByMicroRegiao('11001');
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
Municípios por Microrregiões
try
{
$api = new IBGEApiClient();
$response = $api->buscarMunicipiosByMicroRegioes(array('11001','11002'));
foreach($response->getData() as $r) {
echo ' nome = ' . $r->getNome() . "\n"; # printe o nome
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
License
Este projeto está licenciado com Apache - veja LICENSE.md pra mais detalhes
nibblelab/ibgeapiclient-php 适用场景与选型建议
nibblelab/ibgeapiclient-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 52 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 09 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nibblelab/ibgeapiclient-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nibblelab/ibgeapiclient-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 52
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2019-09-05