-
Notifications
You must be signed in to change notification settings - Fork 22
Reportback items endpoint #5055
Changes from 5 commits
0a07294
c76304d
3be9fed
5a2beb6
a33aaa9
4206867
79b8519
bc66055
74c1967
7848854
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
| } | ||
| $base_url .= '/' . NORTHSTAR_VERSION; | ||
|
|
||
|
|
@@ -99,6 +100,7 @@ function _dosomething_northstar_build_http_client() { | |
| ); | ||
|
|
||
| return $client; | ||
|
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -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'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wanna remove this lil line?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,8 +115,15 @@ private function build($data) { | |
| 'verb' => $data->verb, | ||
| ], | ||
| ]; | ||
|
|
||
| $northstar_user = dosomething_northstar_get_northstar_user($data->uid); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated! |
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = 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... :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'], | ||
| ]; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was
NORTSTAR_URLnot working locally?There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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:8000where as before, it printedhttp://northstar-qa.dosomething.org:8000. Is this ok?