]> gitweb.factorcode.org Git - factor.git/commitdiff
gravatar: implement the "email hash" to calculate the gravatar id.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 14 Jun 2022 20:27:27 +0000 (13:27 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 14 Jun 2022 20:27:27 +0000 (13:27 -0700)
https://en.gravatar.com/site/implement/hash/

extra/gravatar/gravatar.factor

index 8a068f1fa33533ce0b356824e4470835ad7ad049..a08d688a64c8a93cf19caf09d352e911eefdec2e 100644 (file)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2011 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: accessors assocs classes.tuple formatting http.client
-images.http json.reader kernel sequences strings ;
+USING: accessors ascii assocs checksums checksums.md5
+classes.tuple formatting http.client images.http json.reader
+kernel math.parser sequences strings ;
 
 IN: gravatar
 
@@ -10,6 +11,9 @@ TUPLE: info aboutMe accounts currentLocation displayName emails
 hash id ims name phoneNumbers photos preferredUsername
 profileBackground profileUrl requestHash thumbnailUrl urls ;
 
+: gravatar-id ( email -- gravatar-id )
+    [ blank? ] trim >lower md5 checksum-bytes bytes>hex-string ;
+
 : gravatar-info ( gravatar-id -- info )
     "http://gravatar.com/%s.json" sprintf http-get nip
     >string json> "entry" of first info from-slots ;