Пример #1
0
 /**
  * usage: 
  *			$apiObj = TokBoxUser::createUser($jabberId, $accessSecret); 
  *			$profile_array = get_tokbox_user_profile($apiObj,$requested_id);
  *
  * @author sumotoy@*****.com
  */
 public static function getUserProfile(TokBoxApi $userObj, $target_jabberId)
 {
     $apiObj = new TokBoxApi(API_Config::PARTNER_KEY, API_Config::PARTNER_SECRET);
     $valid = $apiObj->validateAccessToken($userObj->getSecret(), $userObj->getJabberId());
     if (!$valid) {
         throw new Exception("Unable to connect to " . API_Config::API_SERVER . ". Please check to make sure API calls are executing properly");
     }
     $validXml = simplexml_load_string($valid, 'SimpleXMLElement', LIBXML_NOCDATA);
     if ($validXml->validateAccessToken->isValid == 'false') {
         throw new Exception("The Jabber ID and Access Secret combination you passed in are not valid");
     }
     $profile = $userObj->getUserProfile($target_jabberId);
     if (!$profile) {
         throw new Exception("Unable to connect to " . API_Config::API_SERVER . ". Please check to make sure API calls are executing properly");
     }
     $profileXml = simplexml_load_string($profile, 'SimpleXMLElement', LIBXML_NOCDATA);
     if (isset($profileXml->error)) {
         throw new Exception($profileXml->error, (int) $profileXml->error['code']);
     }
     $profileResults = array();
     $profileResults['userid'] = (string) $profileXml->user->userid;
     $profileResults['jabberid'] = (string) $profileXml->user->jabberid;
     $profileResults['firstname'] = (string) $profileXml->user->firstname;
     $profileResults['lastname'] = (string) $profileXml->user->lastname;
     $profileResults['displayName'] = (string) $profileXml->user->displayName;
     $profileResults['username'] = (string) $profileXml->user->username;
     $profileResults['isOnline'] = (string) $profileXml->user->isOnline;
     $profileResults['show'] = (string) $profileXml->user->show;
     return $profileResults;
 }
Пример #2
0
 public static function generateInvite(TokBoxApi $callApiObj, $callId, $calleeJid)
 {
     $isValid = $callApiObj->validateAccessToken($callApiObj->getSecret(), $callApiObj->getJabberId());
     if (!$isValid) {
         throw new Exception("Unable to connect to " . API_Config::API_SERVER . ". Please check to make sure API calls are executing properly");
     }
     $isValidXml = simplexml_load_string($isValid, 'SimpleXMLElement', LIBXML_NOCDATA);
     if ($isValidXml->validateAccessToken->isValid == 'false') {
         throw new NotLoggedInException("The user is not properly validated");
     }
     $createInvite = $callApiObj->createInvite($callId, $calleeJid, $callApiObj->getJabberId());
     if (!$createInvite) {
         throw new Exception("Unable to connect to " . API_Config::API_SERVER . ". Please check to make sure API calls are executing properly");
     }
     $createInviteXml = simplexml_load_string($createInvite, 'SimpleXMLElement', LIBXML_NOCDATA);
     return $createInviteXml->createInvite->inviteId;
 }
Пример #3
0
 public static function addFriends(TokBoxApi $userObj, $contacts)
 {
     $apiObj = new TokBoxApi(API_Config::PARTNER_KEY, API_Config::PARTNER_SECRET);
     $valid = $apiObj->validateAccessToken($userObj->getSecret(), $userObj->getJabberId());
     if (!$valid) {
         throw new Exception("Unable to connect to " . API_Config::API_SERVER . ". Please check to make sure API calls are executing properly");
     }
     $validXml = simplexml_load_string($valid, 'SimpleXMLElement', LIBXML_NOCDATA);
     if ($validXml->validateAccessToken->isValid == 'false') {
         throw new Exception("The Jabber ID and Access Secret combination you passed in are not valid");
     }
     $addContact = $userObj->addContact($contacts, $userObjObj->getJabberId());
     if (!$addContact) {
         throw new Exception("Unable to connect to " . API_Config::API_SERVER . ". Please check to make sure API calls are executing properly");
     }
     $addContactXml = simplexml_load_string($addContact, 'SimpleXMLElement', LIBXML_NOCDATA);
     $addContactResults = array();
     foreach ($addContactXml->addContact->batchAddResult->contactResult as $result) {
         $addContactResults[$result['jabberId']] = $result['result'];
     }
     return $addContactResults;
 }