module Aws.DynamoDb.Streams.Commands.GetRecords
(
GetRecords(..)
, getRecords
, grShardIterator
, grLimit
, GetRecordsResponse(..)
, grrRecords
, grrNextShardIterator
) where
import Aws.Core
import Aws.DynamoDb.Streams.Core
import Aws.DynamoDb.Streams.Types
import Control.Applicative
import Control.Applicative.Unicode
import Data.Aeson
import Data.Typeable
data GetRecords
= GetRecords
{ _grShardIterator ∷ !ShardIterator
, _grLimit ∷ !(Maybe Int)
} deriving (Eq, Ord, Show, Read, Typeable)
getRecords
∷ ShardIterator
→ GetRecords
getRecords it = GetRecords
{ _grShardIterator = it
, _grLimit = Nothing
}
instance ToJSON GetRecords where
toJSON GetRecords{..} = object
[ "ShardIterator" .= _grShardIterator
, "Limit" .= _grLimit
]
instance FromJSON GetRecords where
parseJSON =
withObject "GetRecords" $ \o →
pure GetRecords
⊛ o .: "ShardIterator"
⊛ o .:? "Limit"
grShardIterator
∷ Functor f
⇒ (ShardIterator → f ShardIterator)
→ GetRecords
→ f GetRecords
grShardIterator i GetRecords{..} =
(\_grShardIterator → GetRecords{..})
<$> i _grShardIterator
grLimit
∷ Functor f
⇒ (Maybe Int → f (Maybe Int))
→ GetRecords
→ f GetRecords
grLimit i GetRecords{..} =
(\_grLimit → GetRecords{..})
<$> i _grLimit
data GetRecordsResponse
= GetRecordsResponse
{ _grrNextShardIterator ∷ !(Maybe ShardIterator)
, _grrRecords ∷ ![Record]
} deriving (Eq, Ord, Show, Read, Typeable)
instance ToJSON GetRecordsResponse where
toJSON GetRecordsResponse{..} = object
[ "NextShardIterator" .= _grrNextShardIterator
, "Records" .= _grrRecords
]
instance FromJSON GetRecordsResponse where
parseJSON =
withObject "GetRecordsResponse" $ \o →
pure GetRecordsResponse
⊛ o .:? "NextShardIterator"
⊛ o .: "Records"
grrRecords
∷ Functor f
⇒ ([Record] → f [Record])
→ GetRecordsResponse
→ f GetRecordsResponse
grrRecords i GetRecordsResponse{..} =
(\_grrRecords → GetRecordsResponse{..})
<$> i _grrRecords
grrNextShardIterator
∷ Functor f
⇒ (Maybe ShardIterator → f (Maybe ShardIterator))
→ GetRecordsResponse
→ f GetRecordsResponse
grrNextShardIterator i GetRecordsResponse{..} =
(\_grrNextShardIterator → GetRecordsResponse{..})
<$> i _grrNextShardIterator
instance ResponseConsumer r GetRecordsResponse where
type ResponseMetadata GetRecordsResponse = StreamsMetadata
responseConsumer _ = streamsResponseConsumer
instance SignQuery GetRecords where
type ServiceConfiguration GetRecords = StreamsConfiguration
signQuery cmd = streamsSignQuery StreamsQuery
{ _stqAction = ActionGetRecords
, _stqBody = encode cmd
}
instance Transaction GetRecords GetRecordsResponse
instance AsMemoryResponse GetRecordsResponse where
type MemoryResponse GetRecordsResponse = GetRecordsResponse
loadToMemory = return
instance ListResponse GetRecordsResponse Record where
listResponse = _grrRecords
instance IteratedTransaction GetRecords GetRecordsResponse where
nextIteratedRequest req@GetRecords{..} GetRecordsResponse{..} = do
nextShardIterator ← _grrNextShardIterator
return req
{ _grShardIterator = nextShardIterator
}