-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathClientBase.php
More file actions
43 lines (38 loc) · 1.06 KB
/
ClientBase.php
File metadata and controls
43 lines (38 loc) · 1.06 KB
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
39
40
41
42
43
<?php
namespace Dadata;
abstract class ClientBase
{
public $client;
public function __construct($baseUrl, $token, $secret = null, $proxy = '')
{
$headers = [
"Content-Type" => "application/json",
"Accept" => "application/json",
"Authorization" => "Token " . $token,
];
if ($secret) {
$headers["X-Secret"] = $secret;
}
$options = [
"base_uri" => $baseUrl,
"headers" => $headers,
"timeout" => Settings::TIMEOUT_SEC
];
if ($proxy) {
$options['proxy'] = $proxy;
}
$this->client = new \GuzzleHttp\Client($options);
}
protected function get($url, $query = [])
{
$response = $this->client->get($url, ["query" => $query]);
return json_decode($response->getBody(), true);
}
protected function post($url, $data)
{
$response = $this->client->post($url, [
"json" => $data
]);
return json_decode($response->getBody(), true);
}
}