PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Joomla/Twitter/Block.php

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