diff --git a/spec/Main.hs b/spec/Main.hs
index 1ca278e..2db5958 100644
--- a/spec/Main.hs
+++ b/spec/Main.hs
@@ -49,7 +49,7 @@ mockedTests = do
feedTests :: Spec
feedTests =
describe "rss feed" $ do
- it "should make a feed" $ do
+ it "should make a feed using embedded guest authors" $ do
ctxt <- initFauxRequestNoCache
let wpfeed = WPFeed
"https://myurl.com/feed"
@@ -62,6 +62,19 @@ feedTests =
(renderFeedContent ctxt)
ft <- toXMLFeed (_wordpress ctxt) wpfeed
ft `shouldBe` "\n\n https://myurl.com/feed\n My Blog\n 2014-10-20T07:00:00Z\n \n https://myurl.com/2014/10/foo-bar/\n <i>Foo</i> bar\n 2014-10-20T07:00:00Z\n 2014-10-20T07:00:00Z\n summary\n This is the title: <i>Foo</i> bar\n \n Emma Goldman\n \n \n \n\n"
+{- it "should make a feed using list of author ids" $ do
+ ctxt <- initFauxRequestNoCache
+ let wpfeed = WPFeed
+ "https://myurl.com/feed"
+ "My Blog"
+ Nothing
+ Nothing
+ "https://myurl.com"
+ buildEntryLinks
+ GuestAuthorsViaReq
+ (renderFeedContent ctxt)
+ ft <- toXMLFeed (_wordpress ctxt) wpfeed
+ ft `shouldBe` "\n\n https://myurl.com/feed\n My Blog\n 2014-10-20T07:00:00Z\n \n https://myurl.com/2014/10/foo-bar/\n <i>Foo</i> bar\n 2014-10-20T07:00:00Z\n 2014-10-20T07:00:00Z\n summary\n This is the title: <i>Foo</i> bar\n \n Lucy Parsons\n \n \n Emma Goldman\n \n \n \n\n" -}
larcenyFillTests :: Spec
larcenyFillTests = do
diff --git a/src/Web/Offset/Cache.hs b/src/Web/Offset/Cache.hs
index ab27c0e..e12daa9 100644
--- a/src/Web/Offset/Cache.hs
+++ b/src/Web/Offset/Cache.hs
@@ -96,15 +96,15 @@ cacheSwitch b k = cacheSet b (formatKey k)
cacheSet :: CacheBehavior -> Text -> Text -> Redis Bool
cacheSet b k v =
case b of
- (CacheSeconds n) -> rsetex k n v
- CacheForever -> rset k v
+ CacheSeconds n -> rsetex k n v
+ CacheForever n -> rset k v
NoCache -> return True
cacheSetAlwaysExpire :: CacheBehavior -> Text -> Text -> Redis Bool
cacheSetAlwaysExpire b k v =
case b of
- (CacheSeconds n) -> rsetex k n v
- CacheForever -> rsetex k (10 * 60) v -- cache 10 minutes
+ CacheSeconds n -> rsetex k n v
+ CacheForever n -> rsetex k n v
NoCache -> return True
wpExpireAggregatesInt :: RunRedis -> IO Bool
diff --git a/src/Web/Offset/Cache/Types.hs b/src/Web/Offset/Cache/Types.hs
index c098a13..03caccf 100644
--- a/src/Web/Offset/Cache/Types.hs
+++ b/src/Web/Offset/Cache/Types.hs
@@ -5,5 +5,5 @@ module Web.Offset.Cache.Types where
import Database.Redis (Redis)
-data CacheBehavior = NoCache | CacheSeconds Int | CacheForever deriving (Show, Eq)
+data CacheBehavior = NoCache | CacheSeconds Int | CacheForever Int deriving (Show, Eq)
type RunRedis = forall a. Redis a -> IO a
diff --git a/src/Web/Offset/Feed.hs b/src/Web/Offset/Feed.hs
index b78248c..800a7dc 100644
--- a/src/Web/Offset/Feed.hs
+++ b/src/Web/Offset/Feed.hs
@@ -32,7 +32,7 @@ data WPFeed =
, wpGetAuthors :: WPAuthorStyle
, wpRenderEntry :: Object -> IO (Maybe T.Text) }
-data WPAuthorStyle = GuestAuthors | DefaultAuthor
+data WPAuthorStyle = GuestAuthors | GuestAuthorsViaReq | DefaultAuthor
toXMLFeed :: Wordpress b -> WPFeed -> IO T.Text
toXMLFeed wp wpFeed@(WPFeed uri title icon logo _ _ _ _) = do
@@ -101,6 +101,7 @@ toEntry wp wpFeed entry@WPEntry{..} = do
let baseEntry = makeEntry guid (TextHTML wpEntryTitle) wpEntryUpdated
authors <- case wpGetAuthors wpFeed of
GuestAuthors -> getAuthorsInline wpEntryJSON
+ GuestAuthorsViaReq -> getAuthorsViaReq wp wpEntryJSON
DefaultAuthor -> getAuthorViaReq wp wpEntryJSON
return $ baseEntry { entryPublished = Just wpEntryPublished
, entrySummary = Just (TextHTML wpEntrySummary)
@@ -166,6 +167,21 @@ getAuthorViaReq wp v =
Nothing -> return []
Just authorName ->return (maybeToList authorName)
+getAuthorsViaReq :: Wordpress b -> Object -> IO [WPPerson]
+getAuthorsViaReq wp v =
+ do let mAuthorId = parseMaybe (\obj -> obj .: "authors") v :: Maybe [Int]
+ case mAuthorId of
+ Nothing -> return []
+ Just authorIds ->
+ do let authList = map (\id -> ("include[]", tshow id)) authorIds
+ eRespError <- cachingGetRetry wp (EndpointKey ("wp/v2/authors") authList)
+ case eRespError of
+ Left _ -> return []
+ Right resp ->
+ case decodeWPResponseBody resp of
+ Nothing -> return []
+ Just list -> return list
+
entryGuid :: T.Text -> Int -> Object -> URI
entryGuid baseURI wpId wpJSON =
unsafeURI $ T.unpack $