PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/twitter/directmessages.php

https://bitbucket.org/biojazzard/joomla-eboracast
PHP | 220 lines | 92 code | 29 blank | 99 comment | 12 complexity | 37d8735263329f1fcc0ee7a8ed39faae 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 Direct Messages class for the Joomla Platform.
  12. *
  13. * @package Joomla.Platform
  14. * @subpackage Twitter
  15. * @since 12.3
  16. */
  17. class JTwitterDirectmessages extends JTwitterObject
  18. {
  19. /**
  20. * Method to get the most recent direct messages sent to the authenticating user.
  21. *
  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) or equal to the specified ID.
  24. * @param integer $count Specifies the number of direct messages to try and retrieve, up to a maximum of 200.
  25. * @param boolean $entities When set to true, each tweet will include a node called "entities,". This node offers a variety of metadata
  26. * about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  27. * @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
  28. *
  29. * @return array The decoded JSON response
  30. *
  31. * @since 12.3
  32. */
  33. public function getDirectMessages($since_id = 0, $max_id = 0, $count = 20, $entities = null, $skip_status = null)
  34. {
  35. // Check the rate limit for remaining hits
  36. $this->checkRateLimit('direct_messages');
  37. // Set the API path
  38. $path = '/direct_messages.json';
  39. // Check if since_id is specified.
  40. if ($since_id)
  41. {
  42. $data['since_id'] = $since_id;
  43. }
  44. // Check if max_id is specified.
  45. if ($max_id)
  46. {
  47. $data['max_id'] = $max_id;
  48. }
  49. // Check if count is specified.
  50. if ($count)
  51. {
  52. $data['count'] = $count;
  53. }
  54. // Check if entities is specified.
  55. if (!is_null($entities))
  56. {
  57. $data['include_entities'] = $entities;
  58. }
  59. // Check if skip_status is specified.
  60. if (!is_null($skip_status))
  61. {
  62. $data['skip_status'] = $skip_status;
  63. }
  64. // Send the request.
  65. return $this->sendRequest($path, 'GET', $data);
  66. }
  67. /**
  68. * Method to get the most recent direct messages sent by the authenticating user.
  69. *
  70. * @param integer $since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
  71. * @param integer $max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
  72. * @param integer $count Specifies the number of direct messages to try and retrieve, up to a maximum of 200.
  73. * @param integer $page Specifies the page of results to retrieve.
  74. * @param boolean $entities When set to true, each tweet will include a node called "entities,". This node offers a variety of metadata
  75. * about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  76. *
  77. * @return array The decoded JSON response
  78. *
  79. * @since 12.3
  80. */
  81. public function getSentDirectMessages($since_id = 0, $max_id = 0, $count = 20, $page = 0, $entities = null)
  82. {
  83. // Check the rate limit for remaining hits
  84. $this->checkRateLimit('direct_messages', 'sent');
  85. // Set the API path
  86. $path = '/direct_messages/sent.json';
  87. // Check if since_id is specified.
  88. if ($since_id)
  89. {
  90. $data['since_id'] = $since_id;
  91. }
  92. // Check if max_id is specified.
  93. if ($max_id)
  94. {
  95. $data['max_id'] = $max_id;
  96. }
  97. // Check if count is specified.
  98. if ($count)
  99. {
  100. $data['count'] = $count;
  101. }
  102. // Check if page is specified.
  103. if ($page)
  104. {
  105. $data['page'] = $page;
  106. }
  107. // Check if entities is specified.
  108. if (!is_null($entities))
  109. {
  110. $data['include_entities'] = $entities;
  111. }
  112. // Send the request.
  113. return $this->sendRequest($path, 'GET', $data);
  114. }
  115. /**
  116. * Method to send a new direct message to the specified user from the authenticating user.
  117. *
  118. * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
  119. * @param string $text The text of your direct message. Be sure to keep the message under 140 characters.
  120. *
  121. * @return array The decoded JSON response
  122. *
  123. * @since 12.3
  124. * @throws RuntimeException
  125. */
  126. public function sendDirectMessages($user, $text)
  127. {
  128. // Set the API path
  129. $path = '/direct_messages/new.json';
  130. // Determine which type of data was passed for $user
  131. if (is_numeric($user))
  132. {
  133. $data['user_id'] = $user;
  134. }
  135. elseif (is_string($user))
  136. {
  137. $data['screen_name'] = $user;
  138. }
  139. else
  140. {
  141. // We don't have a valid entry
  142. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  143. }
  144. $data['text'] = $text;
  145. // Send the request.
  146. return $this->sendRequest($path, 'POST', $data);
  147. }
  148. /**
  149. * Method to get a single direct message, specified by an id parameter.
  150. *
  151. * @param integer $id The ID of the direct message.
  152. *
  153. * @return array The decoded JSON response
  154. *
  155. * @since 12.3
  156. */
  157. public function getDirectMessagesById($id)
  158. {
  159. // Check the rate limit for remaining hits
  160. $this->checkRateLimit('direct_messages', 'show');
  161. // Set the API path
  162. $path = '/direct_messages/show.json';
  163. $data['id'] = $id;
  164. // Send the request.
  165. return $this->sendRequest($path, 'GET', $data);
  166. }
  167. /**
  168. * Method to delete the direct message specified in the required ID parameter.
  169. *
  170. * @param integer $id The ID of the direct message.
  171. * @param boolean $entities When set to true, each tweet will include a node called "entities,". This node offers a variety of metadata
  172. * about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  173. *
  174. * @return array The decoded JSON response
  175. *
  176. * @since 12.3
  177. */
  178. public function deleteDirectMessages($id, $entities = null)
  179. {
  180. // Set the API path
  181. $path = '/direct_messages/destroy.json';
  182. $data['id'] = $id;
  183. // Check if entities is specified.
  184. if (!is_null($entities))
  185. {
  186. $data['include_entities'] = $entities;
  187. }
  188. // Send the request.
  189. return $this->sendRequest($path, 'POST', $data);
  190. }
  191. }