-
Notifications
You must be signed in to change notification settings - Fork 0
/
LaravelZvonokApiClient.php
62 lines (53 loc) · 1.67 KB
/
LaravelZvonokApiClient.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace GCSC\LaravelZvonokApi;
use GuzzleHttp\Client as GuzzleClient;
use Psr\Http\Message\ResponseInterface;
class LaravelZvonokApiClient
{
protected $client;
public function __construct(array $configs = [])
{
$this->client = new GuzzleClient(array_merge(
config('laravel-zvonok-api.guzzle_config'),
[
'base_uri' => config('laravel-zvonok-api.api_url'),
],
$configs
));
}
/**
* @return GuzzleClient
*/
public function getClient(): GuzzleClient
{
return $this->client;
}
public function request(string $method, string $path = '', array $options = []): ResponseInterface
{
if (strtolower($method) == 'post') {
$key = 'multipart';
if (! isset($options[$key])) {
$options[$key] = [];
}
$options[$key] = array_merge($options[$key], [
[
'name' => 'public_key',
'contents' => config('laravel-zvonok-api.api_key'),
],
]);
} else {
$key = 'query';
if (! isset($options[$key])) {
$options[$key] = [];
}
$options[$key] = array_merge($options[$key], ['public_key' => config('laravel-zvonok-api.api_key')]);
}
return $this->client->request($method, $path, $options);
}
public function getResponse(string $method, string $path = '', array $options = [])
{
$response = $this->request($method, $path, $options);
$body = $response->getBody()->__toString();
return json_decode($body);
}
}