users.php
10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<?php
/**
* @package Joomla.Platform
* @subpackage Twitter
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die();
/**
* Twitter API Users class for the Joomla Platform.
*
* @since 3.1.4
* @deprecated 4.0 Use the `joomla/twitter` package via Composer instead
*/
class JTwitterUsers extends JTwitterObject
{
/**
* Method to get up to 100 users worth of extended information, specified by either ID, screen name, or combination of the two.
*
* @param string $screen_name A comma separated list of screen names, up to 100 are allowed in a single request.
* @param string $id A comma separated list of user IDs, up to 100 are allowed in a single request.
* @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a variety of
* metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
*
* @return array The decoded JSON response
*
* @since 3.1.4
* @throws RuntimeException
*/
public function getUsersLookup($screen_name = null, $id = null, $entities = null)
{
// Check the rate limit for remaining hits
$this->checkRateLimit('users', 'lookup');
// Set user IDs and screen names.
if ($id)
{
$data['user_id'] = $id;
}
if ($screen_name)
{
$data['screen_name'] = $screen_name;
}
if ($id == null && $screen_name == null)
{
// We don't have a valid entry
throw new RuntimeException('You must specify either a comma separated list of screen names, user IDs, or a combination of the two');
}
// Set the API path
$path = '/users/lookup.json';
// Check if string_ids is specified
if (!is_null($entities))
{
$data['include_entities'] = $entities;
}
// Send the request.
return $this->sendRequest($path, 'POST', $data);
}
/**
* Method to access the profile banner in various sizes for the user with the indicated screen_name.
*
* @param mixed $user Either an integer containing the user ID or a string containing the screen name.
*
* @return array The decoded JSON response
*
* @since 3.1.4
*/
public function getUserProfileBanner($user)
{
// Check the rate limit for remaining hits
$this->checkRateLimit('users', 'profile_banner');
// Set the API path
$path = '/users/profile_banner.json';
// Determine which type of data was passed for $user
if (is_numeric($user))
{
$data['user_id'] = $user;
}
elseif (is_string($user))
{
$data['screen_name'] = $user;
}
else
{
// We don't have a valid entry
throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
}
// Send the request.
return $this->sendRequest($path, 'GET', $data);
}
/**
* Method used to search for users
*
* @param string $query The search query to run against people search.
* @param integer $page Specifies the page of results to retrieve.
* @param integer $count The number of people to retrieve. Maximum of 20 allowed per page.
* @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a
* variety of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
*
* @return array The decoded JSON response
*
* @since 3.1.4
* @throws RuntimeException
*/
public function searchUsers($query, $page = 0, $count = 0, $entities = null)
{
// Check the rate limit for remaining hits
$this->checkRateLimit('users', 'search');
$data['q'] = rawurlencode($query);
// Check if page is specified.
if ($page > 0)
{
$data['page'] = $page;
}
// Check if per_page is specified
if ($count > 0)
{
$data['count'] = $count;
}
// Check if entities is specified.
if (!is_null($entities))
{
$data['include_entities'] = $entities;
}
// Set the API path
$path = '/users/search.json';
// Send the request.
return $this->sendRequest($path, 'GET', $data);
}
/**
* Method to get extended information of a given user, specified by ID or screen name as per the required id parameter.
*
* @param mixed $user Either an integer containing the user ID or a string containing the screen name.
* @param boolean $entities Set to true to return IDs as strings, false to return as integers.
*
* @return array The decoded JSON response
*
* @since 3.1.4
* @throws RuntimeException
*/
public function getUser($user, $entities = null)
{
// Check the rate limit for remaining hits
$this->checkRateLimit('users', 'show/:id');
// Determine which type of data was passed for $user
if (is_numeric($user))
{
$data['user_id'] = $user;
}
elseif (is_string($user))
{
$data['screen_name'] = $user;
}
else
{
// We don't have a valid entry
throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
}
// Set the API path
$path = '/users/show.json';
// Check if entities is specified
if (!is_null($entities))
{
$data['include_entities'] = $entities;
}
// Send the request.
return $this->sendRequest($path, 'GET', $data);
}
/**
* Method to get an array of users that the specified user can contribute to.
*
* @param mixed $user Either an integer containing the user ID or a string containing the screen name.
* @param boolean $entities Set to true to return IDs as strings, false to return as integers.
* @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
*
* @return array The decoded JSON response
*
* @since 3.1.4
* @throws RuntimeException
*/
public function getContributees($user, $entities = null, $skip_status = null)
{
// Check the rate limit for remaining hits
$this->checkRateLimit('users', 'contributees');
// Determine which type of data was passed for $user
if (is_numeric($user))
{
$data['user_id'] = $user;
}
elseif (is_string($user))
{
$data['screen_name'] = $user;
}
else
{
// We don't have a valid entry
throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
}
// Set the API path
$path = '/users/contributees.json';
// Check if entities is specified
if (!is_null($entities))
{
$data['include_entities'] = $entities;
}
// Check if skip_status is specified
if (!is_null($skip_status))
{
$data['skip_status'] = $skip_status;
}
// Send the request.
return $this->sendRequest($path, 'GET', $data);
}
/**
* Method to get an array of users who can contribute to the specified account.
*
* @param mixed $user Either an integer containing the user ID or a string containing the screen name.
* @param boolean $entities Set to true to return IDs as strings, false to return as integers.
* @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
*
* @return array The decoded JSON response
*
* @since 3.1.4
* @throws RuntimeException
*/
public function getContributors($user, $entities = null, $skip_status = null)
{
// Check the rate limit for remaining hits
$this->checkRateLimit('users', 'contributors');
// Determine which type of data was passed for $user
if (is_numeric($user))
{
$data['user_id'] = $user;
}
elseif (is_string($user))
{
$data['screen_name'] = $user;
}
else
{
// We don't have a valid entry
throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
}
// Set the API path
$path = '/users/contributors.json';
// Check if entities is specified
if (!is_null($entities))
{
$data['include_entities'] = $entities;
}
// Check if skip_status is specified
if (!is_null($skip_status))
{
$data['skip_status'] = $skip_status;
}
// Send the request.
return $this->sendRequest($path, 'GET', $data);
}
/**
* Method access to Twitter's suggested user list.
*
* @param boolean $lang Restricts the suggested categories to the requested language.
*
* @return array The decoded JSON response
*
* @since 3.1.4
*/
public function getSuggestions($lang = null)
{
// Check the rate limit for remaining hits
$this->checkRateLimit('users', 'suggestions');
// Set the API path
$path = '/users/suggestions.json';
$data = array();
// Check if entities is true
if ($lang)
{
$data['lang'] = $lang;
}
// Send the request.
return $this->sendRequest($path, 'GET', $data);
}
/**
* method to access the users in a given category of the Twitter suggested user list.
*
* @param string $slug The short name of list or a category.
* @param boolean $lang Restricts the suggested categories to the requested language.
*
* @return array The decoded JSON response
*
* @since 3.1.4
*/
public function getSuggestionsSlug($slug, $lang = null)
{
// Check the rate limit for remaining hits
$this->checkRateLimit('users', 'suggestions/:slug');
// Set the API path
$path = '/users/suggestions/' . $slug . '.json';
$data = array();
// Check if entities is true
if ($lang)
{
$data['lang'] = $lang;
}
// Send the request.
return $this->sendRequest($path, 'GET', $data);
}
/**
* Method to access the users in a given category of the Twitter suggested user list and return
* their most recent status if they are not a protected user.
*
* @param string $slug The short name of list or a category.
*
* @return array The decoded JSON response
*
* @since 3.1.4
*/
public function getSuggestionsSlugMembers($slug)
{
// Check the rate limit for remaining hits
$this->checkRateLimit('users', 'suggestions/:slug/members');
// Set the API path
$path = '/users/suggestions/' . $slug . '/members.json';
// Send the request.
return $this->sendRequest($path);
}
}