Last active
October 8, 2015 15:54
-
-
Save mshmsh5000/1f011e2073c05ba00652 to your computer and use it in GitHub Desktop.
function dosomething_northstar_get_northstar_user($id)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get user data from Northstar. | |
* | |
* @param int $id | |
* Northstar user ID | |
* | |
* @return object | |
*/ | |
function dosomething_northstar_get_northstar_user($id) { | |
$northstar_user_info = cache_get('northstar_user_info_' . $id, 'cache_northstar_user_info'); | |
if (empty($northstar_user_info)) { | |
$client = _dosomething_northstar_build_http_client(); | |
$northstar_user_info = drupal_http_request($client['base_url'] . '/users/drupal_id/' . $id, array( | |
'headers' => $client['headers'], | |
'method' => 'GET', | |
)); | |
// Don't cache error responses. | |
if (!empty($northstar_user_info->error)) { | |
$error = sprintf("Error fetching Northstar user data, uid=%d: '%s'", $id, $northstar_user_info->error); | |
watchdog_exception('northstar', new Exception($error)); | |
} else { | |
cache_set('northstar_user_info_' . $id, $northstar_user_info, 'cache_northstar_user_info', REQUEST_TIME + 60*60*24); | |
} | |
} | |
return $northstar_user_info; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good stuff! I had no idea
sprintf()
was a thing in PHP. Recently learned aboutprintf()
in bash, but didn't realize PHP had its own :)Learningz 📖