Skip to content

Commit

Permalink
Coping with updated CloudWatchLogs pagination scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanhay committed Sep 3, 2015
1 parent 1348b86 commit fbc25dd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions gen/src/Gen/Types/Pager.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Control.Monad
import Data.Aeson
import Data.List.NonEmpty (NonEmpty (..))
import qualified Data.List.NonEmpty as NE
import Data.Maybe
import Gen.Types.Id
import Gen.Types.Notation

Expand All @@ -44,12 +45,17 @@ data Pager a
deriving (Eq, Show, Functor, Foldable)

instance FromJSON (Pager Id) where
parseJSON = withObject "pager" $ \o -> more o <|> next o
parseJSON = withObject "pager" $ \o -> next o <|> more o
where
next o = Next
<$> o .: "result_key"
<$> resultKey o
<*> parseJSON (Object o)

resultKey o = do
o .: "result_key"
<|> (o .: "result_key" >>=
maybe (fail "Empty result_key")
pure . listToMaybe)
more o = do
let f k = o .: k <|> ((:|[]) <$> o .: k)

Expand Down

0 comments on commit fbc25dd

Please sign in to comment.