PageRenderTime 62ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Joomla/Twitter/Lists.php

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