Пример #1
0
 /**
  * Returns this user as a GenericUser
  *
  * @return UserLike
  * @throws OasysException
  * @throws \InvalidArgumentException
  */
 public function getUserData()
 {
     $_response = parent::getUserData();
     if (HttpResponse::Ok != ($_code = Option::get($_response, 'code', Curl::getLastHttpCode()))) {
         throw new OasysException('Unexpected response code', $_code, null, $_response);
     }
     $_profile = Option::get($_response, 'result');
     if (empty($_profile)) {
         throw new \InvalidArgumentException('No profile available to convert.');
     }
     $_profileId = Option::get($_profile, 'id');
     $_nameGoogle = Option::get($_profile, 'name');
     $_name = array('formatted' => Option::get($_profile, 'displayName'), 'familyName' => Option::get($_nameGoogle, 'familyName'), 'givenName' => Option::get($_nameGoogle, 'givenName'));
     $_email = null;
     // Get the account email. Google returns a list of emails.
     foreach (Option::get($_profile, 'emails') as $_emailIteration) {
         if (Option::get($_emailIteration, 'type') == 'account') {
             $_email = Option::get($_emailResult, 'value');
             break;
             // ugly, but works
         }
     }
     return new GenericUser(array('user_id' => $_profileId, 'name' => $_name, 'gender' => Option::get($_profile, 'gender'), 'email_address' => $_email, 'urls' => array(Option::get($_profile, 'url')), 'thumbnail_url' => Option::getDeep($_profile, 'image', 'url'), 'user_data' => $_profile));
 }
Пример #2
0
 /**
  * Execute a request
  *
  * @param string $url         Request URL
  * @param mixed  $payload     The payload to send
  * @param string $method      The HTTP method to send
  * @param array  $headers     Array of HTTP headers to send in array( 'header: value', 'header: value', ... ) format
  * @param array  $curlOptions Array of options to pass to CURL
  *
  * @throws AuthenticationException
  * @return array
  */
 protected function _makeRequest($url, array $payload = array(), $method = self::Get, array $headers = array(), array $curlOptions = array())
 {
     static $_defaultCurlOptions = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => 0);
     //	Start clean...
     $this->_resetRequest();
     //	Add in any user-supplied CURL options
     $_curlOptions = array_merge($_defaultCurlOptions, $curlOptions);
     //	Add certificate info for SSL
     if (null !== ($_certificateFile = $this->getConfig('certificate_file'))) {
         $_curlOptions[CURLOPT_SSL_VERIFYPEER] = true;
         $_curlOptions[CURLOPT_SSL_VERIFYHOST] = 2;
         $_curlOptions[CURLOPT_CAINFO] = $_certificateFile;
     }
     //	And finally our headers
     if (null !== ($_agent = $this->getConfig('user_agent'))) {
         $headers[] = 'User-Agent: ' . $_agent;
     }
     $_curlOptions[CURLOPT_HTTPHEADER] = $headers;
     //	Convert payload to query string for a GET
     if (static::Get == $method && !empty($payload)) {
         $url .= (false === strpos($url, '?') ? '?' : '&') . http_build_query($payload);
         $payload = array();
     }
     //	And finally make the request
     if (false === ($_result = Curl::request($method, $url, $this->_translatePayload($payload, false), $_curlOptions))) {
         throw new AuthenticationException(Curl::getErrorAsString());
     }
     //	Save off response
     $this->_lastResponseCode = $_code = Curl::getLastHttpCode();
     //	Shift result from array...
     if (is_array($_result) && isset($_result[0]) && sizeof($_result) == 1 && $_result[0] instanceof \stdClass) {
         $_result = $_result[0];
     }
     $_contentType = Curl::getInfo('content_type');
     if (DataFormatTypes::JSON == $this->_responseFormat && false !== stripos($_contentType, 'application/json', 0)) {
         $_result = $this->_translatePayload($_result);
     }
     return $this->_lastResponse = array('result' => $_result, 'code' => $_code, 'content_type' => $_contentType);
 }
Пример #3
0
 /**
  * Response is always empty from this call. HTTP response code of 204 is success. Anything is an error.
  *
  * @param string $object
  * @param string $id
  * @param array  $fields
  *
  * @throws InternalServerErrorException
  * @return bool|mixed
  */
 public function updateObject($object, $id, $fields = array())
 {
     $_response = $this->fetch('/services/data/' . static::API_VERSION_TAG . '/sobjects/' . $object . '/' . $id, json_encode($fields), static::Patch);
     //	Curl error is false...
     if (false === $_response) {
         return false;
     }
     if (HttpResponse::NoContent == Curl::getLastHttpCode()) {
         return true;
     }
     //	Sometimes they send back xml...
     if (is_string($_response) && false !== stripos($_response, '<?xml')) {
         try {
             if (null === ($_response = Convert::toObject(simplexml_load_string($_response)))) {
                 throw new InternalServerErrorException('Unrecognizable response from server: ' . print_r($_response, true));
             }
             //	Otherwise we have a nice object which we return as json
         } catch (\Exception $_ex) {
             //	error...
             Log::error('Exception parsing response: ' . print_r($_response, true));
         }
     }
     return $_response;
 }
Пример #4
0
 /**
  * @return int
  */
 public function getLastHttpCode()
 {
     return Curl::getLastHttpCode();
 }
Пример #5
0
 /**
  * Returns this user as a GenericUser
  *
  *
  * @throws \DreamFactory\Oasys\Exceptions\OasysException
  * @throws \InvalidArgumentException
  * @return UserLike
  */
 public function getUserData()
 {
     $_response = parent::getUserData();
     if (HttpResponse::Ok != ($_code = Option::get($_response, 'code', Curl::getLastHttpCode()))) {
         throw new OasysException('Unexpected response code', $_code, null, $_response);
     }
     $_profile = Option::get($_response, 'result');
     if (empty($_profile)) {
         throw new \InvalidArgumentException('No profile available to convert.');
     }
     $_profileId = Option::get($_profile, 'id');
     $_name = array('formatted' => Option::get($_profile, 'name'), 'familyName' => Option::get($_profile, 'last_name'), 'givenName' => Option::get($_profile, 'first_name'));
     return new GenericUser(array('user_id' => $_profileId, 'published' => Option::get($_profile, 'updated_time'), 'updated' => Option::get($_profile, 'updated_time'), 'display_name' => $_name['formatted'], 'name' => $_name, 'preferred_username' => Option::get($_profile, 'username'), 'gender' => Option::get($_profile, 'gender'), 'email_address' => Option::get($_profile, 'email'), 'urls' => array(Option::get($_profile, 'link')), 'relationships' => Option::get($_profile, 'friends'), 'thumbnail_url' => $this->_config->getEndpointUrl() . '/' . $_profileId . '/picture?width=150&height=150', 'user_data' => $_profile));
 }