Skip to content
This repository was archived by the owner on Oct 29, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ protected function transformReportbackItem($data) {
protected function transformUser($data) {
return array(
'id' => $data->id,
'first_name' => $data->first_name,
'last_name' => $data->last_name,
'photo' => $data->photo,
'country' => $data->country,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ function dosomething_northstar_register_user($form_state) {
function _dosomething_northstar_build_http_client() {
$base_url = NORTHSTAR_URL;
if (getenv('DS_ENVIRONMENT') === 'local') {
$base_url .= ":" . NORTHSTAR_PORT;
// $base_url .= ":" . NORTHSTAR_PORT;
$base_url = 'http://northstar.dev:' . NORTHSTAR_PORT;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was NORTSTAR_URL not working locally?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the URL was sending me to qa instead of local where I wanted to test but looks good now so I'll change back!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually changed this back - right now, the $base_url prints http://northstar.dev:8000 where as before, it printed http://northstar-qa.dosomething.org:8000. Is this ok?

}
$base_url .= '/' . NORTHSTAR_VERSION;

Expand All @@ -99,6 +100,7 @@ function _dosomething_northstar_build_http_client() {
);

return $client;

}

/**
Expand All @@ -124,6 +126,27 @@ function dosomething_northstar_update_user($form_state) {

}

/**
*Get user data from northstar.
*/
function dosomething_northstar_get_northstar_user($id) {
$northstar_user_info = cache_get('northstar_user_info_' . $id, 'cache');

if (empty($northstar_user_info)) {
$client = _dosomething_northstar_build_http_client();
// $id = '55916765bffebcff078b4568';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanna remove this lil line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed!


$northstar_user_info = drupal_http_request($client['base_url'] . '/users/_id/' . $id, array(
'headers' => $client['headers'],
'method' => 'GET',
));

cache_set('northstar_user_info_' . $id, $response, 'cache', REQUEST_TIME + 60*60*24);
}

return $northstar_user_info;
}

/**
* Build a user json object, that's accepted by Northstar.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,15 @@ private function build($data) {
'verb' => $data->verb,
],
];

$northstar_user = dosomething_northstar_get_northstar_user($data->uid);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you json_decode the whole thing here, so you don't have to do it for each thing below?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated!


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not vital at all (or maybe just a future update to consider), but might be cleaner if you could save the nested array to $northstar_user and then cast it to an object:

$northstar_user = json_decode($northstar_user->data, true);
$northstar_user = (object) $northstar_user['data'][0];

So then you can get each item similar to how code above retrieves it for consistency:

$this->user = [
  'id' => $data->uid,
  'first_name' => $northstar_user->first_name,
  'last_name' => $northstar_user->last_name,
  'photo' => $northstar_user->photo,
  'country' => $northstar_user->country,
];

Something like that... :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that looks a lot better, I'll update now, thanks Diego!

$this->user = [
'id' => $data->uid,
'first_name' => json_decode($northstar_user->data, true)['data'][0]['first_name'],
'last_name' => json_decode($northstar_user->data, true)['data'][0]['last_name'],
'photo' => json_decode($northstar_user->data, true)['data'][0]['photo'],
'country' => json_decode($northstar_user->data, true)['data'][0]['country'],
];
}

Expand Down