PageRenderTime 56ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Joomla/Twitter/Favorites.php

https://github.com/piotr-cz/joomla-framework
PHP | 131 lines | 52 code | 17 blank | 62 comment | 6 complexity | a394bb30a79926f87e75903bf9542b5d 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 Favorites class for the Joomla Framework.
  11. *
  12. * @since 1.0
  13. */
  14. class Favorites extends Object
  15. {
  16. /**
  17. * Method to get the most recent favorite statuses for the authenticating or specified user.
  18. *
  19. * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
  20. * @param integer $count Specifies the number of tweets to try and retrieve, up to a maximum of 200. Retweets are always included
  21. * in the count, so it is always suggested to set $include_rts to true
  22. * @param integer $since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
  23. * @param integer $max_id Returns results with an ID less than (that is, older than) the specified ID.
  24. * @param boolean $entities When set to true, each tweet will include a node called "entities,". This node offers a variety
  25. * of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  26. *
  27. * @return array The decoded JSON response
  28. *
  29. * @since 1.0
  30. */
  31. public function getFavorites($user = null, $count = 20, $since_id = 0, $max_id = 0, $entities = null)
  32. {
  33. // Check the rate limit for remaining hits
  34. $this->checkRateLimit('favorites', 'list');
  35. // Set the API path.
  36. $path = '/favorites/list.json';
  37. // Determine which type of data was passed for $user
  38. if (is_numeric($user))
  39. {
  40. $data['user_id'] = $user;
  41. }
  42. elseif (is_string($user))
  43. {
  44. $data['screen_name'] = $user;
  45. }
  46. // Set the count string
  47. $data['count'] = $count;
  48. // Check if since_id is specified.
  49. if ($since_id > 0)
  50. {
  51. $data['since_id'] = $since_id;
  52. }
  53. // Check if max_id is specified.
  54. if ($max_id > 0)
  55. {
  56. $data['max_id'] = $max_id;
  57. }
  58. // Check if entities is specified.
  59. if (!is_null($entities))
  60. {
  61. $data['include_entities'] = $entities;
  62. }
  63. // Send the request.
  64. return $this->sendRequest($path, 'GET', $data);
  65. }
  66. /**
  67. * Method to favorite the status specified in the ID parameter as the authenticating user
  68. *
  69. * @param integer $id The numerical ID of the desired status.
  70. * @param boolean $entities When set to true, each tweet will include a node called "entities,". This node offers a variety
  71. * of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  72. *
  73. * @return array The decoded JSON response
  74. *
  75. * @since 1.0
  76. */
  77. public function createFavorites($id, $entities = null)
  78. {
  79. // Set the API path.
  80. $path = '/favorites/create.json';
  81. $data['id'] = $id;
  82. // Check if entities is specified.
  83. if (!is_null($entities))
  84. {
  85. $data['include_entities'] = $entities;
  86. }
  87. // Send the request.
  88. return $this->sendRequest($path, 'POST', $data);
  89. }
  90. /**
  91. * Method to un-favorites the status specified in the ID parameter as the authenticating user.
  92. *
  93. * @param integer $id The numerical ID of the desired status.
  94. * @param boolean $entities When set to true, each tweet will include a node called "entities,". This node offers a variety
  95. * of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  96. *
  97. * @return array The decoded JSON response
  98. *
  99. * @since 1.0
  100. */
  101. public function deleteFavorites($id, $entities = null)
  102. {
  103. // Set the API path.
  104. $path = '/favorites/destroy.json';
  105. $data['id'] = $id;
  106. // Check if entities is specified.
  107. if (!is_null($entities))
  108. {
  109. $data['include_entities'] = $entities;
  110. }
  111. // Send the request.
  112. return $this->sendRequest($path, 'POST', $data);
  113. }
  114. }