Open quietmint opened 8 years ago
Hey @quietmint. That's a great idea. I'll try to sketch out a solution asap. Could you perhaps provide some input on how you'd like to use such a service, like from a controller or/and a directive? Example code would much appreciated.
Thanks!
For some reason, Gravatar JSON profiles are not CORS-enabled, so it's necessary to use JSONP. Something like this (as a factory) appears to work:
function gravatarProfile($http, md5) {
return function(email) {
var profileUrl = 'https://www.gravatar.com/' + md5(email) + '.json?callback=JSON_CALLBACK';
return $http.jsonp(profileUrl).then(function(success) {
if (Array.isArray(success.data.entry) && success.data.entry.length > 0) {
return success.data.entry[0];
}
});
}
}
(example code only... it would make sense to perform some basic validation on email
before firing the JSONP request)
My page has an input field for the user to type their e-mail address. My plan is to inject gravatarProfile
into my controller and fetch the user's profile so I can get a username associated with their profile.
function updateName() {
$scope.me.displayName = null;
gravatarProfile($scope.me.email).then(function(profile) {
$scope.me.displayName = profile.displayName;
});
}
Hi, I started to work on a first version of this feature. Please have a look and tell me what you think https://github.com/wallin/angular-gravatar/tree/profile-data
checkout the example
folder
Can we include a factory/service that provides a function to returns a user's Gravatar profile? This is available from Gravatar as JSON, and you already include the md5 library necessary to generate such a request URL.
Example profile: https://en.gravatar.com/205e460b479e2e5b48aec07710c08d50.json