Skip to content

Commit 04166fa

Browse files
committed
Added Debug, Metrics and Health endpoints
1 parent b212dd6 commit 04166fa

15 files changed

Lines changed: 195 additions & 10 deletions

examples/info_operations.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/** @noinspection ForgottenDebugOutputInspection */
4+
5+
include '../vendor/autoload.php';
6+
7+
use Typesense\Client;
8+
9+
try {
10+
$client = new Client(
11+
[
12+
'api_key' => 'xyz',
13+
'nodes' => [
14+
[
15+
'host' => 'localhost',
16+
'port' => '8108',
17+
'protocol' => 'http',
18+
],
19+
],
20+
'connection_timeout_seconds' => 2,
21+
]
22+
);
23+
echo '<pre>';
24+
25+
print_r($client->debug->retrieve());
26+
print_r($client->metrics->retrieve());
27+
print_r($client->health->retrieve());
28+
} catch (Exception $e) {
29+
echo $e->getMessage();
30+
}

src/Alias.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use GuzzleHttp\Exception\GuzzleException;
66
use Typesense\Exceptions\TypesenseClientError;
7-
use Typesense\Lib\Configuration;
87

98
/**
109
* Class Alias

src/Aliases.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use GuzzleHttp\Exception\GuzzleException;
66
use Typesense\Exceptions\TypesenseClientError;
7-
use Typesense\Lib\Configuration;
87

98
/**
109
* Class Aliases

src/Client.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ class Client
3535
*/
3636
public Keys $keys;
3737

38+
/**
39+
* @var Debug
40+
*/
41+
public Debug $debug;
42+
43+
/**
44+
* @var Metrics
45+
*/
46+
public Metrics $metrics;
47+
48+
/**
49+
* @var Health
50+
*/
51+
public Health $health;
52+
3853
/**
3954
* @var ApiCall
4055
*/
@@ -55,6 +70,9 @@ public function __construct(array $config)
5570
$this->collections = new Collections($this->apiCall);
5671
$this->aliases = new Aliases($this->apiCall);
5772
$this->keys = new Keys($this->apiCall);
73+
$this->debug = new Debug($this->apiCall);
74+
$this->metrics = new Metrics($this->apiCall);
75+
$this->health = new Health($this->apiCall);
5876
}
5977

6078
/**
@@ -80,4 +98,28 @@ public function getKeys(): Keys
8098
{
8199
return $this->keys;
82100
}
101+
102+
/**
103+
* @return Debug
104+
*/
105+
public function getDebug(): Debug
106+
{
107+
return $this->debug;
108+
}
109+
110+
/**
111+
* @return Metrics
112+
*/
113+
public function getMetrics(): Metrics
114+
{
115+
return $this->metrics;
116+
}
117+
118+
/**
119+
* @return Health
120+
*/
121+
public function getHealth(): Health
122+
{
123+
return $this->health;
124+
}
83125
}

src/Collection.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use GuzzleHttp\Exception\GuzzleException;
66
use Typesense\Exceptions\TypesenseClientError;
7-
use Typesense\Lib\Configuration;
87

98
/**
109
* Class Collection

src/Collections.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use GuzzleHttp\Exception\GuzzleException;
66
use Typesense\Exceptions\TypesenseClientError;
7-
use Typesense\Lib\Configuration;
87

98
/**
109
* Class Collections

src/Debug.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Typesense;
4+
5+
use GuzzleHttp\Exception\GuzzleException;
6+
use Typesense\Exceptions\TypesenseClientError;
7+
8+
/**
9+
* Class Debug
10+
*
11+
* @package \Typesense
12+
* @date 10/12/20
13+
*/
14+
class Debug
15+
{
16+
public const RESOURCE_PATH = '/debug';
17+
18+
/**
19+
* @var ApiCall
20+
*/
21+
private ApiCall $apiCall;
22+
23+
/**
24+
* Alias constructor.
25+
*
26+
* @param ApiCall $apiCall
27+
*/
28+
public function __construct(ApiCall $apiCall)
29+
{
30+
$this->apiCall = $apiCall;
31+
}
32+
33+
/**
34+
* @return array
35+
* @throws TypesenseClientError|GuzzleException
36+
*/
37+
public function retrieve(): array
38+
{
39+
return $this->apiCall->get(Debug::RESOURCE_PATH, []);
40+
}
41+
}

src/Document.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use GuzzleHttp\Exception\GuzzleException;
66
use Typesense\Exceptions\TypesenseClientError;
7-
use Typesense\Lib\Configuration;
87

98
/**
109
* Class Document

src/Documents.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use GuzzleHttp\Exception\GuzzleException;
66
use Typesense\Exceptions\TypesenseClientError;
7-
use Typesense\Lib\Configuration;
87

98
/**
109
* Class Documents

src/Health.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Typesense;
4+
5+
use GuzzleHttp\Exception\GuzzleException;
6+
use Typesense\Exceptions\TypesenseClientError;
7+
8+
/**
9+
* Class Health
10+
*
11+
* @package \Typesense
12+
* @date 10/12/20
13+
*/
14+
class Health
15+
{
16+
public const RESOURCE_PATH = '/health';
17+
18+
/**
19+
* @var ApiCall
20+
*/
21+
private ApiCall $apiCall;
22+
23+
/**
24+
* Alias constructor.
25+
*
26+
* @param ApiCall $apiCall
27+
*/
28+
public function __construct(ApiCall $apiCall)
29+
{
30+
$this->apiCall = $apiCall;
31+
}
32+
33+
/**
34+
* @return array
35+
* @throws TypesenseClientError|GuzzleException
36+
*/
37+
public function retrieve(): array
38+
{
39+
return $this->apiCall->get(Health::RESOURCE_PATH, []);
40+
}
41+
}

0 commit comments

Comments
 (0)