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\Api; |
15
|
|
|
|
16
|
|
|
use BenatEspina\StackExchangeApiClient\Api\User\ElectedModerators; |
17
|
|
|
use BenatEspina\StackExchangeApiClient\Api\User\Me; |
18
|
|
|
use BenatEspina\StackExchangeApiClient\Api\User\Moderators; |
19
|
|
|
use BenatEspina\StackExchangeApiClient\Api\User\Users; |
20
|
|
|
use BenatEspina\StackExchangeApiClient\Api\User\UsersByIds; |
21
|
|
|
use BenatEspina\StackExchangeApiClient\Authentication\Authentication; |
22
|
|
|
use BenatEspina\StackExchangeApiClient\Authentication\AuthenticationIsRequired; |
23
|
|
|
use BenatEspina\StackExchangeApiClient\Http\HttpClient; |
24
|
|
|
use BenatEspina\StackExchangeApiClient\Serializer\Serializer; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @author Beñat Espiña <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
final class UserApi |
30
|
|
|
{ |
31
|
|
|
public const QUERY_PARAMS = [ |
32
|
|
|
'order' => 'desc', |
33
|
|
|
'sort' => 'reputation', |
34
|
|
|
'site' => 'stackoverflow', |
35
|
|
|
'filter' => HttpClient::FILTER_ALL, |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
private $client; |
39
|
|
|
private $serializer; |
40
|
|
|
private $authentication; |
41
|
|
|
|
42
|
|
|
public function __construct(HttpClient $client, Serializer $serializer, Authentication $authentication = null) |
43
|
|
|
{ |
44
|
|
|
$this->client = $client; |
45
|
|
|
$this->serializer = $serializer; |
46
|
|
|
$this->authentication = $authentication; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function electedModerators(array $parameters = self::QUERY_PARAMS) |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
return (new ElectedModerators( |
52
|
|
|
$this->client, |
53
|
|
|
$this->serializer |
54
|
|
|
))->__invoke($parameters); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function me(array $parameters = self::QUERY_PARAMS) |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$this->checkAuthenticationIsEnabled(); |
60
|
|
|
|
61
|
|
|
return (new Me( |
62
|
|
|
$this->client, |
63
|
|
|
$this->serializer, |
64
|
|
|
$this->authentication |
|
|
|
|
65
|
|
|
))->__invoke($parameters); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function moderators(array $parameters = self::QUERY_PARAMS) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
return (new Moderators( |
71
|
|
|
$this->client, |
72
|
|
|
$this->serializer |
73
|
|
|
))->__invoke($parameters); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function users(array $parameters = self::QUERY_PARAMS) |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
return (new Users( |
79
|
|
|
$this->client, |
80
|
|
|
$this->serializer |
81
|
|
|
))->__invoke($parameters); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function usersByIds($ids, array $parameters = self::QUERY_PARAMS) |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
return (new UsersByIds( |
87
|
|
|
$this->client, |
88
|
|
|
$this->serializer |
89
|
|
|
))->__invoke($ids, $parameters); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
private function checkAuthenticationIsEnabled() : void |
93
|
|
|
{ |
94
|
|
|
if (!$this->authentication instanceof Authentication) { |
95
|
|
|
throw new AuthenticationIsRequired(); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.