Completed
Pull Request — master (#16)
by Sergey
02:15
created

GuzzleHttpClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace seregazhuk\SmsIntel\Api;
4
5
use Guzzle\Http\ClientInterface;
6
use seregazhuk\SmsIntel\Contracts\HttpClient;
7
8
class GuzzleHttpClient implements HttpClient
9
{
10
    /**
11
     * @var ClientInterface
12
     */
13
    protected $client;
14
15
    /**
16
     * @param ClientInterface $client
17
     */
18
    public function __construct(ClientInterface $client)
19
    {
20
        $this->client = $client;
21
    }
22
23
    /**
24
     * @param string $uri
25
     * @param array $params
26
     * @return string
27
     */
28
    public function get($uri, $params = [])
29
    {
30
        if (!empty($params)) {
31
            $uri .= '?' . http_build_query($params);
32
        }
33
34
        return $this
35
            ->client
36
            ->get($uri)
37
            ->send()
38
            ->getBody(true);
39
    }
40
41
    /**
42
     * @param string $uri
43
     * @param array $body
44
     * @return string
45
     */
46
    public function post($uri, $body = [])
47
    {
48
        return $this
49
            ->client
50
            ->post($uri, [], $body)
51
            ->send()
52
            ->getBody(true);
53
    }
54
55
    /**
56
     * @param string $url
57
     * @return $this
58
     */
59
    public function setBaseUrl($url)
60
    {
61
        $this->client->setBaseUrl($url);
62
63
        return $this;
64
    }
65
}
66