|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Oryzone PHPoAuthUserData package <https://github.com/Oryzone/PHPoAuthUserData>. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Oryzone, developed by Luciano Mammino <[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
|
|
|
namespace OAuth\UserData\Extractor; |
|
13
|
|
|
|
|
14
|
|
|
use OAuth\UserData\Utils\ArrayUtils; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class Harvest |
|
18
|
|
|
* @package OAuth\UserData\Extractor |
|
19
|
|
|
*/ |
|
20
|
|
|
class Harvest extends LazyExtractor |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Request constants |
|
24
|
|
|
*/ |
|
25
|
|
|
const REQUEST_PROFILE = '/account/who_am_i'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Constructor |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct() |
|
31
|
|
|
{ |
|
32
|
|
|
parent::__construct( |
|
33
|
|
|
self::getDefaultLoadersMap(), |
|
34
|
|
|
self::getDefaultNormalizersMap(), |
|
35
|
|
|
self::getSupportedFields() |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
protected static function getSupportedFields() |
|
40
|
|
|
{ |
|
41
|
|
|
return array( |
|
42
|
|
|
self::FIELD_UNIQUE_ID, |
|
43
|
|
|
self::FIELD_USERNAME, |
|
44
|
|
|
self::FIELD_FIRST_NAME, |
|
45
|
|
|
self::FIELD_LAST_NAME, |
|
46
|
|
|
self::FIELD_FULL_NAME, |
|
47
|
|
|
self::FIELD_IMAGE_URL, |
|
48
|
|
|
self::FIELD_EMAIL, |
|
49
|
|
|
self::FIELD_EXTRA |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function profileLoader() |
|
54
|
|
|
{ |
|
55
|
|
|
return json_decode($this->service->request(self::REQUEST_PROFILE), true); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
protected function uniqueIdNormalizer($data) |
|
59
|
|
|
{ |
|
60
|
|
|
return $data['user']['id']; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
protected function usernameNormalizer($data) |
|
64
|
|
|
{ |
|
65
|
|
|
return isset($data['user']['email']) ? $data['user']['email'] : null; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
protected function fullNameNormalizer($data) |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->firstNameNormalizer($data) . ' ' . $this->lastNameNormalizer($data); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
protected function firstNameNormalizer($data) |
|
74
|
|
|
{ |
|
75
|
|
|
return isset($data['user']['first_name']) ? $data['user']['first_name'] : null; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
protected function lastNameNormalizer($data) |
|
79
|
|
|
{ |
|
80
|
|
|
return isset($data['user']['last_name']) ? $data['user']['last_name'] : null; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
protected function imageUrlNormalizer($data) |
|
84
|
|
|
{ |
|
85
|
|
|
return isset($data['user']['avatar_url']) ? 'https://api.harvestapp.com/' . $data['user']['avatar_url'] : null; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
protected function emailNormalizer($data) |
|
89
|
|
|
{ |
|
90
|
|
|
return isset($data['user']['email']) ? $data['user']['email'] : null; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
protected function extraNormalizer($data) |
|
94
|
|
|
{ |
|
95
|
|
|
return ArrayUtils::removeKeys($data['user'], array( |
|
96
|
|
|
'id', |
|
97
|
|
|
'first_name', |
|
98
|
|
|
'last_name', |
|
99
|
|
|
'email', |
|
100
|
|
|
'avatar_url' |
|
101
|
|
|
)); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|