PageRenderTime 6ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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