Skip to content

Commit 135e361

Browse files
add instance status and restart
1 parent 18524b5 commit 135e361

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,33 @@ php artisan vendor:publish --tag=Z-API
2121
Z_API_HOST='https://api.z-api.io'
2222
```
2323

24+
## Recursos
25+
- Obter situação da instância `/status`
26+
27+
get
28+
```php
29+
use Accordous\ZAPIClient\Services\ZAPIService;
30+
31+
$service = new ZAPIService($instanciaId, $instanciaToken);
32+
33+
$response = $service->instance()->situacao();
34+
35+
$result = $response->json();
36+
```
37+
38+
- Reiniciar instância `/restart`
39+
40+
get
41+
```php
42+
use Accordous\ZAPIClient\Services\ZAPIService;
43+
44+
$service = new ZAPIService($instanciaId, $instanciaToken);
45+
46+
$response = $service->instance()->reiniciar();
47+
48+
$result = $response->json();
49+
```
50+
2451
## Recursos
2552
- Enviar texto simples `/send-text`
2653

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Accordous\ZAPIClient\Services\Endpoints;
4+
5+
class InstanceEndpoint extends Endpoint
6+
{
7+
private const STATUS = '/status';
8+
private const RESTART = '/restart';
9+
10+
/**
11+
* @return \GuzzleHttp\Promise\PromiseInterface|\Illuminate\Http\Client\Response
12+
*/
13+
public function situacao()
14+
{
15+
return $this->client()->get(self::STATUS);
16+
}
17+
18+
/**
19+
* @return \GuzzleHttp\Promise\PromiseInterface|\Illuminate\Http\Client\Response
20+
*/
21+
public function reiniciar()
22+
{
23+
return $this->client()->get(self::RESTART);
24+
}
25+
26+
protected function rules(): array
27+
{
28+
return [];
29+
}
30+
31+
protected function messages(): array
32+
{
33+
return [];
34+
}
35+
36+
protected function attributes(): array
37+
{
38+
return [];
39+
}
40+
}

src/Services/ZAPIService.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Accordous\ZAPIClient\Services;
44

5+
use Accordous\ZAPIClient\Services\Endpoints\InstanceEndpoint;
56
use Accordous\ZAPIClient\Services\Endpoints\MessagesEndpoint;
67
use Illuminate\Support\Facades\Config;
78
use Illuminate\Support\Facades\Http;
@@ -13,6 +14,11 @@ class ZAPIService
1314
*/
1415
private $http;
1516

17+
/**
18+
* @var InstanceEndpoint
19+
*/
20+
private $instance;
21+
1622
/**
1723
* @var MessagesEndpoint
1824
*/
@@ -32,9 +38,18 @@ public function __construct($instanceId = null, $instanceToken = null)
3238
'Cache-Control' => 'no-cache',
3339
]);
3440

41+
$this->instance = new InstanceEndpoint($this->http);
3542
$this->messages = new MessagesEndpoint($this->http);
3643
}
3744

45+
/**
46+
* @return InstanceEndpoint
47+
*/
48+
public function instance(): InstanceEndpoint
49+
{
50+
return $this->instance;
51+
}
52+
3853
/**
3954
* @return MessagesEndpoint
4055
*/

0 commit comments

Comments
 (0)