1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Stack Exchange Api Client library. |
5
|
|
|
* |
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace BenatEspina\StackExchangeApiClient; |
15
|
|
|
|
16
|
|
|
use BenatEspina\StackExchangeApiClient\Api\AccessTokenApi; |
17
|
|
|
use BenatEspina\StackExchangeApiClient\Api\AnswerApi; |
18
|
|
|
use BenatEspina\StackExchangeApiClient\Authentication\Authentication; |
19
|
|
|
use BenatEspina\StackExchangeApiClient\Http\GuzzleHttpClient; |
20
|
|
|
use BenatEspina\StackExchangeApiClient\Http\HttpClient; |
21
|
|
|
use BenatEspina\StackExchangeApiClient\Serializer\NoSerializeSerializer; |
22
|
|
|
use BenatEspina\StackExchangeApiClient\Serializer\Serializer; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Beñat Espiña <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
final class StackExchange |
28
|
|
|
{ |
29
|
|
|
private $client; |
30
|
|
|
private $serializer; |
31
|
|
|
private $authentication; |
32
|
|
|
|
33
|
|
|
public static function withoutAuth() : self |
34
|
|
|
{ |
35
|
|
|
return new self(new GuzzleHttpClient()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public static function withAuth(string $key, string $accessToken) : self |
39
|
|
|
{ |
40
|
|
|
return new self(new GuzzleHttpClient(), new Authentication($key, $accessToken)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function __construct(HttpClient $client, Authentication $authentication = null) |
44
|
|
|
{ |
45
|
|
|
$this->client = $client; |
46
|
|
|
$this->authentication = $authentication; |
47
|
|
|
$this->serializer = new NoSerializeSerializer(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function accessToken(Serializer $serializer = null) : AccessTokenApi |
51
|
|
|
{ |
52
|
|
|
return new AccessTokenApi($this->client, $serializer ?? $this->serializer); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function answer(Serializer $serializer = null) : AnswerApi |
56
|
|
|
{ |
57
|
|
|
return new AnswerApi($this->client, $serializer ?? $this->serializer, $this->authentication); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|