PageRenderTime 70ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/joomla/twitter/lists.php

https://bitbucket.org/biojazzard/joomla-eboracast
PHP | 982 lines | 546 code | 101 blank | 335 comment | 63 complexity | 3ece0077b296f342282dadfbd608f99b MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, MIT, BSD-3-Clause
  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Twitter
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die();
  10. /**
  11. * Twitter API Lists class for the Joomla Platform.
  12. *
  13. * @package Joomla.Platform
  14. * @subpackage Twitter
  15. * @since 12.3
  16. */
  17. class JTwitterLists extends JTwitterObject
  18. {
  19. /**
  20. * Method to get all lists the authenticating or specified user subscribes to, including their own.
  21. *
  22. * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
  23. * @param boolean $reverse Set this to true if you would like owned lists to be returned first. See description
  24. * above for information on how this parameter works.
  25. *
  26. * @return array The decoded JSON response
  27. *
  28. * @since 12.3
  29. * @throws RuntimeException
  30. */
  31. public function getLists($user, $reverse = null)
  32. {
  33. // Check the rate limit for remaining hits
  34. $this->checkRateLimit('lists', 'list');
  35. // Determine which type of data was passed for $user
  36. if (is_numeric($user))
  37. {
  38. $data['user_id'] = $user;
  39. }
  40. elseif (is_string($user))
  41. {
  42. $data['screen_name'] = $user;
  43. }
  44. else
  45. {
  46. // We don't have a valid entry
  47. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  48. }
  49. // Check if reverse is specified.
  50. if (!is_null($reverse))
  51. {
  52. $data['reverse'] = $reverse;
  53. }
  54. // Set the API path
  55. $path = '/lists/list.json';
  56. // Send the request.
  57. return $this->sendRequest($path, 'GET', $data);
  58. }
  59. /**
  60. * Method to get tweet timeline for members of the specified list
  61. *
  62. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  63. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  64. * @param integer $since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
  65. * @param integer $max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
  66. * @param integer $count Specifies the number of results to retrieve per "page."
  67. * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities". This node offers a variety
  68. * of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  69. * @param boolean $include_rts When set to either true, t or 1, the list timeline will contain native retweets (if they exist) in addition
  70. * to the standard stream of tweets.
  71. *
  72. * @return array The decoded JSON response
  73. *
  74. * @since 12.3
  75. * @throws RuntimeException
  76. */
  77. public function getStatuses($list, $owner = null, $since_id = 0, $max_id = 0, $count = 0, $entities = null, $include_rts = null)
  78. {
  79. // Check the rate limit for remaining hits
  80. $this->checkRateLimit('lists', 'statuses');
  81. // Determine which type of data was passed for $list
  82. if (is_numeric($list))
  83. {
  84. $data['list_id'] = $list;
  85. }
  86. elseif (is_string($list))
  87. {
  88. $data['slug'] = $list;
  89. // In this case the owner is required.
  90. if (is_numeric($owner))
  91. {
  92. $data['owner_id'] = $owner;
  93. }
  94. elseif (is_string($owner))
  95. {
  96. $data['owner_screen_name'] = $owner;
  97. }
  98. else
  99. {
  100. // We don't have a valid entry
  101. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  102. }
  103. }
  104. else
  105. {
  106. // We don't have a valid entry
  107. throw new RuntimeException('The specified list is not in the correct format; must use integer or string');
  108. }
  109. // Set the API path
  110. $path = '/lists/statuses.json';
  111. // Check if since_id is specified
  112. if ($since_id > 0)
  113. {
  114. $data['since_id'] = $since_id;
  115. }
  116. // Check if max_id is specified
  117. if ($max_id > 0)
  118. {
  119. $data['max_id'] = $max_id;
  120. }
  121. // Check if count is specified
  122. if ($count > 0)
  123. {
  124. $data['count'] = $count;
  125. }
  126. // Check if entities is specified
  127. if (!is_null($entities))
  128. {
  129. $data['include_entities'] = $entities;
  130. }
  131. // Check if include_rts is specified
  132. if (!is_null($include_rts))
  133. {
  134. $data['include_rts'] = $include_rts;
  135. }
  136. // Send the request.
  137. return $this->sendRequest($path, 'GET', $data);
  138. }
  139. /**
  140. * Method to get the subscribers of the specified list.
  141. *
  142. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  143. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  144. * @param integer $cursor Breaks the results into pages. A single page contains 20 lists. Provide a value of -1 to begin paging.
  145. * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities". This node offers a variety
  146. * of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  147. * @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
  148. *
  149. * @return array The decoded JSON response
  150. *
  151. * @since 12.3
  152. * @throws RuntimeException
  153. */
  154. public function getSubscribers($list, $owner = null, $cursor = null, $entities = null, $skip_status = null)
  155. {
  156. // Check the rate limit for remaining hits
  157. $this->checkRateLimit('lists', 'subscribers');
  158. // Determine which type of data was passed for $list
  159. if (is_numeric($list))
  160. {
  161. $data['list_id'] = $list;
  162. }
  163. elseif (is_string($list))
  164. {
  165. $data['slug'] = $list;
  166. // In this case the owner is required.
  167. if (is_numeric($owner))
  168. {
  169. $data['owner_id'] = $owner;
  170. }
  171. elseif (is_string($owner))
  172. {
  173. $data['owner_screen_name'] = $owner;
  174. }
  175. else
  176. {
  177. // We don't have a valid entry
  178. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  179. }
  180. }
  181. else
  182. {
  183. // We don't have a valid entry
  184. throw new RuntimeException('The specified list is not in the correct format; must use integer or string');
  185. }
  186. // Set the API path
  187. $path = '/lists/subscribers.json';
  188. // Check if cursor is specified
  189. if (!is_null($cursor))
  190. {
  191. $data['cursor'] = $cursor;
  192. }
  193. // Check if entities is specified
  194. if (!is_null($entities))
  195. {
  196. $data['include_entities'] = $entities;
  197. }
  198. // Check if skip_status is specified
  199. if (!is_null($skip_status))
  200. {
  201. $data['skip_status'] = $skip_status;
  202. }
  203. // Send the request.
  204. return $this->sendRequest($path, 'GET', $data);
  205. }
  206. /**
  207. * Method to remove multiple members from a list, by specifying a comma-separated list of member ids or screen names.
  208. *
  209. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  210. * @param string $user_id A comma separated list of user IDs, up to 100 are allowed in a single request.
  211. * @param string $screen_name A comma separated list of screen names, up to 100 are allowed in a single request.
  212. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name of the owner.
  213. *
  214. * @return array The decoded JSON response
  215. *
  216. * @since 12.3
  217. * @throws RuntimeException
  218. */
  219. public function deleteMembers($list, $user_id = null, $screen_name = null, $owner = null)
  220. {
  221. // Determine which type of data was passed for $list
  222. if (is_numeric($list))
  223. {
  224. $data['list_id'] = $list;
  225. }
  226. elseif (is_string($list))
  227. {
  228. $data['slug'] = $list;
  229. // In this case the owner is required.
  230. if (is_numeric($owner))
  231. {
  232. $data['owner_id'] = $owner;
  233. }
  234. elseif (is_string($owner))
  235. {
  236. $data['owner_screen_name'] = $owner;
  237. }
  238. else
  239. {
  240. // We don't have a valid entry
  241. throw new RuntimeException('The specified username for owner is not in the correct format; must use integer or string');
  242. }
  243. }
  244. else
  245. {
  246. // We don't have a valid entry
  247. throw new RuntimeException('The specified list is not in the correct format; must use integer or string');
  248. }
  249. if ($user_id)
  250. {
  251. $data['user_id'] = $user_id;
  252. }
  253. if ($screen_name)
  254. {
  255. $data['screen_name'] = $screen_name;
  256. }
  257. if ($user_id == null && $screen_name == null)
  258. {
  259. // We don't have a valid entry
  260. throw new RuntimeException('You must specify either a comma separated list of screen names, user IDs, or a combination of the two');
  261. }
  262. // Set the API path
  263. $path = '/lists/members/destroy_all.json';
  264. // Send the request.
  265. return $this->sendRequest($path, 'POST', $data);
  266. }
  267. /**
  268. * Method to subscribe the authenticated user to the specified list.
  269. *
  270. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  271. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name of the owner.
  272. *
  273. * @return array The decoded JSON response
  274. *
  275. * @since 12.3
  276. * @throws RuntimeException
  277. */
  278. public function subscribe($list, $owner = null)
  279. {
  280. // Check the rate limit for remaining hits
  281. $this->checkRateLimit('lists', 'subscribers/create');
  282. // Determine which type of data was passed for $list
  283. if (is_numeric($list))
  284. {
  285. $data['list_id'] = $list;
  286. }
  287. elseif (is_string($list))
  288. {
  289. $data['slug'] = $list;
  290. // In this case the owner is required.
  291. if (is_numeric($owner))
  292. {
  293. $data['owner_id'] = $owner;
  294. }
  295. elseif (is_string($owner))
  296. {
  297. $data['owner_screen_name'] = $owner;
  298. }
  299. else
  300. {
  301. // We don't have a valid entry
  302. throw new RuntimeException('The specified username for owner is not in the correct format; must use integer or string');
  303. }
  304. }
  305. else
  306. {
  307. // We don't have a valid entry
  308. throw new RuntimeException('The specified list is not in the correct format; must use integer or string');
  309. }
  310. // Set the API path
  311. $path = '/lists/subscribers/create.json';
  312. // Send the request.
  313. return $this->sendRequest($path, 'POST', $data);
  314. }
  315. /**
  316. * Method to check if the specified user is a member of the specified list.
  317. *
  318. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  319. * @param mixed $user Either an integer containing the user ID or a string containing the screen name of the user to remove.
  320. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name of the owner.
  321. * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities". This node offers a
  322. * variety of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  323. * @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
  324. *
  325. * @return array The decoded JSON response
  326. *
  327. * @since 12.3
  328. * @throws RuntimeException
  329. */
  330. public function isMember($list, $user, $owner = null, $entities = null, $skip_status = null)
  331. {
  332. // Check the rate limit for remaining hits
  333. $this->checkRateLimit('lists', 'members/show');
  334. // Determine which type of data was passed for $list
  335. if (is_numeric($list))
  336. {
  337. $data['list_id'] = $list;
  338. }
  339. elseif (is_string($list))
  340. {
  341. $data['slug'] = $list;
  342. // In this case the owner is required.
  343. if (is_numeric($owner))
  344. {
  345. $data['owner_id'] = $owner;
  346. }
  347. elseif (is_string($owner))
  348. {
  349. $data['owner_screen_name'] = $owner;
  350. }
  351. else
  352. {
  353. // We don't have a valid entry
  354. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  355. }
  356. }
  357. else
  358. {
  359. // We don't have a valid entry
  360. throw new RuntimeException('The specified list is not in the correct format; must use integer or string');
  361. }
  362. if (is_numeric($user))
  363. {
  364. $data['user_id'] = $user;
  365. }
  366. elseif (is_string($user))
  367. {
  368. $data['screen_name'] = $user;
  369. }
  370. else
  371. {
  372. // We don't have a valid entry
  373. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  374. }
  375. // Set the API path
  376. $path = '/lists/members/show.json';
  377. // Check if entities is specified
  378. if (!is_null($entities))
  379. {
  380. $data['include_entities'] = $entities;
  381. }
  382. // Check if skip_status is specified
  383. if (!is_null($skip_status))
  384. {
  385. $data['skip_status'] = $skip_status;
  386. }
  387. // Send the request.
  388. return $this->sendRequest($path, 'GET', $data);
  389. }
  390. /**
  391. * Method to check if the specified user is a subscriber of the specified list.
  392. *
  393. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  394. * @param mixed $user Either an integer containing the user ID or a string containing the screen name of the user to remove.
  395. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name of the owner.
  396. * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities". This node offers a
  397. * variety of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  398. * @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
  399. *
  400. * @return array The decoded JSON response
  401. *
  402. * @since 12.3
  403. * @throws RuntimeException
  404. */
  405. public function isSubscriber($list, $user, $owner = null, $entities = null, $skip_status = null)
  406. {
  407. // Check the rate limit for remaining hits
  408. $this->checkRateLimit('lists', 'subscribers/show');
  409. // Determine which type of data was passed for $list
  410. if (is_numeric($list))
  411. {
  412. $data['list_id'] = $list;
  413. }
  414. elseif (is_string($list))
  415. {
  416. $data['slug'] = $list;
  417. // In this case the owner is required.
  418. if (is_numeric($owner))
  419. {
  420. $data['owner_id'] = $owner;
  421. }
  422. elseif (is_string($owner))
  423. {
  424. $data['owner_screen_name'] = $owner;
  425. }
  426. else
  427. {
  428. // We don't have a valid entry
  429. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  430. }
  431. }
  432. else
  433. {
  434. // We don't have a valid entry
  435. throw new RuntimeException('The specified list is not in the correct format; must use integer or string');
  436. }
  437. if (is_numeric($user))
  438. {
  439. $data['user_id'] = $user;
  440. }
  441. elseif (is_string($user))
  442. {
  443. $data['screen_name'] = $user;
  444. }
  445. else
  446. {
  447. // We don't have a valid entry
  448. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  449. }
  450. // Set the API path
  451. $path = '/lists/subscribers/show.json';
  452. // Check if entities is specified
  453. if (!is_null($entities))
  454. {
  455. $data['include_entities'] = $entities;
  456. }
  457. // Check if skip_status is specified
  458. if (!is_null($skip_status))
  459. {
  460. $data['skip_status'] = $skip_status;
  461. }
  462. // Send the request.
  463. return $this->sendRequest($path, 'GET', $data);
  464. }
  465. /**
  466. * Method to unsubscribe the authenticated user from the specified list.
  467. *
  468. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  469. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name of the owner.
  470. *
  471. * @return array The decoded JSON response
  472. *
  473. * @since 12.3
  474. * @throws RuntimeException
  475. */
  476. public function unsubscribe($list, $owner = null)
  477. {
  478. // Check the rate limit for remaining hits
  479. $this->checkRateLimit('lists', 'subscribers/destroy');
  480. // Determine which type of data was passed for $list
  481. if (is_numeric($list))
  482. {
  483. $data['list_id'] = $list;
  484. }
  485. elseif (is_string($list))
  486. {
  487. $data['slug'] = $list;
  488. // In this case the owner is required.
  489. if (is_numeric($owner))
  490. {
  491. $data['owner_id'] = $owner;
  492. }
  493. elseif (is_string($owner))
  494. {
  495. $data['owner_screen_name'] = $owner;
  496. }
  497. else
  498. {
  499. // We don't have a valid entry
  500. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  501. }
  502. }
  503. else
  504. {
  505. // We don't have a valid entry
  506. throw new RuntimeException('The specified list is not in the correct format; must use integer or string');
  507. }
  508. // Set the API path
  509. $path = '/lists/subscribers/destroy.json';
  510. // Send the request.
  511. return $this->sendRequest($path, 'POST', $data);
  512. }
  513. /**
  514. * Method to add multiple members to a list, by specifying a comma-separated list of member ids or screen names.
  515. *
  516. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  517. * @param string $user_id A comma separated list of user IDs, up to 100 are allowed in a single request.
  518. * @param string $screen_name A comma separated list of screen names, up to 100 are allowed in a single request.
  519. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name of the owner.
  520. *
  521. * @return array The decoded JSON response
  522. *
  523. * @since 12.3
  524. * @throws RuntimeException
  525. */
  526. public function addMembers($list, $user_id = null, $screen_name = null, $owner = null)
  527. {
  528. // Check the rate limit for remaining hits
  529. $this->checkRateLimit('lists', 'members/create_all');
  530. // Determine which type of data was passed for $list
  531. if (is_numeric($list))
  532. {
  533. $data['list_id'] = $list;
  534. }
  535. elseif (is_string($list))
  536. {
  537. $data['slug'] = $list;
  538. // In this case the owner is required.
  539. if (is_numeric($owner))
  540. {
  541. $data['owner_id'] = $owner;
  542. }
  543. elseif (is_string($owner))
  544. {
  545. $data['owner_screen_name'] = $owner;
  546. }
  547. else
  548. {
  549. // We don't have a valid entry
  550. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  551. }
  552. }
  553. else
  554. {
  555. // We don't have a valid entry
  556. throw new RuntimeException('The specified list is not in the correct format; must use integer or string');
  557. }
  558. if ($user_id)
  559. {
  560. $data['user_id'] = $user_id;
  561. }
  562. if ($screen_name)
  563. {
  564. $data['screen_name'] = $screen_name;
  565. }
  566. if ($user_id == null && $screen_name == null)
  567. {
  568. // We don't have a valid entry
  569. throw new RuntimeException('You must specify either a comma separated list of screen names, user IDs, or a combination of the two');
  570. }
  571. // Set the API path
  572. $path = '/lists/members/create_all.json';
  573. // Send the request.
  574. return $this->sendRequest($path, 'POST', $data);
  575. }
  576. /**
  577. * Method to get the members of the specified list.
  578. *
  579. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  580. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  581. * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities". This node offers a variety
  582. * of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  583. * @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
  584. *
  585. * @return array The decoded JSON response
  586. *
  587. * @since 12.3
  588. * @throws RuntimeException
  589. */
  590. public function getMembers($list, $owner = null, $entities = null, $skip_status = null)
  591. {
  592. // Check the rate limit for remaining hits
  593. $this->checkRateLimit('lists', 'members');
  594. // Determine which type of data was passed for $list
  595. if (is_numeric($list))
  596. {
  597. $data['list_id'] = $list;
  598. }
  599. elseif (is_string($list))
  600. {
  601. $data['slug'] = $list;
  602. // In this case the owner is required.
  603. if (is_numeric($owner))
  604. {
  605. $data['owner_id'] = $owner;
  606. }
  607. elseif (is_string($owner))
  608. {
  609. $data['owner_screen_name'] = $owner;
  610. }
  611. else
  612. {
  613. // We don't have a valid entry
  614. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  615. }
  616. }
  617. else
  618. {
  619. // We don't have a valid entry
  620. throw new RuntimeException('The specified list is not in the correct format; must use integer or string');
  621. }
  622. // Set the API path
  623. $path = '/lists/members.json';
  624. // Check if entities is specified
  625. if (!is_null($entities))
  626. {
  627. $data['include_entities'] = $entities;
  628. }
  629. // Check if skip_status is specified
  630. if (!is_null($skip_status))
  631. {
  632. $data['skip_status'] = $skip_status;
  633. }
  634. // Send the request.
  635. return $this->sendRequest($path, 'GET', $data);
  636. }
  637. /**
  638. * Method to get the specified list.
  639. *
  640. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  641. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  642. *
  643. * @return array The decoded JSON response
  644. *
  645. * @since 12.3
  646. * @throws RuntimeException
  647. */
  648. public function getListById($list, $owner = null)
  649. {
  650. // Check the rate limit for remaining hits
  651. $this->checkRateLimit('lists', 'show');
  652. // Determine which type of data was passed for $list
  653. if (is_numeric($list))
  654. {
  655. $data['list_id'] = $list;
  656. }
  657. elseif (is_string($list))
  658. {
  659. $data['slug'] = $list;
  660. // In this case the owner is required.
  661. if (is_numeric($owner))
  662. {
  663. $data['owner_id'] = $owner;
  664. }
  665. elseif (is_string($owner))
  666. {
  667. $data['owner_screen_name'] = $owner;
  668. }
  669. else
  670. {
  671. // We don't have a valid entry
  672. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  673. }
  674. }
  675. else
  676. {
  677. // We don't have a valid entry
  678. throw new RuntimeException('The specified list is not in the correct format; must use integer or string');
  679. }
  680. // Set the API path
  681. $path = '/lists/show.json';
  682. // Send the request.
  683. return $this->sendRequest($path, 'GET', $data);
  684. }
  685. /**
  686. * Method to get a collection of the lists the specified user is subscribed to, 20 lists per page by default. Does not include the user's own lists.
  687. *
  688. * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
  689. * @param integer $count The amount of results to return per page. Defaults to 20. Maximum of 1,000 when using cursors.
  690. * @param integer $cursor Breaks the results into pages. Provide a value of -1 to begin paging.
  691. *
  692. * @return array The decoded JSON response
  693. *
  694. * @since 12.3
  695. * @throws RuntimeException
  696. */
  697. public function getSubscriptions($user, $count = 0, $cursor = null)
  698. {
  699. // Check the rate limit for remaining hits
  700. $this->checkRateLimit('lists', 'subscriptions');
  701. // Determine which type of data was passed for $user
  702. if (is_numeric($user))
  703. {
  704. $data['user_id'] = $user;
  705. }
  706. elseif (is_string($user))
  707. {
  708. $data['screen_name'] = $user;
  709. }
  710. else
  711. {
  712. // We don't have a valid entry
  713. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  714. }
  715. // Check if count is specified.
  716. if ($count > 0)
  717. {
  718. $data['count'] = $count;
  719. }
  720. // Check if cursor is specified.
  721. if (!is_null($cursor))
  722. {
  723. $data['cursor'] = $cursor;
  724. }
  725. // Set the API path
  726. $path = '/lists/subscriptions.json';
  727. // Send the request.
  728. return $this->sendRequest($path, 'GET', $data);
  729. }
  730. /**
  731. * Method to update the specified list
  732. *
  733. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  734. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name of the owner.
  735. * @param string $name The name of the list.
  736. * @param string $mode Whether your list is public or private. Values can be public or private. If no mode is
  737. * specified the list will be public.
  738. * @param string $description The description to give the list.
  739. *
  740. * @return array The decoded JSON response
  741. *
  742. * @since 12.3
  743. * @throws RuntimeException
  744. */
  745. public function update($list, $owner = null, $name = null, $mode = null, $description = null)
  746. {
  747. // Check the rate limit for remaining hits
  748. $this->checkRateLimit('lists', 'update');
  749. // Determine which type of data was passed for $list
  750. if (is_numeric($list))
  751. {
  752. $data['list_id'] = $list;
  753. }
  754. elseif (is_string($list))
  755. {
  756. $data['slug'] = $list;
  757. // In this case the owner is required.
  758. if (is_numeric($owner))
  759. {
  760. $data['owner_id'] = $owner;
  761. }
  762. elseif (is_string($owner))
  763. {
  764. $data['owner_screen_name'] = $owner;
  765. }
  766. else
  767. {
  768. // We don't have a valid entry
  769. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  770. }
  771. }
  772. else
  773. {
  774. // We don't have a valid entry
  775. throw new RuntimeException('The specified list is not in the correct format; must use integer or string');
  776. }
  777. // Check if name is specified.
  778. if ($name)
  779. {
  780. $data['name'] = $name;
  781. }
  782. // Check if mode is specified.
  783. if ($mode)
  784. {
  785. $data['mode'] = $mode;
  786. }
  787. // Check if description is specified.
  788. if ($description)
  789. {
  790. $data['description'] = $description;
  791. }
  792. // Set the API path
  793. $path = '/lists/update.json';
  794. // Send the request.
  795. return $this->sendRequest($path, 'POST', $data);
  796. }
  797. /**
  798. * Method to create a new list for the authenticated user.
  799. *
  800. * @param string $name The name of the list.
  801. * @param string $mode Whether your list is public or private. Values can be public or private. If no mode is
  802. * specified the list will be public.
  803. * @param string $description The description to give the list.
  804. *
  805. * @return array The decoded JSON response
  806. *
  807. * @since 12.3
  808. */
  809. public function create($name, $mode = null, $description = null)
  810. {
  811. // Check the rate limit for remaining hits
  812. $this->checkRateLimit('lists', 'create');
  813. // Check if name is specified.
  814. if ($name)
  815. {
  816. $data['name'] = $name;
  817. }
  818. // Check if mode is specified.
  819. if ($mode)
  820. {
  821. $data['mode'] = $mode;
  822. }
  823. // Check if description is specified.
  824. if ($description)
  825. {
  826. $data['description'] = $description;
  827. }
  828. // Set the API path
  829. $path = '/lists/create.json';
  830. // Send the request.
  831. return $this->sendRequest($path, 'POST', $data);
  832. }
  833. /**
  834. * Method to delete a specified list.
  835. *
  836. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  837. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name of the owner.
  838. *
  839. * @return array The decoded JSON response
  840. *
  841. * @since 12.3
  842. * @throws RuntimeException
  843. */
  844. public function delete($list, $owner = null)
  845. {
  846. // Check the rate limit for remaining hits
  847. $this->checkRateLimit('lists', 'destroy');
  848. // Determine which type of data was passed for $list
  849. if (is_numeric($list))
  850. {
  851. $data['list_id'] = $list;
  852. }
  853. elseif (is_string($list))
  854. {
  855. $data['slug'] = $list;
  856. // In this case the owner is required.
  857. if (is_numeric($owner))
  858. {
  859. $data['owner_id'] = $owner;
  860. }
  861. elseif (is_string($owner))
  862. {
  863. $data['owner_screen_name'] = $owner;
  864. }
  865. else
  866. {
  867. // We don't have a valid entry
  868. throw new RuntimeException('The specified username for owner is not in the correct format; must use integer or string');
  869. }
  870. }
  871. else
  872. {
  873. // We don't have a valid entry
  874. throw new RuntimeException('The specified list is not in the correct format; must use integer or string');
  875. }
  876. // Set the API path
  877. $path = '/lists/destroy.json';
  878. // Send the request.
  879. return $this->sendRequest($path, 'POST', $data);
  880. }
  881. }