Completed
Push — master ( 4fe511...1ebc20 )
by
unknown
01:51
created
src/Provider/Twitter.php 2 patches
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -40,225 +40,225 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.