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 1 commit
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
Prev Previous commit
Next Next commit
returns correct information in api endpoint with manually added id
  • Loading branch information
chloealee committed Sep 9, 2015
commit c76304d50391896e389b0ce8100b06708d21b755
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +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,
// 'country' => $data->country,
'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 Down Expand Up @@ -127,13 +129,18 @@ function dosomething_northstar_update_user($form_state) {
/**
*Get user data from northstar.
*/
// function dosomething_northstar_get_northstar_user($id) {
// $client = _dosomething_northstar_build_http_client();
// $request_method = 'GET';
// $request_retry = 3;
function dosomething_northstar_get_northstar_user($id) {
$client = _dosomething_northstar_build_http_client();
$id = '55916765bffebcff078b4568';
// print_r($client['base_url'] . '/users/_id/' . $id);
// die();
$response = drupal_http_request($client['base_url'] . '/users/_id/' . $id, array(
'headers' => $client['headers'],
'method' => 'GET',
));

// $response = drupal_http_request($client['base_url'] . '/users/_id/' . $id, $request_method, $request_retry);
// }
return $response;
}

/**
* 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,17 +115,15 @@ private function build($data) {
'verb' => $data->verb,
],
];
// call northstar dosomething_helpers_get_northstar_user();
// $northstar_user = dosomething_helpers_get_northstar_user();

// call northstar dosomething_northstar_get_northstar_user();
$northstar_user = dosomething_northstar_get_northstar_user($data->fid);
$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' => $northstar_user->first_name,
// 'last_name' => $northstar_user->last_name,
// 'country' =>$northstar_user->country,
'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