packages feed

couchdb-conduit 0.1.1.0 → 0.1.2.0

raw patch · 4 files changed

+20/−10 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Database.CouchDB.Conduit: couchLogin :: CouchConnection -> ByteString
+ Database.CouchDB.Conduit: couchPass :: CouchConnection -> ByteString

Files

couchdb-conduit.cabal view
@@ -1,5 +1,5 @@ name:           couchdb-conduit-version:        0.1.1.0
+version:        0.1.2.0
 cabal-version:  >= 1.8 build-type:     Simple stability:      Experimental@@ -17,7 +17,7 @@     attoparsec fit togther so well that this package is mostly just a direct combination     of these packages.  The single additional feature in this package is an attoparsec parser     for views, which allows constant memory processing of view returns.-data-files:     test/Database/CouchDB/Conduit/Test/Explicit.hs, test/Database/CouchDB/Conduit/Test/Generic.hs, test/Database/CouchDB/Conduit/Test/Util.hs, test/Database/CouchDB/Conduit/Test/View.hs, test/Main.hs+data-files:     test/Database/CouchDB/Conduit/Test/Explicit.hs, test/Database/CouchDB/Conduit/Test/Generic.hs, test/Database/CouchDB/Conduit/Test/Util.hs, test/Database/CouchDB/Conduit/Test/View.hs, test/Main.hs
  source-repository head   type:         git
src/Database/CouchDB/Conduit.hs view
@@ -34,6 +34,8 @@     couchPort,
     couchManager,
     couchDB,
+    couchLogin,
+    couchPass,
     
     -- * Runtime enviroment and errors #runtime#
     -- $runtime
@@ -115,10 +117,14 @@         --   different databases through a single connection. But, in this 
         --   case, all requests must be preceded by the database name with 
         --   unescaped slash. See 'Path' for details.
+    , couchLogin :: B.ByteString
+        -- ^ CouchDB login. By default is 'B.empty'.
+    , couchPass :: B.ByteString
+        -- ^ CouchDB password. By default is 'B.empty'.
 }
 
 instance Default CouchConnection where
-    def = CouchConnection "localhost" 5984 Nothing B.empty
+    def = CouchConnection "localhost" 5984 Nothing B.empty B.empty B.empty
 
 -----------------------------------------------------------------------------
 -- Runtime
@@ -168,7 +174,7 @@        CouchConnection              -- ^ Couch connection
     -> (CouchConnection -> m a)     -- ^ Function to run
     -> m a
-withCouchConnection c@(CouchConnection _ _ mayMan _) f = 
+withCouchConnection c@(CouchConnection _ _ mayMan _ _ _) f = 
     case mayMan of
         -- Allocate manager with helper
         Nothing -> H.withManager $ \m -> lift $ f $ c {couchManager = Just m}
src/Database/CouchDB/Conduit/Design.hs view
@@ -33,7 +33,7 @@ couchViewPut designName viewName mapF reduceF = do
     -- Get design or empty object
     (rev, A.Object d) <- catch 
-        (couchGetWith (A.Success) path [])
+        (couchGetWith A.Success path [])
         (\(_ :: CouchError) -> return (B.empty, AT.emptyObject))
     couchPutWith A.encode path rev [] $ inferViews (purge_ d)
   where
@@ -49,7 +49,7 @@ 
 -- | Purge underscore fields
 purge_ :: AT.Object -> AT.Object
-purge_ = M.filterWithKey (\k _ -> not $ k `elem` ["_id", "_rev"])
+purge_ = M.filterWithKey (\k _ -> k `notElem` ["_id", "_rev"])
 
 -- | Strip 'A.Value'
 stripObject :: AT.Value -> AT.Object
src/Database/CouchDB/Conduit/LowLevel.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE ScopedTypeVariables, DoAndIfThenElse #-}
 
 -- | Low-level method and tools of accessing CouchDB.
 
@@ -61,9 +61,13 @@             , H.queryString     = HT.renderQuery False qs
             , H.requestBody     = reqBody
             , H.checkStatus = const . const $ Nothing }
-    -- FIXME fromMaybe
-    res <- H.http req (fromJust $ couchManager conn)
-    protectFn res 
+    -- Apply auth if needed
+    let req' = if couchLogin conn == B.empty then req else H.applyBasicAuth 
+            (couchLogin conn) (couchPass conn) req
+    -- FIXME fromJust
+    res <- H.http req' (fromJust $ couchManager conn)
+    protectFn res
+    
 
 -- | Protect 'H.Response' from bad status codes. If status code in list 
 --   of status codes - just return response. Otherwise - throw 'CouchError'.