From 5f6106ecdf8b0d5e9a79384be526b8a66d7d714b Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Wed, 25 Feb 2009 13:47:33 -0500 Subject: [PATCH] Move Users methods to a new class --- .../lib/Horde/Service/Facebook.php | 119 --------------- .../lib/Horde/Service/Facebook/Users.php | 166 +++++++++++++++++++++ framework/Service_Facebook/package.xml | 12 +- 3 files changed, 173 insertions(+), 124 deletions(-) create mode 100644 framework/Service_Facebook/lib/Horde/Service/Facebook/Users.php diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook.php b/framework/Service_Facebook/lib/Horde/Service/Facebook.php index 52df66387..86eac6827 100644 --- a/framework/Service_Facebook/lib/Horde/Service/Facebook.php +++ b/framework/Service_Facebook/lib/Horde/Service/Facebook.php @@ -589,125 +589,6 @@ class Horde_Service_Facebook } /** - * Returns the requested info fields for the requested set of users. - * - * @param string $uids A comma-separated list of user ids - * @param string $fields A comma-separated list of info field names desired - * - * @return array An array of user objects - */ - public function &users_getInfo($uids, $fields) - { - return $this->call_method('facebook.users.getInfo', - array('uids' => $uids, 'fields' => $fields)); - } - - /** - * Returns the requested info fields for the requested set of users. A - * session key must not be specified. Only data about users that have - * authorized your application will be returned. - * - * Check the wiki for fields that can be queried through this API call. - * Data returned from here should not be used for rendering to application - * users, use users.getInfo instead, so that proper privacy rules will be - * applied. - * - * @param string $uids A comma-separated list of user ids - * @param string $fields A comma-separated list of info field names desired - * - * @return array An array of user objects - */ - public function &users_getStandardInfo($uids, $fields) - { - return $this->call_method('facebook.users.getStandardInfo', - array('uids' => $uids, 'fields' => $fields)); - } - - /** - * Returns the user corresponding to the current session object. - * - * @return integer User id - */ - public function &users_getLoggedInUser() - { - return $this->call_method('facebook.users.getLoggedInUser', - array('session_key' => $this->auth->getSessionKey())); - } - - /** - * Returns 1 if the user has the specified permission, 0 otherwise. - * http://wiki.developers.facebook.com/index.php/Users.hasAppPermission - * - * @return integer 1 or 0 - */ - public function &users_hasAppPermission($ext_perm, $uid = null) - { - return $this->call_method('facebook.users.hasAppPermission', - array('ext_perm' => $ext_perm, 'uid' => $uid)); - } - - /** - * Returns whether or not the user corresponding to the current - * session object has the give the app basic authorization. - * - * @return boolean true if the user has authorized the app - */ - public function &users_isAppUser($uid = null, $sid = null) - { - if (empty($uid) && !empty($sid)) { - $params = array('session_key' => $sid); - } elseif (!empty($uid)) { - $params = array('uid' => $uid); - } else { - throw new InvalidArgumentException('isAppUser requires either a uid or a session_key'); - } - return $this->call_method('facebook.users.isAppUser', array('uid' => $uid)); - } - - /** - * Returns whether or not the user corresponding to the current - * session object is verified by Facebook. See the documentation - * for Users.isVerified for details. - * - * @return boolean true if the user is verified - */ - public function &users_isVerified() - { - return $this->call_method('facebook.users.isVerified'); - } - - /** - * Sets the users' current status message. Message does NOT contain the - * word "is" , so make sure to include a verb. - * - * Example: setStatus("is loving the API!") - * will produce the status "Luke is loving the API!" - * - * @param string $status text-only message to set - * @param int $uid user to set for (defaults to the - * logged-in user) - * @param bool $clear whether or not to clear the status, - * instead of setting it - * @param bool $status_includes_verb if true, the word "is" will *not* be - * prepended to the status message - * - * @return boolean - */ - public function &users_setStatus($status, - $uid = null, - $clear = false, - $status_includes_verb = true) - { - $args = array( - 'status' => $status, - 'uid' => $uid, - 'clear' => $clear, - 'status_includes_verb' => $status_includes_verb, - ); - return $this->call_method('facebook.users.setStatus', $args); - } - - /** * Calls the specified normal POST method with the specified parameters. * * @param string $method Name of the Facebook method to invoke diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook/Users.php b/framework/Service_Facebook/lib/Horde/Service/Facebook/Users.php new file mode 100644 index 000000000..8019841b5 --- /dev/null +++ b/framework/Service_Facebook/lib/Horde/Service/Facebook/Users.php @@ -0,0 +1,166 @@ + + * @category Horde + * @package Horde_Service_Facebook + */ +class Horde_Service_Facebook_Users extends Horde_Service_Facebook_Base +{ + /** + * Returns the requested info fields for the requested set of users. + * + * @param string $uids A comma-separated list of user ids + * @param string $fields A comma-separated list of info field names desired + * + * @return array An array of user objects + */ + public function &getInfo($uids, $fields) + { + return $this->_facebook->call_method('facebook.users.getInfo', + array('uids' => $uids, + 'fields' => $fields, + 'session_key' => $this->_sessionKey)); + } + + /** + * Returns the requested info fields for the requested set of users. A + * session key must not be specified. Only data about users that have + * authorized your application will be returned. + * + * Check the wiki for fields that can be queried through this API call. + * Data returned from here should not be used for rendering to application + * users, use users.getInfo instead, so that proper privacy rules will be + * applied. + * + * @param string $uids A comma-separated list of user ids + * @param string $fields A comma-separated list of info field names desired + * + * @return array An array of user objects + */ + public function &getStandardInfo($uids, $fields) + { + return $this->_facebook->call_method('facebook.users.getStandardInfo', + array('uids' => $uids, 'fields' => $fields)); + } + + /** + * Returns the user corresponding to the current session object. + * + * @throws Horde_Service_Facebook_Exception + * @return integer User id + */ + public function &getLoggedInUser() + { + if (empty($this->_sessionKey)) { + throw new Horde_Service_Facebook_Exception('users.getLoggedInUser requires a session_key', + Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY); + } + + return $this->_facebook->call_method('facebook.users.getLoggedInUser', + array('session_key' => $this->_sessionKey)); + } + + /** + * Returns 1 if the user has the specified permission, 0 otherwise. + * http://wiki.developers.facebook.com/index.php/Users.hasAppPermission + * + * @throws Horde_Service_Facebook_Exception + * @return integer 1 or 0 + */ + public function &hasAppPermission($ext_perm, $uid = null) + { + if (empty($uid) && empty($this->_sessionKey)) { + throw new Horde_Service_Facebook_Exception('users.hasAppPermission requires either a uid or a session_key', + Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY) + } + + $params = array('ext_perm' => $ext_perm); + if (empty($uid)) { + $params['session_key'] = $this->_sessionKey; + } else { + $params['uid'] = $uid; + } + + return $this->_facebook->call_method('facebook.users.hasAppPermission', $params); + } + + /** + * Returns whether or not the user corresponding to the current + * session object has the give the app basic authorization. + * + * @throws Horde_Service_Facebook_Exception + * @return boolean true if the user has authorized the app + */ + public function &isAppUser($uid = null) + { + if (empty($uid) && !empty($this->_sessionKey)) { + $params = array('session_key' => $this->_sessionKey); + } elseif (!empty($uid)) { + $params = array('uid' => $uid); + } else { + throw new Horde_Service_Facebook_Exception('users.isAppUser requires either a uid or a session_key', + Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY); + } + + return $this->_facebook->call_method('facebook.users.isAppUser', $params); + } + + /** + * Returns whether or not the user corresponding to the current + * session object is verified by Facebook. See the documentation + * for Users.isVerified for details. + * + * @throws Horde_Service_Facebook_Exception + * @return boolean true if the user is verified + */ + public function &isVerified() + { + if (empty($this->_sessionKey)) { + throw new Horde_Service_Facebook_Exception('users.isVerified requires a session_key', + Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY); + } + + return $this->call_method('facebook.users.isVerified', array('session_key' => $this->_sessionKey)); + } + + /** + * Sets the users' current status message. Message does NOT contain the + * word "is" , so make sure to include a verb. + * + * Example: setStatus("is loving the API!") + * will produce the status "Luke is loving the API!" + * + * @param string $status text-only message to set + * @param int $uid user to set for (defaults to the + * logged-in user) + * @param bool $clear whether or not to clear the status, + * instead of setting it + * @param bool $status_includes_verb if true, the word "is" will *not* be + * prepended to the status message + * + * @return boolean + */ + public function &users_setStatus($status, $uid = null, $clear = false, $includeVerb = true) + { + if (empty($uid) && empty($this->_sessionKey)) { + throw new Horde_Service_Facebook_Exception('users.setStatus requires a uid or a session_key', + Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY); + } + $params = array('status' => $status, + 'clear' => $clear, + 'status_includes_verb' => $includeVerb); + + if (empty($uid)) { + $params['uid'] = $uid; + } else { + $params['session_key'] = $this->_sessionKey; + } + + return $this->_facebook->call_method('facebook.users.setStatus', $params); + } + +} \ No newline at end of file diff --git a/framework/Service_Facebook/package.xml b/framework/Service_Facebook/package.xml index da26c4c0d..eb5ddb215 100644 --- a/framework/Service_Facebook/package.xml +++ b/framework/Service_Facebook/package.xml @@ -37,11 +37,12 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - + + + @@ -69,11 +70,12 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - + - + + + -- 2.11.0