/**
  * Sends a request to the API gateway for getting subscriber's personal
  * contact card.
  *
  * @return Contact contact information for subscriber
  * @throws ServiceException if request was not successful
  */
 public function updateMyInfo(ContactCommon $contact)
 {
     $endpoint = $this->getFqdn() . '/addressBook/v1/myInfo';
     $req = new RestfulRequest($endpoint);
     $req->setAuthorizationHeader($this->getToken())->setHeader('Accept', 'application/json')->setHeader('Content-Type', 'application/json');
     $body = json_encode(array('myInfo' => $contact->toArray()));
     $httpPatch = new HttpPatch($body);
     $result = $req->sendHttpPatch($httpPatch);
     $code = $result->getResponseCode();
     if ($code != 201 && $code != 204) {
         throw new ServiceException($code, $result->getResponseBody());
     }
 }
        $zipcode = $_POST['myInfoAddressZip' . $i];
        $country = $_POST['myInfoAddressCountry' . $i];
        $addressesArr[] = array('preferred' => $pref, 'type' => $type, 'poBox' => $poBox, 'addressLine1' => $addrLine1, 'addressLine2' => $addrLine2, 'city' => $city, 'state' => $state, 'zip' => $zipcode, 'country' => $country);
    }
    $contactArr['addresses'] = array('address' => $addressesArr);
    $emailsArr = array();
    $emailCount = intval($_POST['myInfoEmailIndex']);
    for ($i = 0; $i < $emailCount; ++$i) {
        $emailAddr = $_POST['myInfoEmailAddress' . $i];
        $pref = $_POST['myInfoEmailPref' . $i] === 'True' ? true : false;
        $type = $_POST['myInfoEmailType' . $i];
        $emailsArr[] = array('emailAddress' => $emailAddr, 'preferred' => $pref, 'type' => $type);
    }
    $contactArr['emails'] = array('email' => $emailsArr);
    $weburlsArr = array();
    $weburlCount = intval($_POST['myInfoWeburlIndex']);
    for ($i = 0; $i < $weburlCount; ++$i) {
        $url = $_POST['myInfoWeburl' . $i];
        $pref = $_POST['myInfoWeburlPref' . $i] === 'True' ? true : false;
        $type = $_POST['myInfoWeburlType' . $i];
        $weburlsArr[] = array('url' => $url, 'preferred' => $pref, 'type' => $type);
    }
    $contactArr['weburls'] = array('webUrl' => $weburlsArr);
    $contactCommon = ContactCommon::fromArray($contactArr);
    $location = $aabService->updateMyInfo($contactCommon);
    $arr = array('success' => true, 'text' => 'Successfully updated MyInfo');
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
 private function _handleUpdateMyInfo()
 {
     $scalarVals = array('firstName', 'middleName', 'lastName', 'prefix', 'suffix', 'nickname', 'organization', 'jobTitle', 'anniversary', 'gender', 'spouse', 'children', 'hobby', 'assistant');
     $arrayVals = array('phone', 'phonePref', 'im', 'imPref', 'address', 'addressPref', 'email', 'emailPref', 'weburl', 'weburlPref');
     $vnames = array_merge($scalarVals, $arrayVals);
     $vnames[] = 'updateMyInfo';
     $this->copyToSession($vnames);
     if (!isset($_SESSION['updateMyInfo'])) {
         return;
     }
     $reqParams = $this->_getContactArrayData();
     foreach ($scalarVals as $val) {
         if (isset($_SESSION[$val]) && strlen($_SESSION[$val]) > 0) {
             $reqParams[$val] = $_SESSION[$val];
         }
     }
     try {
         $cc = ContactCommon::fromArray($reqParams);
         $aabSrvc = new AABService($this->apiFQDN, $this->getSessionToken());
         $location = $aabSrvc->updateMyInfo($cc);
         $this->results[C_UPDATE_MY_INFO] = true;
         $this->clearSession($vnames);
     } catch (Exception $e) {
         $this->errors[C_MY_INFO] = $e->getMessage();
         $this->clearSession($vnames);
     }
 }