packages feed

hMollom 0.3.1 → 0.4.0

raw patch · 4 files changed

+55/−16 lines, 4 filesdep ~Cryptodep ~HTTPdep ~aeson

Dependency ranges changed: Crypto, HTTP, aeson, base, bytestring, dataenc, mtl, pureMD5, time

Files

hMollom.cabal view
@@ -1,6 +1,6 @@ name:                hMollom-version:             0.3.1-cabal-version:       >= 1.6+version:             0.4.0+cabal-version:       >= 1.14 stability:           experimental synopsis:            Library to interact with the @Mollom anti-spam service description:         Library to interact with the @Mollom anti-spam service@@ -22,20 +22,25 @@                      src/Network/Mollom/Types.hs                      src/Network/Mollom/Whitelist.hs +source-repository this+  type:     git+  location: git://github.com/itkovian/hMollom.git+  tag:      0.4.0+ library     build-depends:     -        aeson >= 0.5.0.0,+        aeson >= 0.6.0.2,         attoparsec >= 0.10,-        base >= 3 && < 5, +        base >= 4 && < 5,          ghc-prim,         old-locale >= 1,-        time >= 1.1.4,-        Crypto >= 4.2.0,-        bytestring >= 0.9.1.4,-        dataenc >= 0.13,-        mtl >= 1.1.0.2,-        HTTP >= 4000.2.2,-        pureMD5 >= 2.1.0.2,+        time >= 1.4,+        Crypto >= 4.2.4,+        bytestring >= 0.9.2.1,+        dataenc >= 0.14.0.3,+        mtl >= 2.0.1.0,+        HTTP >= 4000.2.3,+        pureMD5 >= 2.1.0.3,         old-time,         random      exposed-modules:@@ -51,4 +56,4 @@      ghc-options:       -Wall     hs-source-dirs:      src-+    default-language:   Haskell2010
src/Network/Mollom/Internals.hs view
@@ -11,6 +11,7 @@   , MollomError(..)   , MollomResponse(..)   , service+  , serviceNoAuth   ) where  import           Control.Arrow (second)@@ -83,7 +84,7 @@         oauthH   = oauthHeader (("oauth_signature", oauthSig) : oauthHVs)         contentH = replaceHeader HdrContentType "application/x-www-form-urlencoded"         acceptH  = replaceHeader HdrAccept "application/json;q=0.8"-    liftIO $ putStrLn $ "URI = " ++ (mollomServer ++ "/" ++ path)+    --liftIO $ putStrLn $ "URI = " ++ (mollomServer ++ "/" ++ path)     result <- liftIO $ liftM (processResponse errors) $ simpleHTTP (oauthH . contentH . acceptH                                                            $ case method of                                                                POST -> let body = buildEncodedQuery params'@@ -96,4 +97,25 @@     ErrorT { runErrorT = return result }  -+-- | This should only be used by the createSite API call. Otherwise, it will return an error.+serviceNoAuth :: A.FromJSON a+              => RequestMethod                        -- ^The HTTP method used in this request.+              -> String                               -- ^The path to the requested resource+              -> [(String, Maybe String)]             -- ^Request parameters+              -> [String]                             -- ^Expected returned values+              -> [((Int, Int, Int), MollomError)]     -- ^Possible error values+              -> ErrorT MollomError IO (MollomResponse a)-- :: ErrorT (IO (Either MollomError (HTTPResponse String)))+serviceNoAuth method path params expected errors = do+    let params' = catSecondMaybes params+        contentH = replaceHeader HdrContentType "application/x-www-form-urlencoded"+        acceptH  = replaceHeader HdrAccept "application/json;q=0.8"+    result <- liftIO $ liftM (processResponse errors) $ simpleHTTP (contentH . acceptH+                                                          $ case method of+                                                               POST -> let body = buildEncodedQuery params'+                                                                       in postRequestWithBody (mollomServer ++ "/" ++ path) +                                                                          "application/x-www-form-urlencoded" +                                                                          body+                                                               GET -> getRequest (mollomServer ++ "/" ++ path)+                                                               _ -> undefined+                                                          )+    ErrorT { runErrorT = return result }
src/Network/Mollom/MollomMonad.hs view
@@ -5,6 +5,7 @@   ( Mollom   , MollomState   , mollomService+  , mollomNoAuthService   , runMollom   ) where @@ -37,6 +38,7 @@       A.Success r' -> return $ mr { response = r' }       _            -> throwError JSONParseError + mollomService :: A.FromJSON a               => String                           -- ^ Public key               -> String                           -- ^ Private key@@ -48,6 +50,9 @@               -> Mollom (MollomResponse a) mollomService pubKey privKey method path params expected errors =     (wrapMollom $ service pubKey privKey method path params expected errors) >>= pJSON++mollomNoAuthService method path params expected errors = +    (wrapMollom $ serviceNoAuth method path params expected errors) >>= pJSON  runMollom :: Mollom a -> MollomConfiguration -> MollomState -> IO (Either MollomError (Maybe ContentID, a)) runMollom m config s = do
src/Network/Mollom/Site.hs view
@@ -65,13 +65,20 @@       mapM A.parseJSON ls   +createSite :: Mollom (MollomResponse SiteResponse) -- ^ The Mollom monad in which the request is made+createSite = do+    let path = "site"+        errors = generalErrors+    mollomNoAuthService POST path [] [] errors++ -- | Request the information Mollom has about a specific site readSite :: Mollom (MollomResponse SiteResponse) -- ^ The Mollom monad in which the request is made readSite = do     config <- ask     let pubKey = mcPublicKey config         privKey = mcPrivateKey config-        path = "content/" ++ ( mcPublicKey config)+        path = "site/" ++ ( mcPublicKey config)         errors = generalErrors     mollomService pubKey privKey GET path [] [] errors @@ -83,7 +90,7 @@     config <- ask     let pubKey = mcPublicKey config         privKey = mcPrivateKey config-        path = "content/" ++ ( mcPublicKey config) ++ "/delete"+        path = "site/" ++ ( mcPublicKey config) ++ "/delete"         errors = [((4,0,4), SiteError SiteUnknown "")]     mollomService pubKey privKey POST path [] [] errors