PageRenderTime 16ms CodeModel.GetById 10ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/class.friends.php

http://php-twitter.googlecode.com/
PHP | 170 lines | 75 code | 14 blank | 81 comment | 12 complexity | 853021af7ba1cbe5d16a3d26425594bb MD5 | raw file
  1<?php
  2/**
  3 * Twitter_Friends
  4 *
  5 * @package php-twitter 2.0
  6 * @subpackage friends
  7 * @author Aaron Brazell
  8 **/
  9
 10class Twitter_Friends 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_Friends
 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	 * Request to follow a designated user
 28	 * 
 29	 * Authenticating user follows another twitter user.
 30	 *
 31	 * @access public
 32	 * @since 2.0
 33	 * @param integer/string $user_id. Required the ID or screen name of the Twitter user to follow
 34	 * @param boolean $notifications. Optional. Whether to recieve notifications from the followed user. Default is false.
 35	 * @return object
 36	 **/
 37	public function follow( $user_id, $notifications = false)
 38	{
 39		$data = array( 'notifications' => false );
 40		if( is_int( $user_id) )
 41			$data['user_id'] = $user_id;
 42		else
 43			$data['screen_name'] = (string) $user_id;
 44			
 45		if( $notifications )
 46			$data['notifications'] = true;
 47			
 48		$this->api_url = 'http://twitter.com/friendships/create.' . $this->type . $this->_glue( $data );
 49		return $this->_post( $this->api_url );
 50	}
 51	
 52	/**
 53	 * Request to unfollow a designated user
 54	 * 
 55	 * Authenticating user unfollows another twitter user.
 56	 *
 57	 * @access public
 58	 * @since 2.0
 59	 * @param integer/string $user_id. Required the ID or screen name of the Twitter user to follow
 60	 * @return object
 61	 **/
 62	public function unfollow( $user_id )
 63	{
 64		if( is_int( $user_id) )
 65			$data['user_id'] = $user_id;
 66		else
 67			$data['screen_name'] = (string) $user_id;
 68			
 69		$this->api_url = 'http://twitter.com/friendships/destroy.' . $this->type . $this->_glue( $data );
 70		return $this->_post( $this->api_url );
 71	}
 72	
 73	/**
 74	 * Returns information about a relationship between two twitter users
 75	 *
 76	 * @access public
 77	 * @since 2.0
 78	 * @param string/integer $target_user. Required
 79	 * @param string/integer/boolean $source_user. Optional. If omitted or false, the $source user will be the authenticating user
 80	 * @return object
 81	 **/
 82	public function show( $target_user, $source_user = false )
 83	{
 84		if( !$source_user )
 85			$source_user = $this->username;
 86		if( is_int( $source_user ) )
 87			$data['source_id'] = $source_user;
 88		else
 89			$data['source_sceen_name'] = (string) $source_user;
 90
 91		if( is_int( $target_user) )
 92			$data['target_id'] = $target_user;
 93		else
 94			$data['target_screen_name'] = (string) $target_user;
 95		$this->api_url = 'http://twitter.com/friendships/show.' . $this->type . $this->_glue( $data );
 96		return $this->_get( $data );
 97	}
 98	
 99	/**
100	 * Return true if User A is following User B. Wrapper around show() method
101	 *
102	 * @access public
103	 * @since 2.0
104	 * @param string/integer $user_a. Required.
105	 * @param string/integer $user_b. Required.
106	 * @return boolean
107	 **/
108	public function is_friend( $user_a, $user_b )
109	{
110		$relationship = $this->show( $user_a, $user_b );
111		return $relationship->source->following;
112	}
113	
114	/**
115	 *  Returns a list of all Twitter user IDs that the specified user follows
116	 *
117	 * @access public
118	 * @since 2.0
119	 * @param string/integer $twitter_user
120	 * @param boolean/integer $page
121	 * @return object
122	 */
123	public function user_follows( $twitter_user, $page = false )
124	{
125		$data = array();
126		if( is_int( $twitter_user ) )
127			$data['user_id'] = $twitter_user;
128		else
129			$data['screen_name'] = $twitter_user;
130		if( $page && is_int($page) )
131			$data['cursor'] = $page;
132		
133		$this->api_url = 'http://twitter.com/friends/ids.' . $this->type;
134		$this->api_url .= $this->_glue( $data );
135		return $this->_get( $this->api_url );
136	}
137	
138	/**
139	 *  Returns a list of all Twitter user IDs that follows the specified user
140	 *
141	 * @access public
142	 * @since 2.0
143	 * @param string/integer $twitter_user
144	 * @param boolean/integer $page
145	 * @return object
146	 */
147	public function user_followers( $twitter_user, $page = false )
148	{
149		$data = array();
150		if( is_int( $twitter_user ) )
151			$data['user_id'] = $twitter_user;
152		else
153			$data['screen_name'] = $twitter_user;
154		if( $page && is_int($page) )
155			$data['cursor'] = $page;
156		
157		$this->api_url = 'http://twitter.com/followers/ids.' . $this->type;
158		$this->api_url .= $this->_glue( $data );
159		return $this->_get( $this->api_url );
160	}
161	
162	/**
163	 * Destroys the object
164	 *
165	 * @access public
166	 * @since 2.0
167	 * @return null
168	 */
169	public function __destruct() {}
170}