@@ -18,177 +18,177 @@ |
||
18 | 18 | */ |
19 | 19 | class Patreon extends OAuth2 |
20 | 20 | { |
21 | - /** |
|
22 | - * {@inheritdoc} |
|
23 | - */ |
|
24 | - protected $scope = 'identity identity[email]'; |
|
25 | - |
|
26 | - /** |
|
27 | - * {@inheritdoc} |
|
28 | - */ |
|
29 | - protected $apiBaseUrl = 'https://www.patreon.com/api'; |
|
30 | - |
|
31 | - /** |
|
32 | - * {@inheritdoc} |
|
33 | - */ |
|
34 | - protected $authorizeUrl = 'https://www.patreon.com/oauth2/authorize'; |
|
35 | - |
|
36 | - /** |
|
37 | - * {@inheritdoc} |
|
38 | - */ |
|
39 | - protected $accessTokenUrl = 'https://www.patreon.com/api/oauth2/token'; |
|
40 | - |
|
41 | - /** |
|
42 | - * {@inheritdoc} |
|
43 | - */ |
|
44 | - protected $apiDocumentation = 'https://docs.patreon.com/#oauth'; |
|
45 | - |
|
46 | - /** |
|
47 | - * {@inheritdoc} |
|
48 | - */ |
|
49 | - protected function initialize() |
|
50 | - { |
|
51 | - parent::initialize(); |
|
52 | - |
|
53 | - if ($this->isRefreshTokenAvailable()) { |
|
54 | - $this->tokenRefreshParameters += [ |
|
55 | - 'client_id' => $this->clientId, |
|
56 | - 'client_secret' => $this->clientSecret, |
|
57 | - ]; |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * {@inheritdoc} |
|
63 | - */ |
|
64 | - public function getUserProfile() |
|
65 | - { |
|
66 | - $response = $this->apiRequest('oauth2/v2/identity', 'GET', [ |
|
67 | - 'fields[user]' => 'created,first_name,last_name,email,full_name,is_email_verified,thumb_url,url', |
|
68 | - ]); |
|
69 | - |
|
70 | - $collection = new Collection($response); |
|
71 | - if (!$collection->exists('data')) { |
|
72 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
73 | - } |
|
74 | - |
|
75 | - $userProfile = new Profile(); |
|
76 | - |
|
77 | - $data = $collection->filter('data'); |
|
78 | - $attributes = $data->filter('attributes'); |
|
79 | - |
|
80 | - $userProfile->identifier = $data->get('id'); |
|
81 | - $userProfile->email = $attributes->get('email'); |
|
82 | - $userProfile->firstName = $attributes->get('first_name'); |
|
83 | - $userProfile->lastName = $attributes->get('last_name'); |
|
84 | - $userProfile->displayName = $attributes->get('full_name') ?: $data->get('id'); |
|
85 | - $userProfile->photoURL = $attributes->get('thumb_url'); |
|
86 | - $userProfile->profileURL = $attributes->get('url'); |
|
87 | - |
|
88 | - $userProfile->emailVerified = $attributes->get('is_email_verified') ? $userProfile->email : ''; |
|
89 | - |
|
90 | - return $userProfile; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Contacts are defined as Patrons here |
|
95 | - */ |
|
96 | - public function getUserContacts() |
|
97 | - { |
|
98 | - $campaignId = $this->config->get('campaign_id') ?: null; |
|
99 | - $tierFilter = $this->config->get('tier_filter') ?: null; |
|
100 | - |
|
101 | - $campaigns = []; |
|
102 | - if ($campaignId === null) { |
|
103 | - $campaignsUrl = 'oauth2/v2/campaigns'; |
|
104 | - do { |
|
105 | - $response = $this->apiRequest($campaignsUrl); |
|
106 | - $data = new Collection($response); |
|
107 | - |
|
108 | - if (!$data->exists('data')) { |
|
109 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
110 | - } |
|
111 | - |
|
112 | - foreach ($data->filter('data')->toArray() as $item) { |
|
113 | - $campaign = new Collection($item); |
|
114 | - $campaigns[] = $campaign->get('id'); |
|
115 | - } |
|
116 | - |
|
117 | - if ($data->filter('links')->exists('next')) { |
|
118 | - $campaignsUrl = $data->filter('links')->get('next'); |
|
119 | - |
|
120 | - $pagedList = true; |
|
121 | - } else { |
|
122 | - $pagedList = false; |
|
123 | - } |
|
124 | - } while ($pagedList); |
|
125 | - } else { |
|
126 | - $campaigns[] = $campaignId; |
|
127 | - } |
|
128 | - |
|
129 | - $contacts = []; |
|
130 | - |
|
131 | - foreach ($campaigns as $campaignId) { |
|
132 | - $params = [ |
|
133 | - 'include' => 'currently_entitled_tiers', |
|
134 | - 'fields[member]' => 'full_name,patron_status,email', |
|
135 | - 'fields[tier]' => 'title', |
|
136 | - ]; |
|
137 | - $membersUrl = 'oauth2/v2/campaigns/' . $campaignId . '/members?' . http_build_query($params); |
|
138 | - |
|
139 | - do { |
|
140 | - $response = $this->apiRequest($membersUrl); |
|
141 | - |
|
142 | - $data = new Collection($response); |
|
143 | - |
|
144 | - if (!$data->exists('data')) { |
|
145 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
146 | - } |
|
147 | - |
|
148 | - $tierTitles = []; |
|
149 | - |
|
150 | - foreach ($data->filter('included')->toArray() as $item) { |
|
151 | - $includedItem = new Collection($item); |
|
152 | - if ($includedItem->get('type') == 'tier') { |
|
153 | - $tierTitles[$includedItem->get('id')] = $includedItem->filter('attributes')->get('title'); |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - foreach ($data->filter('data')->toArray() as $item) { |
|
158 | - $member = new Collection($item); |
|
159 | - |
|
160 | - if ($member->filter('attributes')->get('patron_status') == 'active_patron') { |
|
161 | - $tiers = []; |
|
162 | - $tierObs = $member->filter('relationships')->filter('currently_entitled_tiers')->get('data'); |
|
163 | - foreach ($tierObs as $item) { |
|
164 | - $tier = new Collection($item); |
|
165 | - $tierId = $tier->get('id'); |
|
166 | - $tiers[] = $tierTitles[$tierId]; |
|
167 | - } |
|
168 | - |
|
169 | - if (($tierFilter === null) || (in_array($tierFilter, $tiers))) { |
|
170 | - $userContact = new User\Contact(); |
|
171 | - |
|
172 | - $userContact->identifier = $member->get('id'); |
|
173 | - $userContact->email = $member->filter('attributes')->get('email'); |
|
174 | - $userContact->displayName = $member->filter('attributes')->get('full_name'); |
|
175 | - $userContact->description = json_encode($tiers); |
|
176 | - |
|
177 | - $contacts[] = $userContact; |
|
178 | - } |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - if ($data->filter('links')->exists('next')) { |
|
183 | - $membersUrl = $data->filter('links')->get('next'); |
|
184 | - |
|
185 | - $pagedList = true; |
|
186 | - } else { |
|
187 | - $pagedList = false; |
|
188 | - } |
|
189 | - } while ($pagedList); |
|
190 | - } |
|
191 | - |
|
192 | - return $contacts; |
|
193 | - } |
|
21 | + /** |
|
22 | + * {@inheritdoc} |
|
23 | + */ |
|
24 | + protected $scope = 'identity identity[email]'; |
|
25 | + |
|
26 | + /** |
|
27 | + * {@inheritdoc} |
|
28 | + */ |
|
29 | + protected $apiBaseUrl = 'https://www.patreon.com/api'; |
|
30 | + |
|
31 | + /** |
|
32 | + * {@inheritdoc} |
|
33 | + */ |
|
34 | + protected $authorizeUrl = 'https://www.patreon.com/oauth2/authorize'; |
|
35 | + |
|
36 | + /** |
|
37 | + * {@inheritdoc} |
|
38 | + */ |
|
39 | + protected $accessTokenUrl = 'https://www.patreon.com/api/oauth2/token'; |
|
40 | + |
|
41 | + /** |
|
42 | + * {@inheritdoc} |
|
43 | + */ |
|
44 | + protected $apiDocumentation = 'https://docs.patreon.com/#oauth'; |
|
45 | + |
|
46 | + /** |
|
47 | + * {@inheritdoc} |
|
48 | + */ |
|
49 | + protected function initialize() |
|
50 | + { |
|
51 | + parent::initialize(); |
|
52 | + |
|
53 | + if ($this->isRefreshTokenAvailable()) { |
|
54 | + $this->tokenRefreshParameters += [ |
|
55 | + 'client_id' => $this->clientId, |
|
56 | + 'client_secret' => $this->clientSecret, |
|
57 | + ]; |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * {@inheritdoc} |
|
63 | + */ |
|
64 | + public function getUserProfile() |
|
65 | + { |
|
66 | + $response = $this->apiRequest('oauth2/v2/identity', 'GET', [ |
|
67 | + 'fields[user]' => 'created,first_name,last_name,email,full_name,is_email_verified,thumb_url,url', |
|
68 | + ]); |
|
69 | + |
|
70 | + $collection = new Collection($response); |
|
71 | + if (!$collection->exists('data')) { |
|
72 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
73 | + } |
|
74 | + |
|
75 | + $userProfile = new Profile(); |
|
76 | + |
|
77 | + $data = $collection->filter('data'); |
|
78 | + $attributes = $data->filter('attributes'); |
|
79 | + |
|
80 | + $userProfile->identifier = $data->get('id'); |
|
81 | + $userProfile->email = $attributes->get('email'); |
|
82 | + $userProfile->firstName = $attributes->get('first_name'); |
|
83 | + $userProfile->lastName = $attributes->get('last_name'); |
|
84 | + $userProfile->displayName = $attributes->get('full_name') ?: $data->get('id'); |
|
85 | + $userProfile->photoURL = $attributes->get('thumb_url'); |
|
86 | + $userProfile->profileURL = $attributes->get('url'); |
|
87 | + |
|
88 | + $userProfile->emailVerified = $attributes->get('is_email_verified') ? $userProfile->email : ''; |
|
89 | + |
|
90 | + return $userProfile; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Contacts are defined as Patrons here |
|
95 | + */ |
|
96 | + public function getUserContacts() |
|
97 | + { |
|
98 | + $campaignId = $this->config->get('campaign_id') ?: null; |
|
99 | + $tierFilter = $this->config->get('tier_filter') ?: null; |
|
100 | + |
|
101 | + $campaigns = []; |
|
102 | + if ($campaignId === null) { |
|
103 | + $campaignsUrl = 'oauth2/v2/campaigns'; |
|
104 | + do { |
|
105 | + $response = $this->apiRequest($campaignsUrl); |
|
106 | + $data = new Collection($response); |
|
107 | + |
|
108 | + if (!$data->exists('data')) { |
|
109 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
110 | + } |
|
111 | + |
|
112 | + foreach ($data->filter('data')->toArray() as $item) { |
|
113 | + $campaign = new Collection($item); |
|
114 | + $campaigns[] = $campaign->get('id'); |
|
115 | + } |
|
116 | + |
|
117 | + if ($data->filter('links')->exists('next')) { |
|
118 | + $campaignsUrl = $data->filter('links')->get('next'); |
|
119 | + |
|
120 | + $pagedList = true; |
|
121 | + } else { |
|
122 | + $pagedList = false; |
|
123 | + } |
|
124 | + } while ($pagedList); |
|
125 | + } else { |
|
126 | + $campaigns[] = $campaignId; |
|
127 | + } |
|
128 | + |
|
129 | + $contacts = []; |
|
130 | + |
|
131 | + foreach ($campaigns as $campaignId) { |
|
132 | + $params = [ |
|
133 | + 'include' => 'currently_entitled_tiers', |
|
134 | + 'fields[member]' => 'full_name,patron_status,email', |
|
135 | + 'fields[tier]' => 'title', |
|
136 | + ]; |
|
137 | + $membersUrl = 'oauth2/v2/campaigns/' . $campaignId . '/members?' . http_build_query($params); |
|
138 | + |
|
139 | + do { |
|
140 | + $response = $this->apiRequest($membersUrl); |
|
141 | + |
|
142 | + $data = new Collection($response); |
|
143 | + |
|
144 | + if (!$data->exists('data')) { |
|
145 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
146 | + } |
|
147 | + |
|
148 | + $tierTitles = []; |
|
149 | + |
|
150 | + foreach ($data->filter('included')->toArray() as $item) { |
|
151 | + $includedItem = new Collection($item); |
|
152 | + if ($includedItem->get('type') == 'tier') { |
|
153 | + $tierTitles[$includedItem->get('id')] = $includedItem->filter('attributes')->get('title'); |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + foreach ($data->filter('data')->toArray() as $item) { |
|
158 | + $member = new Collection($item); |
|
159 | + |
|
160 | + if ($member->filter('attributes')->get('patron_status') == 'active_patron') { |
|
161 | + $tiers = []; |
|
162 | + $tierObs = $member->filter('relationships')->filter('currently_entitled_tiers')->get('data'); |
|
163 | + foreach ($tierObs as $item) { |
|
164 | + $tier = new Collection($item); |
|
165 | + $tierId = $tier->get('id'); |
|
166 | + $tiers[] = $tierTitles[$tierId]; |
|
167 | + } |
|
168 | + |
|
169 | + if (($tierFilter === null) || (in_array($tierFilter, $tiers))) { |
|
170 | + $userContact = new User\Contact(); |
|
171 | + |
|
172 | + $userContact->identifier = $member->get('id'); |
|
173 | + $userContact->email = $member->filter('attributes')->get('email'); |
|
174 | + $userContact->displayName = $member->filter('attributes')->get('full_name'); |
|
175 | + $userContact->description = json_encode($tiers); |
|
176 | + |
|
177 | + $contacts[] = $userContact; |
|
178 | + } |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + if ($data->filter('links')->exists('next')) { |
|
183 | + $membersUrl = $data->filter('links')->get('next'); |
|
184 | + |
|
185 | + $pagedList = true; |
|
186 | + } else { |
|
187 | + $pagedList = false; |
|
188 | + } |
|
189 | + } while ($pagedList); |
|
190 | + } |
|
191 | + |
|
192 | + return $contacts; |
|
193 | + } |
|
194 | 194 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | ]); |
69 | 69 | |
70 | 70 | $collection = new Collection($response); |
71 | - if (!$collection->exists('data')) { |
|
71 | + if ( ! $collection->exists('data')) { |
|
72 | 72 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
73 | 73 | } |
74 | 74 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | $response = $this->apiRequest($campaignsUrl); |
106 | 106 | $data = new Collection($response); |
107 | 107 | |
108 | - if (!$data->exists('data')) { |
|
108 | + if ( ! $data->exists('data')) { |
|
109 | 109 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
110 | 110 | } |
111 | 111 | |
@@ -134,14 +134,14 @@ discard block |
||
134 | 134 | 'fields[member]' => 'full_name,patron_status,email', |
135 | 135 | 'fields[tier]' => 'title', |
136 | 136 | ]; |
137 | - $membersUrl = 'oauth2/v2/campaigns/' . $campaignId . '/members?' . http_build_query($params); |
|
137 | + $membersUrl = 'oauth2/v2/campaigns/'.$campaignId.'/members?'.http_build_query($params); |
|
138 | 138 | |
139 | 139 | do { |
140 | 140 | $response = $this->apiRequest($membersUrl); |
141 | 141 | |
142 | 142 | $data = new Collection($response); |
143 | 143 | |
144 | - if (!$data->exists('data')) { |
|
144 | + if ( ! $data->exists('data')) { |
|
145 | 145 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
146 | 146 | } |
147 | 147 |
@@ -17,80 +17,80 @@ |
||
17 | 17 | */ |
18 | 18 | class AutoDesk extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $scope = 'data:read'; |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $scope = 'data:read'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $apiBaseUrl = 'https://developer.api.autodesk.com/'; |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $apiBaseUrl = 'https://developer.api.autodesk.com/'; |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $authorizeUrl |
|
34 | - = 'https://developer.api.autodesk.com/authentication/v1/authorize'; |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $authorizeUrl |
|
34 | + = 'https://developer.api.autodesk.com/authentication/v1/authorize'; |
|
35 | 35 | |
36 | - /** |
|
37 | - * {@inheritdoc} |
|
38 | - */ |
|
39 | - protected $accessTokenUrl |
|
40 | - = 'https://developer.api.autodesk.com/authentication/v1/gettoken'; |
|
36 | + /** |
|
37 | + * {@inheritdoc} |
|
38 | + */ |
|
39 | + protected $accessTokenUrl |
|
40 | + = 'https://developer.api.autodesk.com/authentication/v1/gettoken'; |
|
41 | 41 | |
42 | - /** |
|
43 | - * {@inheritdoc} |
|
44 | - */ |
|
45 | - protected $refreshTokenUrl |
|
46 | - = 'https://developer.api.autodesk.com/authentication/v1/refreshtoken'; |
|
42 | + /** |
|
43 | + * {@inheritdoc} |
|
44 | + */ |
|
45 | + protected $refreshTokenUrl |
|
46 | + = 'https://developer.api.autodesk.com/authentication/v1/refreshtoken'; |
|
47 | 47 | |
48 | - /** |
|
49 | - * {@inheritdoc} |
|
50 | - */ |
|
51 | - protected $apiDocumentation |
|
52 | - = 'https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/overview/'; |
|
48 | + /** |
|
49 | + * {@inheritdoc} |
|
50 | + */ |
|
51 | + protected $apiDocumentation |
|
52 | + = 'https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/overview/'; |
|
53 | 53 | |
54 | - /** |
|
55 | - * {@inheritdoc} |
|
56 | - */ |
|
57 | - protected function initialize() |
|
58 | - { |
|
59 | - parent::initialize(); |
|
54 | + /** |
|
55 | + * {@inheritdoc} |
|
56 | + */ |
|
57 | + protected function initialize() |
|
58 | + { |
|
59 | + parent::initialize(); |
|
60 | 60 | |
61 | - if ($this->isRefreshTokenAvailable()) { |
|
62 | - $this->tokenRefreshParameters += [ |
|
63 | - 'client_id' => $this->clientId, |
|
64 | - 'client_secret' => $this->clientSecret, |
|
65 | - 'grant_type' => 'refresh_token', |
|
66 | - ]; |
|
67 | - } |
|
68 | - } |
|
61 | + if ($this->isRefreshTokenAvailable()) { |
|
62 | + $this->tokenRefreshParameters += [ |
|
63 | + 'client_id' => $this->clientId, |
|
64 | + 'client_secret' => $this->clientSecret, |
|
65 | + 'grant_type' => 'refresh_token', |
|
66 | + ]; |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * {@inheritdoc} |
|
72 | - * |
|
73 | - * See: https://forge.autodesk.com/en/docs/oauth/v2/reference/http/users-@me-GET/ |
|
74 | - */ |
|
75 | - public function getUserProfile() |
|
76 | - { |
|
77 | - $response = $this->apiRequest('userprofile/v1/users/@me'); |
|
70 | + /** |
|
71 | + * {@inheritdoc} |
|
72 | + * |
|
73 | + * See: https://forge.autodesk.com/en/docs/oauth/v2/reference/http/users-@me-GET/ |
|
74 | + */ |
|
75 | + public function getUserProfile() |
|
76 | + { |
|
77 | + $response = $this->apiRequest('userprofile/v1/users/@me'); |
|
78 | 78 | |
79 | - $collection = new Data\Collection($response); |
|
79 | + $collection = new Data\Collection($response); |
|
80 | 80 | |
81 | - $userProfile = new User\Profile(); |
|
81 | + $userProfile = new User\Profile(); |
|
82 | 82 | |
83 | - $userProfile->identifier = $collection->get('userId'); |
|
84 | - $userProfile->displayName |
|
85 | - = $collection->get('firstName') .' '. $collection->get('lastName'); |
|
86 | - $userProfile->firstName = $collection->get('firstName'); |
|
87 | - $userProfile->lastName = $collection->get('lastName'); |
|
88 | - $userProfile->email = $collection->get('emailId'); |
|
89 | - $userProfile->language = $collection->get('language'); |
|
90 | - $userProfile->webSiteURL = $collection->get('websiteUrl'); |
|
91 | - $userProfile->photoURL |
|
92 | - = $collection->filter('profileImages')->get('sizeX360'); |
|
83 | + $userProfile->identifier = $collection->get('userId'); |
|
84 | + $userProfile->displayName |
|
85 | + = $collection->get('firstName') .' '. $collection->get('lastName'); |
|
86 | + $userProfile->firstName = $collection->get('firstName'); |
|
87 | + $userProfile->lastName = $collection->get('lastName'); |
|
88 | + $userProfile->email = $collection->get('emailId'); |
|
89 | + $userProfile->language = $collection->get('language'); |
|
90 | + $userProfile->webSiteURL = $collection->get('websiteUrl'); |
|
91 | + $userProfile->photoURL |
|
92 | + = $collection->filter('profileImages')->get('sizeX360'); |
|
93 | 93 | |
94 | - return $userProfile; |
|
95 | - } |
|
94 | + return $userProfile; |
|
95 | + } |
|
96 | 96 | } |
@@ -82,7 +82,7 @@ |
||
82 | 82 | |
83 | 83 | $userProfile->identifier = $collection->get('userId'); |
84 | 84 | $userProfile->displayName |
85 | - = $collection->get('firstName') .' '. $collection->get('lastName'); |
|
85 | + = $collection->get('firstName').' '.$collection->get('lastName'); |
|
86 | 86 | $userProfile->firstName = $collection->get('firstName'); |
87 | 87 | $userProfile->lastName = $collection->get('lastName'); |
88 | 88 | $userProfile->email = $collection->get('emailId'); |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | ]; |
56 | 56 | |
57 | 57 | |
58 | - $response = $this->apiRequest('me', 'GET', ['projection' => '(' . implode(',', $fields) . ')']); |
|
58 | + $response = $this->apiRequest('me', 'GET', ['projection' => '('.implode(',', $fields).')']); |
|
59 | 59 | $data = new Data\Collection($response); |
60 | 60 | |
61 | - if (!$data->exists('id')) { |
|
61 | + if ( ! $data->exists('id')) { |
|
62 | 62 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
63 | 63 | } |
64 | 64 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $userProfile->identifier = $data->get('id'); |
79 | 79 | $userProfile->email = $this->getUserEmail(); |
80 | 80 | $userProfile->emailVerified = $userProfile->email; |
81 | - $userProfile->displayName = trim($userProfile->firstName . ' ' . $userProfile->lastName); |
|
81 | + $userProfile->displayName = trim($userProfile->firstName.' '.$userProfile->lastName); |
|
82 | 82 | |
83 | 83 | $photo_elements = $data |
84 | 84 | ->filter('profilePicture') |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | if (is_array($elements)) { |
106 | 106 | // Get the largest picture from the list which is the last one. |
107 | 107 | $element = end($elements); |
108 | - if (!empty($element->identifiers)) { |
|
108 | + if ( ! empty($element->identifiers)) { |
|
109 | 109 | return reset($element->identifiers)->identifier; |
110 | 110 | } |
111 | 111 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | |
155 | 155 | if (is_string($status)) { |
156 | 156 | $status = [ |
157 | - 'author' => 'urn:li:person:' . $userID, |
|
157 | + 'author' => 'urn:li:person:'.$userID, |
|
158 | 158 | 'lifecycleState' => 'PUBLISHED', |
159 | 159 | 'specificContent' => [ |
160 | 160 | 'com.linkedin.ugc.ShareContent' => [ |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | { |
198 | 198 | $locale = $data->filter($field_name)->filter('preferredLocale'); |
199 | 199 | if ($locale) { |
200 | - return $locale->get('language') . '_' . $locale->get('country'); |
|
200 | + return $locale->get('language').'_'.$locale->get('country'); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | return 'en_US'; |
@@ -17,204 +17,204 @@ |
||
17 | 17 | */ |
18 | 18 | class LinkedIn extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $scope = 'r_liteprofile r_emailaddress'; |
|
24 | - |
|
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $apiBaseUrl = 'https://api.linkedin.com/v2/'; |
|
29 | - |
|
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $authorizeUrl = 'https://www.linkedin.com/oauth/v2/authorization'; |
|
34 | - |
|
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $accessTokenUrl = 'https://www.linkedin.com/oauth/v2/accessToken'; |
|
39 | - |
|
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - protected $apiDocumentation = 'https://docs.microsoft.com/en-us/linkedin/shared/authentication/authentication'; |
|
44 | - |
|
45 | - /** |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - protected function initialize() |
|
49 | - { |
|
50 | - parent::initialize(); |
|
51 | - |
|
52 | - if ($this->isRefreshTokenAvailable()) { |
|
53 | - $this->tokenRefreshParameters += [ |
|
54 | - 'client_id' => $this->clientId, |
|
55 | - 'client_secret' => $this->clientSecret |
|
56 | - ]; |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * {@inheritdoc} |
|
62 | - */ |
|
63 | - public function getUserProfile() |
|
64 | - { |
|
65 | - $fields = [ |
|
66 | - 'id', |
|
67 | - 'firstName', |
|
68 | - 'lastName', |
|
69 | - 'profilePicture(displayImage~:playableStreams)', |
|
70 | - ]; |
|
71 | - |
|
72 | - |
|
73 | - $response = $this->apiRequest('me', 'GET', ['projection' => '(' . implode(',', $fields) . ')']); |
|
74 | - $data = new Data\Collection($response); |
|
75 | - |
|
76 | - if (!$data->exists('id')) { |
|
77 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
78 | - } |
|
79 | - |
|
80 | - $userProfile = new User\Profile(); |
|
81 | - |
|
82 | - // Handle localized names. |
|
83 | - $userProfile->firstName = $data |
|
84 | - ->filter('firstName') |
|
85 | - ->filter('localized') |
|
86 | - ->get($this->getPreferredLocale($data, 'firstName')); |
|
87 | - |
|
88 | - $userProfile->lastName = $data |
|
89 | - ->filter('lastName') |
|
90 | - ->filter('localized') |
|
91 | - ->get($this->getPreferredLocale($data, 'lastName')); |
|
92 | - |
|
93 | - $userProfile->identifier = $data->get('id'); |
|
94 | - $userProfile->email = $this->getUserEmail(); |
|
95 | - $userProfile->emailVerified = $userProfile->email; |
|
96 | - $userProfile->displayName = trim($userProfile->firstName . ' ' . $userProfile->lastName); |
|
97 | - |
|
98 | - $photo_elements = $data |
|
99 | - ->filter('profilePicture') |
|
100 | - ->filter('displayImage~') |
|
101 | - ->get('elements'); |
|
102 | - $userProfile->photoURL = $this->getUserPhotoUrl($photo_elements); |
|
103 | - |
|
104 | - return $userProfile; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Returns a user photo. |
|
109 | - * |
|
110 | - * @param array $elements |
|
111 | - * List of file identifiers related to this artifact. |
|
112 | - * |
|
113 | - * @return string |
|
114 | - * The user photo URL. |
|
115 | - * |
|
116 | - * @see https://docs.microsoft.com/en-us/linkedin/shared/references/v2/profile/profile-picture |
|
117 | - */ |
|
118 | - public function getUserPhotoUrl($elements) |
|
119 | - { |
|
120 | - if (is_array($elements)) { |
|
121 | - // Get the largest picture from the list which is the last one. |
|
122 | - $element = end($elements); |
|
123 | - if (!empty($element->identifiers)) { |
|
124 | - return reset($element->identifiers)->identifier; |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - return null; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Returns an email address of user. |
|
133 | - * |
|
134 | - * @return string |
|
135 | - * The user email address. |
|
136 | - * |
|
137 | - * @throws \Exception |
|
138 | - */ |
|
139 | - public function getUserEmail() |
|
140 | - { |
|
141 | - $response = $this->apiRequest('emailAddress', 'GET', [ |
|
142 | - 'q' => 'members', |
|
143 | - 'projection' => '(elements*(handle~))', |
|
144 | - ]); |
|
145 | - $data = new Data\Collection($response); |
|
146 | - |
|
147 | - foreach ($data->filter('elements')->toArray() as $element) { |
|
148 | - $item = new Data\Collection($element); |
|
149 | - |
|
150 | - if ($email = $item->filter('handle~')->get('emailAddress')) { |
|
151 | - return $email; |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - return null; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * {@inheritdoc} |
|
160 | - * |
|
161 | - * @see https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/share-on-linkedin |
|
162 | - * @throws \Exception |
|
163 | - */ |
|
164 | - public function setUserStatus($status, $userID = null) |
|
165 | - { |
|
166 | - if (strpos($this->scope, 'w_member_social') === false) { |
|
167 | - throw new \Exception('Set user status requires w_member_social permission!'); |
|
168 | - } |
|
169 | - |
|
170 | - if (is_string($status)) { |
|
171 | - $status = [ |
|
172 | - 'author' => 'urn:li:person:' . $userID, |
|
173 | - 'lifecycleState' => 'PUBLISHED', |
|
174 | - 'specificContent' => [ |
|
175 | - 'com.linkedin.ugc.ShareContent' => [ |
|
176 | - 'shareCommentary' => [ |
|
177 | - 'text' => $status, |
|
178 | - ], |
|
179 | - 'shareMediaCategory' => 'NONE', |
|
180 | - ], |
|
181 | - ], |
|
182 | - 'visibility' => [ |
|
183 | - 'com.linkedin.ugc.MemberNetworkVisibility' => 'PUBLIC', |
|
184 | - ], |
|
185 | - ]; |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - $headers = [ |
|
190 | - 'Content-Type' => 'application/json', |
|
191 | - 'x-li-format' => 'json', |
|
192 | - 'X-Restli-Protocol-Version' => '2.0.0', |
|
193 | - ]; |
|
194 | - |
|
195 | - $response = $this->apiRequest("ugcPosts", 'POST', $status, $headers); |
|
196 | - |
|
197 | - return $response; |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Returns a preferred locale for given field. |
|
202 | - * |
|
203 | - * @param \Hybridauth\Data\Collection $data |
|
204 | - * A data to check. |
|
205 | - * @param string $field_name |
|
206 | - * A field name to perform. |
|
207 | - * |
|
208 | - * @return string |
|
209 | - * A field locale. |
|
210 | - */ |
|
211 | - protected function getPreferredLocale($data, $field_name) |
|
212 | - { |
|
213 | - $locale = $data->filter($field_name)->filter('preferredLocale'); |
|
214 | - if ($locale) { |
|
215 | - return $locale->get('language') . '_' . $locale->get('country'); |
|
216 | - } |
|
217 | - |
|
218 | - return 'en_US'; |
|
219 | - } |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $scope = 'r_liteprofile r_emailaddress'; |
|
24 | + |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $apiBaseUrl = 'https://api.linkedin.com/v2/'; |
|
29 | + |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $authorizeUrl = 'https://www.linkedin.com/oauth/v2/authorization'; |
|
34 | + |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $accessTokenUrl = 'https://www.linkedin.com/oauth/v2/accessToken'; |
|
39 | + |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + protected $apiDocumentation = 'https://docs.microsoft.com/en-us/linkedin/shared/authentication/authentication'; |
|
44 | + |
|
45 | + /** |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + protected function initialize() |
|
49 | + { |
|
50 | + parent::initialize(); |
|
51 | + |
|
52 | + if ($this->isRefreshTokenAvailable()) { |
|
53 | + $this->tokenRefreshParameters += [ |
|
54 | + 'client_id' => $this->clientId, |
|
55 | + 'client_secret' => $this->clientSecret |
|
56 | + ]; |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * {@inheritdoc} |
|
62 | + */ |
|
63 | + public function getUserProfile() |
|
64 | + { |
|
65 | + $fields = [ |
|
66 | + 'id', |
|
67 | + 'firstName', |
|
68 | + 'lastName', |
|
69 | + 'profilePicture(displayImage~:playableStreams)', |
|
70 | + ]; |
|
71 | + |
|
72 | + |
|
73 | + $response = $this->apiRequest('me', 'GET', ['projection' => '(' . implode(',', $fields) . ')']); |
|
74 | + $data = new Data\Collection($response); |
|
75 | + |
|
76 | + if (!$data->exists('id')) { |
|
77 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
78 | + } |
|
79 | + |
|
80 | + $userProfile = new User\Profile(); |
|
81 | + |
|
82 | + // Handle localized names. |
|
83 | + $userProfile->firstName = $data |
|
84 | + ->filter('firstName') |
|
85 | + ->filter('localized') |
|
86 | + ->get($this->getPreferredLocale($data, 'firstName')); |
|
87 | + |
|
88 | + $userProfile->lastName = $data |
|
89 | + ->filter('lastName') |
|
90 | + ->filter('localized') |
|
91 | + ->get($this->getPreferredLocale($data, 'lastName')); |
|
92 | + |
|
93 | + $userProfile->identifier = $data->get('id'); |
|
94 | + $userProfile->email = $this->getUserEmail(); |
|
95 | + $userProfile->emailVerified = $userProfile->email; |
|
96 | + $userProfile->displayName = trim($userProfile->firstName . ' ' . $userProfile->lastName); |
|
97 | + |
|
98 | + $photo_elements = $data |
|
99 | + ->filter('profilePicture') |
|
100 | + ->filter('displayImage~') |
|
101 | + ->get('elements'); |
|
102 | + $userProfile->photoURL = $this->getUserPhotoUrl($photo_elements); |
|
103 | + |
|
104 | + return $userProfile; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Returns a user photo. |
|
109 | + * |
|
110 | + * @param array $elements |
|
111 | + * List of file identifiers related to this artifact. |
|
112 | + * |
|
113 | + * @return string |
|
114 | + * The user photo URL. |
|
115 | + * |
|
116 | + * @see https://docs.microsoft.com/en-us/linkedin/shared/references/v2/profile/profile-picture |
|
117 | + */ |
|
118 | + public function getUserPhotoUrl($elements) |
|
119 | + { |
|
120 | + if (is_array($elements)) { |
|
121 | + // Get the largest picture from the list which is the last one. |
|
122 | + $element = end($elements); |
|
123 | + if (!empty($element->identifiers)) { |
|
124 | + return reset($element->identifiers)->identifier; |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + return null; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Returns an email address of user. |
|
133 | + * |
|
134 | + * @return string |
|
135 | + * The user email address. |
|
136 | + * |
|
137 | + * @throws \Exception |
|
138 | + */ |
|
139 | + public function getUserEmail() |
|
140 | + { |
|
141 | + $response = $this->apiRequest('emailAddress', 'GET', [ |
|
142 | + 'q' => 'members', |
|
143 | + 'projection' => '(elements*(handle~))', |
|
144 | + ]); |
|
145 | + $data = new Data\Collection($response); |
|
146 | + |
|
147 | + foreach ($data->filter('elements')->toArray() as $element) { |
|
148 | + $item = new Data\Collection($element); |
|
149 | + |
|
150 | + if ($email = $item->filter('handle~')->get('emailAddress')) { |
|
151 | + return $email; |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + return null; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * {@inheritdoc} |
|
160 | + * |
|
161 | + * @see https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/share-on-linkedin |
|
162 | + * @throws \Exception |
|
163 | + */ |
|
164 | + public function setUserStatus($status, $userID = null) |
|
165 | + { |
|
166 | + if (strpos($this->scope, 'w_member_social') === false) { |
|
167 | + throw new \Exception('Set user status requires w_member_social permission!'); |
|
168 | + } |
|
169 | + |
|
170 | + if (is_string($status)) { |
|
171 | + $status = [ |
|
172 | + 'author' => 'urn:li:person:' . $userID, |
|
173 | + 'lifecycleState' => 'PUBLISHED', |
|
174 | + 'specificContent' => [ |
|
175 | + 'com.linkedin.ugc.ShareContent' => [ |
|
176 | + 'shareCommentary' => [ |
|
177 | + 'text' => $status, |
|
178 | + ], |
|
179 | + 'shareMediaCategory' => 'NONE', |
|
180 | + ], |
|
181 | + ], |
|
182 | + 'visibility' => [ |
|
183 | + 'com.linkedin.ugc.MemberNetworkVisibility' => 'PUBLIC', |
|
184 | + ], |
|
185 | + ]; |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + $headers = [ |
|
190 | + 'Content-Type' => 'application/json', |
|
191 | + 'x-li-format' => 'json', |
|
192 | + 'X-Restli-Protocol-Version' => '2.0.0', |
|
193 | + ]; |
|
194 | + |
|
195 | + $response = $this->apiRequest("ugcPosts", 'POST', $status, $headers); |
|
196 | + |
|
197 | + return $response; |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Returns a preferred locale for given field. |
|
202 | + * |
|
203 | + * @param \Hybridauth\Data\Collection $data |
|
204 | + * A data to check. |
|
205 | + * @param string $field_name |
|
206 | + * A field name to perform. |
|
207 | + * |
|
208 | + * @return string |
|
209 | + * A field locale. |
|
210 | + */ |
|
211 | + protected function getPreferredLocale($data, $field_name) |
|
212 | + { |
|
213 | + $locale = $data->filter($field_name)->filter('preferredLocale'); |
|
214 | + if ($locale) { |
|
215 | + return $locale->get('language') . '_' . $locale->get('country'); |
|
216 | + } |
|
217 | + |
|
218 | + return 'en_US'; |
|
219 | + } |
|
220 | 220 | } |
@@ -40,225 +40,225 @@ |
||
40 | 40 | */ |
41 | 41 | class Twitter extends OAuth1 |
42 | 42 | { |
43 | - /** |
|
44 | - * {@inheritdoc} |
|
45 | - */ |
|
46 | - protected $apiBaseUrl = 'https://api.twitter.com/1.1/'; |
|
47 | - |
|
48 | - /** |
|
49 | - * {@inheritdoc} |
|
50 | - */ |
|
51 | - protected $authorizeUrl = 'https://api.twitter.com/oauth/authenticate'; |
|
52 | - |
|
53 | - /** |
|
54 | - * {@inheritdoc} |
|
55 | - */ |
|
56 | - protected $requestTokenUrl = 'https://api.twitter.com/oauth/request_token'; |
|
57 | - |
|
58 | - /** |
|
59 | - * {@inheritdoc} |
|
60 | - */ |
|
61 | - protected $accessTokenUrl = 'https://api.twitter.com/oauth/access_token'; |
|
62 | - |
|
63 | - /** |
|
64 | - * {@inheritdoc} |
|
65 | - */ |
|
66 | - protected $apiDocumentation = 'https://dev.twitter.com/web/sign-in/implementing'; |
|
67 | - |
|
68 | - /** |
|
69 | - * {@inheritdoc} |
|
70 | - */ |
|
71 | - protected function getAuthorizeUrl($parameters = []) |
|
72 | - { |
|
73 | - if ($this->config->get('authorize') === true) { |
|
74 | - $this->authorizeUrl = 'https://api.twitter.com/oauth/authorize'; |
|
75 | - } |
|
76 | - |
|
77 | - return parent::getAuthorizeUrl($parameters); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * {@inheritdoc} |
|
82 | - */ |
|
83 | - public function getUserProfile() |
|
84 | - { |
|
85 | - $response = $this->apiRequest('account/verify_credentials.json', 'GET', [ |
|
86 | - 'include_email' => $this->config->get('include_email') === false ? 'false' : 'true', |
|
87 | - ]); |
|
88 | - |
|
89 | - $data = new Data\Collection($response); |
|
90 | - |
|
91 | - if (!$data->exists('id_str')) { |
|
92 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
93 | - } |
|
94 | - |
|
95 | - $userProfile = new User\Profile(); |
|
96 | - |
|
97 | - $userProfile->identifier = $data->get('id_str'); |
|
98 | - $userProfile->displayName = $data->get('screen_name'); |
|
99 | - $userProfile->description = $data->get('description'); |
|
100 | - $userProfile->firstName = $data->get('name'); |
|
101 | - $userProfile->email = $data->get('email'); |
|
102 | - $userProfile->emailVerified = $data->get('email'); |
|
103 | - $userProfile->webSiteURL = $data->get('url'); |
|
104 | - $userProfile->region = $data->get('location'); |
|
105 | - |
|
106 | - $userProfile->profileURL = $data->exists('screen_name') |
|
107 | - ? ('https://twitter.com/' . $data->get('screen_name')) |
|
108 | - : ''; |
|
109 | - |
|
110 | - $photoSize = $this->config->get('photo_size') ?: 'original'; |
|
111 | - $photoSize = $photoSize === 'original' ? '' : "_{$photoSize}"; |
|
112 | - $userProfile->photoURL = $data->exists('profile_image_url_https') |
|
113 | - ? str_replace('_normal', $photoSize, $data->get('profile_image_url_https')) |
|
114 | - : ''; |
|
115 | - |
|
116 | - $userProfile->data = [ |
|
117 | - 'followed_by' => $data->get('followers_count'), |
|
118 | - 'follows' => $data->get('friends_count'), |
|
119 | - ]; |
|
120 | - |
|
121 | - return $userProfile; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * {@inheritdoc} |
|
126 | - */ |
|
127 | - public function getUserContacts($parameters = []) |
|
128 | - { |
|
129 | - $parameters = ['cursor' => '-1'] + $parameters; |
|
130 | - |
|
131 | - $response = $this->apiRequest('friends/ids.json', 'GET', $parameters); |
|
132 | - |
|
133 | - $data = new Data\Collection($response); |
|
134 | - |
|
135 | - if (!$data->exists('ids')) { |
|
136 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
137 | - } |
|
138 | - |
|
139 | - if ($data->filter('ids')->isEmpty()) { |
|
140 | - return []; |
|
141 | - } |
|
142 | - |
|
143 | - $contacts = []; |
|
144 | - |
|
145 | - // 75 id per time should be okey |
|
146 | - $contactsIds = array_chunk((array)$data->get('ids'), 75); |
|
147 | - |
|
148 | - foreach ($contactsIds as $chunk) { |
|
149 | - $parameters = ['user_id' => implode(',', $chunk)]; |
|
150 | - |
|
151 | - try { |
|
152 | - $response = $this->apiRequest('users/lookup.json', 'GET', $parameters); |
|
153 | - |
|
154 | - if ($response && count($response)) { |
|
155 | - foreach ($response as $item) { |
|
156 | - $contacts[] = $this->fetchUserContact($item); |
|
157 | - } |
|
158 | - } |
|
159 | - } catch (\Exception $e) { |
|
160 | - continue; |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - return $contacts; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * @param $item |
|
169 | - * |
|
170 | - * @return User\Contact |
|
171 | - */ |
|
172 | - protected function fetchUserContact($item) |
|
173 | - { |
|
174 | - $item = new Data\Collection($item); |
|
175 | - |
|
176 | - $userContact = new User\Contact(); |
|
177 | - |
|
178 | - $userContact->identifier = $item->get('id_str'); |
|
179 | - $userContact->displayName = $item->get('name'); |
|
180 | - $userContact->photoURL = $item->get('profile_image_url'); |
|
181 | - $userContact->description = $item->get('description'); |
|
182 | - |
|
183 | - $userContact->profileURL = $item->exists('screen_name') |
|
184 | - ? ('https://twitter.com/' . $item->get('screen_name')) |
|
185 | - : ''; |
|
186 | - |
|
187 | - return $userContact; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * {@inheritdoc} |
|
192 | - */ |
|
193 | - public function setUserStatus($status) |
|
194 | - { |
|
195 | - if (is_string($status)) { |
|
196 | - $status = ['status' => $status]; |
|
197 | - } |
|
198 | - |
|
199 | - // Prepare request parameters. |
|
200 | - $params = []; |
|
201 | - if (isset($status['status'])) { |
|
202 | - $params['status'] = $status['status']; |
|
203 | - } |
|
204 | - if (isset($status['picture'])) { |
|
205 | - $media = $this->apiRequest('https://upload.twitter.com/1.1/media/upload.json', 'POST', [ |
|
206 | - 'media' => base64_encode(file_get_contents($status['picture'])), |
|
207 | - ]); |
|
208 | - $params['media_ids'] = $media->media_id; |
|
209 | - } |
|
210 | - |
|
211 | - $response = $this->apiRequest('statuses/update.json', 'POST', $params); |
|
212 | - |
|
213 | - return $response; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * {@inheritdoc} |
|
218 | - */ |
|
219 | - public function getUserActivity($stream = 'me') |
|
220 | - { |
|
221 | - $apiUrl = ($stream == 'me') |
|
222 | - ? 'statuses/user_timeline.json' |
|
223 | - : 'statuses/home_timeline.json'; |
|
224 | - |
|
225 | - $response = $this->apiRequest($apiUrl); |
|
226 | - |
|
227 | - if (!$response) { |
|
228 | - return []; |
|
229 | - } |
|
230 | - |
|
231 | - $activities = []; |
|
232 | - |
|
233 | - foreach ($response as $item) { |
|
234 | - $activities[] = $this->fetchUserActivity($item); |
|
235 | - } |
|
236 | - |
|
237 | - return $activities; |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * @param $item |
|
242 | - * @return User\Activity |
|
243 | - */ |
|
244 | - protected function fetchUserActivity($item) |
|
245 | - { |
|
246 | - $item = new Data\Collection($item); |
|
247 | - |
|
248 | - $userActivity = new User\Activity(); |
|
249 | - |
|
250 | - $userActivity->id = $item->get('id_str'); |
|
251 | - $userActivity->date = $item->get('created_at'); |
|
252 | - $userActivity->text = $item->get('text'); |
|
253 | - |
|
254 | - $userActivity->user->identifier = $item->filter('user')->get('id_str'); |
|
255 | - $userActivity->user->displayName = $item->filter('user')->get('name'); |
|
256 | - $userActivity->user->photoURL = $item->filter('user')->get('profile_image_url'); |
|
257 | - |
|
258 | - $userActivity->user->profileURL = $item->filter('user')->get('screen_name') |
|
259 | - ? ('https://twitter.com/' . $item->filter('user')->get('screen_name')) |
|
260 | - : ''; |
|
261 | - |
|
262 | - return $userActivity; |
|
263 | - } |
|
43 | + /** |
|
44 | + * {@inheritdoc} |
|
45 | + */ |
|
46 | + protected $apiBaseUrl = 'https://api.twitter.com/1.1/'; |
|
47 | + |
|
48 | + /** |
|
49 | + * {@inheritdoc} |
|
50 | + */ |
|
51 | + protected $authorizeUrl = 'https://api.twitter.com/oauth/authenticate'; |
|
52 | + |
|
53 | + /** |
|
54 | + * {@inheritdoc} |
|
55 | + */ |
|
56 | + protected $requestTokenUrl = 'https://api.twitter.com/oauth/request_token'; |
|
57 | + |
|
58 | + /** |
|
59 | + * {@inheritdoc} |
|
60 | + */ |
|
61 | + protected $accessTokenUrl = 'https://api.twitter.com/oauth/access_token'; |
|
62 | + |
|
63 | + /** |
|
64 | + * {@inheritdoc} |
|
65 | + */ |
|
66 | + protected $apiDocumentation = 'https://dev.twitter.com/web/sign-in/implementing'; |
|
67 | + |
|
68 | + /** |
|
69 | + * {@inheritdoc} |
|
70 | + */ |
|
71 | + protected function getAuthorizeUrl($parameters = []) |
|
72 | + { |
|
73 | + if ($this->config->get('authorize') === true) { |
|
74 | + $this->authorizeUrl = 'https://api.twitter.com/oauth/authorize'; |
|
75 | + } |
|
76 | + |
|
77 | + return parent::getAuthorizeUrl($parameters); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * {@inheritdoc} |
|
82 | + */ |
|
83 | + public function getUserProfile() |
|
84 | + { |
|
85 | + $response = $this->apiRequest('account/verify_credentials.json', 'GET', [ |
|
86 | + 'include_email' => $this->config->get('include_email') === false ? 'false' : 'true', |
|
87 | + ]); |
|
88 | + |
|
89 | + $data = new Data\Collection($response); |
|
90 | + |
|
91 | + if (!$data->exists('id_str')) { |
|
92 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
93 | + } |
|
94 | + |
|
95 | + $userProfile = new User\Profile(); |
|
96 | + |
|
97 | + $userProfile->identifier = $data->get('id_str'); |
|
98 | + $userProfile->displayName = $data->get('screen_name'); |
|
99 | + $userProfile->description = $data->get('description'); |
|
100 | + $userProfile->firstName = $data->get('name'); |
|
101 | + $userProfile->email = $data->get('email'); |
|
102 | + $userProfile->emailVerified = $data->get('email'); |
|
103 | + $userProfile->webSiteURL = $data->get('url'); |
|
104 | + $userProfile->region = $data->get('location'); |
|
105 | + |
|
106 | + $userProfile->profileURL = $data->exists('screen_name') |
|
107 | + ? ('https://twitter.com/' . $data->get('screen_name')) |
|
108 | + : ''; |
|
109 | + |
|
110 | + $photoSize = $this->config->get('photo_size') ?: 'original'; |
|
111 | + $photoSize = $photoSize === 'original' ? '' : "_{$photoSize}"; |
|
112 | + $userProfile->photoURL = $data->exists('profile_image_url_https') |
|
113 | + ? str_replace('_normal', $photoSize, $data->get('profile_image_url_https')) |
|
114 | + : ''; |
|
115 | + |
|
116 | + $userProfile->data = [ |
|
117 | + 'followed_by' => $data->get('followers_count'), |
|
118 | + 'follows' => $data->get('friends_count'), |
|
119 | + ]; |
|
120 | + |
|
121 | + return $userProfile; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * {@inheritdoc} |
|
126 | + */ |
|
127 | + public function getUserContacts($parameters = []) |
|
128 | + { |
|
129 | + $parameters = ['cursor' => '-1'] + $parameters; |
|
130 | + |
|
131 | + $response = $this->apiRequest('friends/ids.json', 'GET', $parameters); |
|
132 | + |
|
133 | + $data = new Data\Collection($response); |
|
134 | + |
|
135 | + if (!$data->exists('ids')) { |
|
136 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
137 | + } |
|
138 | + |
|
139 | + if ($data->filter('ids')->isEmpty()) { |
|
140 | + return []; |
|
141 | + } |
|
142 | + |
|
143 | + $contacts = []; |
|
144 | + |
|
145 | + // 75 id per time should be okey |
|
146 | + $contactsIds = array_chunk((array)$data->get('ids'), 75); |
|
147 | + |
|
148 | + foreach ($contactsIds as $chunk) { |
|
149 | + $parameters = ['user_id' => implode(',', $chunk)]; |
|
150 | + |
|
151 | + try { |
|
152 | + $response = $this->apiRequest('users/lookup.json', 'GET', $parameters); |
|
153 | + |
|
154 | + if ($response && count($response)) { |
|
155 | + foreach ($response as $item) { |
|
156 | + $contacts[] = $this->fetchUserContact($item); |
|
157 | + } |
|
158 | + } |
|
159 | + } catch (\Exception $e) { |
|
160 | + continue; |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + return $contacts; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * @param $item |
|
169 | + * |
|
170 | + * @return User\Contact |
|
171 | + */ |
|
172 | + protected function fetchUserContact($item) |
|
173 | + { |
|
174 | + $item = new Data\Collection($item); |
|
175 | + |
|
176 | + $userContact = new User\Contact(); |
|
177 | + |
|
178 | + $userContact->identifier = $item->get('id_str'); |
|
179 | + $userContact->displayName = $item->get('name'); |
|
180 | + $userContact->photoURL = $item->get('profile_image_url'); |
|
181 | + $userContact->description = $item->get('description'); |
|
182 | + |
|
183 | + $userContact->profileURL = $item->exists('screen_name') |
|
184 | + ? ('https://twitter.com/' . $item->get('screen_name')) |
|
185 | + : ''; |
|
186 | + |
|
187 | + return $userContact; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * {@inheritdoc} |
|
192 | + */ |
|
193 | + public function setUserStatus($status) |
|
194 | + { |
|
195 | + if (is_string($status)) { |
|
196 | + $status = ['status' => $status]; |
|
197 | + } |
|
198 | + |
|
199 | + // Prepare request parameters. |
|
200 | + $params = []; |
|
201 | + if (isset($status['status'])) { |
|
202 | + $params['status'] = $status['status']; |
|
203 | + } |
|
204 | + if (isset($status['picture'])) { |
|
205 | + $media = $this->apiRequest('https://upload.twitter.com/1.1/media/upload.json', 'POST', [ |
|
206 | + 'media' => base64_encode(file_get_contents($status['picture'])), |
|
207 | + ]); |
|
208 | + $params['media_ids'] = $media->media_id; |
|
209 | + } |
|
210 | + |
|
211 | + $response = $this->apiRequest('statuses/update.json', 'POST', $params); |
|
212 | + |
|
213 | + return $response; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * {@inheritdoc} |
|
218 | + */ |
|
219 | + public function getUserActivity($stream = 'me') |
|
220 | + { |
|
221 | + $apiUrl = ($stream == 'me') |
|
222 | + ? 'statuses/user_timeline.json' |
|
223 | + : 'statuses/home_timeline.json'; |
|
224 | + |
|
225 | + $response = $this->apiRequest($apiUrl); |
|
226 | + |
|
227 | + if (!$response) { |
|
228 | + return []; |
|
229 | + } |
|
230 | + |
|
231 | + $activities = []; |
|
232 | + |
|
233 | + foreach ($response as $item) { |
|
234 | + $activities[] = $this->fetchUserActivity($item); |
|
235 | + } |
|
236 | + |
|
237 | + return $activities; |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * @param $item |
|
242 | + * @return User\Activity |
|
243 | + */ |
|
244 | + protected function fetchUserActivity($item) |
|
245 | + { |
|
246 | + $item = new Data\Collection($item); |
|
247 | + |
|
248 | + $userActivity = new User\Activity(); |
|
249 | + |
|
250 | + $userActivity->id = $item->get('id_str'); |
|
251 | + $userActivity->date = $item->get('created_at'); |
|
252 | + $userActivity->text = $item->get('text'); |
|
253 | + |
|
254 | + $userActivity->user->identifier = $item->filter('user')->get('id_str'); |
|
255 | + $userActivity->user->displayName = $item->filter('user')->get('name'); |
|
256 | + $userActivity->user->photoURL = $item->filter('user')->get('profile_image_url'); |
|
257 | + |
|
258 | + $userActivity->user->profileURL = $item->filter('user')->get('screen_name') |
|
259 | + ? ('https://twitter.com/' . $item->filter('user')->get('screen_name')) |
|
260 | + : ''; |
|
261 | + |
|
262 | + return $userActivity; |
|
263 | + } |
|
264 | 264 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | |
89 | 89 | $data = new Data\Collection($response); |
90 | 90 | |
91 | - if (!$data->exists('id_str')) { |
|
91 | + if ( ! $data->exists('id_str')) { |
|
92 | 92 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
93 | 93 | } |
94 | 94 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $userProfile->region = $data->get('location'); |
105 | 105 | |
106 | 106 | $userProfile->profileURL = $data->exists('screen_name') |
107 | - ? ('https://twitter.com/' . $data->get('screen_name')) |
|
107 | + ? ('https://twitter.com/'.$data->get('screen_name')) |
|
108 | 108 | : ''; |
109 | 109 | |
110 | 110 | $photoSize = $this->config->get('photo_size') ?: 'original'; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | $data = new Data\Collection($response); |
134 | 134 | |
135 | - if (!$data->exists('ids')) { |
|
135 | + if ( ! $data->exists('ids')) { |
|
136 | 136 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
137 | 137 | } |
138 | 138 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | $contacts = []; |
144 | 144 | |
145 | 145 | // 75 id per time should be okey |
146 | - $contactsIds = array_chunk((array)$data->get('ids'), 75); |
|
146 | + $contactsIds = array_chunk((array) $data->get('ids'), 75); |
|
147 | 147 | |
148 | 148 | foreach ($contactsIds as $chunk) { |
149 | 149 | $parameters = ['user_id' => implode(',', $chunk)]; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | $userContact->description = $item->get('description'); |
182 | 182 | |
183 | 183 | $userContact->profileURL = $item->exists('screen_name') |
184 | - ? ('https://twitter.com/' . $item->get('screen_name')) |
|
184 | + ? ('https://twitter.com/'.$item->get('screen_name')) |
|
185 | 185 | : ''; |
186 | 186 | |
187 | 187 | return $userContact; |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | |
225 | 225 | $response = $this->apiRequest($apiUrl); |
226 | 226 | |
227 | - if (!$response) { |
|
227 | + if ( ! $response) { |
|
228 | 228 | return []; |
229 | 229 | } |
230 | 230 | |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | $userActivity->user->photoURL = $item->filter('user')->get('profile_image_url'); |
257 | 257 | |
258 | 258 | $userActivity->user->profileURL = $item->filter('user')->get('screen_name') |
259 | - ? ('https://twitter.com/' . $item->filter('user')->get('screen_name')) |
|
259 | + ? ('https://twitter.com/'.$item->filter('user')->get('screen_name')) |
|
260 | 260 | : ''; |
261 | 261 | |
262 | 262 | return $userActivity; |
@@ -31,66 +31,66 @@ |
||
31 | 31 | class Keycloak extends OAuth2 |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * {@inheritdoc} |
|
36 | - */ |
|
37 | - public $scope = 'openid profile email'; |
|
38 | - |
|
39 | - /** |
|
40 | - * {@inheritdoc} |
|
41 | - */ |
|
42 | - protected $apiDocumentation = 'https://www.keycloak.org/docs/latest/securing_apps/#_oidc'; |
|
43 | - |
|
44 | - /** |
|
45 | - * {@inheritdoc} |
|
46 | - */ |
|
47 | - protected function configure() |
|
48 | - { |
|
49 | - parent::configure(); |
|
50 | - |
|
51 | - if (!$this->config->exists('url')) { |
|
52 | - throw new InvalidApplicationCredentialsException( |
|
53 | - 'You must define a provider url' |
|
54 | - ); |
|
55 | - } |
|
56 | - $url = $this->config->get('url'); |
|
57 | - |
|
58 | - if (!$this->config->exists('realm')) { |
|
59 | - throw new InvalidApplicationCredentialsException( |
|
60 | - 'You must define a realm' |
|
61 | - ); |
|
62 | - } |
|
63 | - $realm = $this->config->get('realm'); |
|
64 | - |
|
65 | - $this->apiBaseUrl = $url . '/realms/' . $realm . '/protocol/openid-connect/'; |
|
66 | - |
|
67 | - $this->authorizeUrl = $this->apiBaseUrl . 'auth'; |
|
68 | - $this->accessTokenUrl = $this->apiBaseUrl . 'token'; |
|
69 | - |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * {@inheritdoc} |
|
74 | - */ |
|
75 | - public function getUserProfile() |
|
76 | - { |
|
77 | - $response = $this->apiRequest('userinfo'); |
|
78 | - |
|
79 | - $data = new Data\Collection($response); |
|
80 | - |
|
81 | - if (!$data->exists('sub')) { |
|
82 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
83 | - } |
|
84 | - |
|
85 | - $userProfile = new User\Profile(); |
|
86 | - |
|
87 | - $userProfile->identifier = $data->get('sub'); |
|
88 | - $userProfile->displayName = $data->get('preferred_username'); |
|
89 | - $userProfile->email = $data->get('email'); |
|
90 | - $userProfile->firstName = $data->get('given_name'); |
|
91 | - $userProfile->lastName = $data->get('family_name'); |
|
92 | - $userProfile->emailVerified = $data->get('email_verified'); |
|
93 | - |
|
94 | - return $userProfile; |
|
95 | - } |
|
34 | + /** |
|
35 | + * {@inheritdoc} |
|
36 | + */ |
|
37 | + public $scope = 'openid profile email'; |
|
38 | + |
|
39 | + /** |
|
40 | + * {@inheritdoc} |
|
41 | + */ |
|
42 | + protected $apiDocumentation = 'https://www.keycloak.org/docs/latest/securing_apps/#_oidc'; |
|
43 | + |
|
44 | + /** |
|
45 | + * {@inheritdoc} |
|
46 | + */ |
|
47 | + protected function configure() |
|
48 | + { |
|
49 | + parent::configure(); |
|
50 | + |
|
51 | + if (!$this->config->exists('url')) { |
|
52 | + throw new InvalidApplicationCredentialsException( |
|
53 | + 'You must define a provider url' |
|
54 | + ); |
|
55 | + } |
|
56 | + $url = $this->config->get('url'); |
|
57 | + |
|
58 | + if (!$this->config->exists('realm')) { |
|
59 | + throw new InvalidApplicationCredentialsException( |
|
60 | + 'You must define a realm' |
|
61 | + ); |
|
62 | + } |
|
63 | + $realm = $this->config->get('realm'); |
|
64 | + |
|
65 | + $this->apiBaseUrl = $url . '/realms/' . $realm . '/protocol/openid-connect/'; |
|
66 | + |
|
67 | + $this->authorizeUrl = $this->apiBaseUrl . 'auth'; |
|
68 | + $this->accessTokenUrl = $this->apiBaseUrl . 'token'; |
|
69 | + |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * {@inheritdoc} |
|
74 | + */ |
|
75 | + public function getUserProfile() |
|
76 | + { |
|
77 | + $response = $this->apiRequest('userinfo'); |
|
78 | + |
|
79 | + $data = new Data\Collection($response); |
|
80 | + |
|
81 | + if (!$data->exists('sub')) { |
|
82 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
83 | + } |
|
84 | + |
|
85 | + $userProfile = new User\Profile(); |
|
86 | + |
|
87 | + $userProfile->identifier = $data->get('sub'); |
|
88 | + $userProfile->displayName = $data->get('preferred_username'); |
|
89 | + $userProfile->email = $data->get('email'); |
|
90 | + $userProfile->firstName = $data->get('given_name'); |
|
91 | + $userProfile->lastName = $data->get('family_name'); |
|
92 | + $userProfile->emailVerified = $data->get('email_verified'); |
|
93 | + |
|
94 | + return $userProfile; |
|
95 | + } |
|
96 | 96 | } |
@@ -48,24 +48,24 @@ discard block |
||
48 | 48 | { |
49 | 49 | parent::configure(); |
50 | 50 | |
51 | - if (!$this->config->exists('url')) { |
|
51 | + if ( ! $this->config->exists('url')) { |
|
52 | 52 | throw new InvalidApplicationCredentialsException( |
53 | 53 | 'You must define a provider url' |
54 | 54 | ); |
55 | 55 | } |
56 | 56 | $url = $this->config->get('url'); |
57 | 57 | |
58 | - if (!$this->config->exists('realm')) { |
|
58 | + if ( ! $this->config->exists('realm')) { |
|
59 | 59 | throw new InvalidApplicationCredentialsException( |
60 | 60 | 'You must define a realm' |
61 | 61 | ); |
62 | 62 | } |
63 | 63 | $realm = $this->config->get('realm'); |
64 | 64 | |
65 | - $this->apiBaseUrl = $url . '/realms/' . $realm . '/protocol/openid-connect/'; |
|
65 | + $this->apiBaseUrl = $url.'/realms/'.$realm.'/protocol/openid-connect/'; |
|
66 | 66 | |
67 | - $this->authorizeUrl = $this->apiBaseUrl . 'auth'; |
|
68 | - $this->accessTokenUrl = $this->apiBaseUrl . 'token'; |
|
67 | + $this->authorizeUrl = $this->apiBaseUrl.'auth'; |
|
68 | + $this->accessTokenUrl = $this->apiBaseUrl.'token'; |
|
69 | 69 | |
70 | 70 | } |
71 | 71 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | $data = new Data\Collection($response); |
80 | 80 | |
81 | - if (!$data->exists('sub')) { |
|
81 | + if ( ! $data->exists('sub')) { |
|
82 | 82 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
83 | 83 | } |
84 | 84 |
@@ -12,143 +12,143 @@ |
||
12 | 12 | */ |
13 | 13 | final class Collection |
14 | 14 | { |
15 | - /** |
|
16 | - * Data collection |
|
17 | - * |
|
18 | - * @var mixed |
|
19 | - */ |
|
20 | - protected $collection = null; |
|
21 | - |
|
22 | - /** |
|
23 | - * @param mixed $data |
|
24 | - */ |
|
25 | - public function __construct($data = null) |
|
26 | - { |
|
27 | - $this->collection = (object)$data; |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * Retrieves the whole collection as array |
|
32 | - * |
|
33 | - * @return mixed |
|
34 | - */ |
|
35 | - public function toArray() |
|
36 | - { |
|
37 | - return (array)$this->collection; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Retrieves an item |
|
42 | - * |
|
43 | - * @param $property |
|
44 | - * |
|
45 | - * @return mixed |
|
46 | - */ |
|
47 | - public function get($property) |
|
48 | - { |
|
49 | - if ($this->exists($property)) { |
|
50 | - return $this->collection->$property; |
|
51 | - } |
|
52 | - |
|
53 | - return null; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Add or update an item |
|
58 | - * |
|
59 | - * @param $property |
|
60 | - * @param mixed $value |
|
61 | - */ |
|
62 | - public function set($property, $value) |
|
63 | - { |
|
64 | - if ($property) { |
|
65 | - $this->collection->$property = $value; |
|
66 | - } |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * .. until I come with a better name.. |
|
71 | - * |
|
72 | - * @param $property |
|
73 | - * |
|
74 | - * @return Collection |
|
75 | - */ |
|
76 | - public function filter($property) |
|
77 | - { |
|
78 | - if ($this->exists($property)) { |
|
79 | - $data = $this->get($property); |
|
80 | - |
|
81 | - if (!is_a($data, 'Collection')) { |
|
82 | - $data = new Collection($data); |
|
83 | - } |
|
84 | - |
|
85 | - return $data; |
|
86 | - } |
|
87 | - |
|
88 | - return new Collection([]); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Checks whether an item within the collection |
|
93 | - * |
|
94 | - * @param $property |
|
95 | - * |
|
96 | - * @return bool |
|
97 | - */ |
|
98 | - public function exists($property) |
|
99 | - { |
|
100 | - return property_exists($this->collection, $property); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Finds whether the collection is empty |
|
105 | - * |
|
106 | - * @return bool |
|
107 | - */ |
|
108 | - public function isEmpty() |
|
109 | - { |
|
110 | - return !(bool)$this->count(); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Count all items in collection |
|
115 | - * |
|
116 | - * @return int |
|
117 | - */ |
|
118 | - public function count() |
|
119 | - { |
|
120 | - return count($this->properties()); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Returns all items properties names |
|
125 | - * |
|
126 | - * @return array |
|
127 | - */ |
|
128 | - public function properties() |
|
129 | - { |
|
130 | - $properties = []; |
|
131 | - |
|
132 | - foreach ($this->collection as $key => $value) { |
|
133 | - $properties[] = $key; |
|
134 | - } |
|
135 | - |
|
136 | - return $properties; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Returns all items values |
|
141 | - * |
|
142 | - * @return array |
|
143 | - */ |
|
144 | - public function values() |
|
145 | - { |
|
146 | - $values = []; |
|
147 | - |
|
148 | - foreach ($this->collection as $value) { |
|
149 | - $values[] = $value; |
|
150 | - } |
|
151 | - |
|
152 | - return $values; |
|
153 | - } |
|
15 | + /** |
|
16 | + * Data collection |
|
17 | + * |
|
18 | + * @var mixed |
|
19 | + */ |
|
20 | + protected $collection = null; |
|
21 | + |
|
22 | + /** |
|
23 | + * @param mixed $data |
|
24 | + */ |
|
25 | + public function __construct($data = null) |
|
26 | + { |
|
27 | + $this->collection = (object)$data; |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * Retrieves the whole collection as array |
|
32 | + * |
|
33 | + * @return mixed |
|
34 | + */ |
|
35 | + public function toArray() |
|
36 | + { |
|
37 | + return (array)$this->collection; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Retrieves an item |
|
42 | + * |
|
43 | + * @param $property |
|
44 | + * |
|
45 | + * @return mixed |
|
46 | + */ |
|
47 | + public function get($property) |
|
48 | + { |
|
49 | + if ($this->exists($property)) { |
|
50 | + return $this->collection->$property; |
|
51 | + } |
|
52 | + |
|
53 | + return null; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Add or update an item |
|
58 | + * |
|
59 | + * @param $property |
|
60 | + * @param mixed $value |
|
61 | + */ |
|
62 | + public function set($property, $value) |
|
63 | + { |
|
64 | + if ($property) { |
|
65 | + $this->collection->$property = $value; |
|
66 | + } |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * .. until I come with a better name.. |
|
71 | + * |
|
72 | + * @param $property |
|
73 | + * |
|
74 | + * @return Collection |
|
75 | + */ |
|
76 | + public function filter($property) |
|
77 | + { |
|
78 | + if ($this->exists($property)) { |
|
79 | + $data = $this->get($property); |
|
80 | + |
|
81 | + if (!is_a($data, 'Collection')) { |
|
82 | + $data = new Collection($data); |
|
83 | + } |
|
84 | + |
|
85 | + return $data; |
|
86 | + } |
|
87 | + |
|
88 | + return new Collection([]); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Checks whether an item within the collection |
|
93 | + * |
|
94 | + * @param $property |
|
95 | + * |
|
96 | + * @return bool |
|
97 | + */ |
|
98 | + public function exists($property) |
|
99 | + { |
|
100 | + return property_exists($this->collection, $property); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Finds whether the collection is empty |
|
105 | + * |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | + public function isEmpty() |
|
109 | + { |
|
110 | + return !(bool)$this->count(); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Count all items in collection |
|
115 | + * |
|
116 | + * @return int |
|
117 | + */ |
|
118 | + public function count() |
|
119 | + { |
|
120 | + return count($this->properties()); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Returns all items properties names |
|
125 | + * |
|
126 | + * @return array |
|
127 | + */ |
|
128 | + public function properties() |
|
129 | + { |
|
130 | + $properties = []; |
|
131 | + |
|
132 | + foreach ($this->collection as $key => $value) { |
|
133 | + $properties[] = $key; |
|
134 | + } |
|
135 | + |
|
136 | + return $properties; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Returns all items values |
|
141 | + * |
|
142 | + * @return array |
|
143 | + */ |
|
144 | + public function values() |
|
145 | + { |
|
146 | + $values = []; |
|
147 | + |
|
148 | + foreach ($this->collection as $value) { |
|
149 | + $values[] = $value; |
|
150 | + } |
|
151 | + |
|
152 | + return $values; |
|
153 | + } |
|
154 | 154 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function __construct($data = null) |
26 | 26 | { |
27 | - $this->collection = (object)$data; |
|
27 | + $this->collection = (object) $data; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function toArray() |
36 | 36 | { |
37 | - return (array)$this->collection; |
|
37 | + return (array) $this->collection; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | if ($this->exists($property)) { |
79 | 79 | $data = $this->get($property); |
80 | 80 | |
81 | - if (!is_a($data, 'Collection')) { |
|
81 | + if ( ! is_a($data, 'Collection')) { |
|
82 | 82 | $data = new Collection($data); |
83 | 83 | } |
84 | 84 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function isEmpty() |
109 | 109 | { |
110 | - return !(bool)$this->count(); |
|
110 | + return ! (bool) $this->count(); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -45,407 +45,407 @@ |
||
45 | 45 | */ |
46 | 46 | class Facebook extends OAuth2 |
47 | 47 | { |
48 | - /** |
|
49 | - * {@inheritdoc} |
|
50 | - */ |
|
51 | - protected $scope = 'email, public_profile'; |
|
52 | - |
|
53 | - /** |
|
54 | - * {@inheritdoc} |
|
55 | - */ |
|
56 | - protected $apiBaseUrl = 'https://graph.facebook.com/v8.0/'; |
|
57 | - |
|
58 | - /** |
|
59 | - * {@inheritdoc} |
|
60 | - */ |
|
61 | - protected $authorizeUrl = 'https://www.facebook.com/dialog/oauth'; |
|
62 | - |
|
63 | - /** |
|
64 | - * {@inheritdoc} |
|
65 | - */ |
|
66 | - protected $accessTokenUrl = 'https://graph.facebook.com/oauth/access_token'; |
|
67 | - |
|
68 | - /** |
|
69 | - * {@inheritdoc} |
|
70 | - */ |
|
71 | - protected $apiDocumentation = 'https://developers.facebook.com/docs/facebook-login/overview'; |
|
72 | - |
|
73 | - /** |
|
74 | - * @var string Profile URL template as the fallback when no `link` returned from the API. |
|
75 | - */ |
|
76 | - protected $profileUrlTemplate = 'https://www.facebook.com/%s'; |
|
77 | - |
|
78 | - /** |
|
79 | - * {@inheritdoc} |
|
80 | - */ |
|
81 | - protected function initialize() |
|
82 | - { |
|
83 | - parent::initialize(); |
|
84 | - |
|
85 | - // Require proof on all Facebook api calls |
|
86 | - // https://developers.facebook.com/docs/graph-api/securing-requests#appsecret_proof |
|
87 | - if ($accessToken = $this->getStoredData('access_token')) { |
|
88 | - $this->apiRequestParameters['appsecret_proof'] = hash_hmac('sha256', $accessToken, $this->clientSecret); |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * {@inheritdoc} |
|
94 | - */ |
|
95 | - public function maintainToken() |
|
96 | - { |
|
97 | - if (!$this->isConnected()) { |
|
98 | - return; |
|
99 | - } |
|
100 | - |
|
101 | - // Handle token exchange prior to the standard handler for an API request |
|
102 | - $exchange_by_expiry_days = $this->config->get('exchange_by_expiry_days') ?: 45; |
|
103 | - if ($exchange_by_expiry_days !== null) { |
|
104 | - $projected_timestamp = time() + 60 * 60 * 24 * $exchange_by_expiry_days; |
|
105 | - if (!$this->hasAccessTokenExpired() && $this->hasAccessTokenExpired($projected_timestamp)) { |
|
106 | - $this->exchangeAccessToken(); |
|
107 | - } |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Exchange the Access Token with one that expires further in the future. |
|
113 | - * |
|
114 | - * @return string Raw Provider API response |
|
115 | - * @throws \Hybridauth\Exception\HttpClientFailureException |
|
116 | - * @throws \Hybridauth\Exception\HttpRequestFailedException |
|
117 | - * @throws \Hybridauth\Exception\InvalidAccessTokenException |
|
118 | - */ |
|
119 | - public function exchangeAccessToken() |
|
120 | - { |
|
121 | - $exchangeTokenParameters = [ |
|
122 | - 'grant_type' => 'fb_exchange_token', |
|
123 | - 'client_id' => $this->clientId, |
|
124 | - 'client_secret' => $this->clientSecret, |
|
125 | - 'fb_exchange_token' => $this->getStoredData('access_token'), |
|
126 | - ]; |
|
127 | - |
|
128 | - $response = $this->httpClient->request( |
|
129 | - $this->accessTokenUrl, |
|
130 | - 'GET', |
|
131 | - $exchangeTokenParameters |
|
132 | - ); |
|
133 | - |
|
134 | - $this->validateApiResponse('Unable to exchange the access token'); |
|
135 | - |
|
136 | - $this->validateAccessTokenExchange($response); |
|
137 | - |
|
138 | - return $response; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * {@inheritdoc} |
|
143 | - */ |
|
144 | - public function getUserProfile() |
|
145 | - { |
|
146 | - $fields = [ |
|
147 | - 'id', |
|
148 | - 'name', |
|
149 | - 'first_name', |
|
150 | - 'last_name', |
|
151 | - 'website', |
|
152 | - 'locale', |
|
153 | - 'about', |
|
154 | - 'email', |
|
155 | - 'hometown', |
|
156 | - 'birthday', |
|
157 | - ]; |
|
48 | + /** |
|
49 | + * {@inheritdoc} |
|
50 | + */ |
|
51 | + protected $scope = 'email, public_profile'; |
|
52 | + |
|
53 | + /** |
|
54 | + * {@inheritdoc} |
|
55 | + */ |
|
56 | + protected $apiBaseUrl = 'https://graph.facebook.com/v8.0/'; |
|
57 | + |
|
58 | + /** |
|
59 | + * {@inheritdoc} |
|
60 | + */ |
|
61 | + protected $authorizeUrl = 'https://www.facebook.com/dialog/oauth'; |
|
62 | + |
|
63 | + /** |
|
64 | + * {@inheritdoc} |
|
65 | + */ |
|
66 | + protected $accessTokenUrl = 'https://graph.facebook.com/oauth/access_token'; |
|
67 | + |
|
68 | + /** |
|
69 | + * {@inheritdoc} |
|
70 | + */ |
|
71 | + protected $apiDocumentation = 'https://developers.facebook.com/docs/facebook-login/overview'; |
|
72 | + |
|
73 | + /** |
|
74 | + * @var string Profile URL template as the fallback when no `link` returned from the API. |
|
75 | + */ |
|
76 | + protected $profileUrlTemplate = 'https://www.facebook.com/%s'; |
|
77 | + |
|
78 | + /** |
|
79 | + * {@inheritdoc} |
|
80 | + */ |
|
81 | + protected function initialize() |
|
82 | + { |
|
83 | + parent::initialize(); |
|
84 | + |
|
85 | + // Require proof on all Facebook api calls |
|
86 | + // https://developers.facebook.com/docs/graph-api/securing-requests#appsecret_proof |
|
87 | + if ($accessToken = $this->getStoredData('access_token')) { |
|
88 | + $this->apiRequestParameters['appsecret_proof'] = hash_hmac('sha256', $accessToken, $this->clientSecret); |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * {@inheritdoc} |
|
94 | + */ |
|
95 | + public function maintainToken() |
|
96 | + { |
|
97 | + if (!$this->isConnected()) { |
|
98 | + return; |
|
99 | + } |
|
100 | + |
|
101 | + // Handle token exchange prior to the standard handler for an API request |
|
102 | + $exchange_by_expiry_days = $this->config->get('exchange_by_expiry_days') ?: 45; |
|
103 | + if ($exchange_by_expiry_days !== null) { |
|
104 | + $projected_timestamp = time() + 60 * 60 * 24 * $exchange_by_expiry_days; |
|
105 | + if (!$this->hasAccessTokenExpired() && $this->hasAccessTokenExpired($projected_timestamp)) { |
|
106 | + $this->exchangeAccessToken(); |
|
107 | + } |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Exchange the Access Token with one that expires further in the future. |
|
113 | + * |
|
114 | + * @return string Raw Provider API response |
|
115 | + * @throws \Hybridauth\Exception\HttpClientFailureException |
|
116 | + * @throws \Hybridauth\Exception\HttpRequestFailedException |
|
117 | + * @throws \Hybridauth\Exception\InvalidAccessTokenException |
|
118 | + */ |
|
119 | + public function exchangeAccessToken() |
|
120 | + { |
|
121 | + $exchangeTokenParameters = [ |
|
122 | + 'grant_type' => 'fb_exchange_token', |
|
123 | + 'client_id' => $this->clientId, |
|
124 | + 'client_secret' => $this->clientSecret, |
|
125 | + 'fb_exchange_token' => $this->getStoredData('access_token'), |
|
126 | + ]; |
|
127 | + |
|
128 | + $response = $this->httpClient->request( |
|
129 | + $this->accessTokenUrl, |
|
130 | + 'GET', |
|
131 | + $exchangeTokenParameters |
|
132 | + ); |
|
133 | + |
|
134 | + $this->validateApiResponse('Unable to exchange the access token'); |
|
135 | + |
|
136 | + $this->validateAccessTokenExchange($response); |
|
137 | + |
|
138 | + return $response; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * {@inheritdoc} |
|
143 | + */ |
|
144 | + public function getUserProfile() |
|
145 | + { |
|
146 | + $fields = [ |
|
147 | + 'id', |
|
148 | + 'name', |
|
149 | + 'first_name', |
|
150 | + 'last_name', |
|
151 | + 'website', |
|
152 | + 'locale', |
|
153 | + 'about', |
|
154 | + 'email', |
|
155 | + 'hometown', |
|
156 | + 'birthday', |
|
157 | + ]; |
|
158 | 158 | |
159 | - if (strpos($this->scope, 'user_link') !== false) { |
|
160 | - $fields[] = 'link'; |
|
161 | - } |
|
162 | - |
|
163 | - if (strpos($this->scope, 'user_gender') !== false) { |
|
164 | - $fields[] = 'gender'; |
|
165 | - } |
|
166 | - |
|
167 | - // Note that en_US is needed for gender fields to match convention. |
|
168 | - $locale = $this->config->get('locale') ?: 'en_US'; |
|
169 | - $response = $this->apiRequest('me', 'GET', [ |
|
170 | - 'fields' => implode(',', $fields), |
|
171 | - 'locale' => $locale, |
|
172 | - ]); |
|
173 | - |
|
174 | - $data = new Data\Collection($response); |
|
175 | - |
|
176 | - if (!$data->exists('id')) { |
|
177 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
178 | - } |
|
179 | - |
|
180 | - $userProfile = new User\Profile(); |
|
181 | - |
|
182 | - $userProfile->identifier = $data->get('id'); |
|
183 | - $userProfile->displayName = $data->get('name'); |
|
184 | - $userProfile->firstName = $data->get('first_name'); |
|
185 | - $userProfile->lastName = $data->get('last_name'); |
|
186 | - $userProfile->profileURL = $data->get('link'); |
|
187 | - $userProfile->webSiteURL = $data->get('website'); |
|
188 | - $userProfile->gender = $data->get('gender'); |
|
189 | - $userProfile->language = $data->get('locale'); |
|
190 | - $userProfile->description = $data->get('about'); |
|
191 | - $userProfile->email = $data->get('email'); |
|
192 | - |
|
193 | - // Fallback for profile URL in case Facebook does not provide "pretty" link with username (if user set it). |
|
194 | - if (empty($userProfile->profileURL)) { |
|
195 | - $userProfile->profileURL = $this->getProfileUrl($userProfile->identifier); |
|
196 | - } |
|
197 | - |
|
198 | - $userProfile->region = $data->filter('hometown')->get('name'); |
|
199 | - |
|
200 | - $photoSize = $this->config->get('photo_size') ?: '150'; |
|
201 | - |
|
202 | - $userProfile->photoURL = $this->apiBaseUrl . $userProfile->identifier; |
|
203 | - $userProfile->photoURL .= '/picture?width=' . $photoSize . '&height=' . $photoSize; |
|
204 | - |
|
205 | - $userProfile->emailVerified = $userProfile->email; |
|
206 | - |
|
207 | - $userProfile = $this->fetchUserRegion($userProfile); |
|
208 | - |
|
209 | - $userProfile = $this->fetchBirthday($userProfile, $data->get('birthday')); |
|
210 | - |
|
211 | - return $userProfile; |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Retrieve the user region. |
|
216 | - * |
|
217 | - * @param User\Profile $userProfile |
|
218 | - * |
|
219 | - * @return \Hybridauth\User\Profile |
|
220 | - */ |
|
221 | - protected function fetchUserRegion(User\Profile $userProfile) |
|
222 | - { |
|
223 | - if (!empty($userProfile->region)) { |
|
224 | - $regionArr = explode(',', $userProfile->region); |
|
225 | - |
|
226 | - if (count($regionArr) > 1) { |
|
227 | - $userProfile->city = trim($regionArr[0]); |
|
228 | - $userProfile->country = trim($regionArr[1]); |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - return $userProfile; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Retrieve the user birthday. |
|
237 | - * |
|
238 | - * @param User\Profile $userProfile |
|
239 | - * @param string $birthday |
|
240 | - * |
|
241 | - * @return \Hybridauth\User\Profile |
|
242 | - */ |
|
243 | - protected function fetchBirthday(User\Profile $userProfile, $birthday) |
|
244 | - { |
|
245 | - $result = (new Data\Parser())->parseBirthday($birthday); |
|
246 | - |
|
247 | - $userProfile->birthYear = (int)$result[0]; |
|
248 | - $userProfile->birthMonth = (int)$result[1]; |
|
249 | - $userProfile->birthDay = (int)$result[2]; |
|
250 | - |
|
251 | - return $userProfile; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * /v2.0/me/friends only returns the user's friends who also use the app. |
|
256 | - * In the cases where you want to let people tag their friends in stories published by your app, |
|
257 | - * you can use the Taggable Friends API. |
|
258 | - * |
|
259 | - * https://developers.facebook.com/docs/apps/faq#unable_full_friend_list |
|
260 | - */ |
|
261 | - public function getUserContacts() |
|
262 | - { |
|
263 | - $contacts = []; |
|
264 | - |
|
265 | - $apiUrl = 'me/friends?fields=link,name'; |
|
266 | - |
|
267 | - do { |
|
268 | - $response = $this->apiRequest($apiUrl); |
|
269 | - |
|
270 | - $data = new Data\Collection($response); |
|
271 | - |
|
272 | - if (!$data->exists('data')) { |
|
273 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
274 | - } |
|
275 | - |
|
276 | - if (!$data->filter('data')->isEmpty()) { |
|
277 | - foreach ($data->filter('data')->toArray() as $item) { |
|
278 | - $contacts[] = $this->fetchUserContact($item); |
|
279 | - } |
|
280 | - } |
|
281 | - |
|
282 | - if ($data->filter('paging')->exists('next')) { |
|
283 | - $apiUrl = $data->filter('paging')->get('next'); |
|
284 | - |
|
285 | - $pagedList = true; |
|
286 | - } else { |
|
287 | - $pagedList = false; |
|
288 | - } |
|
289 | - } while ($pagedList); |
|
290 | - |
|
291 | - return $contacts; |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * Parse the user contact. |
|
296 | - * |
|
297 | - * @param array $item |
|
298 | - * |
|
299 | - * @return \Hybridauth\User\Contact |
|
300 | - */ |
|
301 | - protected function fetchUserContact($item) |
|
302 | - { |
|
303 | - $userContact = new User\Contact(); |
|
304 | - |
|
305 | - $item = new Data\Collection($item); |
|
306 | - |
|
307 | - $userContact->identifier = $item->get('id'); |
|
308 | - $userContact->displayName = $item->get('name'); |
|
309 | - |
|
310 | - $userContact->profileURL = $item->exists('link') |
|
311 | - ?: $this->getProfileUrl($userContact->identifier); |
|
312 | - |
|
313 | - $userContact->photoURL = $this->apiBaseUrl . $userContact->identifier . '/picture?width=150&height=150'; |
|
314 | - |
|
315 | - return $userContact; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * {@inheritdoc} |
|
320 | - */ |
|
321 | - public function setPageStatus($status, $pageId) |
|
322 | - { |
|
323 | - $status = is_string($status) ? ['message' => $status] : $status; |
|
324 | - |
|
325 | - // Post on user wall. |
|
326 | - if ($pageId === 'me') { |
|
327 | - return $this->setUserStatus($status); |
|
328 | - } |
|
329 | - |
|
330 | - // Retrieve writable user pages and filter by given one. |
|
331 | - $pages = $this->getUserPages(true); |
|
332 | - $pages = array_filter($pages, function ($page) use ($pageId) { |
|
333 | - return $page->id == $pageId; |
|
334 | - }); |
|
335 | - |
|
336 | - if (!$pages) { |
|
337 | - throw new InvalidArgumentException('Could not find a page with given id.'); |
|
338 | - } |
|
339 | - |
|
340 | - $page = reset($pages); |
|
341 | - |
|
342 | - // Use page access token instead of user access token. |
|
343 | - $headers = [ |
|
344 | - 'Authorization' => 'Bearer ' . $page->access_token, |
|
345 | - ]; |
|
346 | - |
|
347 | - // Refresh proof for API call. |
|
348 | - $parameters = $status + [ |
|
349 | - 'appsecret_proof' => hash_hmac('sha256', $page->access_token, $this->clientSecret), |
|
350 | - ]; |
|
351 | - |
|
352 | - $response = $this->apiRequest("{$pageId}/feed", 'POST', $parameters, $headers); |
|
353 | - |
|
354 | - return $response; |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * {@inheritdoc} |
|
359 | - */ |
|
360 | - public function getUserPages($writable = false) |
|
361 | - { |
|
362 | - $pages = $this->apiRequest('me/accounts'); |
|
363 | - |
|
364 | - if (!$writable) { |
|
365 | - return $pages->data; |
|
366 | - } |
|
367 | - |
|
368 | - // Filter user pages by CREATE_CONTENT permission. |
|
369 | - return array_filter($pages->data, function ($page) { |
|
370 | - return in_array('CREATE_CONTENT', $page->tasks); |
|
371 | - }); |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * {@inheritdoc} |
|
376 | - */ |
|
377 | - public function getUserActivity($stream = 'me') |
|
378 | - { |
|
379 | - $apiUrl = $stream == 'me' ? 'me/feed' : 'me/home'; |
|
380 | - |
|
381 | - $response = $this->apiRequest($apiUrl); |
|
382 | - |
|
383 | - $data = new Data\Collection($response); |
|
384 | - |
|
385 | - if (!$data->exists('data')) { |
|
386 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
387 | - } |
|
388 | - |
|
389 | - $activities = []; |
|
390 | - |
|
391 | - foreach ($data->filter('data')->toArray() as $item) { |
|
392 | - $activities[] = $this->fetchUserActivity($item); |
|
393 | - } |
|
394 | - |
|
395 | - return $activities; |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * @param $item |
|
400 | - * |
|
401 | - * @return User\Activity |
|
402 | - */ |
|
403 | - protected function fetchUserActivity($item) |
|
404 | - { |
|
405 | - $userActivity = new User\Activity(); |
|
406 | - |
|
407 | - $item = new Data\Collection($item); |
|
408 | - |
|
409 | - $userActivity->id = $item->get('id'); |
|
410 | - $userActivity->date = $item->get('created_time'); |
|
411 | - |
|
412 | - if ('video' == $item->get('type') || 'link' == $item->get('type')) { |
|
413 | - $userActivity->text = $item->get('link'); |
|
414 | - } |
|
415 | - |
|
416 | - if (empty($userActivity->text) && $item->exists('story')) { |
|
417 | - $userActivity->text = $item->get('link'); |
|
418 | - } |
|
419 | - |
|
420 | - if (empty($userActivity->text) && $item->exists('message')) { |
|
421 | - $userActivity->text = $item->get('message'); |
|
422 | - } |
|
423 | - |
|
424 | - if (!empty($userActivity->text) && $item->exists('from')) { |
|
425 | - $userActivity->user->identifier = $item->filter('from')->get('id'); |
|
426 | - $userActivity->user->displayName = $item->filter('from')->get('name'); |
|
427 | - |
|
428 | - $userActivity->user->profileURL = $this->getProfileUrl($userActivity->user->identifier); |
|
429 | - |
|
430 | - $userActivity->user->photoURL = $this->apiBaseUrl . $userActivity->user->identifier; |
|
431 | - $userActivity->user->photoURL .= '/picture?width=150&height=150'; |
|
432 | - } |
|
433 | - |
|
434 | - return $userActivity; |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Get profile URL. |
|
439 | - * |
|
440 | - * @param int $identity User ID. |
|
441 | - * @return string|null NULL when identity is not provided. |
|
442 | - */ |
|
443 | - protected function getProfileUrl($identity) |
|
444 | - { |
|
445 | - if (!is_numeric($identity)) { |
|
446 | - return null; |
|
447 | - } |
|
448 | - |
|
449 | - return sprintf($this->profileUrlTemplate, $identity); |
|
450 | - } |
|
159 | + if (strpos($this->scope, 'user_link') !== false) { |
|
160 | + $fields[] = 'link'; |
|
161 | + } |
|
162 | + |
|
163 | + if (strpos($this->scope, 'user_gender') !== false) { |
|
164 | + $fields[] = 'gender'; |
|
165 | + } |
|
166 | + |
|
167 | + // Note that en_US is needed for gender fields to match convention. |
|
168 | + $locale = $this->config->get('locale') ?: 'en_US'; |
|
169 | + $response = $this->apiRequest('me', 'GET', [ |
|
170 | + 'fields' => implode(',', $fields), |
|
171 | + 'locale' => $locale, |
|
172 | + ]); |
|
173 | + |
|
174 | + $data = new Data\Collection($response); |
|
175 | + |
|
176 | + if (!$data->exists('id')) { |
|
177 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
178 | + } |
|
179 | + |
|
180 | + $userProfile = new User\Profile(); |
|
181 | + |
|
182 | + $userProfile->identifier = $data->get('id'); |
|
183 | + $userProfile->displayName = $data->get('name'); |
|
184 | + $userProfile->firstName = $data->get('first_name'); |
|
185 | + $userProfile->lastName = $data->get('last_name'); |
|
186 | + $userProfile->profileURL = $data->get('link'); |
|
187 | + $userProfile->webSiteURL = $data->get('website'); |
|
188 | + $userProfile->gender = $data->get('gender'); |
|
189 | + $userProfile->language = $data->get('locale'); |
|
190 | + $userProfile->description = $data->get('about'); |
|
191 | + $userProfile->email = $data->get('email'); |
|
192 | + |
|
193 | + // Fallback for profile URL in case Facebook does not provide "pretty" link with username (if user set it). |
|
194 | + if (empty($userProfile->profileURL)) { |
|
195 | + $userProfile->profileURL = $this->getProfileUrl($userProfile->identifier); |
|
196 | + } |
|
197 | + |
|
198 | + $userProfile->region = $data->filter('hometown')->get('name'); |
|
199 | + |
|
200 | + $photoSize = $this->config->get('photo_size') ?: '150'; |
|
201 | + |
|
202 | + $userProfile->photoURL = $this->apiBaseUrl . $userProfile->identifier; |
|
203 | + $userProfile->photoURL .= '/picture?width=' . $photoSize . '&height=' . $photoSize; |
|
204 | + |
|
205 | + $userProfile->emailVerified = $userProfile->email; |
|
206 | + |
|
207 | + $userProfile = $this->fetchUserRegion($userProfile); |
|
208 | + |
|
209 | + $userProfile = $this->fetchBirthday($userProfile, $data->get('birthday')); |
|
210 | + |
|
211 | + return $userProfile; |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Retrieve the user region. |
|
216 | + * |
|
217 | + * @param User\Profile $userProfile |
|
218 | + * |
|
219 | + * @return \Hybridauth\User\Profile |
|
220 | + */ |
|
221 | + protected function fetchUserRegion(User\Profile $userProfile) |
|
222 | + { |
|
223 | + if (!empty($userProfile->region)) { |
|
224 | + $regionArr = explode(',', $userProfile->region); |
|
225 | + |
|
226 | + if (count($regionArr) > 1) { |
|
227 | + $userProfile->city = trim($regionArr[0]); |
|
228 | + $userProfile->country = trim($regionArr[1]); |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + return $userProfile; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Retrieve the user birthday. |
|
237 | + * |
|
238 | + * @param User\Profile $userProfile |
|
239 | + * @param string $birthday |
|
240 | + * |
|
241 | + * @return \Hybridauth\User\Profile |
|
242 | + */ |
|
243 | + protected function fetchBirthday(User\Profile $userProfile, $birthday) |
|
244 | + { |
|
245 | + $result = (new Data\Parser())->parseBirthday($birthday); |
|
246 | + |
|
247 | + $userProfile->birthYear = (int)$result[0]; |
|
248 | + $userProfile->birthMonth = (int)$result[1]; |
|
249 | + $userProfile->birthDay = (int)$result[2]; |
|
250 | + |
|
251 | + return $userProfile; |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * /v2.0/me/friends only returns the user's friends who also use the app. |
|
256 | + * In the cases where you want to let people tag their friends in stories published by your app, |
|
257 | + * you can use the Taggable Friends API. |
|
258 | + * |
|
259 | + * https://developers.facebook.com/docs/apps/faq#unable_full_friend_list |
|
260 | + */ |
|
261 | + public function getUserContacts() |
|
262 | + { |
|
263 | + $contacts = []; |
|
264 | + |
|
265 | + $apiUrl = 'me/friends?fields=link,name'; |
|
266 | + |
|
267 | + do { |
|
268 | + $response = $this->apiRequest($apiUrl); |
|
269 | + |
|
270 | + $data = new Data\Collection($response); |
|
271 | + |
|
272 | + if (!$data->exists('data')) { |
|
273 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
274 | + } |
|
275 | + |
|
276 | + if (!$data->filter('data')->isEmpty()) { |
|
277 | + foreach ($data->filter('data')->toArray() as $item) { |
|
278 | + $contacts[] = $this->fetchUserContact($item); |
|
279 | + } |
|
280 | + } |
|
281 | + |
|
282 | + if ($data->filter('paging')->exists('next')) { |
|
283 | + $apiUrl = $data->filter('paging')->get('next'); |
|
284 | + |
|
285 | + $pagedList = true; |
|
286 | + } else { |
|
287 | + $pagedList = false; |
|
288 | + } |
|
289 | + } while ($pagedList); |
|
290 | + |
|
291 | + return $contacts; |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * Parse the user contact. |
|
296 | + * |
|
297 | + * @param array $item |
|
298 | + * |
|
299 | + * @return \Hybridauth\User\Contact |
|
300 | + */ |
|
301 | + protected function fetchUserContact($item) |
|
302 | + { |
|
303 | + $userContact = new User\Contact(); |
|
304 | + |
|
305 | + $item = new Data\Collection($item); |
|
306 | + |
|
307 | + $userContact->identifier = $item->get('id'); |
|
308 | + $userContact->displayName = $item->get('name'); |
|
309 | + |
|
310 | + $userContact->profileURL = $item->exists('link') |
|
311 | + ?: $this->getProfileUrl($userContact->identifier); |
|
312 | + |
|
313 | + $userContact->photoURL = $this->apiBaseUrl . $userContact->identifier . '/picture?width=150&height=150'; |
|
314 | + |
|
315 | + return $userContact; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * {@inheritdoc} |
|
320 | + */ |
|
321 | + public function setPageStatus($status, $pageId) |
|
322 | + { |
|
323 | + $status = is_string($status) ? ['message' => $status] : $status; |
|
324 | + |
|
325 | + // Post on user wall. |
|
326 | + if ($pageId === 'me') { |
|
327 | + return $this->setUserStatus($status); |
|
328 | + } |
|
329 | + |
|
330 | + // Retrieve writable user pages and filter by given one. |
|
331 | + $pages = $this->getUserPages(true); |
|
332 | + $pages = array_filter($pages, function ($page) use ($pageId) { |
|
333 | + return $page->id == $pageId; |
|
334 | + }); |
|
335 | + |
|
336 | + if (!$pages) { |
|
337 | + throw new InvalidArgumentException('Could not find a page with given id.'); |
|
338 | + } |
|
339 | + |
|
340 | + $page = reset($pages); |
|
341 | + |
|
342 | + // Use page access token instead of user access token. |
|
343 | + $headers = [ |
|
344 | + 'Authorization' => 'Bearer ' . $page->access_token, |
|
345 | + ]; |
|
346 | + |
|
347 | + // Refresh proof for API call. |
|
348 | + $parameters = $status + [ |
|
349 | + 'appsecret_proof' => hash_hmac('sha256', $page->access_token, $this->clientSecret), |
|
350 | + ]; |
|
351 | + |
|
352 | + $response = $this->apiRequest("{$pageId}/feed", 'POST', $parameters, $headers); |
|
353 | + |
|
354 | + return $response; |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * {@inheritdoc} |
|
359 | + */ |
|
360 | + public function getUserPages($writable = false) |
|
361 | + { |
|
362 | + $pages = $this->apiRequest('me/accounts'); |
|
363 | + |
|
364 | + if (!$writable) { |
|
365 | + return $pages->data; |
|
366 | + } |
|
367 | + |
|
368 | + // Filter user pages by CREATE_CONTENT permission. |
|
369 | + return array_filter($pages->data, function ($page) { |
|
370 | + return in_array('CREATE_CONTENT', $page->tasks); |
|
371 | + }); |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * {@inheritdoc} |
|
376 | + */ |
|
377 | + public function getUserActivity($stream = 'me') |
|
378 | + { |
|
379 | + $apiUrl = $stream == 'me' ? 'me/feed' : 'me/home'; |
|
380 | + |
|
381 | + $response = $this->apiRequest($apiUrl); |
|
382 | + |
|
383 | + $data = new Data\Collection($response); |
|
384 | + |
|
385 | + if (!$data->exists('data')) { |
|
386 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
387 | + } |
|
388 | + |
|
389 | + $activities = []; |
|
390 | + |
|
391 | + foreach ($data->filter('data')->toArray() as $item) { |
|
392 | + $activities[] = $this->fetchUserActivity($item); |
|
393 | + } |
|
394 | + |
|
395 | + return $activities; |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * @param $item |
|
400 | + * |
|
401 | + * @return User\Activity |
|
402 | + */ |
|
403 | + protected function fetchUserActivity($item) |
|
404 | + { |
|
405 | + $userActivity = new User\Activity(); |
|
406 | + |
|
407 | + $item = new Data\Collection($item); |
|
408 | + |
|
409 | + $userActivity->id = $item->get('id'); |
|
410 | + $userActivity->date = $item->get('created_time'); |
|
411 | + |
|
412 | + if ('video' == $item->get('type') || 'link' == $item->get('type')) { |
|
413 | + $userActivity->text = $item->get('link'); |
|
414 | + } |
|
415 | + |
|
416 | + if (empty($userActivity->text) && $item->exists('story')) { |
|
417 | + $userActivity->text = $item->get('link'); |
|
418 | + } |
|
419 | + |
|
420 | + if (empty($userActivity->text) && $item->exists('message')) { |
|
421 | + $userActivity->text = $item->get('message'); |
|
422 | + } |
|
423 | + |
|
424 | + if (!empty($userActivity->text) && $item->exists('from')) { |
|
425 | + $userActivity->user->identifier = $item->filter('from')->get('id'); |
|
426 | + $userActivity->user->displayName = $item->filter('from')->get('name'); |
|
427 | + |
|
428 | + $userActivity->user->profileURL = $this->getProfileUrl($userActivity->user->identifier); |
|
429 | + |
|
430 | + $userActivity->user->photoURL = $this->apiBaseUrl . $userActivity->user->identifier; |
|
431 | + $userActivity->user->photoURL .= '/picture?width=150&height=150'; |
|
432 | + } |
|
433 | + |
|
434 | + return $userActivity; |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Get profile URL. |
|
439 | + * |
|
440 | + * @param int $identity User ID. |
|
441 | + * @return string|null NULL when identity is not provided. |
|
442 | + */ |
|
443 | + protected function getProfileUrl($identity) |
|
444 | + { |
|
445 | + if (!is_numeric($identity)) { |
|
446 | + return null; |
|
447 | + } |
|
448 | + |
|
449 | + return sprintf($this->profileUrlTemplate, $identity); |
|
450 | + } |
|
451 | 451 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function maintainToken() |
96 | 96 | { |
97 | - if (!$this->isConnected()) { |
|
97 | + if ( ! $this->isConnected()) { |
|
98 | 98 | return; |
99 | 99 | } |
100 | 100 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | $exchange_by_expiry_days = $this->config->get('exchange_by_expiry_days') ?: 45; |
103 | 103 | if ($exchange_by_expiry_days !== null) { |
104 | 104 | $projected_timestamp = time() + 60 * 60 * 24 * $exchange_by_expiry_days; |
105 | - if (!$this->hasAccessTokenExpired() && $this->hasAccessTokenExpired($projected_timestamp)) { |
|
105 | + if ( ! $this->hasAccessTokenExpired() && $this->hasAccessTokenExpired($projected_timestamp)) { |
|
106 | 106 | $this->exchangeAccessToken(); |
107 | 107 | } |
108 | 108 | } |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | |
174 | 174 | $data = new Data\Collection($response); |
175 | 175 | |
176 | - if (!$data->exists('id')) { |
|
176 | + if ( ! $data->exists('id')) { |
|
177 | 177 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
178 | 178 | } |
179 | 179 | |
@@ -199,8 +199,8 @@ discard block |
||
199 | 199 | |
200 | 200 | $photoSize = $this->config->get('photo_size') ?: '150'; |
201 | 201 | |
202 | - $userProfile->photoURL = $this->apiBaseUrl . $userProfile->identifier; |
|
203 | - $userProfile->photoURL .= '/picture?width=' . $photoSize . '&height=' . $photoSize; |
|
202 | + $userProfile->photoURL = $this->apiBaseUrl.$userProfile->identifier; |
|
203 | + $userProfile->photoURL .= '/picture?width='.$photoSize.'&height='.$photoSize; |
|
204 | 204 | |
205 | 205 | $userProfile->emailVerified = $userProfile->email; |
206 | 206 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | */ |
221 | 221 | protected function fetchUserRegion(User\Profile $userProfile) |
222 | 222 | { |
223 | - if (!empty($userProfile->region)) { |
|
223 | + if ( ! empty($userProfile->region)) { |
|
224 | 224 | $regionArr = explode(',', $userProfile->region); |
225 | 225 | |
226 | 226 | if (count($regionArr) > 1) { |
@@ -244,9 +244,9 @@ discard block |
||
244 | 244 | { |
245 | 245 | $result = (new Data\Parser())->parseBirthday($birthday); |
246 | 246 | |
247 | - $userProfile->birthYear = (int)$result[0]; |
|
248 | - $userProfile->birthMonth = (int)$result[1]; |
|
249 | - $userProfile->birthDay = (int)$result[2]; |
|
247 | + $userProfile->birthYear = (int) $result[0]; |
|
248 | + $userProfile->birthMonth = (int) $result[1]; |
|
249 | + $userProfile->birthDay = (int) $result[2]; |
|
250 | 250 | |
251 | 251 | return $userProfile; |
252 | 252 | } |
@@ -269,11 +269,11 @@ discard block |
||
269 | 269 | |
270 | 270 | $data = new Data\Collection($response); |
271 | 271 | |
272 | - if (!$data->exists('data')) { |
|
272 | + if ( ! $data->exists('data')) { |
|
273 | 273 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
274 | 274 | } |
275 | 275 | |
276 | - if (!$data->filter('data')->isEmpty()) { |
|
276 | + if ( ! $data->filter('data')->isEmpty()) { |
|
277 | 277 | foreach ($data->filter('data')->toArray() as $item) { |
278 | 278 | $contacts[] = $this->fetchUserContact($item); |
279 | 279 | } |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | $userContact->profileURL = $item->exists('link') |
311 | 311 | ?: $this->getProfileUrl($userContact->identifier); |
312 | 312 | |
313 | - $userContact->photoURL = $this->apiBaseUrl . $userContact->identifier . '/picture?width=150&height=150'; |
|
313 | + $userContact->photoURL = $this->apiBaseUrl.$userContact->identifier.'/picture?width=150&height=150'; |
|
314 | 314 | |
315 | 315 | return $userContact; |
316 | 316 | } |
@@ -329,11 +329,11 @@ discard block |
||
329 | 329 | |
330 | 330 | // Retrieve writable user pages and filter by given one. |
331 | 331 | $pages = $this->getUserPages(true); |
332 | - $pages = array_filter($pages, function ($page) use ($pageId) { |
|
332 | + $pages = array_filter($pages, function($page) use ($pageId) { |
|
333 | 333 | return $page->id == $pageId; |
334 | 334 | }); |
335 | 335 | |
336 | - if (!$pages) { |
|
336 | + if ( ! $pages) { |
|
337 | 337 | throw new InvalidArgumentException('Could not find a page with given id.'); |
338 | 338 | } |
339 | 339 | |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | |
342 | 342 | // Use page access token instead of user access token. |
343 | 343 | $headers = [ |
344 | - 'Authorization' => 'Bearer ' . $page->access_token, |
|
344 | + 'Authorization' => 'Bearer '.$page->access_token, |
|
345 | 345 | ]; |
346 | 346 | |
347 | 347 | // Refresh proof for API call. |
@@ -361,12 +361,12 @@ discard block |
||
361 | 361 | { |
362 | 362 | $pages = $this->apiRequest('me/accounts'); |
363 | 363 | |
364 | - if (!$writable) { |
|
364 | + if ( ! $writable) { |
|
365 | 365 | return $pages->data; |
366 | 366 | } |
367 | 367 | |
368 | 368 | // Filter user pages by CREATE_CONTENT permission. |
369 | - return array_filter($pages->data, function ($page) { |
|
369 | + return array_filter($pages->data, function($page) { |
|
370 | 370 | return in_array('CREATE_CONTENT', $page->tasks); |
371 | 371 | }); |
372 | 372 | } |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | |
383 | 383 | $data = new Data\Collection($response); |
384 | 384 | |
385 | - if (!$data->exists('data')) { |
|
385 | + if ( ! $data->exists('data')) { |
|
386 | 386 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
387 | 387 | } |
388 | 388 | |
@@ -421,13 +421,13 @@ discard block |
||
421 | 421 | $userActivity->text = $item->get('message'); |
422 | 422 | } |
423 | 423 | |
424 | - if (!empty($userActivity->text) && $item->exists('from')) { |
|
424 | + if ( ! empty($userActivity->text) && $item->exists('from')) { |
|
425 | 425 | $userActivity->user->identifier = $item->filter('from')->get('id'); |
426 | 426 | $userActivity->user->displayName = $item->filter('from')->get('name'); |
427 | 427 | |
428 | 428 | $userActivity->user->profileURL = $this->getProfileUrl($userActivity->user->identifier); |
429 | 429 | |
430 | - $userActivity->user->photoURL = $this->apiBaseUrl . $userActivity->user->identifier; |
|
430 | + $userActivity->user->photoURL = $this->apiBaseUrl.$userActivity->user->identifier; |
|
431 | 431 | $userActivity->user->photoURL .= '/picture?width=150&height=150'; |
432 | 432 | } |
433 | 433 | |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | */ |
443 | 443 | protected function getProfileUrl($identity) |
444 | 444 | { |
445 | - if (!is_numeric($identity)) { |
|
445 | + if ( ! is_numeric($identity)) { |
|
446 | 446 | return null; |
447 | 447 | } |
448 | 448 |
@@ -17,77 +17,77 @@ |
||
17 | 17 | */ |
18 | 18 | class Spotify extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $scope = 'user-read-email'; |
|
24 | - |
|
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - public $apiBaseUrl = 'https://api.spotify.com/v1/'; |
|
29 | - |
|
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - public $authorizeUrl = 'https://accounts.spotify.com/authorize'; |
|
34 | - |
|
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $accessTokenUrl = 'https://accounts.spotify.com/api/token'; |
|
39 | - |
|
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - protected $apiDocumentation = 'https://developer.spotify.com/documentation/general/guides/authorization-guide/'; |
|
44 | - |
|
45 | - /** |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function getUserProfile() |
|
49 | - { |
|
50 | - $response = $this->apiRequest('me'); |
|
51 | - |
|
52 | - $data = new Data\Collection($response); |
|
53 | - |
|
54 | - if (!$data->exists('id')) { |
|
55 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
56 | - } |
|
57 | - |
|
58 | - $userProfile = new User\Profile(); |
|
59 | - |
|
60 | - $userProfile->identifier = $data->get('id'); |
|
61 | - $userProfile->displayName = $data->get('display_name'); |
|
62 | - $userProfile->email = $data->get('email'); |
|
63 | - $userProfile->emailVerified = $data->get('email'); |
|
64 | - $userProfile->profileURL = $data->filter('external_urls')->get('spotify'); |
|
65 | - $userProfile->photoURL = $data->filter('images')->get('url'); |
|
66 | - $userProfile->country = $data->get('country'); |
|
67 | - |
|
68 | - if ($data->exists('birthdate')) { |
|
69 | - $this->fetchBirthday($userProfile, $data->get('birthdate')); |
|
70 | - } |
|
71 | - |
|
72 | - return $userProfile; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Fetch use birthday |
|
77 | - * |
|
78 | - * @param User\Profile $userProfile |
|
79 | - * @param $birthday |
|
80 | - * |
|
81 | - * @return User\Profile |
|
82 | - */ |
|
83 | - protected function fetchBirthday(User\Profile $userProfile, $birthday) |
|
84 | - { |
|
85 | - $result = (new Data\Parser())->parseBirthday($birthday); |
|
86 | - |
|
87 | - $userProfile->birthDay = (int)$result[0]; |
|
88 | - $userProfile->birthMonth = (int)$result[1]; |
|
89 | - $userProfile->birthYear = (int)$result[2]; |
|
90 | - |
|
91 | - return $userProfile; |
|
92 | - } |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $scope = 'user-read-email'; |
|
24 | + |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + public $apiBaseUrl = 'https://api.spotify.com/v1/'; |
|
29 | + |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + public $authorizeUrl = 'https://accounts.spotify.com/authorize'; |
|
34 | + |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $accessTokenUrl = 'https://accounts.spotify.com/api/token'; |
|
39 | + |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + protected $apiDocumentation = 'https://developer.spotify.com/documentation/general/guides/authorization-guide/'; |
|
44 | + |
|
45 | + /** |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function getUserProfile() |
|
49 | + { |
|
50 | + $response = $this->apiRequest('me'); |
|
51 | + |
|
52 | + $data = new Data\Collection($response); |
|
53 | + |
|
54 | + if (!$data->exists('id')) { |
|
55 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
56 | + } |
|
57 | + |
|
58 | + $userProfile = new User\Profile(); |
|
59 | + |
|
60 | + $userProfile->identifier = $data->get('id'); |
|
61 | + $userProfile->displayName = $data->get('display_name'); |
|
62 | + $userProfile->email = $data->get('email'); |
|
63 | + $userProfile->emailVerified = $data->get('email'); |
|
64 | + $userProfile->profileURL = $data->filter('external_urls')->get('spotify'); |
|
65 | + $userProfile->photoURL = $data->filter('images')->get('url'); |
|
66 | + $userProfile->country = $data->get('country'); |
|
67 | + |
|
68 | + if ($data->exists('birthdate')) { |
|
69 | + $this->fetchBirthday($userProfile, $data->get('birthdate')); |
|
70 | + } |
|
71 | + |
|
72 | + return $userProfile; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Fetch use birthday |
|
77 | + * |
|
78 | + * @param User\Profile $userProfile |
|
79 | + * @param $birthday |
|
80 | + * |
|
81 | + * @return User\Profile |
|
82 | + */ |
|
83 | + protected function fetchBirthday(User\Profile $userProfile, $birthday) |
|
84 | + { |
|
85 | + $result = (new Data\Parser())->parseBirthday($birthday); |
|
86 | + |
|
87 | + $userProfile->birthDay = (int)$result[0]; |
|
88 | + $userProfile->birthMonth = (int)$result[1]; |
|
89 | + $userProfile->birthYear = (int)$result[2]; |
|
90 | + |
|
91 | + return $userProfile; |
|
92 | + } |
|
93 | 93 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | $data = new Data\Collection($response); |
53 | 53 | |
54 | - if (!$data->exists('id')) { |
|
54 | + if ( ! $data->exists('id')) { |
|
55 | 55 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
56 | 56 | } |
57 | 57 | |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | { |
85 | 85 | $result = (new Data\Parser())->parseBirthday($birthday); |
86 | 86 | |
87 | - $userProfile->birthDay = (int)$result[0]; |
|
88 | - $userProfile->birthMonth = (int)$result[1]; |
|
89 | - $userProfile->birthYear = (int)$result[2]; |
|
87 | + $userProfile->birthDay = (int) $result[0]; |
|
88 | + $userProfile->birthMonth = (int) $result[1]; |
|
89 | + $userProfile->birthYear = (int) $result[2]; |
|
90 | 90 | |
91 | 91 | return $userProfile; |
92 | 92 | } |
@@ -17,47 +17,47 @@ |
||
17 | 17 | */ |
18 | 18 | class Seznam extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $apiBaseUrl = 'https://login.szn.cz/'; |
|
24 | - |
|
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $authorizeUrl = 'https://login.szn.cz/api/v1/oauth/auth'; |
|
29 | - |
|
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $accessTokenUrl = 'https://login.szn.cz/api/v1/oauth/token'; |
|
34 | - |
|
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $apiDocumentation = 'https://vyvojari.seznam.cz/oauth/doc'; |
|
39 | - |
|
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - public function getUserProfile() |
|
44 | - { |
|
45 | - $response = $this->apiRequest('api/v1/user', 'GET', ['format' => 'json']); |
|
46 | - |
|
47 | - $data = new Data\Collection($response); |
|
48 | - |
|
49 | - if (!$data->exists('oauth_user_id')) { |
|
50 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
51 | - } |
|
52 | - |
|
53 | - $userProfile = new User\Profile(); |
|
54 | - |
|
55 | - $userProfile->identifier = $data->get('oauth_user_id'); |
|
56 | - $userProfile->email = $data->get('account_name'); |
|
57 | - $userProfile->firstName = $data->get('firstname'); |
|
58 | - $userProfile->lastName = $data->get('lastname'); |
|
59 | - $userProfile->photoURL = $data->get('avatar_url'); |
|
60 | - |
|
61 | - return $userProfile; |
|
62 | - } |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $apiBaseUrl = 'https://login.szn.cz/'; |
|
24 | + |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $authorizeUrl = 'https://login.szn.cz/api/v1/oauth/auth'; |
|
29 | + |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $accessTokenUrl = 'https://login.szn.cz/api/v1/oauth/token'; |
|
34 | + |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $apiDocumentation = 'https://vyvojari.seznam.cz/oauth/doc'; |
|
39 | + |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + public function getUserProfile() |
|
44 | + { |
|
45 | + $response = $this->apiRequest('api/v1/user', 'GET', ['format' => 'json']); |
|
46 | + |
|
47 | + $data = new Data\Collection($response); |
|
48 | + |
|
49 | + if (!$data->exists('oauth_user_id')) { |
|
50 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
51 | + } |
|
52 | + |
|
53 | + $userProfile = new User\Profile(); |
|
54 | + |
|
55 | + $userProfile->identifier = $data->get('oauth_user_id'); |
|
56 | + $userProfile->email = $data->get('account_name'); |
|
57 | + $userProfile->firstName = $data->get('firstname'); |
|
58 | + $userProfile->lastName = $data->get('lastname'); |
|
59 | + $userProfile->photoURL = $data->get('avatar_url'); |
|
60 | + |
|
61 | + return $userProfile; |
|
62 | + } |
|
63 | 63 | } |
@@ -46,7 +46,7 @@ |
||
46 | 46 | |
47 | 47 | $data = new Data\Collection($response); |
48 | 48 | |
49 | - if (!$data->exists('oauth_user_id')) { |
|
49 | + if ( ! $data->exists('oauth_user_id')) { |
|
50 | 50 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
51 | 51 | } |
52 | 52 |