Last active
October 31, 2019 19:47
-
-
Save azjezz/35037a4bb4cd44236566bf346da4ba2c to your computer and use it in GitHub Desktop.
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
function user(uuid) { | |
let headers = new Headers({ | |
'Accept': 'application/json' | |
}) | |
let request = new Request('https://connect.symfony.com/api/users/' + uuid, { | |
method: 'GET', | |
headers: headers, | |
mode: 'cors', | |
cache: 'default' | |
}) | |
return fetch(request).then(response => response.json()).then(user => { | |
let data = { | |
'name': user.name, | |
'username': user.username, | |
'dashboard': 'https://connect.symfony.com/admin/user/' + uuid, | |
} | |
user._links.forEach((link) => { | |
if (link.type.startsWith('image')) { | |
data.avatar = link.href | |
} else if ('text/html' === link.type) { | |
data.profile = link.href | |
} | |
}) | |
return data | |
}) | |
} | |
user('some-uuid').then(user => { | |
// user = { name: ..., username: ..., dashboard: ..., avatar: ..., profile: ... } | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment