|
1
|
|
|
<?php |
|
2
|
|
|
namespace Kerox\Messenger\Api; |
|
3
|
|
|
|
|
4
|
|
|
use GuzzleHttp\Client; |
|
5
|
|
|
use Kerox\Messenger\Request\UserRequest; |
|
6
|
|
|
use Kerox\Messenger\Response\UserResponse; |
|
7
|
|
|
use Kerox\Messenger\UserInterface; |
|
8
|
|
|
|
|
9
|
|
|
class User extends AbstractApi implements UserInterface |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Send constructor. |
|
14
|
|
|
* |
|
15
|
|
|
* @param string $pageToken |
|
16
|
|
|
* @param \GuzzleHttp\Client $client |
|
17
|
|
|
*/ |
|
18
|
|
|
public function __construct(string $pageToken, Client $client) |
|
19
|
|
|
{ |
|
20
|
|
|
parent::__construct($pageToken, $client); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param string $userId |
|
25
|
|
|
* @param array|null $fields |
|
26
|
|
|
* @return \Kerox\Messenger\Response\UserResponse |
|
27
|
|
|
*/ |
|
28
|
|
|
public function profile(string $userId, array $fields = null): UserResponse |
|
29
|
|
|
{ |
|
30
|
|
|
$allowedFields = $this->getAllowedFields(); |
|
31
|
|
|
if ($fields !== null) { |
|
32
|
|
|
foreach ($fields as $field) { |
|
33
|
|
|
if (!in_array($field, $allowedFields)) { |
|
34
|
|
|
throw new \InvalidArgumentException($field . ' is not a valid value. $userProfileFields must only contain ' . implode(', ', $allowedFields)); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
} else { |
|
38
|
|
|
$fields = $allowedFields; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$request = new UserRequest($this->pageToken, $fields); |
|
42
|
|
|
$response = $this->client->get(sprintf('/%s', $userId), $request->build()); |
|
43
|
|
|
|
|
44
|
|
|
return new UserResponse($response); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
private function getAllowedFields(): array |
|
51
|
|
|
{ |
|
52
|
|
|
return [ |
|
53
|
|
|
UserInterface::FIRST_NAME, |
|
54
|
|
|
UserInterface::LAST_NAME, |
|
55
|
|
|
UserInterface::PROFILE_PIC, |
|
56
|
|
|
UserInterface::LOCALE, |
|
57
|
|
|
UserInterface::TIMEZONE, |
|
58
|
|
|
UserInterface::GENDER, |
|
59
|
|
|
UserInterface::IS_PAYMENT_ENABLED, |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|