gutocf / brasil-api-php-sdk
SDK for BrasilAPI
Installs: 1 645
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.4
- myclabs/php-enum: ^1.8
- spatie/data-transfer-object: ^3.9
Requires (Dev)
- phpstan/phpstan: ^1.6
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.6
- timeweb/phpstan-enum: ^3.0
This package is auto-updated.
Last update: 2024-10-08 19:31:00 UTC
README
PHP SDK for BrasilAPI.
Requirements
- PHP ^8.0
Note: this package requires php:^8.0. For php:7.4 check out version 1.0.
Note: this package requires php:^8.0. For php:7.4 check out version 1.0.
Installation
You can install the package via composer:
composer require gutocf/brasil-api-php-sdk
Usage
First you need to get an instance of the BrasilAPI class:
use Gutocf\BrasilAPI\BrasilAPI; $BrasilAPI = new BrasilAPI();
After that, you can use the service methods as follows. All services methods return an object or array of objects children of DataTransferObject
from the spatie/data-transfer-object library.
CEP (V1)
//Gets a bank by its code. $cep = $BrasilAPI->cepV1()->get('88045540');
CEP (V2)
//Gets a bank by its code. $cep = $BrasilAPI->cepV2()->get('88045540');
Banks
//Gets all banks. $banks = $BrasilAPI->banksV1()->getAll(); //Gets a bank by its code. $bank = $BrasilAPI->banksV1()->get(1);
Holidays
//Gets holidays by year $banks = $BrasilAPI->holidaysV1()->getByYear(2022);
CNPJ
//Gets information about a CNPJ $banks = $BrasilAPI->cnpjV1()->get('39729684000100');
DDD
//Gets information about a DDD $ddd = $BrasilAPI->dddV1()->get(48);
FIPE
Reference Tables
use Gutocf\BrasilAPI\Entity\V1\Fipe\Enum\VehicleType; //Gets all reference tables $referenceTables = $BrasilAPI->fipeV1()->getAllReferenceTables();
Vehicles
//Gets vehicle price information by FIPE code $vehicles = $BrasilAPI->fipeV1()->getAllVehicleByCode('003281-6'); //Gets vehicle price information by FIPE code for a specific table $vehicles = $BrasilAPI->fipeV1()->getAllVehicleByCode('003281-6', 123);
Brands
use Gutocf\BrasilAPI\Entity\V1\Fipe\Enum\VehicleType; //Gets all brands $brands = $BrasilAPI->fipeV1()->getAllBrandsByType(); //Gets all brands by vehicle type $brands = $BrasilAPI->fipeV1()->getAllBrandsByType(VehicleType::CARS()); //Gets all brands by vehicle type for a specific table $brands = $BrasilAPI->fipeV1()->getAllBrandsByType(VehicleType::CARS(), 123);
IBGE
Cities by State
$cities = $BrasilAPI->ibgeV1()->getCitiesByState('SC');
States
$states = $BrasilAPI->ibgeV1()->getAllStates();
State by initials or code
$state = $BrasilAPI->ibgeV1()->getState('sc'); //OR $state = $BrasilAPI->ibgeV1()->getState(42);
Error handling
HTTP errors communicating with the Brasil API will throw exceptions as follows: