diff --git a/README.md b/README.md
index 713778a..887a4d5 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
-# SDK PHP - APIGratis by API BRASIL 🚀
-Conjunto de API, para desenvolvedores.
+# SDK PHP by API BRASIL 🚀
+### Conjunto de API, para desenvolvedores
_Transforme seus projetos em soluções inteligentes com nossa API. Com recursos como API do WhatsApp, geolocalização, rastreamento de encomendas, verificação de CPF/CNPJ e mais, você pode criar soluções eficientes e funcionais. Comece agora._
@@ -30,16 +30,180 @@ https://packagist.org/packages/jhowbhz/apigratis-sdk-php
| Up | Services available | Description | Free | Beta | Stable |
------|-------------------------------|-------------------|---------| ------------------------- | ------------------------- |
-| ✅ | WhatsAppService | API do WhatsApp Gratuita. | ✅ | ✅ | ✅ |
-| ✅ | Receita Data CNPJ | API Dados CNPJ Receita. | ✅ | ✅ | ✅ |
-| ✅ | Receita Data CPF | API Dados de CPF Serasa. | ⌛ | ⌛ | ⌛ |
-| ✅ | CorreiosService | API Busca encomendas Correios Brazil. | ✅ | ✅ | ✅ |
-| ✅ | CEPLocation | API CEP Geolocation + IBGE Brazil. | ✅ | ✅ | ✅ |
-| ✅ | VehiclesService | API Placa Dados. | ✅ | ✅ | ✅ |
-| ✅ | FipeService | API Placa FIPE. | ✅ | ✅ | ✅ |
+| ✅ | AuthService | API Login e Logout | ✅ | ✅ | ✅ |
+| ✅ | ProfileService | API Dados do Usuario | ✅ | ✅ | ✅ |
+| ✅ | ServerService | API Lista Servidores | ✅ | ✅ | ✅ |
+| ✅ | DeviceService | API Criar, Editar Dispositivos | ✅ | ✅ | ✅ |
+| ✅ | WhatsAppService | API WhatsApp | ✅ | ✅ | ✅ |
+| ✅ | Receita Data CNPJ | API Dados CNPJ Receita | ✅ | ✅ | ✅ |
+| ✅ | Receita Data CPF | API Dados de CPF Serasa | ✅ | ✅ | ✅ |
+| ✅ | CorreiosService | API Busca encomendas Correios Brazil | ✅ | ✅ | ✅ |
+| ✅ | CEPLocation | API CEP Geolocation + IBGE Brazil | ✅ | ✅ | ✅ |
+| ✅ | VehiclesService | API Placa Dados | ✅ | ✅ | ✅ |
+| ✅ | FipeService | API Placa FIPE | ✅ | ✅ | ✅ |
+
+## AuthService
+Com essa API você poderá obter o Bearer Token
+
+### Para fazer login válido por 1 ano
+```php
+ [
+ "email" => "jhondoe@gmail.com",
+ "password" => "123456"
+ ]
+]);
+
+var_dump($login);
+die;
+```
+
+### Com essa API você poderá fazer logout, invalidando o Bearer Token
+
+```php
+ "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.....",
+]);
+
+var_dump($logout);
+die;
+```
+
+## DeviceService
+Com essa API é possÃvel criar, editar e deletar dispositivos
+
+### Para criar um dispositivo
+```php
+ "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.....",
+ "SecretKey" => "f87eb607-a8cc-43ea-b439.....",
+ "body" => [
+ "type" => "cellphone",
+ "device_name" => "zap1",
+ "device_key" => "zapzap1",
+ "device_ip" => "198.29.10.50",
+ "server_search" => "341d6f36-b888....",
+ "webhook_wh_message" => "",
+ "webhook_wh_status" => ""
+ ]
+]);
+
+var_dump($store);
+die;
+```
+
+### Para atualizar um dispositivo
+
+```php
+require_once('vendor/autoload.php');
+use ApiBrasil\Service;
+
+$update = Service::Device("search", [
+ "Bearer" => "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.....",
+ "body" => [
+ "type" => "cellphone",
+ "search" => "82faab0a-24f4-4b8b-9926-455ea9b3cdb7",
+ "server_search" => "a2c85262-f830-4b90-a8da-ff67b7a7ed6e",
+ "device_name" => "zap2",
+ "device_key" => "zapzap1",
+ "device_ip" => "198.29.10.50",
+ "webhook_wh_message" => "",
+ "webhook_wh_status":""
+ ]
+]);
+
+var_dump($update);
+die;
+```
+
+### Para exibir um dispositivo
+```php
+
+require_once('vendor/autoload.php');
+use ApiBrasil\Service;
+
+$show = Service::Device("show", [
+ "Bearer" => "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.....",
+ "body" => [
+ "search" => "82faab0a-24f4-4b8b-9926-455ea9b3cdb7",
+ ]
+]);
+
+var_dump($show);
+die;
+```
+
+## ServerService
+Com essa API é possÃvel listar todos os servidores ativos
+
+```php
+ "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.....",
+ "method" => "GET",
+]);
+
+var_dump($servers);
+die;
+```
+
+## ProfileService
+Com essa API é possÃvel listar detalhes do seu perfil
+
+```php
+ "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.....",
+ "method" => "GET",
+]);
+
+var_dump($profile);
+die;
+```
+
+## PlanService
+Com essa API é possÃvel listar detalhes do seu plano
+
+```php
+ "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.....",
+ "method" => "GET",
+]);
+
+var_dump($plan);
+die;
+```
## WhatsAppService
-- Como enviar mensagens de texto
+Com essa API é possÃvel enviar mensagens de texto e outros
```php
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.....",
"DeviceToken" => "d019580b-3c8c-40e3-b9a0....",
"body" => [
@@ -56,11 +220,12 @@ $response = Service::WhatsApp("sendText", [
]
]);
-var_dump($response);
+var_dump($sendText);
die;
```
+
## VehiclesService
-- Obtenha dados da placa de um veÃculo
+Com essa API você obtem dados de caracteristicas de um veÃculo pela placa
```php
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.....",
"DeviceToken" => "d019580b-3c8c-40e3-b9a0....",
"body" => [
@@ -191,6 +359,8 @@ $cnpj = Service::CEP("cep", [
]
]);
-var_dump($cnpj);
+var_dump($cep);
die;
```
+## Observação
+Você poderá obter mais endpoints na documentação de cada api, ou no link https://doc.apibrasil.io
\ No newline at end of file
diff --git a/src/Base.php b/src/Base.php
index d087439..ed080c5 100644
--- a/src/Base.php
+++ b/src/Base.php
@@ -22,6 +22,9 @@ public static function defaultRequest(String $method, String $base_uri, String $
$headers['Content-Type'] = 'application/json'; // set content type json
$headers['Accept'] = 'application/json'; // set accept json
+ //headers
+ $headers['Agent'] = 'ApiBrasil/2.0.0 (https://www.apibrasil.io)'; // set user agent
+
$request = new Request($method, $action, $headers, json_encode($body)); // create request
$response = $client->send($request); // send request
diff --git a/src/Service.php b/src/Service.php
index bc488ee..d68e978 100644
--- a/src/Service.php
+++ b/src/Service.php
@@ -6,20 +6,137 @@
class Service extends Base
{
+
+ public static function Server(String $action = '', Array $data = []) {
+
+ try {
+
+ $base_uri = "https://gateway.apibrasil.io/api/v2/servers/";
+ $method = $data['method'] ?? 'POST';
+
+ $headers = [
+ "Content-Type" => "application/json",
+ "Accept" => "application/json",
+ "Authorization" => "Bearer ".$data['Bearer'],
+ ];
+
+ $body = $data['body'] ?? [];
+
+ $response = self::defaultRequest($method, $base_uri, $action, $headers, $body);
+ return $response;
+
+ } catch (ClientException $e) {
+
+ $response = $e->getResponse();
+ return json_decode((string)($response->getBody()->getContents()));
+
+ }
+
+ }
+
+ public static function Auth(String $action = '', Array $data = []) {
+
+ try {
+
+ $base_uri = "https://gateway.apibrasil.io/api/v2/";
+ $method = $data['method'] ?? 'POST';
+
+ $headers = [
+ "Content-Type" => "application/json",
+ "Accept" => "application/json",
+ ];
+
+ $body = $data['body'] ?? [];
+
+ $response = self::defaultRequest($method, $base_uri, $action, $headers, $body);
+ return $response;
+
+ } catch (ClientException $e) {
+
+ $response = $e->getResponse();
+ return json_decode((string)($response->getBody()->getContents()));
+
+ }
+
+ }
+
+ public static function Profile(String $action = '', Array $data = []) {
+
+ try {
+
+ $base_uri = "https://gateway.apibrasil.io/api/v2/profile/";
+ $method = $data['method'] ?? 'POST';
+
+ $headers = [
+ "Content-Type" => "application/json",
+ "Accept" => "application/json",
+ "Authorization" => "Bearer ".$data['Bearer'],
+ ];
+
+ $body = $data['body'] ?? [];
+
+ $response = self::defaultRequest($method, $base_uri, $action, $headers, $body);
+ return $response;
+
+ } catch (ClientException $e) {
+
+ $response = $e->getResponse();
+ return json_decode((string)($response->getBody()->getContents()));
+
+ }
+
+ }
+
+ public static function Device(String $action = '', Array $data = []) {
+
+ try {
+
+ $base_uri = "https://gateway.apibrasil.io/api/v2/devices/";
+ $method = $data['method'] ?? 'POST';
+
+ $headers = [
+ "Content-Type" => "application/json",
+ "Accept" => "application/json",
+ "Authorization" => "Bearer ".$data['Bearer'],
+ ];
+
+ // para criar um dispositivo é necessário informar o SecretKey
+ if (isset($data['SecretKey'])) {
+ $headers['SecretKey'] = $data['SecretKey'];
+ }
+
+ $body = $data['body'] ?? [];
+
+ $response = self::defaultRequest($method, $base_uri, $action, $headers, $body);
+ return $response;
+
+ } catch (ClientException $e) {
+
+ $response = $e->getResponse();
+ return json_decode((string)($response->getBody()->getContents()));
+
+ }
+
+ }
+
public static function WhatsApp(String $action = '', Array $data = []) {
try {
- $base_uri = "https://cluster.apigratis.com/api/v2/whatsapp/";
+ $base_uri = "https://gateway.apibrasil.io/api/v2/whatsapp/";
$method = $data['method'] ?? 'POST';
$headers = [
"Content-Type" => "application/json",
"Accept" => "application/json",
"Authorization" => "Bearer ".$data['Bearer'],
- "DeviceToken" => $data['DeviceToken'] ?? '',
];
+ // para usar a classe é necessário informar o DeviceToken
+ if (isset($data['DeviceToken'])) {
+ $headers['DeviceToken'] = $data['DeviceToken'];
+ }
+
$body = $data['body'] ?? [];
$response = self::defaultRequest($method, $base_uri, $action, $headers, $body);
@@ -33,20 +150,24 @@ public static function WhatsApp(String $action = '', Array $data = []) {
}
}
+
public static function Vehicles(String $action = '', Array $data = []) {
try {
- $base_uri = "https://cluster.apigratis.com/api/v2/vehicles/".$action;
+ $base_uri = "https://gateway.apibrasil.io/api/v2/vehicles/".$action;
$method = $data['method'] ?? 'POST';
$headers = [
"Content-Type" => "application/json",
"Accept" => "application/json",
"Authorization" => "Bearer ".$data['Bearer'],
- "DeviceToken" => $data['DeviceToken'] ?? '',
];
+ if (isset($data['DeviceToken'])) {
+ $headers['DeviceToken'] = $data['DeviceToken'];
+ }
+
$body = $data['body'] ?? [];
$response = self::defaultRequest($method, $base_uri, $action, $headers, $body);
@@ -60,20 +181,24 @@ public static function Vehicles(String $action = '', Array $data = []) {
}
}
+
public static function Correios(String $action = '', Array $data = []) {
try {
- $base_uri = "https://cluster.apigratis.com/api/v2/correios/".$action;
+ $base_uri = "https://gateway.apibrasil.io/api/v2/correios/".$action;
$method = $data['method'] ?? 'POST';
$headers = [
"Content-Type" => "application/json",
"Accept" => "application/json",
"Authorization" => "Bearer ".$data['Bearer'],
- "DeviceToken" => $data['DeviceToken'] ?? '',
];
+ if (isset($data['DeviceToken'])) {
+ $headers['DeviceToken'] = $data['DeviceToken'];
+ }
+
$body = $data['body'] ?? [];
$response = self::defaultRequest($method, $base_uri, $action, $headers, $body);
@@ -87,20 +212,24 @@ public static function Correios(String $action = '', Array $data = []) {
}
}
+
public static function CNPJ(String $action = '', Array $data = []) {
try {
- $base_uri = "https://cluster.apigratis.com/api/v2/dados/".$action;
+ $base_uri = "https://gateway.apibrasil.io/api/v2/dados/".$action;
$method = $data['method'] ?? 'POST';
$headers = [
"Content-Type" => "application/json",
"Accept" => "application/json",
"Authorization" => "Bearer ".$data['Bearer'],
- "DeviceToken" => $data['DeviceToken'] ?? '',
];
+ if (isset($data['DeviceToken'])) {
+ $headers['DeviceToken'] = $data['DeviceToken'];
+ }
+
$body = $data['body'] ?? [];
$response = self::defaultRequest($method, $base_uri, $action, $headers, $body);
@@ -119,15 +248,18 @@ public static function CEP(String $action = '', Array $data = []) {
try {
- $base_uri = "https://cluster.apigratis.com/api/v2/cep/".$action;
+ $base_uri = "https://gateway.apibrasil.io/api/v2/cep/".$action;
$method = $data['method'] ?? 'POST';
$headers = [
"Content-Type" => "application/json",
"Accept" => "application/json",
"Authorization" => "Bearer ".$data['Bearer'],
- "DeviceToken" => $data['DeviceToken'] ?? '',
];
+
+ if (isset($data['DeviceToken'])) {
+ $headers['DeviceToken'] = $data['DeviceToken'];
+ }
$body = $data['body'] ?? [];