Services_Digg
[ class tree: Services_Digg ] [ index: Services_Digg ] [ all elements ]

Source for file User.php

Documentation is available at User.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * User class for Digg API
  7.  *
  8.  * PHP version 5.1.0+
  9.  *
  10.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  11.  * that is available through the world-wide-web at the following URI:
  12.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  13.  * the PHP License and are unable to obtain it through the web, please
  14.  * send a note to license@php.net so we can mail you a copy immediately.
  15.  *
  16.  * @category    Services
  17.  * @package     Services_Digg
  18.  * @author      Joe Stump <joe@joestump.net>
  19.  * @copyright   1997-2007 The PHP Group
  20.  * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
  21.  * @version     CVS: $Id:$
  22.  * @link        http://pear.php.net/package/Services_Digg
  23.  */
  24.  
  25. /**
  26.  * Services_Digg_User
  27.  *  
  28.  * @category    Services
  29.  * @package     Services_Digg
  30.  * @author      Joe Stump <joe@joestump.net>
  31.  */
  32. {
  33.     /**
  34.      * __call
  35.      *
  36.      * This overloaded method handles '/user/{user name}/{endpoint}', such as
  37.      * '/user/joestump/diggs'. It does not handle more detailed endpoints, such
  38.      * ss '/user/joestump/activity/comments', which has its own method.
  39.      *
  40.      * @access      public
  41.      * @param       string      $function       Simple endpoint for users
  42.      * @param       array       $args           Arguments to pass to API
  43.      * @return      mixed 
  44.      * @throws      Services_Digg_Exception
  45.      */
  46.     public function __call($function$args
  47.     {
  48.         if (!isset($args[0]|| !strlen($args[0])) {
  49.             throw new Services_Digg_Exception('Invalid or unsupplied username');
  50.         }
  51.  
  52.         $params = array();
  53.         if (isset($args[1]&& count($args[1])) {
  54.             $params $args[1];
  55.         }
  56.  
  57.         $username $args[0];
  58.         $endPoint '/user/' $username '/' $function;        
  59.         return $this->sendRequest($endPoint$params);
  60.     }
  61.  
  62.     /**
  63.      * Get a user's comment activity
  64.      *
  65.      * @access      public
  66.      * @param       string      $username 
  67.      * @param       array       $params 
  68.      * @throws      Services_Digg_Exception
  69.      */
  70.     public function getCommentActivity($usernamearray $params = array()) 
  71.     {
  72.         $endPoint '/user/' $username '/activity/comments';
  73.         return $this->sendRequest($endPoint$params);
  74.     }
  75.  
  76.     /**
  77.      * Get a user's digg activity
  78.      *
  79.      * @access      public
  80.      * @param       string      $username 
  81.      * @param       array       $params 
  82.      * @throws      Services_Digg_Exception
  83.      */
  84.     public function getDiggsActivity($usernamearray $params = array()) 
  85.     {
  86.         $endPoint '/user/' $username '/activity/diggs';
  87.         return $this->sendRequest($endPoint$params);
  88.     }
  89.  
  90.     /**
  91.      * Is the user friends with a person
  92.      *
  93.      * Checks to see if the given $username is friends with the currently
  94.      * instantiated user from $this->name.
  95.      *
  96.      * @access      public
  97.      * @param       string      $username       Username to check against
  98.      * @param       string      $friend         Username to check for
  99.      * @return      boolean 
  100.      */
  101.     public function isFriend($username$friend
  102.     {
  103.         $endPoint '/user/' $username '/friend/' $friend;
  104.         try {
  105.             $result $this->sendRequest($endPoint);
  106.             return true;
  107.         catch (Services_Digg_Exception $error{
  108.             return false;
  109.         }
  110.     }
  111.  
  112.     /**
  113.      * Is the person a fan of this user
  114.      *
  115.      * Checks to see if the given $username is a fan of the currently
  116.      * instantiated user from $this->name.
  117.      *
  118.      * @access      public
  119.      * @param       string      $username       Username to check against
  120.      * @param       string      $fan            Username to check for
  121.      * @return      boolean 
  122.      */
  123.     public function isFan($username$fan)
  124.     {
  125.         $endPoint '/user/' $username '/fan/' $fan;
  126.         try {
  127.             $result $this->sendRequest($endPointarray());
  128.             return true;
  129.         catch (Services_Digg_Exception $error{
  130.             return false;
  131.         }
  132.     }
  133.  
  134.     /**
  135.      * Get a user's friends' submissions
  136.      *
  137.      * @access      public
  138.      * @param       string      $username       Username to get friends' subs
  139.      * @param       array       $params 
  140.      * @throws      Services_Digg_Exception
  141.      */
  142.     public function getFriendsSubmissions($usernamearray $params = array())
  143.     {
  144.         $endPoint '/user/' $username '/friends/submissions';
  145.         return $this->sendRequest($endPoint$params);
  146.     }
  147.  
  148.     /**
  149.      * Get a user's friends' dugg stories
  150.      *
  151.      * @access      public
  152.      * @param       string      $username       Username to get friends' duggs
  153.      * @param       array       $params 
  154.      * @throws      Services_Digg_Exception
  155.      */
  156.     public function getFriendsDugg($usernamearray $params = array())
  157.     {
  158.         $endPoint '/user/' $username '/friends/dugg';
  159.         return $this->sendRequest($endPoint$params);
  160.     }
  161.  
  162.     /**
  163.      * Get a user's friends' commented stories
  164.      *
  165.      * @access      public
  166.      * @param       string      $username       Username to get friends' cmts
  167.      * @param       array       $params 
  168.      * @throws      Services_Digg_Exception
  169.      */
  170.     public function getFriendsCommented($usernamearray $params = array())
  171.     {
  172.         $endPoint '/user/' $username '/friends/commented';
  173.         return $this->sendRequest($endPoint$params);
  174.     }
  175.  
  176.     /**
  177.      * Get a user's friends' popular stories that they dugg
  178.      *
  179.      * @access      public
  180.      * @param       string      $username 
  181.      * @param       array       $params 
  182.      * @throws      Services_Digg_Exception
  183.      */
  184.     public function getFriendsPopular($usernamearray $params = array())
  185.     {
  186.         $endPoint '/user/' $username '/friends/popular';
  187.         return $this->sendRequest($endPoint$params);
  188.     }
  189.  
  190.     /**
  191.      * Get a user's friends' upcoming stories that they dugg
  192.      *
  193.      * @access      public
  194.      * @param       string      $username 
  195.      * @param       array       $params 
  196.      * @throws      Services_Digg_Exception
  197.      */
  198.     public function getFriendsUpcoming($usernamearray $params = array())
  199.     {
  200.         $endPoint '/user/' $username '/friends/upcoming';
  201.         return $this->sendRequest($endPoint$params);
  202.     }
  203. }
  204.  
  205. ?>

Documentation generated on Tue, 04 Dec 2007 15:00:13 -0500 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.