-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hemera.php
38 lines (34 loc) · 1.04 KB
/
Hemera.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace equicolor\hemera;
use GuzzleHttp\Client;
class Hemera {
protected $client;
public function __construct($baseUri) {
$this->client = new Client([
'base_uri' => $baseUri,
'timeout' => 2.0,
]);
}
public function act($topic, $cmd, $params = []) {
$query = $this->buildQuery($topic, $cmd, $params);
try {
$response = $this->client->request('GET', '/', [
'query' => $query
]);
$status = $response->getStatusCode();
// if ($status === 200) {
return (string) $response->getBody();
// } else {
// throw new \Exception('Bad response ' . $status . ": \n" . (string) $response->getBody());
// }
} catch (\Exception $e) {
var_dump($e); die;
}
}
protected function buildQuery($topic, $cmd, $params = []) {
return array_merge([
'topic' => $topic,
'cmd' => $cmd,
], $params);
}
}