Completed
Push — master ( b408c6...9b0fcb )
by Michał
01:56
created

BarenoteClient::getNotesEndpoint()   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
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Barenote;
3
4
5
use Barenote\Domain\Credentials;
6
use Barenote\Domain\Token;
7
use Barenote\Endpoint\Authentication;
8
use Barenote\Endpoint\Notes;
9
use Barenote\Transport\HttpfulTransport;
10
use Barenote\Transport\Transport;
11
12
class BarenoteClient
13
{
14
    /**
15
     * @var Transport
16
     */
17
    private $transport;
18
    private $endpoints = [];
19
20
    /**
21
     * BarenoteClient constructor.
22
     * @param string $host
23
     */
24
    public function __construct(string $host)
25
    {
26
        $this->transport = new HttpfulTransport();
27
        $this->transport->setHost($host);
28
29
        $this->endpoints['authentication'] = new Authentication($this->transport);
30
        $this->endpoints['notes'] = new Notes($this->transport);
31
    }
32
  
33
    public function authenticate(string $username, string $password): Token
34
    {
35
        $credentials = new Credentials($username, $password);
36
        $token = $this->getAuthenticationEndpoint()->authenticate($credentials);
37
        $this->transport->setToken($token);
38
39
        return $token;
40
    }
41
42
    /**
43
     * @return Authentication
44
     */
45
    private function getAuthenticationEndpoint()
46
    {
47
        return $this->endpoints['authentication'];
48
    }
49
50
    /**
51
     * @return Notes
52
     */
53
    public function getNotesEndpoint()
54
    {
55
        return $this->endpoints['notes'];
56
    }
57
}