packages feed

fb 0.12.4.1 → 0.12.5

raw patch · 4 files changed

+61/−7 lines, 4 filesdep +resourcetPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: resourcet

API changes (from Hackage documentation)

- Facebook: fetchAllNextPages :: (Monad m, MonadResource n, MonadBaseControl IO n, FromJSON a) => Pager a -> FacebookT anyAuth m (Source n a)
+ Facebook: fetchAllNextPages :: (Monad m, MonadResourceBase n, FromJSON a) => Pager a -> FacebookT anyAuth m (Source n a)
- Facebook: fetchAllPreviousPages :: (Monad m, MonadResource n, MonadBaseControl IO n, FromJSON a) => Pager a -> FacebookT anyAuth m (Source n a)
+ Facebook: fetchAllPreviousPages :: (Monad m, MonadResourceBase n, FromJSON a) => Pager a -> FacebookT anyAuth m (Source n a)

Files

fb.cabal view
@@ -1,5 +1,5 @@ name:              fb-version:           0.12.4.1+version:           0.12.5 license:           BSD3 license-file:      LICENSE author:            Felipe Lessa@@ -66,6 +66,7 @@     , transformers       >= 0.2     && < 0.4     , transformers-base     , monad-control+    , resourcet     , conduit            >= 0.5     && < 0.6     , http-types     , http-conduit       >= 1.5     && < 1.7
src/Facebook/Base.hs view
@@ -3,6 +3,7 @@     ( fbreq     , ToSimpleQuery(..)     , asJson+    , asJsonHelper     , asBS     , FacebookException(..)     , fbhttp
src/Facebook/Graph.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE DeriveDataTypeable, FlexibleContexts, OverloadedStrings #-}+{-# LANGUAGE ConstraintKinds, DeriveDataTypeable, FlexibleContexts, OverloadedStrings #-} module Facebook.Graph     ( Id(..)     , getObject@@ -22,6 +22,7 @@ import Control.Monad (mzero) import Control.Monad.IO.Class (liftIO) import Control.Monad.Trans.Control (MonadBaseControl)+import Control.Monad.Trans.Resource (MonadResourceBase) import Data.ByteString.Char8 (ByteString) import Data.Int (Int8, Int16, Int32) import Data.List (intersperse)@@ -165,7 +166,7 @@ -- this page as well.  Previous pages will not be considered. -- Next pages will be fetched on-demand. fetchAllNextPages ::-  (Monad m, C.MonadResource n, MonadBaseControl IO n, A.FromJSON a) =>+  (Monad m, MonadResourceBase n, A.FromJSON a) =>   Pager a -> FacebookT anyAuth m (C.Source n a) fetchAllNextPages = fetchAllHelper pagerNext @@ -175,14 +176,14 @@ -- from this page as well.  Next pages will not be -- considered.  Previous pages will be fetched on-demand. fetchAllPreviousPages ::-  (Monad m, C.MonadResource n, MonadBaseControl IO n, A.FromJSON a) =>+  (Monad m, MonadResourceBase n, A.FromJSON a) =>   Pager a -> FacebookT anyAuth m (C.Source n a) fetchAllPreviousPages = fetchAllHelper pagerPrevious   -- | (Internal) See 'fetchAllNextPages' and 'fetchAllPreviousPages'. fetchAllHelper ::-  (Monad m, C.MonadResource n, MonadBaseControl IO n, A.FromJSON a) =>+  (Monad m, MonadResourceBase n, A.FromJSON a) =>   (Pager a -> Maybe String) -> Pager a -> FacebookT anyAuth m (C.Source n a) fetchAllHelper pagerRef pager = do   manager <- getManager@@ -191,8 +192,8 @@       go [] (Just next) = do         req <- liftIO (H.parseUrl next)         let get = fbhttpHelper manager req { H.redirectCount = 3 }-        start =<< asJson =<< lift get-      start p = go (pagerData p) $! pagerRef pager+        start =<< lift (C.runResourceT $ asJsonHelper =<< get)+      start p = go (pagerData p) $! pagerRef p   return (start pager)  
tests/Main.hs view
@@ -8,6 +8,7 @@ import Control.Monad.IO.Class (MonadIO(liftIO)) import Control.Monad.Trans.Class (lift) import Data.Int (Int8, Int16, Int32)+import Data.Maybe (isJust, isNothing) import Data.Text (Text) import Data.Time (parseTime) import Data.Word (Word8, Word16, Word32, Word)@@ -174,6 +175,56 @@         token <- FB.getAppAccessToken         val   <- FB.listSubscriptions token         length val `seq` return ()++  describe' "fetchNextPage" $ do+    let fetchNextPageWorks :: FB.Pager A.Value -> FB.FacebookT anyAuth (C.ResourceT IO) ()+        fetchNextPageWorks pager+          | isNothing (FB.pagerNext pager) = return ()+          | otherwise = FB.fetchNextPage pager >>= maybe not_ (\_ -> return ())+          where not_ = fail "Pager had a next page but fetchNextPage didn't work."+    it "seems to work on a public list of comments" $ do+      runNoAuth $ do+        fetchNextPageWorks =<< FB.getObject "/135529993185189_397300340341485/comments" [] Nothing+    it "seems to work on a private list of app insights" $ do+      runAuth $ do+        token <- FB.getAppAccessToken+        fetchNextPageWorks =<< FB.getObject "/app/insights" [] (Just token)++  describe' "fetchNextPage/fetchPreviousPage" $ do+    let backAndForthWorks :: FB.Pager A.Value -> FB.FacebookT anyAuth (C.ResourceT IO) ()+        backAndForthWorks pager = do+          Just pager2 <- FB.fetchNextPage     pager+          Just pager3 <- FB.fetchPreviousPage pager2+          pager3 &?= pager+    it "seems to work on a public list of comments" $ do+      runNoAuth $ do+        backAndForthWorks =<< FB.getObject "/135529993185189_397300340341485/comments" [] Nothing+    it "seems to work on a private list of app insights" $ do+      runAuth $ do+        token <- FB.getAppAccessToken+        backAndForthWorks =<< FB.getObject "/app/insights" [] (Just token)++  describe' "fetchAllNextPages" $ do+    let hasAtLeast :: C.Source IO A.Value -> Int -> IO ()+        src `hasAtLeast` n = src C.$$ go n+          where go 0 = return ()+                go m = C.await >>= maybe not_ (\_ -> go (m-1))+                not_ = fail $ "Source does not have at least " ++ show n ++ " elements."+    it "seems to work on a public list of comments" $ do+      runNoAuth $ do+        pager <- FB.getObject "/135529993185189_397300340341485/comments" [] Nothing+        src   <- FB.fetchAllNextPages pager+        liftIO $ src `hasAtLeast` 200 -- items+    it "seems to work on a private list of app insights" $ do+      runAuth $ do+        token <- FB.getAppAccessToken+        pager <- FB.getObject "/app/insights" [] (Just token)+        src   <- FB.fetchAllNextPages pager+        let firstPageElms = length (FB.pagerData pager)+            hasNextPage   = isJust (FB.pagerNext pager)+        if hasNextPage+          then liftIO $ src `hasAtLeast` (firstPageElms * 3) -- items+          else fail "This isn't an insightful app =(."  newtype PageName = PageName Text deriving (Eq, Show) instance A.FromJSON PageName where