PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/joomla/twitter/block.php

https://bitbucket.org/biojazzard/joomla-eboracast
PHP | 162 lines | 72 code | 19 blank | 71 comment | 8 complexity | 7764332b9de14ba1d08236fb431a9e48 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 Block class for the Joomla Platform.
  12. *
  13. * @package Joomla.Platform
  14. * @subpackage Twitter
  15. * @since 12.3
  16. */
  17. class JTwitterBlock extends JTwitterObject
  18. {
  19. /**
  20. * Method to get the user ids the authenticating user is blocking.
  21. *
  22. * @param boolean $stringify_ids Provide this option to have ids returned as strings instead.
  23. * @param integer $cursor Causes the list of IDs to be broken into pages of no more than 5000 IDs at a time. The number of IDs returned
  24. * is not guaranteed to be 5000 as suspended users are filtered out after connections are queried. If no cursor
  25. * is provided, a value of -1 will be assumed, which is the first "page."
  26. *
  27. * @return array The decoded JSON response
  28. *
  29. * @since 12.3
  30. */
  31. public function getBlocking($stringify_ids = null, $cursor = null)
  32. {
  33. // Check the rate limit for remaining hits
  34. $this->checkRateLimit('blocks', 'ids');
  35. $data = array();
  36. // Check if stringify_ids is specified
  37. if (!is_null($stringify_ids))
  38. {
  39. $data['stringify_ids'] = $stringify_ids;
  40. }
  41. // Check if cursor is specified
  42. if (!is_null($stringify_ids))
  43. {
  44. $data['cursor'] = $cursor;
  45. }
  46. // Set the API path
  47. $path = '/blocks/ids.json';
  48. // Send the request.
  49. return $this->sendRequest($path, 'GET', $data);
  50. }
  51. /**
  52. * Method to block the specified user from following the authenticating user.
  53. *
  54. * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
  55. * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a
  56. * variety of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  57. * @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
  58. *
  59. * @return array The decoded JSON response
  60. *
  61. * @since 12.3
  62. * @throws RuntimeException
  63. */
  64. public function block($user, $entities = null, $skip_status = null)
  65. {
  66. // Check the rate limit for remaining hits
  67. $this->checkRateLimit('blocks', 'create');
  68. // Determine which type of data was passed for $user
  69. if (is_numeric($user))
  70. {
  71. $data['user_id'] = $user;
  72. }
  73. elseif (is_string($user))
  74. {
  75. $data['screen_name'] = $user;
  76. }
  77. else
  78. {
  79. // We don't have a valid entry
  80. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  81. }
  82. // Check if entities is specified
  83. if (!is_null($entities))
  84. {
  85. $data['include_entities'] = $entities;
  86. }
  87. // Check if skip_statuses is specified
  88. if (!is_null($skip_status))
  89. {
  90. $data['skip_status'] = $skip_status;
  91. }
  92. // Set the API path
  93. $path = '/blocks/create.json';
  94. // Send the request.
  95. return $this->sendRequest($path, 'POST', $data);
  96. }
  97. /**
  98. * Method to unblock the specified user from following the authenticating user.
  99. *
  100. * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
  101. * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a
  102. * variety of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  103. * @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
  104. *
  105. * @return array The decoded JSON response
  106. *
  107. * @since 12.3
  108. * @throws RuntimeException
  109. */
  110. public function unblock($user, $entities = null, $skip_status = null)
  111. {
  112. // Check the rate limit for remaining hits
  113. $this->checkRateLimit('blocks', 'destroy');
  114. // Determine which type of data was passed for $user
  115. if (is_numeric($user))
  116. {
  117. $data['user_id'] = $user;
  118. }
  119. elseif (is_string($user))
  120. {
  121. $data['screen_name'] = $user;
  122. }
  123. else
  124. {
  125. // We don't have a valid entry
  126. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  127. }
  128. // Check if entities is specified
  129. if (!is_null($entities))
  130. {
  131. $data['include_entities'] = $entities;
  132. }
  133. // Check if skip_statuses is specified
  134. if (!is_null($skip_status))
  135. {
  136. $data['skip_status'] = $skip_status;
  137. }
  138. // Set the API path
  139. $path = '/blocks/destroy.json';
  140. // Send the request.
  141. return $this->sendRequest($path, 'POST', $data);
  142. }
  143. }