diff options
Diffstat (limited to 'src/main/java')
3 files changed, 37 insertions, 2 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/util/Gravatar.java b/src/main/java/io/trygvis/esper/testing/util/Gravatar.java new file mode 100644 index 0000000..c98662d --- /dev/null +++ b/src/main/java/io/trygvis/esper/testing/util/Gravatar.java @@ -0,0 +1,28 @@ +package io.trygvis.esper.testing.util; + +import java.io.*; +import java.security.*; + +public class Gravatar { + public static String hex(byte[] array) { + StringBuilder sb = new StringBuilder(); + for (byte anArray : array) { + sb.append(Integer.toHexString((anArray & 0xFF) | 0x100).substring(1, 3)); + } + return sb.toString(); + } + + public static String md5Hex(String message) { + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + return hex(md.digest(message.getBytes("CP1252"))); + } catch (NoSuchAlgorithmException e) { + } catch (UnsupportedEncodingException e) { + } + return null; + } + + public static String gravatar(String mail) { + return "http://www.gravatar.com/avatar/" + md5Hex(mail.trim().toLowerCase()); + } +} diff --git a/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java b/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java index 4ab95c6..22290d9 100755 --- a/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java +++ b/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java @@ -148,7 +148,7 @@ public class CoreResource extends AbstractResource { protected final SqlF<PersonDto, PersonJson> getPersonJson = new SqlF<PersonDto, PersonJson>() { public PersonJson apply(PersonDto person) throws SQLException { - return new PersonJson(person.uuid, person.name); + return new PersonJson(person.uuid, person.name, person.mail); } }; diff --git a/src/main/java/io/trygvis/esper/testing/web/resource/PersonJson.java b/src/main/java/io/trygvis/esper/testing/web/resource/PersonJson.java index 65b081c..285ae8e 100755 --- a/src/main/java/io/trygvis/esper/testing/web/resource/PersonJson.java +++ b/src/main/java/io/trygvis/esper/testing/web/resource/PersonJson.java @@ -4,13 +4,20 @@ import io.trygvis.esper.testing.*; import java.util.*; +import static io.trygvis.esper.testing.util.Gravatar.*; + public class PersonJson { public final Uuid uuid; public final String name; + public final String mail; + public final String gravatar; - public PersonJson(Uuid uuid, String name) { + public PersonJson(Uuid uuid, String name, String mail) { this.uuid = uuid; this.name = name; + this.mail = mail; + + gravatar = gravatar(mail); } } |