Completed
Push — master ( 32a55a...fb9711 )
by Mitchel
02:18
created

Client::post()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Bunq;
4
5
use Bunq\Exception\BunqException;
6
use GuzzleHttp\ClientInterface;
7
use GuzzleHttp\Exception\ClientException;
8
9
final class Client implements BunqClient
10
{
11
    /**
12
     * @var ClientInterface
13
     */
14
    private $httpClient;
15
16
    /**
17
     * @param ClientInterface $httpClient
18
     */
19
    public function __construct(ClientInterface $httpClient)
20
    {
21
        $this->httpClient = $httpClient;
22
    }
23
24
    /**
25
     * @param string $url
26
     * @param array  $options
27
     *
28
     * @return array
29
     */
30
    public function get($url, array $options = [])
31
    {
32
        return $this->requestAPI('GET', (string)$url, $options);
33
    }
34
35
    /**
36
     * @param string $url
37
     * @param array  $options
38
     *
39
     * @return array
40
     */
41
    public function post($url, array $options = [])
42
    {
43
        return $this->requestAPI('POST', (string)$url, $options);
44
    }
45
46
    /**
47
     * @param string $url
48
     * @param array  $options
49
     *
50
     * @return array
51
     */
52
    public function put($url, array $options = [])
53
    {
54
        return $this->requestAPI('PUT', $url, $options);
55
    }
56
57
    /**
58
     * Handles the API Calling.
59
     *
60
     * @param string $method
61
     * @param string $url
62
     * @param array  $options
63
     *
64
     * @return array
65
     * @throws BunqException
66
     */
67
    private function requestAPI($method, $url, array $options = [])
68
    {
69
        try {
70
            $response = $this->httpClient->request((string)$method, $url, $options);
71
72
            return json_decode($response->getBody(), true);
73
        } catch (ClientException $e) {
74
            throw new BunqException($e);
75
        }
76
    }
77
}
78