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 Instagram |
18
|
|
|
* @package OAuth\UserData\Extractor |
19
|
|
|
*/ |
20
|
|
|
class Instagram extends LazyExtractor |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
const REQUEST_PROFILE = '/users/self'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Constructor |
27
|
|
|
*/ |
28
|
|
|
public function __construct() |
29
|
|
|
{ |
30
|
|
|
parent::__construct( |
31
|
|
|
self::getDefaultLoadersMap(), |
32
|
|
|
self::getDefaultNormalizersMap(), |
33
|
|
|
self::getSupportedFields() |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected static function getSupportedFields() |
38
|
|
|
{ |
39
|
|
|
return array( |
40
|
|
|
self::FIELD_UNIQUE_ID, |
41
|
|
|
self::FIELD_USERNAME, |
42
|
|
|
self::FIELD_FULL_NAME, |
43
|
|
|
self::FIELD_FIRST_NAME, |
44
|
|
|
self::FIELD_LAST_NAME, |
45
|
|
|
self::FIELD_DESCRIPTION, |
46
|
|
|
self::FIELD_WEBSITES, |
47
|
|
|
self::FIELD_IMAGE_URL, |
48
|
|
|
self::FIELD_PROFILE_URL, |
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 isset($data['data']['id']) ? $data['data']['id'] : null; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function usernameNormalizer($data) |
64
|
|
|
{ |
65
|
|
|
return isset($data['data']['username']) ? $data['data']['username'] : null; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
protected function fullNameNormalizer($data) |
69
|
|
|
{ |
70
|
|
|
return isset($data['data']['full_name']) ? $data['data']['full_name'] : null; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
protected function firstNameNormalizer() |
74
|
|
|
{ |
75
|
|
|
$fullName = $this->getField(self::FIELD_FULL_NAME); |
76
|
|
|
if ($fullName) { |
77
|
|
|
$names = explode(' ', $fullName); |
78
|
|
|
|
79
|
|
|
return $names[0]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return null; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
protected function lastNameNormalizer() |
86
|
|
|
{ |
87
|
|
|
$fullName = $this->getField(self::FIELD_FULL_NAME); |
88
|
|
|
if ($fullName) { |
89
|
|
|
$names = explode(' ', $fullName); |
90
|
|
|
|
91
|
|
|
return $names[sizeof($names) - 1]; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return null; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
protected function descriptionNormalizer($data) |
98
|
|
|
{ |
99
|
|
|
return isset($data['data']['bio']) ? $data['data']['bio'] : null; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
protected function websitesNormalizer($data) |
103
|
|
|
{ |
104
|
|
|
$websites = array(); |
105
|
|
|
if (isset($data['data']['website'])) { |
106
|
|
|
$websites[] = $data['data']['website']; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $websites; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
protected function profileUrlNormalizer() |
113
|
|
|
{ |
114
|
|
|
$username = $this->getField(self::FIELD_USERNAME); |
115
|
|
|
|
116
|
|
|
if (null !== $username) { |
117
|
|
|
return sprintf('http://instagram.com/%s', $username); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return null; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
protected function imageUrlNormalizer($data) |
124
|
|
|
{ |
125
|
|
|
return isset($data['data']['profile_picture']) ? $data['data']['profile_picture'] : null; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
protected function extraNormalizer($data) |
129
|
|
|
{ |
130
|
|
|
return ArrayUtils::removeKeys($data['data'], array( |
131
|
|
|
'id', |
132
|
|
|
'username', |
133
|
|
|
'full_name', |
134
|
|
|
'website', |
135
|
|
|
'profile_picture', |
136
|
|
|
'bio', |
137
|
|
|
)); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|