summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonaldStewart <>2008-03-03 23:06:48 (GMT)
committerLuite Stegeman <luite@luite.com>2008-03-03 23:06:48 (GMT)
commite3b717112ccdb4a30ea88ae831283f17a3423740 (patch)
tree32c61c662443c7c700dd37d06376ab4a2fe98c03
version 0.10.1
-rw-r--r--LICENSE30
-rw-r--r--Network/Gravatar.hs38
-rw-r--r--Setup.lhs3
-rw-r--r--gravatar.cabal28
-rw-r--r--tests/tests.hs4
5 files changed, 103 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..9a53f79
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,30 @@
+Copyright (c) 2008 Don Stewart
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the author nor the names of his contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/Network/Gravatar.hs b/Network/Gravatar.hs
new file mode 100644
index 0000000..bf65271
--- /dev/null
+++ b/Network/Gravatar.hs
@@ -0,0 +1,38 @@
+--------------------------------------------------------------------
+-- |
+-- Module : Network.Gravatar
+-- Copyright : (c) Galois, Inc. 2008
+-- License : BSD3
+--
+-- Maintainer: Don Stewart <dons@galois.com>
+-- Stability : provisional
+-- Portability:
+--
+--------------------------------------------------------------------
+--
+-- Return the url of a gravatar
+--
+
+module Network.Gravatar (
+ gravatar
+ , Rating(..)
+ ) where
+
+import Data.Digest.OpenSSL.MD5
+import Data.List
+import Data.Char
+import qualified Data.ByteString.Char8 as S
+
+-- | Classification ratings for gravatars
+data Rating = G | PG | R | X
+ deriving (Eq,Ord,Bounded,Enum,Show,Read)
+
+baseURL = "http://www.gravatar.com/avatar.php?"
+gravatar_id = "gravatar_id"
+
+-- | Return the url of a gravatar for an email address (a globally recognized avatar).
+gravatar :: String -> String
+gravatar who = concat [baseURL ,gravatar_id ,"=" ,(md5sum (S.pack (clean who)))]
+ where
+ clean = let f = reverse . dropWhile isSpace in f . f
+
diff --git a/Setup.lhs b/Setup.lhs
new file mode 100644
index 0000000..5bde0de
--- /dev/null
+++ b/Setup.lhs
@@ -0,0 +1,3 @@
+#!/usr/bin/env runhaskell
+> import Distribution.Simple
+> main = defaultMain
diff --git a/gravatar.cabal b/gravatar.cabal
new file mode 100644
index 0000000..2a8dd13
--- /dev/null
+++ b/gravatar.cabal
@@ -0,0 +1,28 @@
+name: gravatar
+version: 0.1
+homepage: http://code.haskell.org/~dons/code/gravatar
+synopsis: Find the url of the gravatar associated with an email address.
+description:
+ Gravatars <gravatar.com> are globally unique images associated with an email
+ address, widely used in social networking sites. This library
+ lets you find the URL of a gravatar .png associated with an email
+ address.
+category: Network
+license: BSD3
+license-file: LICENSE
+author: Don Stewart
+maintainer: <dons@galois.com>
+cabal-version: >= 1.2
+build-type: Simple
+
+flag small_base
+ description: Choose the new smaller, split-up base package.
+
+library
+ exposed-modules: Network.Gravatar
+
+ if flag(small_base)
+ build-depends: base >= 3, bytestring
+ else
+ build-depends: base < 3
+ build-depends: nano-md5
diff --git a/tests/tests.hs b/tests/tests.hs
new file mode 100644
index 0000000..000d205
--- /dev/null
+++ b/tests/tests.hs
@@ -0,0 +1,4 @@
+import Network.Gravatar
+
+main = do
+ print $ gravatar "dons@galois.com" == "http://www.gravatar.com/avatar.php?gravatar_id=f21827076a1d0725c4f4bd5a640102e9"