/inc/class.dm.php

http://php-twitter.googlecode.com/ · PHP · 120 lines · 46 code · 14 blank · 60 comment · 4 complexity · bd0ea413947257056188d725db2a01e1 MD5 · raw file

  1. <?php
  2. /**
  3. * Twitter_Dm
  4. *
  5. * @package php-twitter 2.0
  6. * @subpackage direct_messages
  7. * @author Aaron Brazell
  8. **/
  9. class Twitter_Dm extends Twitter {
  10. /**
  11. * Setup Twitter client connection details
  12. *
  13. * Ensure you set a user agent, whether via the constructor or by assigning a value to the property directly.
  14. * Also, if you are not running this from the Eastern timezone, be sure to set your proper timezone.
  15. *
  16. * @access public
  17. * @since 2.0
  18. * @return Twitter_Lists
  19. */
  20. public function __construct( $username = null, $password = null, $user_agent = null, $headers = null, $timezone = 'America/New_York')
  21. {
  22. parent::__construct($username, $password, $user_agent, $headers, $timezone);
  23. }
  24. /**
  25. * Send a request for Direct Messages
  26. *
  27. * @access public
  28. * @since 2.0
  29. * @param string $scope public for public timeline, user for user timeline, mentions for @ replies
  30. * @param array $args Parameters that can be passed in key/pair format. All are optional. Some only apply to certain scopes.
  31. * - since_id: INT. Only tweets after the specified Status ID are returned
  32. * - max_id: INT. Only tweets up to a specified Status ID are returned
  33. * - count: INT. Number of tweets to return. Defaults to 20.
  34. * - page: INT: Paged result set to display.
  35. * @return object
  36. */
  37. public function get_dms( $args = array() )
  38. {
  39. if( !class_exists('Twitter_Timeline') )
  40. require('class.timeline.php');
  41. $defaults = array(
  42. 'count' => 20
  43. );
  44. $args = wp_parse_args( $defaults, $args );
  45. return Twitter_Timeline::get_timeline( 'dm', $args )
  46. }
  47. /**
  48. * Get a listing of direct messages sent by the authenticating user
  49. *
  50. * @access public
  51. * @since 2.0
  52. * @param string $scope public for public timeline, user for user timeline, mentions for @ replies
  53. * @param array $args Parameters that can be passed in key/pair format. All are optional. Some only apply to certain scopes.
  54. * - since_id: INT. Only tweets after the specified Status ID are returned
  55. * - max_id: INT. Only tweets up to a specified Status ID are returned
  56. * - count: INT. Number of tweets to return. Defaults to 20.
  57. * - page: INT: Paged result set to display.
  58. * @return object
  59. */
  60. public function sent_dms( $args = array() )
  61. {
  62. if( !class_exists('Twitter_Timeline') )
  63. require('class.timeline.php');
  64. $defaults = array(
  65. 'count' => 20
  66. );
  67. $args = wp_parse_args( $defaults, $args );
  68. return Twitter_Timeline::get_timeline( 'dmsent', $args )
  69. }
  70. /**
  71. * Send a new Direct Message
  72. *
  73. * @access public
  74. * @since 2.0
  75. * @param string/integer $recipient. Required. The username or user ID of the recipient
  76. * @param string $message. Required. Will be URL encoded and truncated to 140 charachters.
  77. * @return object
  78. **/
  79. public function send_dm( $recipient, $message )
  80. {
  81. $data = array();
  82. if( is_int( $recipient ) )
  83. $data['user_id'] => $recipient;
  84. else
  85. $data['screen_name'] => $recipient;
  86. $data['text'] = substr( urlencode( $message ), 0, 140 );
  87. $this->api_url = 'http://twitter.com/direct_messages/new.' . $this->type;
  88. return $this->_post( $this->api_url, $data );
  89. }
  90. /**
  91. * Delete a DM
  92. *
  93. * @access public
  94. * @since 2.0
  95. * @param integer $dmid. Required. Specified ID of DM must be sent to authenticating user.
  96. * @return object
  97. **/
  98. public function delete_dm( $dmid )
  99. {
  100. if( !is_int( $dmid ) )
  101. return false;
  102. $this->api_url = 'http://twitter.com/direct_messages/' . $dmid . '.' . $this->type;
  103. return $this->_post( $this->api_url, array( 'id' => $dmid ) );
  104. }
  105. public function __destruct() {}
  106. }