/**
  * Parses the XML returned from LinkedIn API
  * and creates array of $this->aData from it
  *
  * @param string xml xml string received from LinkedIn API
  *
  * @return object $this
  *
  * @throws \Lampcms\Exception if xml could not
  * be parsed for any reason
  */
 protected function parseXML($xml)
 {
     d('xml: ' . $xml);
     $oXML = new \Lampcms\Dom\Document();
     if (false === $oXML->loadXML($xml)) {
         $err = 'Unexpected Error parsing response XML';
         throw new \Lampcms\DevException($err);
     }
     $lid = $oXML->evaluate('string(/person/id[1])');
     // it will be string!
     if (!$lid) {
         throw new \Lampcms\Exception('Unable to get LinkedIn ID');
     }
     $this->aData['linkedin_id'] = (string) $lid;
     if ('' !== ($industry = $oXML->evaluate('string(/person/industry[1])'))) {
         $this->aData['industry'] = $industry;
     }
     if ('' !== ($summary = $oXML->evaluate('string(/person/summary[1])'))) {
         $this->aData['description'] = $summary;
     }
     if ('' !== ($city = $oXML->evaluate('string(/person/location/name[1])'))) {
         $this->aData['city'] = $city;
     }
     if ('' !== ($cc = $oXML->evaluate('string(/person/location/country/code[1])'))) {
         $this->aData['cc'] = \strtoupper($cc);
     }
     if ('' !== ($avtr = $oXML->evaluate('string(/person/picture-url[1])'))) {
         $this->aData['avatar_external'] = $avtr;
     }
     if ('' !== ($fn = $oXML->evaluate('string(/person/first-name[1])'))) {
         $this->aData['fn'] = $fn;
     }
     if ('' !== ($ln = $oXML->evaluate('string(/person/last-name[1])'))) {
         $this->aData['ln'] = $ln;
     }
     $this->aData['linkedin'] = array('tokens' => $this->aAccessToken);
     if ('' !== ($url = $oXML->evaluate('string(/person/public-profile-url[1])'))) {
         $this->aData['linkedin']['url'] = $url;
     }
     d('$this->aData: ' . print_r($this->aData, 1));
     return $this;
 }
 /**
  * Get email address from LinkedIN API
  *
  */
 protected function getEmailAddress()
 {
     d('cp');
     try {
         $this->oAuth->fetch(self::EMAIL_URL, null, OAUTH_HTTP_METHOD_GET, array('Connection' => 'close'));
         $resp = $this->oAuth->getLastResponse();
         /**
          * May return empty element
          *
          * $resp: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
          * <email-address />
          *
          */
         d('EMAIL ADDRESS RESPONSE: ' . $resp);
         $oXML = new \Lampcms\Dom\Document();
         if (false === $oXML->loadXML($resp)) {
             $err = 'Unexpected Error parsing email address response XML';
             e($err);
             return;
         }
         $email = $oXML->evaluate('string(/email-address[1])');
         d('email: ' . $email);
         if (!empty($email)) {
             $this->email = \mb_strtolower($email);
         }
     } catch (\OAuthException $e) {
         e('Unable to fetch email address. OAuthException: ' . $e->getMessage());
         $aDebug = $this->oAuth->getLastResponseInfo();
         d('debug: ' . print_r($aDebug, 1));
     }
 }